Skip to content

Commit

Permalink
B-22056 - env var updates to match planned in param store.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-mchugh committed Jan 8, 2025
1 parent 24daa1a commit 1729cbd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
10 changes: 9 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,17 @@ export TZ="UTC"
#
# export STORAGE_BACKEND=s3
# export EMAIL_BACKEND=ses
# export RECEIVER_BACKEND="sns&sqs"
#
# Instructions for using S3 storage backend here: https://dp3.atlassian.net/wiki/spaces/MT/pages/1470955567/How+to+test+storing+data+in+S3+locally
# Instructions for using SES email backend here: https://dp3.atlassian.net/wiki/spaces/MT/pages/1467973894/How+to+test+sending+email+locally
# Instructions for using SNS&SQS backend here: ...
#
# The default and equivalent to not being set is:
#
# export STORAGE_BACKEND=local
# export EMAIL_BACKEND=local
# export RECEIVER_BACKEND=local
#
# Setting region and profile conditionally while we migrate from com to govcloud.
if [ "$STORAGE_BACKEND" == "s3" ]; then
Expand All @@ -255,6 +258,11 @@ export AWS_S3_KEY_NAMESPACE=$USER
export AWS_SES_DOMAIN="devlocal.dp3.us"
export AWS_SES_REGION="us-gov-west-1"

if [ "$RECEIVER_BACKEND" == "sns&sqs" ]; then
export SNS_TAGS_UPDATED_TOPIC="app_s3_tag_events"
export SNS_REGION="us-gov-west-1"
fi

# To use s3 links aws-bucketname/xx/user/ for local builds,
# you'll need to add the following to your .envrc.local:
#
Expand Down Expand Up @@ -441,4 +449,4 @@ then
fi

# Check that all required environment variables are set
check_required_variables
check_required_variables
30 changes: 15 additions & 15 deletions pkg/cli/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import (
const (
// ReceiverBackend is the Receiver Backend Flag
ReceiverBackendFlag string = "receiver-backend"
// AWSSNSObjectTagsAddedTopic is the AWS SNS Object Tags Added Topic Flag
AWSSNSObjectTagsAddedTopicFlag string = "aws-sns-object-tags-added-topic"
// AWSS3RegionFlag is the AWS SNS Region Flag
AWSSNSRegionFlag string = "aws-sns-region"
// AWSSNSAccountId is the application's AWS account id
AWSSNSAccountId string = "aws-account-id"
// SNSTagsUpdatedTopicFlag is the SNS Tags Updated Topic Flag
SNSTagsUpdatedTopicFlag string = "sns-tags-updated-topic"
// SNSRegionFlag is the SNS Region flag
SNSRegionFlag string = "sns-region"
// SNSAccountId is the application's AWS account id
SNSAccountId string = "aws-account-id"
)

// InitReceiverFlags initializes Storage command line flags
func InitReceiverFlags(flag *pflag.FlagSet) {
flag.String(ReceiverBackendFlag, "local", "Receiver backend to use, either local or sns&sqs.")
flag.String(AWSSNSObjectTagsAddedTopicFlag, "", "SNS Topic for receiving event messages")
flag.String(AWSSNSRegionFlag, "", "AWS region used for SNS and SQS")
flag.String(AWSSNSAccountId, "", "AWS account Id")
flag.String(SNSTagsUpdatedTopicFlag, "", "SNS Topic for receiving event messages")
flag.String(SNSRegionFlag, "", "Region used for SNS and SQS")
flag.String(SNSAccountId, "", "SNS account Id")
}

// CheckReceiver validates Storage command line flags
Expand All @@ -35,17 +35,17 @@ func CheckReceiver(v *viper.Viper) error {
}

if receiverBackend == "sns&sqs" {
r := v.GetString(AWSSNSRegionFlag)
r := v.GetString(SNSRegionFlag)
if r == "" {
return fmt.Errorf("invalid value for %s: %s", AWSSNSRegionFlag, r)
return fmt.Errorf("invalid value for %s: %s", SNSRegionFlag, r)
}
topic := v.GetString(AWSSNSObjectTagsAddedTopicFlag)
topic := v.GetString(SNSTagsUpdatedTopicFlag)
if topic == "" {
return fmt.Errorf("invalid value for %s: %s", AWSSNSObjectTagsAddedTopicFlag, topic)
return fmt.Errorf("invalid value for %s: %s", SNSTagsUpdatedTopicFlag, topic)
}
accountId := v.GetString(AWSSNSAccountId)
accountId := v.GetString(SNSAccountId)
if topic == "" {
return fmt.Errorf("invalid value for %s: %s", AWSSNSAccountId, accountId)
return fmt.Errorf("invalid value for %s: %s", SNSAccountId, accountId)
}
}

Expand Down
16 changes: 4 additions & 12 deletions pkg/notifications/notification_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,28 +199,20 @@ func (n NotificationReceiverContext) CloseoutQueue(appCtx appcontext.AppContext,

// GetDefaultTopic returns the topic value set within the environment
func (n NotificationReceiverContext) GetDefaultTopic() (string, error) {
// v := viper.New()
n.viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
// v.AutomaticEnv()
topicName := n.viper.GetString(cli.AWSSNSObjectTagsAddedTopicFlag)
topicName := n.viper.GetString(cli.SNSTagsUpdatedTopicFlag)
receiverBackend := n.viper.GetString(cli.ReceiverBackendFlag)
if topicName == "" && receiverBackend == "sns&sqs" {
return "", errors.New("aws_sns_object_tags_added_topic key not available")
return "", errors.New("sns_tags_updated_topic key not available")
}
return topicName, nil
}

// InitReceiver initializes the receiver backend
func InitReceiver(v ViperType, logger *zap.Logger) (NotificationReceiver, error) {

// v := viper.New()
// v.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
// v.AutomaticEnv()

if v.GetString(cli.ReceiverBackendFlag) == "sns&sqs" {
// Setup notification receiver service with SNS & SQS backend dependencies
awsSNSRegion := v.GetString(cli.AWSSNSRegionFlag)
awsAccountId := v.GetString(cli.AWSSNSAccountId)
awsSNSRegion := v.GetString(cli.SNSRegionFlag)
awsAccountId := v.GetString(cli.SNSAccountId)

logger.Info("Using aws sns&sqs receiver backend", zap.String("region", awsSNSRegion))

Expand Down
6 changes: 3 additions & 3 deletions pkg/notifications/notification_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func (_m *Viper) GetString(key string) string {
switch key {
case cli.ReceiverBackendFlag:
return "sns&sqs"
case cli.AWSRegionFlag:
case cli.SNSRegionFlag:
return "us-gov-west-1"
case cli.AWSSNSAccountId:
case cli.SNSAccountId:
return "12345"
case cli.AWSSNSObjectTagsAddedTopicFlag:
case cli.SNSTagsUpdatedTopicFlag:
return "fake_sns_topic"
}
return ""
Expand Down

0 comments on commit 1729cbd

Please sign in to comment.