~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/cmd/juju/commands/import_sshkeys.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
package commands
5
5
 
6
6
import (
7
 
        "errors"
8
7
        "fmt"
9
8
 
10
9
        "github.com/juju/cmd"
 
10
        "github.com/juju/errors"
11
11
 
12
12
        "github.com/juju/juju/cmd/juju/block"
13
13
        "github.com/juju/juju/cmd/modelcmd"
39
39
 
40
40
Multiple identities may be specified in a space delimited list:
41
41
 
42
 
    juju import-ssh-key rheinlein lp:iasmiov gh:hharrison
 
42
juju import-ssh-key gh:rheinlein lp:iasmiov gh:hharrison
43
43
 
44
44
See also: 
45
45
    add-ssh-key
69
69
 
70
70
// Init implements Command.Init.
71
71
func (c *importKeysCommand) Init(args []string) error {
72
 
        switch len(args) {
73
 
        case 0:
 
72
        if len(args) == 0 {
74
73
                return errors.New("no ssh key id specified")
75
 
        default:
76
 
                c.sshKeyIds = args
 
74
        }
 
75
        c.sshKeyIds = args
 
76
        for _, k := range c.sshKeyIds {
 
77
                if len(k) < 3 {
 
78
                        return errors.NotValidf("%q key ID", k)
 
79
                }
 
80
                switch k[:3] {
 
81
                case "lp:", "gh:":
 
82
                default:
 
83
                        return errors.NewNotSupported(nil,
 
84
                                fmt.Sprintf("prefix in Key ID %q not supported, only lp: and gh: are allowed", k))
 
85
                }
77
86
        }
78
87
        return nil
79
88
}