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"
17
14
"github.com/juju/juju/cloud"
18
15
"github.com/juju/juju/environs"
34
31
// RestrictedConfigAttributes is specified in the EnvironProvider interface.
35
32
func (joyentProvider) RestrictedConfigAttributes() []string {
33
return []string{sdcUrl}
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()
44
if _, ok := attrs["control-dir"]; !ok {
45
uuid, err := utils.NewUUID()
47
return nil, errors.Trace(err)
49
attrs["control-dir"] = fmt.Sprintf("%x", uuid.Raw())
51
return cfg.Apply(attrs)
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 {
78
59
return nil, errors.Trace(err)
61
return p.PrepareForCreateEnvironment(cfg)
81
cfg, err = p.PrepareForCreateEnvironment(cfg)
83
return nil, errors.Trace(err)
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)
87
68
return nil, errors.Trace(err)
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.`
102
83
// verifyCredentials issues a cheap, non-modifying request to Joyent to
103
84
// verify the configured credentials. If verification fails, a user-friendly
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())
127
108
return nil, errors.Errorf("cannot create credentials: %v", err)
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()},