Skip to content

Commit dec8208

Browse files
add azure and s3 support
1 parent 0aba843 commit dec8208

File tree

2 files changed

+69
-21
lines changed

2 files changed

+69
-21
lines changed

codefresh/context/storage.go

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func FlattenStorageContextConfig(spec cfClient.ContextSpec) []interface{} {
4141

4242
}
4343

44-
func storageSchema() *schema.Schema {
44+
func storageSchema(authSchema *schema.Schema) *schema.Schema {
4545
return &schema.Schema{
4646
Type: schema.TypeList,
4747
Optional: true,
@@ -55,23 +55,7 @@ func storageSchema() *schema.Schema {
5555
MaxItems: 1,
5656
Elem: &schema.Resource{
5757
Schema: map[string]*schema.Schema{
58-
"auth": {
59-
Type: schema.TypeList,
60-
Required: true,
61-
MaxItems: 1,
62-
Elem: &schema.Resource{
63-
Schema: map[string]*schema.Schema{
64-
"type": {
65-
Type: schema.TypeString,
66-
Required: true,
67-
},
68-
"json_config": {
69-
Type: schema.TypeMap,
70-
Required: true,
71-
},
72-
},
73-
},
74-
},
58+
"auth": authSchema,
7559
},
7660
},
7761
},
@@ -81,9 +65,68 @@ func storageSchema() *schema.Schema {
8165
}
8266

8367
func GcsSchema() *schema.Schema {
84-
return storageSchema()
68+
sch := &schema.Schema{
69+
Type: schema.TypeList,
70+
Required: true,
71+
MaxItems: 1,
72+
Elem: &schema.Resource{
73+
Schema: map[string]*schema.Schema{
74+
"type": {
75+
Type: schema.TypeString,
76+
Required: true,
77+
},
78+
"json_config": {
79+
Type: schema.TypeMap,
80+
Required: true,
81+
},
82+
},
83+
},
84+
}
85+
return storageSchema(sch)
8586
}
8687

8788
func S3Schema() *schema.Schema {
88-
return storageSchema()
89+
sch := &schema.Schema{
90+
Type: schema.TypeList,
91+
Required: true,
92+
MaxItems: 1,
93+
Elem: &schema.Resource{
94+
Schema: map[string]*schema.Schema{
95+
"type": {
96+
Type: schema.TypeString,
97+
Required: true,
98+
},
99+
"json_config": {
100+
Type: schema.TypeMap,
101+
Required: true,
102+
},
103+
},
104+
},
105+
}
106+
return storageSchema(sch)
107+
}
108+
109+
func AzureStorage() *schema.Schema {
110+
sch := &schema.Schema{
111+
Type: schema.TypeList,
112+
Required: true,
113+
MaxItems: 1,
114+
Elem: &schema.Resource{
115+
Schema: map[string]*schema.Schema{
116+
"type": {
117+
Type: schema.TypeString,
118+
Required: true,
119+
},
120+
"account_name": {
121+
Type: schema.TypeString,
122+
Required: true,
123+
},
124+
"account_key": {
125+
Type: schema.TypeString,
126+
Required: true,
127+
},
128+
},
129+
},
130+
}
131+
return storageSchema(sch)
89132
}

codefresh/resource_context.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const (
1616
contextSecretYaml = "secret-yaml"
1717
contextGoogleStorage = "storage.gc"
1818
contextS3Storage = "storage.s3"
19+
contextAzureStorage = "storage.azuref"
1920
)
2021

2122
var supportedContextType = []string{
@@ -140,6 +141,7 @@ func resourceContext() *schema.Resource {
140141
},
141142
normalizeFieldName(contextGoogleStorage): storageContext.GcsSchema(),
142143
normalizeFieldName(contextS3Storage): storageContext.S3Schema(),
144+
normalizeFieldName(contextAzureStorage): storageContext.AzureStorage(),
143145
},
144146
},
145147
},
@@ -239,7 +241,7 @@ func flattenContextSpec(spec cfClient.ContextSpec) []interface{} {
239241
m[normalizeFieldName(currentContextType)] = flattenContextConfig(spec)
240242
case contextYaml, contextSecretYaml:
241243
m[normalizeFieldName(currentContextType)] = flattenContextYaml(spec)
242-
case contextGoogleStorage, contextS3Storage:
244+
case contextGoogleStorage, contextS3Storage, contextAzureStorage:
243245
m[normalizeFieldName(currentContextType)] = storageContext.FlattenStorageContextConfig(spec)
244246
default:
245247
log.Printf("[DEBUG] Invalid context type = %v", currentContextType)
@@ -293,6 +295,9 @@ func mapResourceToContext(d *schema.ResourceData) *cfClient.Context {
293295
} else if data, ok := d.GetOk("spec.0." + normalizeFieldName(contextS3Storage) + ".0.data"); ok {
294296
normalizedContextType = contextS3Storage
295297
normalizedContextData = storageContext.ConvertStorageContext(data.([]interface{}))
298+
} else if data, ok := d.GetOk("spec.0." + normalizeFieldName(contextAzureStorage) + ".0.data"); ok {
299+
normalizedContextType = contextAzureStorage
300+
normalizedContextData = storageContext.ConvertStorageContext(data.([]interface{}))
296301
}
297302

298303
return &cfClient.Context{

0 commit comments

Comments
 (0)