Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions openstack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ func Authenticate(client *golangsdk.ProviderClient, options golangsdk.AuthOption
case v2:
return v2auth(client, endpoint, authOptions, golangsdk.EndpointOpts{})
case v3:
if authOptions.AgencyDomainName != "" && authOptions.AgencyName != "" {
return v3authWithAgency(client, endpoint, &authOptions, golangsdk.EndpointOpts{})
}
return v3auth(client, endpoint, &authOptions, golangsdk.EndpointOpts{})
default:
// The switch statement must be out of date from the versions list.
Expand All @@ -133,13 +136,11 @@ func Authenticate(client *golangsdk.ProviderClient, options golangsdk.AuthOption
if isAkSkOptions {
if akskAuthOptions.AgencyDomainName != "" && akskAuthOptions.AgencyName != "" {
return authWithAgencyByAKSK(client, endpoint, akskAuthOptions, golangsdk.EndpointOpts{})
} else {
return v3AKSKAuth(client, endpoint, akskAuthOptions, golangsdk.EndpointOpts{})
}
return v3AKSKAuth(client, endpoint, akskAuthOptions, golangsdk.EndpointOpts{})

} else {
return fmt.Errorf("Unrecognized auth options provider: %s", reflect.TypeOf(options))
}
return fmt.Errorf("Unrecognized auth options provider: %s", reflect.TypeOf(options))
}

}
Expand Down Expand Up @@ -219,21 +220,6 @@ func v3auth(client *golangsdk.ProviderClient, endpoint string, opts tokens3.Auth
return err
}

opts1, ok := opts.(*golangsdk.AuthOptions)
if ok && opts1.AgencyDomainName != "" && opts1.AgencyName != "" {
opts2 := golangsdk.AgencyAuthOptions{
TokenID: token.ID,
AgencyName: opts1.AgencyName,
AgencyDomainName: opts1.AgencyDomainName,
DelegatedProject: opts1.DelegatedProject,
}
result = tokens3.Create(v3Client, &opts2)
token, err = result.ExtractToken()
if err != nil {
return err
}
}

project, err := result.ExtractProject()
if err != nil {
return err
Expand Down Expand Up @@ -262,6 +248,27 @@ func v3auth(client *golangsdk.ProviderClient, endpoint string, opts tokens3.Auth
return nil
}

func v3authWithAgency(client *golangsdk.ProviderClient, endpoint string, opts *golangsdk.AuthOptions, eo golangsdk.EndpointOpts) error {
token := opts.TokenID
if token == "" {
err := v3auth(client, endpoint, opts, eo)
if err != nil {
return err
}
token = client.TokenID
client.TokenID = ""
}

opts1 := golangsdk.AgencyAuthOptions{
TokenID: token,
AgencyName: opts.AgencyName,
AgencyDomainName: opts.AgencyDomainName,
DelegatedProject: opts.DelegatedProject,
}

return v3auth(client, endpoint, &opts1, eo)
}

func getEntryByServiceId(entries []tokens3.CatalogEntry, serviceId string) *tokens3.CatalogEntry {
if entries == nil {
return nil
Expand Down