Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
9 changes: 6 additions & 3 deletions pkg/cli/cmd_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
37 changes: 20 additions & 17 deletions pkg/commands/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down