Merge pull request #54 in YUNIONIO/onecloud from ~TANGBIN/onecloud:feature/tb-token-endpoint-list to release/2.0.0

* commit 'ea609cdbd1a7b677bbfe58a61a08fbfb7121d277':
  auth token add list endpoints method
This commit is contained in:
李泽玺
2018-08-15 19:52:35 +08:00
4 changed files with 43 additions and 0 deletions
+10
View File
@@ -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
}
+4
View File
@@ -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 {
+25
View File
@@ -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)
+4
View File
@@ -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 {