Skip to content

Commit e81c6db

Browse files
committed
Merge pull request #135 from QuentinPerez/skip_ssh_key
skipSSHKey fix #129
2 parents 75a8568 + 33a796f commit e81c6db

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,8 @@ $ scw inspect myserver | jq '.[0].public_ip.address'
10891089
#### Features
10901090

10911091
* `scw -D login` displays a fake password
1092+
* Support --skip-ssh-key `scw login` ([#129](https://github.com/scaleway/scaleway-cli/issues/129))
1093+
* 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))
10921094
* Syncing cache to disk after server creation when running `scw run` in a non-detached mode
10931095
* Bump to Golang 1.5
10941096
* Support --tmp-ssh-key `scw {run,create}` option ([#99](https://github.com/scaleway/scaleway-cli/issues/99))

pkg/cli/cmd_login.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ func init() {
2626
cmdLogin.Flag.StringVar(&organization, []string{"o", "-organization"}, "", "Organization")
2727
cmdLogin.Flag.StringVar(&token, []string{"t", "-token"}, "", "Token")
2828
cmdLogin.Flag.BoolVar(&loginHelp, []string{"h", "-help"}, false, "Print usage")
29+
cmdLogin.Flag.BoolVar(&loginSkipSSHKey, []string{"s", "-skip-ssh-key"}, false, "Don't ask to upload an SSH Key")
2930
}
3031

3132
// FLags
32-
var organization string // -o flag
33-
var token string // -t flag
34-
var loginHelp bool // -h, --help flag
33+
var organization string // -o flag
34+
var token string // -t flag
35+
var loginHelp bool // -h, --help flag
36+
var loginSkipSSHKey bool // -s, --skip-ssh-key flag
3537

3638
func runLogin(cmd *Command, rawArgs []string) error {
3739
if loginHelp {
@@ -46,6 +48,7 @@ func runLogin(cmd *Command, rawArgs []string) error {
4648
args := commands.LoginArgs{
4749
Organization: organization,
4850
Token: token,
51+
SkipSSHKey: loginSkipSSHKey,
4952
}
5053
ctx := cmd.GetContext(rawArgs)
5154
return commands.RunLogin(ctx, args)

pkg/commands/login.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ type LoginArgs struct {
2626
Organization string
2727
Token string
2828
SSHKey string
29+
SkipSSHKey bool
2930
}
3031

3132
// selectKey allows to choice a key in ~/.ssh
3233
func selectKey(args *LoginArgs) error {
33-
fmt.Println("Do you want to upload a SSH key ?")
34+
fmt.Println("Do you want to upload an SSH key ?")
3435
home, err := config.GetHomeDir()
3536
if err != nil {
3637
return err
@@ -205,23 +206,25 @@ func RunLogin(ctx CommandContext, args LoginArgs) error {
205206
if err != nil {
206207
return fmt.Errorf("Unable to contact ScalewayAPI: %s", err)
207208
}
208-
if err := selectKey(&args); err != nil {
209-
logrus.Errorf("Unable to select a key: %v", err)
210-
} else {
211-
if args.SSHKey != "" {
212-
userID, err := apiConnection.GetUserID()
213-
if err != nil {
214-
logrus.Errorf("Unable to contact ScalewayAPI: %s", err)
215-
} else {
216-
217-
SSHKey := api.ScalewayUserPatchSSHKeyDefinition{
218-
SSHPublicKeys: []api.ScalewayKeyDefinition{{
219-
Key: strings.Trim(args.SSHKey, "\n"),
220-
}},
221-
}
209+
if !args.SkipSSHKey {
210+
if err := selectKey(&args); err != nil {
211+
logrus.Errorf("Unable to select a key: %v", err)
212+
} else {
213+
if args.SSHKey != "" {
214+
userID, err := apiConnection.GetUserID()
215+
if err != nil {
216+
logrus.Errorf("Unable to contact ScalewayAPI: %s", err)
217+
} else {
218+
219+
SSHKey := api.ScalewayUserPatchSSHKeyDefinition{
220+
SSHPublicKeys: []api.ScalewayKeyDefinition{{
221+
Key: strings.Trim(args.SSHKey, "\n"),
222+
}},
223+
}
222224

223-
if err = apiConnection.PatchUserSSHKey(userID, SSHKey); err != nil {
224-
logrus.Errorf("Unable to patch SSHkey: %v", err)
225+
if err = apiConnection.PatchUserSSHKey(userID, SSHKey); err != nil {
226+
logrus.Errorf("Unable to patch SSHkey: %v", err)
227+
}
225228
}
226229
}
227230
}

0 commit comments

Comments
 (0)