From 0d3d8b6499d39003174fd935334502e7b5dacf49 Mon Sep 17 00:00:00 2001 From: Sarvar Muminov <43311+msarvar@users.noreply.github.com> Date: Wed, 22 Sep 2021 15:06:10 -0700 Subject: [PATCH] Do nothing when sns topic is not provided (#117) --- server/lyft/aws/sns/writer.go | 11 ++++++++++- server/server.go | 16 +++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/server/lyft/aws/sns/writer.go b/server/lyft/aws/sns/writer.go index ec0f6b6f48..b11440c8fe 100644 --- a/server/lyft/aws/sns/writer.go +++ b/server/lyft/aws/sns/writer.go @@ -16,6 +16,10 @@ type Writer interface { Write([]byte) error } +func NewNoopWriter() Writer { + return &noopWriter{} +} + // NewWriterWithStats returns a new instance of Writer that will connect to the specifed // sns topic using the specified session func NewWriterWithStats( @@ -30,7 +34,6 @@ func NewWriterWithStats( topicArn: aws.String(topicArn), }, } - } type writer struct { @@ -64,3 +67,9 @@ func (w *writerWithStats) Write(payload []byte) error { w.scope.NewCounter(metrics.ExecutionSuccessMetric) return nil } + +type noopWriter struct{} + +func (n *noopWriter) Write(payload []byte) error { + return nil +} diff --git a/server/server.go b/server/server.go index 6357597bc6..1f09c6f0f0 100644 --- a/server/server.go +++ b/server/server.go @@ -591,11 +591,17 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { return nil, errors.Wrap(err, "initializing new aws session") } - snsWriter := sns.NewWriterWithStats( - session, - userConfig.LyftAuditJobsSnsTopicArn, - statsScope, - ) + var snsWriter sns.Writer + + if userConfig.LyftAuditJobsSnsTopicArn != "" { + snsWriter = sns.NewWriterWithStats( + session, + userConfig.LyftAuditJobsSnsTopicArn, + statsScope, + ) + } else { + snsWriter = sns.NewNoopWriter() + } auditProjectCmdRunner := &lyftDecorators.AuditProjectCommandWrapper{ SnsWriter: snsWriter,