Skip to content

Commit 2ebefb6

Browse files
authored
fix authentication by only setting user supplied fields (#127)
The code currently sets all fields even if the user supplied them or not. This results in the fields being set to the empty string value which isn't valid for some of them. This makes it very hard to authenticate. fixes #126 Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
1 parent 3e9c771 commit 2ebefb6

File tree

2 files changed

+13
-33
lines changed

2 files changed

+13
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- All remaining config parameters that are supported via [terraform-provider-openstack](https://registry.terraform.io/providers/terraform-provider-openstack)
13+
- Made it easier to configure authentication by not requiring so many fields.
1314

1415
### Changed
1516

internal/clients/openstack.go

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,39 +67,18 @@ func TerraformSetupBuilder(version, providerSource, providerVersion string) terr
6767
// https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs
6868
// Exceptions:
6969
// "cloud" is not used, because we dont support giving a clouds.yaml directly to the provider.
70-
ps.Configuration = map[string]any{
71-
"auth_url": creds["auth_url"],
72-
"region": creds["region"],
73-
"user_name": creds["user_name"],
74-
"user_id": creds["user_id"],
75-
"application_credential_id": creds["application_credential_id"],
76-
"application_credential_name": creds["application_credential_name"],
77-
"application_credential_secret": creds["application_credential_secret"],
78-
"tenant_id": creds["tenant_id"],
79-
"tenant_name": creds["tenant_name"],
80-
"password": creds["password"],
81-
"token": creds["token"],
82-
"user_domain_name": creds["user_domain_name"],
83-
"user_domain_id": creds["user_domain_id"],
84-
"project_domain_name": creds["project_domain_name"],
85-
"project_domain_id": creds["project_domain_id"],
86-
"domain_id": creds["domain_id"],
87-
"domain_name": creds["domain_name"],
88-
"default_domain": creds["default_domain"],
89-
"system_scope": creds["system_scope"],
90-
"insecure": creds["insecure"],
91-
"cacert_file": creds["cacert_file"],
92-
"cert": creds["cert"],
93-
"key": creds["key"],
94-
"endpoint_type": creds["endpoint_type"],
95-
"endpoint_overrides": creds["endpoint_overrides"],
96-
"swauth": creds["swauth"],
97-
"use_octavia": creds["use_octavia"],
98-
"disable_no_cache_header": creds["disable_no_cache_header"],
99-
"delayed_auth": creds["delayed_auth"],
100-
"allow_reauth": creds["allow_reauth"],
101-
"max_retries": creds["max_retries"],
102-
"enable_logging": creds["enable_logging"],
70+
credFields := []string{"auth_url", "region", "user_name", "user_id", "application_credential_id", "application_credential_name", "application_credential_secret",
71+
"tenant_id", "tenant_name", "password", "token", "user_domain_name", "user_domain_id", "project_domain_name", "project_domain_id", "domain_id", "domain_name",
72+
"default_domain", "system_scope", "insecure", "cacert_file", "cert", "key", "endpoint_type", "endpoint_overrides", "swauth", "use_octavia", "disable_no_cache_header",
73+
"delayed_auth", "allow_reauth", "max_retries", "enable_logging"}
74+
75+
ps.Configuration = map[string]any{}
76+
77+
// ensures only the provided fields are set in the config
78+
for _, credField := range credFields {
79+
if v, ok := creds[credField]; ok {
80+
ps.Configuration[credField] = v
81+
}
10382
}
10483
return ps, nil
10584
}

0 commit comments

Comments
 (0)