Skip to content

Commit

Permalink
Merge pull request #77 from kionsoftware/add-service-redirects
Browse files Browse the repository at this point in the history
Support service redirects
  • Loading branch information
codybuell authored Jan 16, 2025
2 parents 787fbc5 + 8cb16e5 commit 6aaa3fe
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 4 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
--------
Expand Down
2 changes: 1 addition & 1 deletion VERSION.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.8.0
v0.9.0
12 changes: 11 additions & 1 deletion lib/helper/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/structs/configuraton-structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 13 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -787,14 +795,17 @@ 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,
AccountTypeID: car.AccountTypeID,
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
Expand Down

0 comments on commit 6aaa3fe

Please sign in to comment.