From 83f3c6459f346533aa88008d4e0d9f33205eeda4 Mon Sep 17 00:00:00 2001 From: Eloy Tolosa Date: Sun, 10 Nov 2024 17:28:29 +0100 Subject: [PATCH] Renamed chrome launcher profile to "Chrome" to have same name rule as the rest Added new browser extra flags to granted config file --- pkg/assume/assume.go | 6 +++++- pkg/cfaws/assumer_aws_sso.go | 1 - pkg/config/config.go | 5 +++-- pkg/granted/console.go | 8 ++++---- pkg/launcher/chrome_profile.go | 6 +++--- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/pkg/assume/assume.go b/pkg/assume/assume.go index 0cb5da4f..177a47a2 100644 --- a/pkg/assume/assume.go +++ b/pkg/assume/assume.go @@ -97,6 +97,7 @@ func processArgsAndExecFlag(c *cli.Context, assumeFlags *cfflags.Flags) (string, } func AssumeCommand(c *cli.Context) error { + // assumeFlags allows flags to be passed on either side of the role argument. // to access flags in this command, use assumeFlags.String("region") etc instead of c.String("region") assumeFlags, err := cfflags.New("assumeFlags", GlobalFlags(), c) @@ -430,7 +431,7 @@ func AssumeCommand(c *cli.Context) error { var l Launcher switch cfg.DefaultBrowser { case browser.ChromeKey, browser.BraveKey, browser.EdgeKey, browser.ChromiumKey: - l = launcher.ChromeProfile{ + l = launcher.Chrome{ BrowserType: cfg.DefaultBrowser, ExecutablePath: browserPath, } @@ -471,6 +472,9 @@ func AssumeCommand(c *cli.Context) error { return fmt.Errorf("error building browser launch command: %w", err) } + // add browser extra flags here to avoid modifying all interface methods (current and future ones) + args = append(args, cfg.CustomBrowserExtraFlags...) + var startErr error if l.UseForkProcess() { clio.Debugf("running command using forkprocess: %s", args) diff --git a/pkg/cfaws/assumer_aws_sso.go b/pkg/cfaws/assumer_aws_sso.go index fb6d5a29..007dadd7 100644 --- a/pkg/cfaws/assumer_aws_sso.go +++ b/pkg/cfaws/assumer_aws_sso.go @@ -216,7 +216,6 @@ func (c *Profile) SSOLogin(ctx context.Context, configOpts ConfigOpts) (aws.Cred cfg := aws.NewConfig() cfg.Region = c.SSORegion() - return c.SSOLoginWithToken(ctx, cfg, accessToken, secureSSOTokenStorage, configOpts) } diff --git a/pkg/config/config.go b/pkg/config/config.go index f905a110..97e7aca4 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -34,8 +34,9 @@ type BrowserLaunchTemplate struct { type Config struct { DefaultBrowser string // used to override the builtin filepaths for custom installation locations - CustomBrowserPath string - CustomSSOBrowserPath string + CustomBrowserPath string + CustomSSOBrowserPath string + CustomBrowserExtraFlags []string // AWSConsoleBrowserLaunchTemplate is an optional launch template to use // for opening the AWS console. If specified it overrides the DefaultBrowser diff --git a/pkg/granted/console.go b/pkg/granted/console.go index 535788b5..380abd0c 100644 --- a/pkg/granted/console.go +++ b/pkg/granted/console.go @@ -74,19 +74,19 @@ var ConsoleCommand = cli.Command{ } else { switch cfg.DefaultBrowser { case browser.ChromeKey: - l = launcher.ChromeProfile{ + l = launcher.Chrome{ ExecutablePath: cfg.CustomBrowserPath, } case browser.BraveKey: - l = launcher.ChromeProfile{ + l = launcher.Chrome{ ExecutablePath: cfg.CustomBrowserPath, } case browser.EdgeKey: - l = launcher.ChromeProfile{ + l = launcher.Chrome{ ExecutablePath: cfg.CustomBrowserPath, } case browser.ChromiumKey: - l = launcher.ChromeProfile{ + l = launcher.Chrome{ ExecutablePath: cfg.CustomBrowserPath, } case browser.FirefoxKey: diff --git a/pkg/launcher/chrome_profile.go b/pkg/launcher/chrome_profile.go index 3065a092..cbe19910 100644 --- a/pkg/launcher/chrome_profile.go +++ b/pkg/launcher/chrome_profile.go @@ -12,14 +12,14 @@ import ( "github.com/common-fate/granted/pkg/browser" ) -type ChromeProfile struct { +type Chrome struct { // ExecutablePath is the path to the Chrome binary on the system. ExecutablePath string BrowserType string } -func (l ChromeProfile) LaunchCommand(url string, profile string) ([]string, error) { +func (l Chrome) LaunchCommand(url string, profile string) ([]string, error) { // Chrome profiles can't contain slashes profileName := strings.ReplaceAll(profile, "/", "-") profileDir := findBrowserProfile(profileName, l.BrowserType) @@ -236,4 +236,4 @@ func getLocalStatePath(browserType string) (stateFile string, err error) { return stateFile, nil } -func (l ChromeProfile) UseForkProcess() bool { return true } +func (l Chrome) UseForkProcess() bool { return true }