Skip to content

Commit

Permalink
Do nothing when sns topic is not provided (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
msarvar committed Sep 27, 2021
1 parent df78401 commit 0d3d8b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
11 changes: 10 additions & 1 deletion server/lyft/aws/sns/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -30,7 +34,6 @@ func NewWriterWithStats(
topicArn: aws.String(topicArn),
},
}

}

type writer struct {
Expand Down Expand Up @@ -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
}
16 changes: 11 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0d3d8b6

Please sign in to comment.