Skip to content

Commit

Permalink
add meta field for version checking for getters
Browse files Browse the repository at this point in the history
  • Loading branch information
kpcraig committed Oct 2, 2023
1 parent 5a7b660 commit 4b47080
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
46 changes: 25 additions & 21 deletions vault/resource_database_secret_backend_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ func getMSSQLConnectionDetailsFromResponse(d *schema.ResourceData, prefix string
return result, nil
}

func getPostgresConnectionDetailsFromResponse(d *schema.ResourceData, prefix string, resp *api.Secret) map[string]interface{} {
func getPostgresConnectionDetailsFromResponse(d *schema.ResourceData, prefix string, resp *api.Secret, meta interface{}) map[string]interface{} {
result := getConnectionDetailsFromResponseWithDisableEscaping(d, prefix, resp)
details := resp.Data["connection_details"]
data, ok := details.(map[string]interface{})
Expand All @@ -1060,14 +1060,16 @@ func getPostgresConnectionDetailsFromResponse(d *schema.ResourceData, prefix str
}

// cloud specific
if v, ok := data["auth_type"]; ok {
result["auth_type"] = v.(string)
}
if v, ok := d.GetOk(prefix + "service_account_json"); ok {
result["service_account_json"] = v.(string)
} else {
if v, ok := data["service_account_json"]; ok {
if provider.IsAPISupported(meta, provider.VaultVersion115) {
if v, ok := data["auth_type"]; ok {
result["auth_type"] = v.(string)
}
if v, ok := d.GetOk(prefix + "service_account_json"); ok {
result["service_account_json"] = v.(string)
} else {
if v, ok := data["service_account_json"]; ok {
result["service_account_json"] = v.(string)
}
}
}

Expand All @@ -1088,7 +1090,7 @@ func getConnectionDetailsFromResponseWithDisableEscaping(d *schema.ResourceData,
return result
}

func getMySQLConnectionDetailsFromResponse(d *schema.ResourceData, prefix string, resp *api.Secret) map[string]interface{} {
func getMySQLConnectionDetailsFromResponse(d *schema.ResourceData, prefix string, resp *api.Secret, meta interface{}) map[string]interface{} {
result := getConnectionDetailsFromResponseWithUserPass(d, prefix, resp)
details := resp.Data["connection_details"]
data, ok := details.(map[string]interface{})
Expand All @@ -1110,15 +1112,17 @@ func getMySQLConnectionDetailsFromResponse(d *schema.ResourceData, prefix string
}
}

// cloud specific
if v, ok := data["auth_type"]; ok {
result["auth_type"] = v.(string)
}
if v, ok := d.GetOk(prefix + "service_account_json"); ok {
result["service_account_json"] = v.(string)
} else {
if v, ok := data["service_account_json"]; ok {
if provider.IsAPISupported(meta, provider.VaultVersion115) {
// cloud specific
if v, ok := data["auth_type"]; ok {
result["auth_type"] = v.(string)
}
if v, ok := d.GetOk(prefix + "service_account_json"); ok {
result["service_account_json"] = v.(string)
} else {
if v, ok := data["service_account_json"]; ok {
result["service_account_json"] = v.(string)
}
}
}

Expand Down Expand Up @@ -1786,7 +1790,7 @@ func databaseSecretBackendConnectionRead(d *schema.ResourceData, meta interface{
return err
}

result, err := getDBConnectionConfig(d, engine, 0, resp)
result, err := getDBConnectionConfig(d, engine, 0, resp, meta)
if err != nil {
return err
}
Expand Down Expand Up @@ -1842,7 +1846,7 @@ func getDBCommonConfig(d *schema.ResourceData, resp *api.Secret,
}

func getDBConnectionConfig(d *schema.ResourceData, engine *dbEngine, idx int,
resp *api.Secret,
resp *api.Secret, meta interface{},
) (map[string]interface{}, error) {
var result map[string]interface{}

Expand Down Expand Up @@ -1871,7 +1875,7 @@ func getDBConnectionConfig(d *schema.ResourceData, engine *dbEngine, idx int,
}
result = values
case dbEngineMySQL:
result = getMySQLConnectionDetailsFromResponse(d, prefix, resp)
result = getMySQLConnectionDetailsFromResponse(d, prefix, resp, meta)
case dbEngineMySQLRDS:
result = getConnectionDetailsFromResponseWithUserPass(d, prefix, resp)
case dbEngineMySQLAurora:
Expand All @@ -1881,7 +1885,7 @@ func getDBConnectionConfig(d *schema.ResourceData, engine *dbEngine, idx int,
case dbEngineOracle:
result = getConnectionDetailsFromResponseWithUserPass(d, prefix, resp)
case dbEnginePostgres:
result = getPostgresConnectionDetailsFromResponse(d, prefix, resp)
result = getPostgresConnectionDetailsFromResponse(d, prefix, resp, meta)
case dbEngineElasticSearch:
result = getElasticsearchConnectionDetailsFromResponse(d, prefix, resp)
case dbEngineSnowflake:
Expand Down
6 changes: 3 additions & 3 deletions vault/resource_database_secrets_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func databaseSecretsMountRead(d *schema.ResourceData, meta interface{}) error {
store := &dbConfigStore{}
if v, ok := resp.Data["keys"]; ok {
for _, v := range v.([]interface{}) {
if err := readDBEngineConfig(d, client, store, v.(string)); err != nil {
if err := readDBEngineConfig(d, client, store, v.(string), meta); err != nil {
return err
}
}
Expand All @@ -315,7 +315,7 @@ func databaseSecretsMountDelete(d *schema.ResourceData, meta interface{}) error
return mountDelete(d, meta)
}

func readDBEngineConfig(d *schema.ResourceData, client *api.Client, store *dbConfigStore, name string) error {
func readDBEngineConfig(d *schema.ResourceData, client *api.Client, store *dbConfigStore, name string, meta interface{}) error {
root := d.Id()

path := databaseSecretBackendConnectionPath(root, name)
Expand All @@ -336,7 +336,7 @@ func readDBEngineConfig(d *schema.ResourceData, client *api.Client, store *dbCon
}

idx := len(store.Get(engine))
result, err := getDBConnectionConfig(d, engine, idx, resp)
result, err := getDBConnectionConfig(d, engine, idx, resp, meta)
if err != nil {
return err
}
Expand Down

0 comments on commit 4b47080

Please sign in to comment.