diff --git a/CHANGELOG.md b/CHANGELOG.md index 375f0a3..a2a23c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,31 @@ Notes for upgrading... ### Fixed +[0.9.0] - 2025.01.16 +-------------------- + +Version 0.9.0 adds the ability to federate directly into a specific service through favorites or the `console` command. No more hopping into the console dashboard then searching for and navigating to your destination. Note that the specified service is injected into the federation URLs `Destination` parameter. So, for example, the full path for the RDS service is `/rds/home?region=us-east-1#Home`, we just need the first part of the path `rds`. + +```bash +# Add a service to your favorites +favorites: + - name: mysandbox + account: "121212121212" + cloud_access_role: Admin + access_type: web + service: rds + +# Then call it +kion fav mysandbox + +# Or step through the selection wizard +kion con rds +``` + +### Added + +- Ability to federate directly to a service [kionsoftware/kion-cli/pull/77] + [0.8.0] - 2025.01.07 -------------------- diff --git a/README.md b/README.md index 2625ccc..6aef46e 100644 --- a/README.md +++ b/README.md @@ -286,6 +286,14 @@ OPTIONS __Run Command:__ ```text +ARGS + + [service] Optional argument to specify a service + page to open as opposed to the default + dashboard. For `kion con rds` would + federate directly to the RDS services + page. + OPTIONS --favorite val, --fav val, -f val Specify which favorite to run against. @@ -398,6 +406,8 @@ favorites[N].name Favorite name, used when calling `kion fav [n favorites[N].account Account number associated with the favorite. favorites[N].cloud_access_role Cloud Access Role used to authenicate with the favorite. favorites[N].access_type Favorite access type, 'web' or 'cli', defaults 'cli'. +favorites[N].service Service to open by default, for example 'rds', 'ec2', etc. + Applies only to 'web' access types, defaults to the dashboard. PROFILES -------- diff --git a/VERSION.md b/VERSION.md index b19b521..f979ade 100644 --- a/VERSION.md +++ b/VERSION.md @@ -1 +1 @@ -v0.8.0 +v0.9.0 diff --git a/lib/helper/browser.go b/lib/helper/browser.go index 1009e1d..623f9eb 100644 --- a/lib/helper/browser.go +++ b/lib/helper/browser.go @@ -191,11 +191,21 @@ func OpenBrowser(url string, typeID uint) error { // OpenBrowserDirect opens up a URL in the users system default browser. It // uses the redirect_uri query parameter to handle the logout and redirect to // the federated login page. -func OpenBrowserRedirect(target string, session structs.SessionInfo, config structs.Browser) error { +func OpenBrowserRedirect(target string, session structs.SessionInfo, config structs.Browser, redirect string) error { var err error var logoutURL string var replacement string + // inject a redirect to service if provided + if redirect != "" { + re := regexp.MustCompile(`(Destination=[^&]+)`) + target = re.ReplaceAllStringFunc(target, func(match string) string { + parts := re.FindStringSubmatch(match) + return fmt.Sprintf("%s%s", parts[1], redirect+"%2F") + }) + } + + // determine the logout url based on the account type switch session.AccountTypeID { case 1: // commmercial diff --git a/lib/structs/configuraton-structs.go b/lib/structs/configuraton-structs.go index 73f2bda..c9d949e 100644 --- a/lib/structs/configuraton-structs.go +++ b/lib/structs/configuraton-structs.go @@ -36,6 +36,7 @@ type Favorite struct { CAR string `yaml:"cloud_access_role"` AccessType string `yaml:"access_type"` Region string `yaml:"region"` + Service string `yaml:"service"` } // Profile holds an alternate configuration for Kion and Favorites. diff --git a/main.go b/main.go index 7d809e4..eb1d2ad 100644 --- a/main.go +++ b/main.go @@ -43,6 +43,14 @@ var ( // // //////////////////////////////////////////////////////////////////////////////// +// getSecondArgument returns the second argument passed to the cli. +func getSecondArgument(cCtx *cli.Context) string { + if cCtx.Args().Len() > 0 { + return cCtx.Args().Get(0) + } + return "" +} + // setEndpoint sets the target Kion installation to interact with. If not // passed to the tool as an argument, set in the env, or present in the // configuration dotfile it will prompt the user to provide it. @@ -708,7 +716,7 @@ func favorites(cCtx *cli.Context) error { AwsIamRoleName: car.AwsIamRoleName, Region: favorite.Region, } - return helper.OpenBrowserRedirect(url, session, config.Browser) + return helper.OpenBrowserRedirect(url, session, config.Browser, favorite.Service) } else { // placeholder for our stak var stak kion.STAK @@ -787,6 +795,9 @@ func fedConsole(cCtx *cli.Context) error { return err } + // grab the second argument, used as a redirect parameter + redirect := getSecondArgument(cCtx) + session := structs.SessionInfo{ AccountName: car.AccountName, AccountNumber: car.AccountNumber, @@ -794,7 +805,7 @@ func fedConsole(cCtx *cli.Context) error { AwsIamRoleName: car.AwsIamRoleName, Region: cCtx.String("region"), } - return helper.OpenBrowserRedirect(url, session, config.Browser) + return helper.OpenBrowserRedirect(url, session, config.Browser, redirect) } // listFavorites prints out the users stored favorites. Extra information is