Skip to content

Commit

Permalink
US65433: workspaceID changes in case of glp
Browse files Browse the repository at this point in the history
  • Loading branch information
mahesh-hpe committed Aug 1, 2024
1 parent 91d4f78 commit 931cf2f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
21 changes: 13 additions & 8 deletions internal/acceptance_test/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ func getAPIClient() (*api_client.APIClient, api_client.Configuration) {
headers["Authorization"] = os.Getenv("HPEGL_IAM_TOKEN")
headers["subject"] = os.Getenv(constants.CmpSubjectKey)
}

iamVersion := utils.GetEnv("HPEGL_IAM_VERSION", constants.IamGlcs)
queryParam := map[string]string{
constants.LocationKey: os.Getenv("HPEGL_VMAAS_LOCATION"),
}
if iamVersion == constants.IamGlp {
queryParam[constants.WorkspaceKey] = os.Getenv("HPEGL_VMAAS_SPACE_NAME")
} else {
queryParam[constants.SpaceKey] = os.Getenv("HPEGL_VMAAS_SPACE_NAME")
}
cfg := api_client.Configuration{
Host: os.Getenv("HPEGL_VMAAS_API_URL"),
DefaultHeader: headers,
DefaultQueryParams: map[string]string{
constants.LocationKey: os.Getenv("HPEGL_VMAAS_LOCATION"),
constants.SpaceKey: os.Getenv("HPEGL_VMAAS_SPACE_NAME"),
},
Host: os.Getenv("HPEGL_VMAAS_API_URL"),
DefaultHeader: headers,
DefaultQueryParams: queryParam,
}
apiClient := api_client.NewAPIClient(&cfg)
err := apiClient.SetMeta(nil, func(ctx *context.Context, meta interface{}) {
Expand All @@ -41,7 +46,7 @@ func getAPIClient() (*api_client.APIClient, api_client.Configuration) {
"user_secret": os.Getenv("HPEGL_USER_SECRET"),
"api_vended_service_client": true,
"iam_token": os.Getenv("HPEGL_IAM_TOKEN"),
"iam_version": utils.GetEnv("HPEGL_IAM_VERSION", "glcs"),
"iam_version": iamVersion,
},
}
if utils.GetEnvBool(constants.MockIAMKey) {
Expand Down
20 changes: 13 additions & 7 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (C) Copyright 2021 Hewlett Packard Enterprise Development LP
// (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP

package client

Expand Down Expand Up @@ -53,14 +53,20 @@ func (i InitialiseClient) NewClient(r *schema.ResourceData) (interface{}, error)

// Create VMaas Client
client := new(Client)
iamVersion := utils.GetEnv("HPEGL_IAM_VERSION", constants.IamGlcs)
queryParam := map[string]string{
constants.LocationKey: vmaasProviderSettings[constants.LOCATION].(string),
}
if iamVersion == constants.IamGlp {
queryParam[constants.WorkspaceKey] = vmaasProviderSettings[constants.SPACENAME].(string)
} else {
queryParam[constants.SpaceKey] = vmaasProviderSettings[constants.SPACENAME].(string)
}

cfg := api_client.Configuration{
Host: vmaasProviderSettings[constants.APIURL].(string),
DefaultHeader: getHeaders(),
DefaultQueryParams: map[string]string{
constants.SpaceKey: vmaasProviderSettings[constants.SPACENAME].(string),
constants.LocationKey: vmaasProviderSettings[constants.LOCATION].(string),
},
Host: vmaasProviderSettings[constants.APIURL].(string),
DefaultHeader: getHeaders(),
DefaultQueryParams: queryParam,
}
apiClient := api_client.NewAPIClient(&cfg)
utils.SetMeta(apiClient, r)
Expand Down
21 changes: 12 additions & 9 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// (C) Copyright 2021 Hewlett Packard Enterprise Development LP
// (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP

// Package constants - constants that are used in pkg/client and pkg/resources
package constants

const (
// ServiceName - the service mnemonic
ServiceName = "vmaas"
ServiceURL = "https://iac-vmaas.us1.greenlake-hpe.com"
ServiceName = "vmaas"
ServiceURL = "https://iac-vmaas.us1.greenlake-hpe.com"
IamGlp string = "glp"
IamGlcs string = "glcs"

LOCATION = "location"
SPACENAME = "space_name"
APIURL = "api_url"
INSECURE = "allow_insecure"
SpaceKey = "space"
LocationKey = "location"
LOCATION = "location"
SPACENAME = "space_name"
APIURL = "api_url"
INSECURE = "allow_insecure"
SpaceKey = "space"
WorkspaceKey = "workspaceID"
LocationKey = "location"

MockIAMKey = "TF_ACC_MOCK_IAM"
CmpSubjectKey = "TF_ACC_CMP_SUBJECT"
Expand Down

0 comments on commit 931cf2f

Please sign in to comment.