Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move config, config-profiles and completions to setup #993

Merged
merged 1 commit into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* No longer show help for sub-commands by default
* Warnings about invalid accounts/roles in config.yaml are now Debug messages #980
* Default ProfileFormat is now the `Friendly` format #992
* `config`, `config-profiles` and `completions` are now sub-commands of `setup` #975

### New Features

Expand Down
14 changes: 7 additions & 7 deletions cmd/aws-sso/completions_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ type CompleteCmd struct {
func (cc *CompleteCmd) Run(ctx *RunContext) error {
var err error

if ctx.Cli.Completions.Source {
if ctx.Cli.Setup.Completions.Source {
err = helper.NewSourceHelper(os.Executable, os.Stdout).
Generate(ctx.Cli.Completions.Shell)
} else if ctx.Cli.Completions.Install {
Generate(ctx.Cli.Setup.Completions.Shell)
} else if ctx.Cli.Setup.Completions.Install {
// install the current auto-complete helper
err = helper.InstallHelper(ctx.Cli.Completions.Shell, ctx.Cli.Completions.ShellScript)
} else if ctx.Cli.Completions.Uninstall {
err = helper.InstallHelper(ctx.Cli.Setup.Completions.Shell, ctx.Cli.Setup.Completions.ShellScript)
} else if ctx.Cli.Setup.Completions.Uninstall {
// uninstall the current auto-complete helper
err = helper.UninstallHelper(ctx.Cli.Completions.Shell, ctx.Cli.Completions.ShellScript)
} else if ctx.Cli.Completions.UninstallPre19 {
err = helper.UninstallHelper(ctx.Cli.Setup.Completions.Shell, ctx.Cli.Setup.Completions.ShellScript)
} else if ctx.Cli.Setup.Completions.UninstallPre19 {
// make sure we haven't installed our new completions first...
if files := hasV19Installed(); len(files) == 0 {
for _, f := range files {
Expand Down
36 changes: 17 additions & 19 deletions cmd/aws-sso/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,22 @@ type CLI struct {
Threads int `kong:"help='Override number of threads for talking to AWS (default: 5)'"`

// Commands
Cache CacheCmd `kong:"cmd,help='Force reload of cached AWS SSO role info and config.yaml'"`
Completions CompleteCmd `kong:"cmd,help='Manage shell completions'"`
Console ConsoleCmd `kong:"cmd,help='Open AWS Console using specificed AWS role/profile'"`
Config ConfigCmd `kong:"cmd,help='Run the configuration wizard'"`
ConfigProfiles ConfigProfilesCmd `kong:"cmd,help='Update ~/.aws/config with AWS SSO profiles from the cache'"`
Credentials CredentialsCmd `kong:"cmd,help='Generate static AWS credentials for use with AWS CLI'"`
Default DefaultCmd `kong:"cmd,hidden,default='1'"` // list command without args
Ecs EcsCmd `kong:"cmd,help='ECS server/client commands'"`
Eval EvalCmd `kong:"cmd,help='Print AWS environment vars for use with eval $(aws-sso eval ...)'"`
Exec ExecCmd `kong:"cmd,help='Execute command using specified IAM role in a new shell'"`
List ListCmd `kong:"cmd,help='List all accounts / roles (default command)'"`
Login LoginCmd `kong:"cmd,help='Login to an AWS Identity Center instance'"`
Logout LogoutCmd `kong:"cmd,help='Logout from an AWS Identity Center instance and invalidate all credentials'"`
ListSSORoles ListSSORolesCmd `kong:"cmd,hidden,help='List AWS SSO Roles (debugging)'"`
Process ProcessCmd `kong:"cmd,help='Generate JSON for credential_process in ~/.aws/config'"`
Tags TagsCmd `kong:"cmd,help='List tags'"`
Time TimeCmd `kong:"cmd,help='Print how much time before current STS Token expires'"`
Version VersionCmd `kong:"cmd,help='Print version and exit'"`
Cache CacheCmd `kong:"cmd,help='Force reload of cached AWS SSO role info and config.yaml'"`
Setup SetupCmd `kong:"cmd,help='Setup Wizard, Completions, etc'"`
Console ConsoleCmd `kong:"cmd,help='Open AWS Console using specificed AWS role/profile'"`
Credentials CredentialsCmd `kong:"cmd,help='Generate static AWS credentials for use with AWS CLI'"`
Default DefaultCmd `kong:"cmd,hidden,default='1'"` // list command without args
Ecs EcsCmd `kong:"cmd,help='ECS server/client commands'"`
Eval EvalCmd `kong:"cmd,help='Print AWS environment vars for use with eval $(aws-sso eval ...)'"`
Exec ExecCmd `kong:"cmd,help='Execute command using specified IAM role in a new shell'"`
List ListCmd `kong:"cmd,help='List all accounts / roles (default command)'"`
Login LoginCmd `kong:"cmd,help='Login to an AWS Identity Center instance'"`
Logout LogoutCmd `kong:"cmd,help='Logout from an AWS Identity Center instance and invalidate all credentials'"`
ListSSORoles ListSSORolesCmd `kong:"cmd,hidden,help='List AWS SSO Roles (debugging)'"`
Process ProcessCmd `kong:"cmd,help='Generate JSON for credential_process in ~/.aws/config'"`
Tags TagsCmd `kong:"cmd,help='List tags'"`
Time TimeCmd `kong:"cmd,help='Print how much time before current STS Token expires'"`
Version VersionCmd `kong:"cmd,help='Print version and exit'"`
}

func main() {
Expand Down Expand Up @@ -177,7 +175,7 @@ func main() {

if _, err := os.Stat(cli.ConfigFile); errors.Is(err, os.ErrNotExist) {
log.Warnf("No config file found! Will now prompt you for a basic config...")
if err = setupWizard(&runCtx, false, false, runCtx.Cli.Config.Advanced); err != nil {
if err = setupWizard(&runCtx, false, false, runCtx.Cli.Setup.Wizard.Advanced); err != nil {
log.Fatalf("%s", err.Error())
}
if ctx.Command() == "config" {
Expand Down
25 changes: 25 additions & 0 deletions cmd/aws-sso/setup_cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

/*
* AWS SSO CLI
* Copyright (c) 2021-2024 Aaron Turner <synfinatic at gmail dot com>
*
* This program is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or with the authors permission any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

type SetupCmd struct {
Completions CompleteCmd `kong:"cmd,help='Manage shell completions'"`
Wizard SetupWizardCmd `kong:"cmd,help='Run the configuration wizard'"`
Profiles SetupProfilesCmd `kong:"cmd,help='Update ~/.aws/config with AWS SSO profiles from the cache'"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ credential_process = {{ $profile.BinaryPath }} -u {{ $profile.Open }} -S "{{ $pr
{{end}}{{end}}{{end}}`
)

type ConfigProfilesCmd struct {
type SetupProfilesCmd struct {
Diff bool `kong:"help='Print a diff of changes to the config file instead of modifying it',xor='action'"`
Force bool `kong:"help='Write a new config file without prompting'"`
Open string `kong:"help='Specify how to open URLs: [clip|exec|open|granted-containers|open-url-in-container]'"`
Print bool `kong:"help='Print profile entries instead of modifying config file',xor='action'"`
AwsConfig string `kong:"help='Path to AWS config file',env='AWS_CONFIG_FILE',default='~/.aws/config'"`
}

func (cc *ConfigProfilesCmd) Run(ctx *RunContext) error {
func (cc *SetupProfilesCmd) Run(ctx *RunContext) error {
var err error
var action url.ConfigProfilesAction

if ctx.Cli.ConfigProfiles.Open != "" {
if action, err = url.NewConfigProfilesAction(ctx.Cli.ConfigProfiles.Open); err != nil {
if ctx.Cli.Setup.Profiles.Open != "" {
if action, err = url.NewConfigProfilesAction(ctx.Cli.Setup.Profiles.Open); err != nil {
return err
}
} else {
Expand All @@ -66,9 +66,9 @@ func (cc *ConfigProfilesCmd) Run(ctx *RunContext) error {
return err
}

if ctx.Cli.ConfigProfiles.Print {
if ctx.Cli.Setup.Profiles.Print {
return awsconfig.PrintAwsConfig(ctx.Settings, urlAction)
}
return awsconfig.UpdateAwsConfig(ctx.Settings, urlAction, ctx.Cli.ConfigProfiles.AwsConfig,
ctx.Cli.ConfigProfiles.Diff, ctx.Cli.ConfigProfiles.Force)
return awsconfig.UpdateAwsConfig(ctx.Settings, urlAction, ctx.Cli.Setup.Profiles.AwsConfig,
ctx.Cli.Setup.Profiles.Diff, ctx.Cli.Setup.Profiles.Force)
}
10 changes: 5 additions & 5 deletions cmd/aws-sso/config_wizard.go → cmd/aws-sso/setup_wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func checkPromptError(err error) {
switch err.Error() {
case "^D":
// https://github.com/synfinatic/aws-sso-cli/issues/531
log.Errorf("Sorry, <Del> not supported")
log.Errorf("sorry, <Del> not supported")
case "^C":
log.Fatalf("User aborted.")
default:
Expand Down Expand Up @@ -170,7 +170,7 @@ func promptStartUrl(defaultValue string) string {
if len(input) > 0 && len(input) < 64 && ssoHostnameRegexp.Match([]byte(input)) {
return nil
}
return fmt.Errorf("Invalid DNS hostname: %s", input)
return fmt.Errorf("invalid DNS hostname: %s", input)
},
Default: defaultValue,
Stdout: &utils.BellSkipper{},
Expand All @@ -191,7 +191,7 @@ func promptStartUrl(defaultValue string) string {
if _, err := net.LookupHost(val); err == nil {
validFQDN = true
} else if err != nil {
log.Errorf("Unable to resolve %s", val)
log.Errorf("unable to resolve %s", val)
}
}
log.Infof("Using %s", val)
Expand Down Expand Up @@ -474,7 +474,7 @@ func promptConsoleDuration(defaultValue int32) int32 {
istr := strings.TrimSpace(input)
x, err := strconv.ParseInt(istr, 10, 64)
if err != nil || x > 720 || x < 15 {
return fmt.Errorf("Value must be a valid integer between 15 and 720")
return fmt.Errorf("value must be a valid integer between 15 and 720")
}
return nil
},
Expand Down Expand Up @@ -784,7 +784,7 @@ func validateInteger(input string) error {
input = strings.TrimSpace(input)
_, err := strconv.ParseInt(input, 10, 64)
if err != nil {
return fmt.Errorf("Value must be a valid integer")
return fmt.Errorf("value must be a valid integer")
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/aws-sso/config_cmd.go → cmd/aws-sso/setup_wizard_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ import (

var ranSetup = false

type ConfigCmd struct {
type SetupWizardCmd struct {
// AddSSO bool `kong:"help='Add a new AWS SSO instance'"`
Advanced bool `kong:"help='Enable advanced configuration'"`
}

func (cc *ConfigCmd) Run(ctx *RunContext) error {
func (cc *SetupWizardCmd) Run(ctx *RunContext) error {
if err := backupConfig(ctx.Cli.ConfigFile); err != nil {
return err
}

return setupWizard(ctx, true, false, ctx.Cli.Config.Advanced) // ctx.Cli.Config.AddSSO)
return setupWizard(ctx, true, false, ctx.Cli.Setup.Wizard.Advanced) // ctx.Cli.Config.AddSSO)
}

func setupWizard(ctx *RunContext, reconfig, addSSO, advanced bool) error {
Expand Down
Loading
Loading