@@ -113,7 +113,7 @@ func (e *env) cloudFromEnv() *Cloud {
113113 cloud := & Cloud {
114114 Cloud : e .GetEnv ("CLOUD" ),
115115 Profile : e .GetEnv ("PROFILE" ),
116- AuthInfo : authInfo {
116+ AuthInfo : AuthInfo {
117117 AuthURL : authOpts .IdentityEndpoint ,
118118 Token : authOpts .TokenID ,
119119 Username : authOpts .Username ,
@@ -176,8 +176,8 @@ type Config struct {
176176// AuthType represents a valid method of authentication: `password`, `token`, `aksk` or `agency`
177177type AuthType string
178178
179- // authInfo represents the auth section of a cloud entry
180- type authInfo struct {
179+ // AuthInfo represents the auth section of a cloud entry
180+ type AuthInfo struct {
181181 // AuthURL is the keystone/identity endpoint URL.
182182 AuthURL string `yaml:"auth_url,omitempty" json:"auth_url,omitempty"`
183183
@@ -259,7 +259,7 @@ type Cloud struct {
259259 Cloud string `yaml:"cloud,omitempty" json:"cloud,omitempty"`
260260 Profile string `yaml:"profile,omitempty" json:"profile,omitempty"`
261261 AuthType AuthType `yaml:"auth_type,omitempty" json:"auth_type,omitempty"`
262- AuthInfo authInfo `yaml:"auth,omitempty" json:"auth,omitempty"`
262+ AuthInfo AuthInfo `yaml:"auth,omitempty" json:"auth,omitempty"`
263263 RegionName string `yaml:"region_name,omitempty" json:"region_name,omitempty"`
264264 Regions []interface {} `yaml:"regions,omitempty" json:"regions,omitempty"`
265265
@@ -374,7 +374,7 @@ func selectExisting(files []string) string {
374374 return ""
375375}
376376
377- // mergeClouds merges two Config recursively (the authInfo also gets merged).
377+ // mergeClouds merges two Config recursively (the AuthInfo also gets merged).
378378// In case both Config define a value, the value in the 'override' cloud takes precedence
379379func mergeClouds (cloud , override interface {}) (* Cloud , error ) {
380380 overrideJson , err := json .Marshal (override )
@@ -525,7 +525,7 @@ func (e *env) loadOpenstackConfig() (*Config, error) {
525525 return cloudConfig , nil
526526}
527527
528- func info2opts (authInfo * authInfo , authType AuthType ) (golangsdk.AuthOptionsProvider , error ) {
528+ func AuthOptionsFromInfo (authInfo * AuthInfo , authType AuthType ) (golangsdk.AuthOptionsProvider , error ) {
529529 // project scope
530530 if authInfo .ProjectID != "" || authInfo .ProjectName != "" {
531531 if authInfo .ProjectDomainName != "" {
@@ -599,9 +599,14 @@ func (e *env) AuthenticatedClient() (*golangsdk.ProviderClient, error) {
599599 if err != nil {
600600 return nil , err
601601 }
602- opts , err := info2opts (& cloud .AuthInfo , cloud .AuthType )
602+ return AuthenticatedClientFromCloud (cloud )
603+ }
604+
605+ // AuthenticatedClientFromCloud create new authenticated client for given cloud config
606+ func AuthenticatedClientFromCloud (cloud * Cloud ) (* golangsdk.ProviderClient , error ) {
607+ opts , err := AuthOptionsFromInfo (& cloud .AuthInfo , cloud .AuthType )
603608 if err != nil {
604- return nil , fmt .Errorf ("failed to convert authInfo to AuthOptsBuilder with env vars: %s" , err )
609+ return nil , fmt .Errorf ("failed to convert AuthInfo to AuthOptsBuilder with env vars: %s" , err )
605610 }
606611 client , err := AuthenticatedClient (opts )
607612 if err != nil {
0 commit comments