diff --git a/awsconfig/profiles.go b/awsconfig/profiles.go index e82b95f2..b86735a6 100644 --- a/awsconfig/profiles.go +++ b/awsconfig/profiles.go @@ -66,7 +66,7 @@ func loadAwsProfiles() { func GetAwsCredentialsFilePath() string { // see https://docs.aws.amazon.com/sdkref/latest/guide/file-location.html - path, _ := os.LookupEnv("AWS_SHARED_CREDENTIALS_FILE") + path := os.Getenv("AWS_SHARED_CREDENTIALS_FILE") if path == "" { path = config.DefaultSharedCredentialsFilename() } @@ -75,7 +75,7 @@ func GetAwsCredentialsFilePath() string { func GetAwsProfileFilePath() string { // see https://docs.aws.amazon.com/sdkref/latest/guide/file-location.html - path, _ := os.LookupEnv("AWS_CONFIG_FILE") + path := os.Getenv("AWS_CONFIG_FILE") if path == "" { path = config.DefaultSharedConfigFilename() } diff --git a/awsworkflow/aws.go b/awsworkflow/aws.go index 875977e8..6b93fa39 100644 --- a/awsworkflow/aws.go +++ b/awsworkflow/aws.go @@ -54,7 +54,7 @@ var defaultAwsConsoleDomain string = "console.aws.amazon.com" var defaultAwsConsoleDomainChina string = "console.amazonaws.cn" func initAWSConsoleDomain(region string) { - awsConsoleDomain, _ := os.LookupEnv("ALRED_AWS_CONSOLE_SERVICES_WORKFLOW_AWS_CONSOLE_DOMAIN") + awsConsoleDomain := os.Getenv("ALRED_AWS_CONSOLE_SERVICES_WORKFLOW_AWS_CONSOLE_DOMAIN") if awsConsoleDomain == "" { if strings.HasPrefix(region, "cn-") { awsConsoleDomain = defaultAwsConsoleDomainChina diff --git a/caching/fetch_tools.go b/caching/fetch_tools.go index 0250bf01..be913d19 100644 --- a/caching/fetch_tools.go +++ b/caching/fetch_tools.go @@ -11,6 +11,7 @@ import ( "time" aw "github.com/deanishe/awgo" + "github.com/rkoval/alfred-aws-console-services-workflow/awsconfig" "github.com/rkoval/alfred-aws-console-services-workflow/searchers/searchutil" "github.com/rkoval/alfred-aws-console-services-workflow/util" ) @@ -63,16 +64,19 @@ func handleFetchErr(wf *aw.Workflow, lastFetchErrPath string, searchArgs searchu // TODO need to fix "no results" display when there's really a fetch error + userHomePath := os.Getenv("HOME") errString := string(data) wf.Configure(aw.SuppressUIDs(true)) if strings.HasPrefix(errString, "NoCredentialProviders") { - util.NewURLItem(wf, "AWS credentials not set in ~/.aws/credentials for profile \""+searchArgs.Profile+"\""). + credentialsFilePath := strings.Replace(awsconfig.GetAwsCredentialsFilePath(), userHomePath, "~", 1) + util.NewURLItem(wf, "AWS credentials not set in "+credentialsFilePath+" for profile \""+searchArgs.Profile+"\""). Subtitle("Press enter to open AWS docs on how to configure"). Arg("https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/#creating-the-credentials-file"). Icon(aw.IconError). Valid(true) } else if strings.HasPrefix(errString, "MissingRegion") { - util.NewURLItem(wf, "AWS region not set in ~/.aws/config for profile \""+searchArgs.Profile+"\""). + configFilePath := strings.Replace(awsconfig.GetAwsProfileFilePath(), userHomePath, "~", 1) + util.NewURLItem(wf, "AWS region not set in "+configFilePath+" for profile \""+searchArgs.Profile+"\""). Subtitle("Press enter to open AWS docs on how to configure"). Arg("https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/#creating-the-config-file"). Icon(aw.IconError). diff --git a/test.sh b/test.sh index f3fdffac..e0144bd5 100755 --- a/test.sh +++ b/test.sh @@ -2,7 +2,6 @@ set -e export TEST=1 source env.sh -export AWS_REGION=us-west-2 export AWS_SHARED_CREDENTIALS_FILE="../tests/test_aws_credentials_file" export AWS_CONFIG_FILE="../tests/test_aws_config_file" ./generate.sh diff --git a/tests/test_aws_credentials_file b/tests/test_aws_credentials_file index a2b2d305..cb009b38 100644 --- a/tests/test_aws_credentials_file +++ b/tests/test_aws_credentials_file @@ -10,7 +10,7 @@ aws_secret_access_key=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy aws_access_key_id=BBBBBBBBBBBBBBBBBBBB aws_secret_access_key=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy -[profile4] +[noregion] aws_access_key_id=BBBBBBBBBBBBBBBBBBBB aws_secret_access_key=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy diff --git a/workflow/.snapshots/TestRun-$us-east-1_@ b/workflow/.snapshots/TestRun-$us-east-1_@ index 2b214345..b37c7935 100644 --- a/workflow/.snapshots/TestRun-$us-east-1_@ +++ b/workflow/.snapshots/TestRun-$us-east-1_@ @@ -21,11 +21,11 @@ noUID: (bool) false }), (*aw.Item)({ - title: (string) (len=8) "profile1", - subtitle: (*string)((len=14) "🌎 us-east-1"), + title: (string) (len=8) "noregion", + subtitle: (*string)((len=76) "⚠️ This profile does not specify a region. Functionality will be limited"), match: (*string)(), - uid: (*string)((len=8) "profile1"), - autocomplete: (*string)((len=21) "$us-east-1 @profile1 "), + uid: (*string)((len=8) "noregion"), + autocomplete: (*string)((len=21) "$us-east-1 @noregion "), arg: (*string)(), valid: (bool) false, file: (bool) false, @@ -42,11 +42,11 @@ noUID: (bool) false }), (*aw.Item)({ - title: (string) (len=8) "profile3", - subtitle: (*string)((len=14) "🌎 sa-east-1"), + title: (string) (len=8) "profile1", + subtitle: (*string)((len=14) "🌎 us-east-1"), match: (*string)(), - uid: (*string)((len=8) "profile3"), - autocomplete: (*string)((len=21) "$us-east-1 @profile3 "), + uid: (*string)((len=8) "profile1"), + autocomplete: (*string)((len=21) "$us-east-1 @profile1 "), arg: (*string)(), valid: (bool) false, file: (bool) false, @@ -63,11 +63,11 @@ noUID: (bool) false }), (*aw.Item)({ - title: (string) (len=8) "profile4", - subtitle: (*string)(), + title: (string) (len=8) "profile3", + subtitle: (*string)((len=14) "🌎 sa-east-1"), match: (*string)(), - uid: (*string)((len=8) "profile4"), - autocomplete: (*string)((len=21) "$us-east-1 @profile4 "), + uid: (*string)((len=8) "profile3"), + autocomplete: (*string)((len=21) "$us-east-1 @profile3 "), arg: (*string)(), valid: (bool) false, file: (bool) false, diff --git a/workflow/.snapshots/TestRun-$us-east-1_@prof b/workflow/.snapshots/TestRun-$us-east-1_@prof index 14dd7a88..aeae6c0e 100644 --- a/workflow/.snapshots/TestRun-$us-east-1_@prof +++ b/workflow/.snapshots/TestRun-$us-east-1_@prof @@ -1,4 +1,4 @@ -([]*aw.Item) (len=4) { +([]*aw.Item) (len=3) { (*aw.Item)({ title: (string) (len=8) "profile1", subtitle: (*string)((len=14) "🌎 us-east-1"), @@ -41,27 +41,6 @@ }), noUID: (bool) false }), - (*aw.Item)({ - title: (string) (len=8) "profile4", - subtitle: (*string)(), - match: (*string)(), - uid: (*string)((len=8) "profile4"), - autocomplete: (*string)((len=21) "$us-east-1 @profile4 "), - arg: (*string)(), - valid: (bool) false, - file: (bool) false, - copytext: (*string)(), - largetype: (*string)(), - ql: (*string)(), - vars: (map[string]string) { - }, - mods: (map[aw.ModKey]*aw.Modifier) , - icon: (*aw.Icon)({ - Value: (string) (len=78) "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/Accounts.icns", - Type: (aw.IconType) "" - }), - noUID: (bool) false - }), (*aw.Item)({ title: (string) (len=12) "bogusprofile", subtitle: (*string)((len=10) "🌎 bogus"), diff --git a/workflow/.snapshots/TestRun-@ b/workflow/.snapshots/TestRun-@ index ac582f24..680a6fcf 100644 --- a/workflow/.snapshots/TestRun-@ +++ b/workflow/.snapshots/TestRun-@ @@ -21,11 +21,11 @@ noUID: (bool) false }), (*aw.Item)({ - title: (string) (len=8) "profile1", - subtitle: (*string)((len=14) "🌎 us-east-1"), + title: (string) (len=8) "noregion", + subtitle: (*string)((len=76) "⚠️ This profile does not specify a region. Functionality will be limited"), match: (*string)(), - uid: (*string)((len=8) "profile1"), - autocomplete: (*string)((len=10) "@profile1 "), + uid: (*string)((len=8) "noregion"), + autocomplete: (*string)((len=10) "@noregion "), arg: (*string)(), valid: (bool) false, file: (bool) false, @@ -42,11 +42,11 @@ noUID: (bool) false }), (*aw.Item)({ - title: (string) (len=8) "profile3", - subtitle: (*string)((len=14) "🌎 sa-east-1"), + title: (string) (len=8) "profile1", + subtitle: (*string)((len=14) "🌎 us-east-1"), match: (*string)(), - uid: (*string)((len=8) "profile3"), - autocomplete: (*string)((len=10) "@profile3 "), + uid: (*string)((len=8) "profile1"), + autocomplete: (*string)((len=10) "@profile1 "), arg: (*string)(), valid: (bool) false, file: (bool) false, @@ -63,11 +63,11 @@ noUID: (bool) false }), (*aw.Item)({ - title: (string) (len=8) "profile4", - subtitle: (*string)(), + title: (string) (len=8) "profile3", + subtitle: (*string)((len=14) "🌎 sa-east-1"), match: (*string)(), - uid: (*string)((len=8) "profile4"), - autocomplete: (*string)((len=10) "@profile4 "), + uid: (*string)((len=8) "profile3"), + autocomplete: (*string)((len=10) "@profile3 "), arg: (*string)(), valid: (bool) false, file: (bool) false, diff --git a/workflow/.snapshots/TestRun-@_$ b/workflow/.snapshots/TestRun-@_$ index 5a06b176..2220d16f 100644 --- a/workflow/.snapshots/TestRun-@_$ +++ b/workflow/.snapshots/TestRun-@_$ @@ -21,11 +21,11 @@ noUID: (bool) false }), (*aw.Item)({ - title: (string) (len=8) "profile1", - subtitle: (*string)((len=14) "🌎 us-east-1"), + title: (string) (len=8) "noregion", + subtitle: (*string)((len=76) "⚠️ This profile does not specify a region. Functionality will be limited"), match: (*string)(), - uid: (*string)((len=8) "profile1"), - autocomplete: (*string)((len=12) "@profile1 $"), + uid: (*string)((len=8) "noregion"), + autocomplete: (*string)((len=12) "@noregion $"), arg: (*string)(), valid: (bool) false, file: (bool) false, @@ -42,11 +42,11 @@ noUID: (bool) false }), (*aw.Item)({ - title: (string) (len=8) "profile3", - subtitle: (*string)((len=14) "🌎 sa-east-1"), + title: (string) (len=8) "profile1", + subtitle: (*string)((len=14) "🌎 us-east-1"), match: (*string)(), - uid: (*string)((len=8) "profile3"), - autocomplete: (*string)((len=12) "@profile3 $"), + uid: (*string)((len=8) "profile1"), + autocomplete: (*string)((len=12) "@profile1 $"), arg: (*string)(), valid: (bool) false, file: (bool) false, @@ -63,11 +63,11 @@ noUID: (bool) false }), (*aw.Item)({ - title: (string) (len=8) "profile4", - subtitle: (*string)(), + title: (string) (len=8) "profile3", + subtitle: (*string)((len=14) "🌎 sa-east-1"), match: (*string)(), - uid: (*string)((len=8) "profile4"), - autocomplete: (*string)((len=12) "@profile4 $"), + uid: (*string)((len=8) "profile3"), + autocomplete: (*string)((len=12) "@profile3 $"), arg: (*string)(), valid: (bool) false, file: (bool) false, diff --git a/workflow/.snapshots/TestRun-@_prof b/workflow/.snapshots/TestRun-@_prof index f72f5fa3..330e3724 100644 --- a/workflow/.snapshots/TestRun-@_prof +++ b/workflow/.snapshots/TestRun-@_prof @@ -1,4 +1,4 @@ -([]*aw.Item) (len=4) { +([]*aw.Item) (len=3) { (*aw.Item)({ title: (string) (len=8) "profile1", subtitle: (*string)((len=14) "🌎 us-east-1"), @@ -41,27 +41,6 @@ }), noUID: (bool) false }), - (*aw.Item)({ - title: (string) (len=8) "profile4", - subtitle: (*string)(), - match: (*string)(), - uid: (*string)((len=8) "profile4"), - autocomplete: (*string)((len=6) "@ prof"), - arg: (*string)(), - valid: (bool) false, - file: (bool) false, - copytext: (*string)(), - largetype: (*string)(), - ql: (*string)(), - vars: (map[string]string) { - }, - mods: (map[aw.ModKey]*aw.Modifier) , - icon: (*aw.Icon)({ - Value: (string) (len=78) "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/Accounts.icns", - Type: (aw.IconType) "" - }), - noUID: (bool) false - }), (*aw.Item)({ title: (string) (len=12) "bogusprofile", subtitle: (*string)((len=10) "🌎 bogus"), diff --git a/workflow/.snapshots/TestRun-@noregion_elasticbeanstalk_applications b/workflow/.snapshots/TestRun-@noregion_elasticbeanstalk_applications new file mode 100644 index 00000000..7e37373d --- /dev/null +++ b/workflow/.snapshots/TestRun-@noregion_elasticbeanstalk_applications @@ -0,0 +1,35 @@ +([]*aw.Item) (len=1) { + (*aw.Item)({ + title: (string) (len=29) "elasticbeanstalk applications", + subtitle: (*string)((len=39) "🔎 Elastic Beanstalk – Applications"), + match: (*string)((len=25) "applications Applications"), + uid: (*string)((len=12) "applications"), + autocomplete: (*string)((len=40) "@noregion elasticbeanstalk applications "), + arg: (*string)((len=66) "https://console.aws.amazon.com/elasticbeanstalk/home#/applications"), + valid: (bool) true, + file: (bool) false, + copytext: (*string)(), + largetype: (*string)(), + ql: (*string)(), + vars: (map[string]string) (len=1) { + (string) (len=6) "action": (string) (len=8) "open-url" + }, + mods: (map[aw.ModKey]*aw.Modifier) (len=1) { + (aw.ModKey) (len=3) "cmd": (*aw.Modifier)({ + Key: (aw.ModKey) (len=3) "cmd", + arg: (*string)(), + subtitle: (*string)((len=21) "Copy URL to clipboard"), + valid: (bool) false, + icon: (*aw.Icon)(), + vars: (map[string]string) (len=1) { + (string) (len=6) "action": (string) (len=17) "copy-to-clipboard" + } + }) + }, + icon: (*aw.Icon)({ + Value: (string) (len=27) "images/elasticbeanstalk.png", + Type: (aw.IconType) "" + }), + noUID: (bool) false + }) +} diff --git a/workflow/.snapshots/TestRun-@prof b/workflow/.snapshots/TestRun-@prof index 113a2278..629e991e 100644 --- a/workflow/.snapshots/TestRun-@prof +++ b/workflow/.snapshots/TestRun-@prof @@ -1,4 +1,4 @@ -([]*aw.Item) (len=4) { +([]*aw.Item) (len=3) { (*aw.Item)({ title: (string) (len=8) "profile1", subtitle: (*string)((len=14) "🌎 us-east-1"), @@ -41,27 +41,6 @@ }), noUID: (bool) false }), - (*aw.Item)({ - title: (string) (len=8) "profile4", - subtitle: (*string)(), - match: (*string)(), - uid: (*string)((len=8) "profile4"), - autocomplete: (*string)((len=10) "@profile4 "), - arg: (*string)(), - valid: (bool) false, - file: (bool) false, - copytext: (*string)(), - largetype: (*string)(), - ql: (*string)(), - vars: (map[string]string) { - }, - mods: (map[aw.ModKey]*aw.Modifier) , - icon: (*aw.Icon)({ - Value: (string) (len=78) "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/Accounts.icns", - Type: (aw.IconType) "" - }), - noUID: (bool) false - }), (*aw.Item)({ title: (string) (len=12) "bogusprofile", subtitle: (*string)((len=10) "🌎 bogus"), diff --git a/workflow/.snapshots/TestRun-elasticbeanstalk_applications_App1_@prof b/workflow/.snapshots/TestRun-elasticbeanstalk_applications_App1_@prof index 82c1057b..ca25b28d 100644 --- a/workflow/.snapshots/TestRun-elasticbeanstalk_applications_App1_@prof +++ b/workflow/.snapshots/TestRun-elasticbeanstalk_applications_App1_@prof @@ -1,4 +1,4 @@ -([]*aw.Item) (len=4) { +([]*aw.Item) (len=3) { (*aw.Item)({ title: (string) (len=8) "profile1", subtitle: (*string)((len=14) "🌎 us-east-1"), @@ -41,27 +41,6 @@ }), noUID: (bool) false }), - (*aw.Item)({ - title: (string) (len=8) "profile4", - subtitle: (*string)(), - match: (*string)(), - uid: (*string)((len=8) "profile4"), - autocomplete: (*string)((len=45) "elasticbeanstalk applications App1 @profile4 "), - arg: (*string)(), - valid: (bool) false, - file: (bool) false, - copytext: (*string)(), - largetype: (*string)(), - ql: (*string)(), - vars: (map[string]string) { - }, - mods: (map[aw.ModKey]*aw.Modifier) , - icon: (*aw.Icon)({ - Value: (string) (len=78) "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/Accounts.icns", - Type: (aw.IconType) "" - }), - noUID: (bool) false - }), (*aw.Item)({ title: (string) (len=12) "bogusprofile", subtitle: (*string)((len=10) "🌎 bogus"), diff --git a/workflow/workflow.go b/workflow/workflow.go index 8a521959..0e0ac6ed 100644 --- a/workflow/workflow.go +++ b/workflow/workflow.go @@ -55,6 +55,8 @@ func Run(wf *aw.Workflow, rawQuery string, transport http.RoundTripper, forceFet if profile.Region != "" { item.Subtitle(fmt.Sprintf("🌎 %s", profile.Region)) + } else { + item.Subtitle("⚠️ This profile does not specify a region. Functionality will be limited") } } log.Printf("filtering with profile override %q", *query.ProfileQuery) diff --git a/workflow/workflow_test.go b/workflow/workflow_test.go index e8a43318..e3f43772 100644 --- a/workflow/workflow_test.go +++ b/workflow/workflow_test.go @@ -236,6 +236,10 @@ var tcs []testCase = []testCase{ query: "@profile1 elasticbeanstalk applications", fixtureName: "../searchers/elastic_beanstalk_applications_test_us-east-1", // reuse test fixture from this other test }, + { + query: "@noregion elasticbeanstalk applications", + fixtureName: "../searchers/elastic_beanstalk_applications_test_us-east-1", // reuse test fixture from this other test + }, { query: "@profile1 elasticbeanstalk applications ", fixtureName: "../searchers/elastic_beanstalk_applications_test_us-east-1", // reuse test fixture from this other test