Skip to content

Commit

Permalink
creds fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Fumigatus committed Dec 13, 2024
1 parent a29bea0 commit 5808ee0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/providerconfig/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ stringData:
credentials: |
{
"url": "https://api.mgmt.cloud.vmware.com",
"refresh_token": ""
"refresh_token": "",
}
36 changes: 12 additions & 24 deletions internal/clients/vra.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ const (
errUnmarshalCredentials = "cannot unmarshal vRA credentials as JSON"
)

const (
keyURL = "url"
keyRefreshToken = "refresh_token"
)
var reqFields = []string{"url", "refresh_token"}
var optFields = []string{"insecure"}

// TerraformSetupBuilder builds Terraform a terraform.SetupFn function which
// returns Terraform provider setup configuration
Expand Down Expand Up @@ -63,31 +61,21 @@ func TerraformSetupBuilder(version, providerSource, providerVersion string) terr
return ps, errors.Wrap(err, errExtractCredentials)
}

// Configuration is a map of provider configuration values.
vraCreds := map[string]string{}
if err := json.Unmarshal(data, &vraCreds); err != nil {
creds := map[string]string{}
if err := json.Unmarshal(data, &creds); err != nil {
return ps, errors.Wrap(err, errUnmarshalCredentials)
}

ps.Configuration = map[string]interface{}{}
if v, ok := vraCreds[keyURL]; ok {
ps.Configuration[keyURL] = v
// Required fields
for _, req := range reqFields {
ps.Configuration[req] = creds[req]
}
if v, ok := vraCreds[keyRefreshToken]; ok {
ps.Configuration[keyRefreshToken] = v
// Optional fields
for _, opt := range optFields {
if v, ok := creds[opt]; ok {
ps.Configuration[opt] = v
}
}

// Set credentials in Terraform provider environment.
/*ps.Env = []string{
fmt.Sprintf("%s=%s", envURL, vraCreds[keyURL]),
fmt.Sprintf("%s=%s", envRefreshToken, vraCreds[keyRefreshToken]),
}*/

// Set credentials in Terraform provider configuration.
/*ps.Configuration = map[string]any{
"username": creds["username"],
"password": creds["password"],
}*/
return ps, nil
}
}

0 comments on commit 5808ee0

Please sign in to comment.