diff --git a/pkg/mcclient/token.go b/pkg/mcclient/token.go index 794df976ad..7a9ba2751b 100644 --- a/pkg/mcclient/token.go +++ b/pkg/mcclient/token.go @@ -11,6 +11,15 @@ type ExternalService struct { Url string } +type Endpoint struct { + Id string + RegionId string + ServiceId string + ServiceName string + Url string + Interface string +} + type TokenCredential interface { gotypes.ISerializable @@ -33,4 +42,5 @@ type TokenCredential interface { GetServiceURL(service, region, zone, endpointType string) (string, error) GetInternalServices(region string) []string GetExternalServices(region string) []ExternalService + GetEndpoints(region string, endpointType string) []Endpoint } diff --git a/pkg/mcclient/token2.go b/pkg/mcclient/token2.go index 9afd072292..d38bd052b9 100644 --- a/pkg/mcclient/token2.go +++ b/pkg/mcclient/token2.go @@ -144,6 +144,10 @@ func (this *TokenCredentialV2) GetExternalServices(region string) []ExternalServ return nil } +func (this *TokenCredentialV2) GetEndpoints(region string, endpointType string) []Endpoint { + return nil +} + func stringArrayContains(arr []string, needle string) bool { for i := 0; i < len(arr); i++ { if arr[i] == needle { diff --git a/pkg/mcclient/token3.go b/pkg/mcclient/token3.go index 69333f8308..f7265da44e 100644 --- a/pkg/mcclient/token3.go +++ b/pkg/mcclient/token3.go @@ -152,6 +152,10 @@ func (this *TokenCredentialV3) GetExternalServices(region string) []ExternalServ return this.Token.Catalog.getExternalServices(region) } +func (this *TokenCredentialV3) GetEndpoints(region string, endpointType string) []Endpoint { + return this.Token.Catalog.getEndpoints(region, endpointType) +} + func (catalog KeystoneServiceCatalogV3) getInternalServices(region string) []string { services := make([]string, 0) for i := 0; i < len(catalog); i++ { @@ -200,6 +204,27 @@ func (catalog KeystoneServiceCatalogV3) getRegions() []string { return regions } +func (catalog KeystoneServiceCatalogV3) getEndpoints(region string, endpointType string) []Endpoint { + endpoints := make([]Endpoint, 0) + for i := 0; i < len(catalog); i++ { + for j := 0; j < len(catalog[i].Endpoints); j++ { + endpoint := catalog[i].Endpoints[j] + if (endpoint.Region_id == region || strings.HasPrefix(endpoint.Region_id, region+"-")) && endpoint.Interface == endpointType { + endpoints = append(endpoints, Endpoint{ + endpoint.Id, + endpoint.Region_id, + catalog[i].Id, + catalog[i].Name, + endpoint.Url, + endpoint.Interface, + }) + } + } + } + + return endpoints +} + func RegionID(region, zone string) string { if len(zone) > 0 { return fmt.Sprintf("%s%c%s", region, REGION_ZONE_SEP, zone) diff --git a/pkg/mcclient/tokensimple.go b/pkg/mcclient/tokensimple.go index 8fbea3a328..2054560440 100644 --- a/pkg/mcclient/tokensimple.go +++ b/pkg/mcclient/tokensimple.go @@ -104,6 +104,10 @@ func (self *SSimpleToken) GetExternalServices(region string) []ExternalService { return nil } +func (this *SSimpleToken) GetEndpoints(region string, endpointType string) []Endpoint { + return nil +} + func SimplifyToken(token TokenCredential) TokenCredential { simToken, ok := token.(*SSimpleToken) if ok {