@@ -307,7 +307,7 @@ func AssumeCommand(c *cli.Context) error {
307307
308308 // if getConsoleURL is true, we'll use the AWS federated login to retrieve a URL to access the console.
309309 // depending on how Granted is configured, this is then printed to the terminal or a browser is launched at the URL automatically.
310- getConsoleURL := ! assumeFlags .Bool ("env" ) && ((assumeFlags .Bool ("console" ) || assumeFlags .String ("console-destination" ) != "" ) || assumeFlags .Bool ("active-role" ) || assumeFlags .StringSlice ("service" ) != nil || assumeFlags .Bool ("url" ) || assumeFlags .String ("browser-profile" ) != "" )
310+ getConsoleURL := ! assumeFlags .Bool ("env" ) && ((assumeFlags .Bool ("console" ) || assumeFlags .String ("console-destination" ) != "" ) || assumeFlags .Bool ("active-role" ) || assumeFlags .String ("service" ) != "" || assumeFlags .Bool ("url" ) || assumeFlags .String ("browser-profile" ) != "" )
311311
312312 // this makes it easy for users to copy the actual command and avoid needing to lookup profiles
313313 if ! cfg .DisableUsageTips && showRerunCommand {
@@ -317,15 +317,11 @@ func AssumeCommand(c *cli.Context) error {
317317 if getConsoleURL {
318318 con := console.AWS {
319319 Profile : profile .Name ,
320+ Service : assumeFlags .String ("service" ),
321+ Region : region ,
320322 Destination : assumeFlags .String ("console-destination" ),
321323 }
322324
323- services := assumeFlags .StringSlice ("service" )
324- con .Service = append (con .Service , services ... )
325-
326- region := assumeFlags .String ("region" )
327- con .Region = region
328-
329325 creds , err := profile .AssumeConsole (c .Context , configOpts )
330326 if err != nil && strings .HasPrefix (err .Error (), "no access" ) {
331327 clio .Debugw ("received a No Access error" , "error" , err )
@@ -342,98 +338,92 @@ func AssumeCommand(c *cli.Context) error {
342338 containerProfile = assumeFlags .String ("browser-profile" )
343339 }
344340
345- consoleURLs , err := con .URLs (creds )
341+ consoleURL , err := con .URL (creds )
346342 if err != nil {
347343 return err
348344 }
349345
350- clio .Debugf ("number of console urls created" , "amount" , len (consoleURLs ))
351- for _ , consoleURL := range consoleURLs {
346+ if cfg .DefaultBrowser == browser .FirefoxKey || cfg .DefaultBrowser == browser .WaterfoxKey || cfg .DefaultBrowser == browser .FirefoxStdoutKey || cfg .DefaultBrowser == browser .FirefoxDevEditionKey || cfg .DefaultBrowser == browser .FirefoxNightlyKey {
347+ // transform the URL into the Firefox Tab Container format.
348+ consoleURL = fmt .Sprintf ("ext+granted-containers:name=%s&url=%s&color=%s&icon=%s" , containerProfile , url .QueryEscape (consoleURL ), profile .CustomGrantedProperty ("color" ), profile .CustomGrantedProperty ("icon" ))
349+ }
352350
353- if cfg .DefaultBrowser == browser .FirefoxKey || cfg .DefaultBrowser == browser .WaterfoxKey || cfg .DefaultBrowser == browser .FirefoxStdoutKey || cfg .DefaultBrowser == browser .FirefoxDevEditionKey || cfg .DefaultBrowser == browser .FirefoxNightlyKey {
354- // transform the URL into the Firefox Tab Container format.
355- consoleURL = fmt .Sprintf ("ext+granted-containers:name=%s&url=%s&color=%s&icon=%s" , containerProfile , url .QueryEscape (consoleURL ), profile .CustomGrantedProperty ("color" ), profile .CustomGrantedProperty ("icon" ))
356- }
351+ justPrintURL := assumeFlags .Bool ("url" ) || cfg .DefaultBrowser == browser .StdoutKey || cfg .DefaultBrowser == browser .FirefoxStdoutKey
352+ if justPrintURL {
353+ // return the url via stdout through the CLI wrapper script and return early.
354+ fmt .Print (assumeprint .SafeOutput (consoleURL ))
355+ return nil
356+ }
357357
358- justPrintURL := assumeFlags .Bool ("url" ) || cfg .DefaultBrowser == browser .StdoutKey || cfg .DefaultBrowser == browser .FirefoxStdoutKey
359- if justPrintURL {
360- // return the url via stdout through the CLI wrapper script and return early.
361- fmt .Print (assumeprint .SafeOutput (consoleURL ))
362- return nil
363- }
358+ browserPath := cfg .CustomBrowserPath
359+ if browserPath == "" && cfg .AWSConsoleBrowserLaunchTemplate == nil {
360+ return errors .New ("default browser not configured. run `granted browser set` to configure" )
361+ }
364362
365- browserPath := cfg .CustomBrowserPath
366- if browserPath == "" && cfg .AWSConsoleBrowserLaunchTemplate == nil {
367- return errors .New ("default browser not configured. run `granted browser set` to configure" )
363+ var l Launcher
364+ switch cfg .DefaultBrowser {
365+ case browser .ChromeKey , browser .BraveKey , browser .EdgeKey , browser .ChromiumKey , browser .VivaldiKey :
366+ l = launcher.ChromeProfile {
367+ BrowserType : cfg .DefaultBrowser ,
368+ ExecutablePath : browserPath ,
368369 }
369-
370- var l Launcher
371- switch cfg .DefaultBrowser {
372- case browser .ChromeKey , browser .BraveKey , browser .EdgeKey , browser .ChromiumKey , browser .VivaldiKey :
373- l = launcher.ChromeProfile {
374- BrowserType : cfg .DefaultBrowser ,
375- ExecutablePath : browserPath ,
376- }
377- case browser .FirefoxKey , browser .WaterfoxKey :
378- l = launcher.Firefox {
379- ExecutablePath : browserPath ,
380- }
381- case browser .SafariKey :
382- l = launcher.Safari {}
383- case browser .ArcKey :
384- l = launcher.Arc {}
385- case browser .FirefoxDevEditionKey :
386- l = launcher.FirefoxDevEdition {
387- ExecutablePath : browserPath ,
388- }
389- case browser .FirefoxNightlyKey :
390- l = launcher.FirefoxNightly {
391- ExecutablePath : browserPath ,
392- }
393- case browser .CustomKey :
394- l , err = launcher .CustomFromLaunchTemplate (cfg .AWSConsoleBrowserLaunchTemplate , c .StringSlice ("browser-launch-template-arg" ))
395- if err == launcher .ErrLaunchTemplateNotConfigured {
396- return errors .New ("error configuring custom browser, ensure that [AWSConsoleBrowserLaunchTemplate] is specified in your Granted config file" )
397- }
398- if err != nil {
399- return err
400- }
401- default :
402- l = launcher.Open {}
370+ case browser .FirefoxKey , browser .WaterfoxKey :
371+ l = launcher.Firefox {
372+ ExecutablePath : browserPath ,
373+ }
374+ case browser .SafariKey :
375+ l = launcher.Safari {}
376+ case browser .ArcKey :
377+ l = launcher.Arc {}
378+ case browser .FirefoxDevEditionKey :
379+ l = launcher.FirefoxDevEdition {
380+ ExecutablePath : browserPath ,
403381 }
382+ case browser .FirefoxNightlyKey :
383+ l = launcher.FirefoxNightly {
384+ ExecutablePath : browserPath ,
385+ }
386+ case browser .CustomKey :
387+ l , err = launcher .CustomFromLaunchTemplate (cfg .AWSConsoleBrowserLaunchTemplate , c .StringSlice ("browser-launch-template-arg" ))
388+ if err == launcher .ErrLaunchTemplateNotConfigured {
389+ return errors .New ("error configuring custom browser, ensure that [AWSConsoleBrowserLaunchTemplate] is specified in your Granted config file" )
390+ }
391+ if err != nil {
392+ return err
393+ }
394+ default :
395+ l = launcher.Open {}
396+ }
404397
405- servicesString := strings .Join (services , " " )
406- printFlagUsage (con .Region , servicesString )
407- clio .Debugf ("Opening a console for %s in your browser..." , profile .Name )
398+ printFlagUsage (con .Region , con .Service )
399+ clio .Infof ("Opening a console for %s in your browser..." , profile .Name )
408400
409- // now build the actual command to run - e.g. 'firefox --new-tab <URL>'
401+ // now build the actual command to run - e.g. 'firefox --new-tab <URL>'
402+ args , err := l .LaunchCommand (consoleURL , containerProfile )
403+ if err != nil {
404+ return fmt .Errorf ("error building browser launch command: %w" , err )
405+ }
410406
411- args , err := l .LaunchCommand (consoleURL , containerProfile )
407+ var startErr error
408+ if l .UseForkProcess () {
409+ clio .Debugf ("running command using forkprocess: %s" , args )
410+ cmd , err := forkprocess .New (args ... )
412411 if err != nil {
413- return fmt .Errorf ("error building browser launch command: %w" , err )
414- }
415-
416- var startErr error
417- if l .UseForkProcess () {
418- clio .Debugf ("running command using forkprocess: %s" , args )
419- cmd , err := forkprocess .New (args ... )
420- if err != nil {
421- return err
422- }
423- startErr = cmd .Start ()
424- } else {
425- clio .Debugf ("running command without forkprocess: %s" , args )
426- cmd := exec .Command (args [0 ], args [1 :]... )
427- startErr = cmd .Start ()
412+ return err
428413 }
414+ startErr = cmd .Start ()
415+ } else {
416+ clio .Debugf ("running command without forkprocess: %s" , args )
417+ cmd := exec .Command (args [0 ], args [1 :]... )
418+ startErr = cmd .Start ()
419+ }
429420
430- if startErr != nil {
431- return clierr .New (fmt .Sprintf ("Granted was unable to open a browser session automatically due to the following error: %s" , startErr .Error ()),
432- // allow them to try open the url manually
433- clierr .Info ("You can open the browser session manually using the following url:" ),
434- clierr .Info (consoleURL ),
435- )
436- }
421+ if startErr != nil {
422+ return clierr .New (fmt .Sprintf ("Granted was unable to open a browser session automatically due to the following error: %s" , startErr .Error ()),
423+ // allow them to try open the url manually
424+ clierr .Info ("You can open the browser session manually using the following url:" ),
425+ clierr .Info (consoleURL ),
426+ )
437427 }
438428 }
439429
0 commit comments