diff --git a/README.md b/README.md index 18347c22ee..bcbb7dd456 100644 --- a/README.md +++ b/README.md @@ -1089,6 +1089,8 @@ $ scw inspect myserver | jq '.[0].public_ip.address' #### Features * `scw -D login` displays a fake password +* Support --skip-ssh-key `scw login` ([#129](https://github.com/scaleway/scaleway-cli/issues/129)) +* Now `scw login` ask your login/password, you can also pass token and organization with -o and -t ([#59](https://github.com/scaleway/scaleway-cli/issues/59)) * Syncing cache to disk after server creation when running `scw run` in a non-detached mode * Bump to Golang 1.5 * Support --tmp-ssh-key `scw {run,create}` option ([#99](https://github.com/scaleway/scaleway-cli/issues/99)) diff --git a/pkg/cli/cmd_login.go b/pkg/cli/cmd_login.go index 558e2fe60e..035742824f 100644 --- a/pkg/cli/cmd_login.go +++ b/pkg/cli/cmd_login.go @@ -26,12 +26,14 @@ func init() { cmdLogin.Flag.StringVar(&organization, []string{"o", "-organization"}, "", "Organization") cmdLogin.Flag.StringVar(&token, []string{"t", "-token"}, "", "Token") cmdLogin.Flag.BoolVar(&loginHelp, []string{"h", "-help"}, false, "Print usage") + cmdLogin.Flag.BoolVar(&loginSkipSSHKey, []string{"s", "-skip-ssh-key"}, false, "Don't ask to upload an SSH Key") } // FLags -var organization string // -o flag -var token string // -t flag -var loginHelp bool // -h, --help flag +var organization string // -o flag +var token string // -t flag +var loginHelp bool // -h, --help flag +var loginSkipSSHKey bool // -s, --skip-ssh-key flag func runLogin(cmd *Command, rawArgs []string) error { if loginHelp { @@ -46,6 +48,7 @@ func runLogin(cmd *Command, rawArgs []string) error { args := commands.LoginArgs{ Organization: organization, Token: token, + SkipSSHKey: loginSkipSSHKey, } ctx := cmd.GetContext(rawArgs) return commands.RunLogin(ctx, args) diff --git a/pkg/commands/login.go b/pkg/commands/login.go index 7d5edb2c1e..a0b8dce7b4 100644 --- a/pkg/commands/login.go +++ b/pkg/commands/login.go @@ -26,11 +26,12 @@ type LoginArgs struct { Organization string Token string SSHKey string + SkipSSHKey bool } // selectKey allows to choice a key in ~/.ssh func selectKey(args *LoginArgs) error { - fmt.Println("Do you want to upload a SSH key ?") + fmt.Println("Do you want to upload an SSH key ?") home, err := config.GetHomeDir() if err != nil { return err @@ -205,23 +206,25 @@ func RunLogin(ctx CommandContext, args LoginArgs) error { if err != nil { return fmt.Errorf("Unable to contact ScalewayAPI: %s", err) } - if err := selectKey(&args); err != nil { - logrus.Errorf("Unable to select a key: %v", err) - } else { - if args.SSHKey != "" { - userID, err := apiConnection.GetUserID() - if err != nil { - logrus.Errorf("Unable to contact ScalewayAPI: %s", err) - } else { - - SSHKey := api.ScalewayUserPatchSSHKeyDefinition{ - SSHPublicKeys: []api.ScalewayKeyDefinition{{ - Key: strings.Trim(args.SSHKey, "\n"), - }}, - } + if !args.SkipSSHKey { + if err := selectKey(&args); err != nil { + logrus.Errorf("Unable to select a key: %v", err) + } else { + if args.SSHKey != "" { + userID, err := apiConnection.GetUserID() + if err != nil { + logrus.Errorf("Unable to contact ScalewayAPI: %s", err) + } else { + + SSHKey := api.ScalewayUserPatchSSHKeyDefinition{ + SSHPublicKeys: []api.ScalewayKeyDefinition{{ + Key: strings.Trim(args.SSHKey, "\n"), + }}, + } - if err = apiConnection.PatchUserSSHKey(userID, SSHKey); err != nil { - logrus.Errorf("Unable to patch SSHkey: %v", err) + if err = apiConnection.PatchUserSSHKey(userID, SSHKey); err != nil { + logrus.Errorf("Unable to patch SSHkey: %v", err) + } } } }