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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/provider/openstack/credentials.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:
15
15
        "gopkg.in/ini.v1"
16
16
 
17
17
        "github.com/juju/juju/cloud"
 
18
        "github.com/juju/juju/environs"
18
19
)
19
20
 
20
21
const (
21
 
        credAttrTenantName = "tenant-name"
22
 
        credAttrUserName   = "username"
23
 
        credAttrPassword   = "password"
24
 
        credAttrDomainName = "domain-name"
25
 
        credAttrAccessKey  = "access-key"
26
 
        credAttrSecretKey  = "secret-key"
 
22
        CredAttrTenantName = "tenant-name"
 
23
        CredAttrUserName   = "username"
 
24
        CredAttrPassword   = "password"
 
25
        CredAttrDomainName = "domain-name"
 
26
        CredAttrAccessKey  = "access-key"
 
27
        CredAttrSecretKey  = "secret-key"
27
28
)
28
29
 
29
30
type OpenstackCredentials struct{}
33
34
        return map[cloud.AuthType]cloud.CredentialSchema{
34
35
                cloud.UserPassAuthType: {
35
36
                        {
36
 
                                credAttrUserName, cloud.CredentialAttr{Description: "The username to authenticate with."},
 
37
                                CredAttrUserName, cloud.CredentialAttr{Description: "The username to authenticate with."},
37
38
                        }, {
38
 
                                credAttrPassword, cloud.CredentialAttr{
 
39
                                CredAttrPassword, cloud.CredentialAttr{
39
40
                                        Description: "The password for the specified username.",
40
41
                                        Hidden:      true,
41
42
                                },
42
43
                        }, {
43
 
                                credAttrTenantName, cloud.CredentialAttr{Description: "The OpenStack tenant name."},
 
44
                                CredAttrTenantName, cloud.CredentialAttr{Description: "The OpenStack tenant name."},
44
45
                        }, {
45
 
                                credAttrDomainName, cloud.CredentialAttr{
 
46
                                CredAttrDomainName, cloud.CredentialAttr{
46
47
                                        Description: "The OpenStack domain name.",
47
48
                                        Optional:    true,
48
49
                                },
50
51
                },
51
52
                cloud.AccessKeyAuthType: {
52
53
                        {
53
 
                                credAttrAccessKey, cloud.CredentialAttr{Description: "The access key to authenticate with."},
 
54
                                CredAttrAccessKey, cloud.CredentialAttr{Description: "The access key to authenticate with."},
54
55
                        }, {
55
 
                                credAttrSecretKey, cloud.CredentialAttr{
 
56
                                CredAttrSecretKey, cloud.CredentialAttr{
56
57
                                        Description: "The secret key to authenticate with.",
57
58
                                        Hidden:      true,
58
59
                                },
59
60
                        }, {
60
 
                                credAttrTenantName, cloud.CredentialAttr{Description: "The OpenStack tenant name."},
 
61
                                CredAttrTenantName, cloud.CredentialAttr{Description: "The OpenStack tenant name."},
61
62
                        },
62
63
                },
63
64
        }
125
126
                credential = cloud.NewCredential(
126
127
                        cloud.UserPassAuthType,
127
128
                        map[string]string{
128
 
                                credAttrUserName:   creds.User,
129
 
                                credAttrPassword:   creds.Secrets,
130
 
                                credAttrTenantName: creds.TenantName,
131
 
                                credAttrDomainName: creds.DomainName,
 
129
                                CredAttrUserName:   creds.User,
 
130
                                CredAttrPassword:   creds.Secrets,
 
131
                                CredAttrTenantName: creds.TenantName,
 
132
                                CredAttrDomainName: creds.DomainName,
132
133
                        },
133
134
                )
134
135
        } else {
135
136
                credential = cloud.NewCredential(
136
137
                        cloud.AccessKeyAuthType,
137
138
                        map[string]string{
138
 
                                credAttrAccessKey:  creds.User,
139
 
                                credAttrSecretKey:  creds.Secrets,
140
 
                                credAttrTenantName: creds.TenantName,
 
139
                                CredAttrAccessKey:  creds.User,
 
140
                                CredAttrSecretKey:  creds.Secrets,
 
141
                                CredAttrTenantName: creds.TenantName,
141
142
                        },
142
143
                )
143
144
        }
148
149
        credential.Label = fmt.Sprintf("openstack region %q project %q user %q", region, creds.TenantName, user)
149
150
        return &credential, user, creds.Region, nil
150
151
}
 
152
 
 
153
// FinalizeCredential is part of the environs.ProviderCredentials interface.
 
154
func (OpenstackCredentials) FinalizeCredential(_ environs.FinalizeCredentialContext, args environs.FinalizeCredentialParams) (*cloud.Credential, error) {
 
155
        return &args.Credential, nil
 
156
}