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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/provider/joyent/provider.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
package joyent
5
5
 
6
6
import (
7
 
        "fmt"
8
 
 
9
7
        "github.com/joyent/gocommon/client"
10
8
        joyenterrors "github.com/joyent/gocommon/errors"
11
9
        "github.com/joyent/gosdc/cloudapi"
12
10
        "github.com/joyent/gosign/auth"
13
11
        "github.com/juju/errors"
14
12
        "github.com/juju/loggo"
15
 
        "github.com/juju/utils"
16
13
 
17
14
        "github.com/juju/juju/cloud"
18
15
        "github.com/juju/juju/environs"
33
30
 
34
31
// RestrictedConfigAttributes is specified in the EnvironProvider interface.
35
32
func (joyentProvider) RestrictedConfigAttributes() []string {
36
 
        return nil
 
33
        return []string{sdcUrl}
37
34
}
38
35
 
39
36
// PrepareForCreateEnvironment is specified in the EnvironProvider interface.
40
37
func (joyentProvider) PrepareForCreateEnvironment(cfg *config.Config) (*config.Config, error) {
41
 
        // Turn an incomplete config into a valid one, if possible.
42
 
        attrs := cfg.UnknownAttrs()
43
 
 
44
 
        if _, ok := attrs["control-dir"]; !ok {
45
 
                uuid, err := utils.NewUUID()
46
 
                if err != nil {
47
 
                        return nil, errors.Trace(err)
48
 
                }
49
 
                attrs["control-dir"] = fmt.Sprintf("%x", uuid.Raw())
50
 
        }
51
 
        return cfg.Apply(attrs)
 
38
        return cfg, nil
52
39
}
53
40
 
54
 
func (p joyentProvider) PrepareForBootstrap(ctx environs.BootstrapContext, args environs.PrepareForBootstrapParams) (environs.Environ, error) {
55
 
        // We don't have a way of passing more than one
56
 
        // API endpoint from clouds.yaml, so we can't
57
 
        // say which Manta URL to use.
58
 
        // Use of Manta is going away. It defaults to
59
 
        // https://us-east.manta.joyent.com, so for now,
60
 
        // if the default value is not correct, it's necessary
61
 
        // to specify the URL in bootstrap config.
 
41
// BootstrapConfig is specified in the EnvironProvider interface.
 
42
func (p joyentProvider) BootstrapConfig(args environs.BootstrapConfigParams) (*config.Config, error) {
62
43
        attrs := map[string]interface{}{}
63
44
        // Add the credential attributes to config.
64
45
        switch authType := args.Credentials.AuthType(); authType {
77
58
        if err != nil {
78
59
                return nil, errors.Trace(err)
79
60
        }
 
61
        return p.PrepareForCreateEnvironment(cfg)
 
62
}
80
63
 
81
 
        cfg, err = p.PrepareForCreateEnvironment(cfg)
82
 
        if err != nil {
83
 
                return nil, errors.Trace(err)
84
 
        }
 
64
// PrepareForBootstrap is specified in the EnvironProvider interface.
 
65
func (p joyentProvider) PrepareForBootstrap(ctx environs.BootstrapContext, cfg *config.Config) (environs.Environ, error) {
85
66
        e, err := p.Open(cfg)
86
67
        if err != nil {
87
68
                return nil, errors.Trace(err)
95
76
}
96
77
 
97
78
const unauthorisedMessage = `
98
 
Please ensure the Manta username and SSH access key you have
99
 
specified are correct. You can create or import an SSH key via
100
 
the "Account Summary" page in the Joyent console.`
 
79
Please ensure the SSH access key you have specified is correct.
 
80
You can create or import an SSH key via the "Account Summary"
 
81
page in the Joyent console.`
101
82
 
102
83
// verifyCredentials issues a cheap, non-modifying request to Joyent to
103
84
// verify the configured credentials. If verification fails, a user-friendly
122
103
}
123
104
 
124
105
func credentials(cfg *environConfig) (*auth.Credentials, error) {
125
 
        authentication, err := auth.NewAuth(cfg.mantaUser(), cfg.privateKey(), cfg.algorithm())
 
106
        authentication, err := auth.NewAuth(cfg.sdcUser(), cfg.privateKey(), cfg.algorithm())
126
107
        if err != nil {
127
108
                return nil, errors.Errorf("cannot create credentials: %v", err)
128
109
        }
129
110
        return &auth.Credentials{
130
111
                UserAuthentication: authentication,
131
 
                MantaKeyId:         cfg.mantaKeyId(),
132
 
                MantaEndpoint:      auth.Endpoint{URL: cfg.mantaUrl()},
133
112
                SdcKeyId:           cfg.sdcKeyId(),
134
113
                SdcEndpoint:        auth.Endpoint{URL: cfg.sdcUrl()},
135
114
        }, nil