Skip to content

Commit e62dd8b

Browse files
add azure support
1 parent dec8208 commit e62dd8b

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

codefresh/context/storage.go

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,39 @@ import (
55
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
66
)
77

8-
func ConvertStorageContext(context []interface{}) map[string]interface{} {
8+
func convertStorageContext(context []interface{}, auth map[string]interface{}) map[string]interface{} {
9+
data := make(map[string]interface{})
10+
data["auth"] = auth
11+
return data
12+
}
13+
14+
func ConvertJsonConfigStorageContext(context []interface{}) map[string]interface{} {
915
contextData := context[0].(map[string]interface{})
1016
contextAuth := contextData["auth"].([]interface{})[0].(map[string]interface{})
11-
data := make(map[string]interface{})
1217
auth := make(map[string]interface{})
1318
auth["type"] = contextAuth["type"]
1419
auth["jsonConfig"] = contextAuth["json_config"]
15-
data["auth"] = auth
16-
return data
20+
return convertStorageContext(context, auth)
21+
}
22+
23+
func ConvertAzureStorageContext(context []interface{}) map[string]interface{} {
24+
contextData := context[0].(map[string]interface{})
25+
contextAuth := contextData["auth"].([]interface{})[0].(map[string]interface{})
26+
auth := make(map[string]interface{})
27+
auth["type"] = contextAuth["type"]
28+
auth["account_name"] = contextAuth["account_name"]
29+
auth["account_key"] = contextAuth["account_key"]
30+
return convertStorageContext(context, auth)
1731
}
1832

19-
func FlattenStorageContextConfig(spec cfClient.ContextSpec) []interface{} {
33+
func flattenStorageContextConfig(spec cfClient.ContextSpec, auth map[string]interface{}) []interface{} {
2034

2135
var res = make([]interface{}, 0)
2236
m := make(map[string]interface{})
2337

2438
dataList := make([]interface{}, 0)
2539
data := make(map[string]interface{})
2640

27-
auth := make(map[string]interface{})
28-
auth["json_config"] = spec.Data["auth"].(map[string]interface{})["jsonConfig"]
29-
auth["type"] = spec.Data["type"]
30-
3141
authList := make([]interface{}, 0)
3242
authList = append(authList, auth)
3343

@@ -41,6 +51,22 @@ func FlattenStorageContextConfig(spec cfClient.ContextSpec) []interface{} {
4151

4252
}
4353

54+
func FlattenJsonConfigStorageContextConfig(spec cfClient.ContextSpec) []interface{} {
55+
auth := make(map[string]interface{})
56+
auth["json_config"] = spec.Data["auth"].(map[string]interface{})["jsonConfig"]
57+
auth["type"] = spec.Data["type"]
58+
return flattenStorageContextConfig(spec, auth)
59+
}
60+
61+
func FlattenAzureStorageContextConfig(spec cfClient.ContextSpec) []interface{} {
62+
auth := make(map[string]interface{})
63+
authParams := spec.Data["auth"].(map[string]interface{})
64+
auth["account_name"] = authParams["account_name"]
65+
auth["account_key"] = authParams["account_key"]
66+
auth["type"] = spec.Data["type"]
67+
return flattenStorageContextConfig(spec, auth)
68+
}
69+
4470
func storageSchema(authSchema *schema.Schema) *schema.Schema {
4571
return &schema.Schema{
4672
Type: schema.TypeList,

codefresh/resource_context.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,10 @@ func flattenContextSpec(spec cfClient.ContextSpec) []interface{} {
241241
m[normalizeFieldName(currentContextType)] = flattenContextConfig(spec)
242242
case contextYaml, contextSecretYaml:
243243
m[normalizeFieldName(currentContextType)] = flattenContextYaml(spec)
244-
case contextGoogleStorage, contextS3Storage, contextAzureStorage:
245-
m[normalizeFieldName(currentContextType)] = storageContext.FlattenStorageContextConfig(spec)
244+
case contextGoogleStorage, contextS3Storage:
245+
m[normalizeFieldName(currentContextType)] = storageContext.FlattenJsonConfigStorageContextConfig(spec)
246+
case contextAzureStorage:
247+
m[normalizeFieldName(currentContextType)] = storageContext.FlattenAzureStorageContextConfig(spec)
246248
default:
247249
log.Printf("[DEBUG] Invalid context type = %v", currentContextType)
248250
return nil
@@ -291,13 +293,13 @@ func mapResourceToContext(d *schema.ResourceData) *cfClient.Context {
291293
_ = yaml.Unmarshal([]byte(data.(string)), &normalizedContextData)
292294
} else if data, ok := d.GetOk("spec.0." + normalizeFieldName(contextGoogleStorage) + ".0.data"); ok {
293295
normalizedContextType = contextGoogleStorage
294-
normalizedContextData = storageContext.ConvertStorageContext(data.([]interface{}))
296+
normalizedContextData = storageContext.ConvertJsonConfigStorageContext(data.([]interface{}))
295297
} else if data, ok := d.GetOk("spec.0." + normalizeFieldName(contextS3Storage) + ".0.data"); ok {
296298
normalizedContextType = contextS3Storage
297-
normalizedContextData = storageContext.ConvertStorageContext(data.([]interface{}))
299+
normalizedContextData = storageContext.ConvertJsonConfigStorageContext(data.([]interface{}))
298300
} else if data, ok := d.GetOk("spec.0." + normalizeFieldName(contextAzureStorage) + ".0.data"); ok {
299301
normalizedContextType = contextAzureStorage
300-
normalizedContextData = storageContext.ConvertStorageContext(data.([]interface{}))
302+
normalizedContextData = storageContext.ConvertAzureStorageContext(data.([]interface{}))
301303
}
302304

303305
return &cfClient.Context{

0 commit comments

Comments
 (0)