github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/provider/rackspace/credentials.go (about)

     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 (Credentials) CredentialSchemas() map[cloud.AuthType]cloud.CredentialSchema {
    20  	return map[cloud.AuthType]cloud.CredentialSchema{
    21  		cloud.UserPassAuthType: {
    22  			{
    23  				Name:           openstack.CredAttrUserName,
    24  				CredentialAttr: cloud.CredentialAttr{Description: "The username to authenticate with."},
    25  			}, {
    26  				Name: openstack.CredAttrPassword,
    27  				CredentialAttr: cloud.CredentialAttr{
    28  					Description: "The password for the specified username.",
    29  					Hidden:      true,
    30  				},
    31  			}, {
    32  				Name:           openstack.CredAttrTenantName,
    33  				CredentialAttr: cloud.CredentialAttr{Description: "The OpenStack tenant name."},
    34  			},
    35  		},
    36  	}
    37  }
    38  
    39  // DetectCredentials is part of the environs.ProviderCredentials interface.
    40  func (c Credentials) DetectCredentials() (*cloud.CloudCredential, error) {
    41  	result, err := c.OpenstackCredentials.DetectCredentials()
    42  	if err != nil {
    43  		return nil, err
    44  	}
    45  
    46  	delete(result.AuthCredentials, string(cloud.AccessKeyAuthType))
    47  
    48  	// delete domain name from creds, since rackspace doesn't use it, and it
    49  	// confuses our code.
    50  	for k, v := range result.AuthCredentials {
    51  		attr := v.Attributes()
    52  		delete(attr, openstack.CredAttrDomainName)
    53  		result.AuthCredentials[k] = cloud.NewCredential(v.AuthType(), attr)
    54  	}
    55  	return result, nil
    56  }