add 'projects/' suffix if this library is used with an older version of the google api library

Signed-off-by: Paco Xu <paco.xu@daocloud.io>
This commit is contained in:
Paco Xu 2021-08-06 11:25:50 +08:00
parent 2d3323d1fb
commit 768d69a423

View File

@ -435,9 +435,15 @@ func CreateGCECloud(config *CloudConfig) (*Cloud, error) {
serviceAlpha.UserAgent = userAgent
if config.APIEndpoint != "" {
service.BasePath = config.APIEndpoint
serviceBeta.BasePath = strings.Replace(config.APIEndpoint, "v1", "beta", -1)
serviceAlpha.BasePath = strings.Replace(config.APIEndpoint, "v1", "alpha", -1)
if strings.HasSuffix(service.BasePath, "/projects/") {
service.BasePath = getProjectsBasePath(config.APIEndpoint)
serviceBeta.BasePath = getProjectsBasePath(strings.Replace(config.APIEndpoint, "v1", "beta", -1))
serviceAlpha.BasePath = getProjectsBasePath(strings.Replace(config.APIEndpoint, "v1", "alpha", -1))
} else {
service.BasePath = config.APIEndpoint
serviceBeta.BasePath = strings.Replace(config.APIEndpoint, "v1", "beta", -1)
serviceAlpha.BasePath = strings.Replace(config.APIEndpoint, "v1", "alpha", -1)
}
}
containerService, err := container.NewService(context.Background(), option.WithTokenSource(config.TokenSource))