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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/provider/rackspace/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:
 
1
// Copyright 2016 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package rackspace
 
5
 
 
6
import (
 
7
        "github.com/juju/juju/cloud"
 
8
        "github.com/juju/juju/provider/openstack"
 
9
)
 
10
 
 
11
// Credentials represents openstack credentials specifically tailored
 
12
// to rackspace.  Mostly this means that they're appropriate for the v2 API, and
 
13
// thus there's no domain name.
 
14
type Credentials struct {
 
15
        openstack.OpenstackCredentials
 
16
}
 
17
 
 
18
// CredentialSchemas is part of the environs.ProviderCredentials interface.
 
19
func (c Credentials) CredentialSchemas() map[cloud.AuthType]cloud.CredentialSchema {
 
20
        m := c.OpenstackCredentials.CredentialSchemas()
 
21
        schema := m[cloud.UserPassAuthType]
 
22
        // remove domain name from attributes.
 
23
        for i, attr := range schema {
 
24
                if attr.Name == openstack.CredAttrDomainName {
 
25
                        m[cloud.UserPassAuthType] = append(schema[:i], schema[i+1:]...)
 
26
                        break
 
27
                }
 
28
        }
 
29
        return m
 
30
}
 
31
 
 
32
// DetectCredentials is part of the environs.ProviderCredentials interface.
 
33
func (c Credentials) DetectCredentials() (*cloud.CloudCredential, error) {
 
34
        result, err := c.OpenstackCredentials.DetectCredentials()
 
35
        if err != nil {
 
36
                return nil, err
 
37
        }
 
38
        // delete domain name from creds, since rackspace doesn't use it, and it
 
39
        // confuses our code.
 
40
        for k, v := range result.AuthCredentials {
 
41
                attr := v.Attributes()
 
42
                if _, ok := attr[openstack.CredAttrDomainName]; ok {
 
43
                        delete(attr, openstack.CredAttrDomainName)
 
44
                        result.AuthCredentials[k] = cloud.NewCredential(v.AuthType(), attr)
 
45
                }
 
46
        }
 
47
        return result, nil
 
48
}