@@ -9,10 +9,11 @@ import (
9
9
)
10
10
11
11
const (
12
- contextConfig = "config"
13
- contextSecret = "secret"
14
- contextYaml = "yaml"
15
- contextSecretYaml = "secret-yaml"
12
+ contextConfig = "config"
13
+ contextSecret = "secret"
14
+ contextYaml = "yaml"
15
+ contextSecretYaml = "secret-yaml"
16
+ contextGoogleStorage = "storage.gc"
16
17
)
17
18
18
19
var supportedContextType = []string {
@@ -135,6 +136,43 @@ func resourceContext() *schema.Resource {
135
136
},
136
137
},
137
138
},
139
+ normalizeFieldName (contextGoogleStorage ): {
140
+ Type : schema .TypeList ,
141
+ Optional : true ,
142
+ ForceNew : true ,
143
+ MaxItems : 1 ,
144
+ ConflictsWith : getConflictingContexts (contextGoogleStorage ),
145
+ Elem : & schema.Resource {
146
+ Schema : map [string ]* schema.Schema {
147
+ "data" : {
148
+ Type : schema .TypeList ,
149
+ Required : true ,
150
+ MaxItems : 1 ,
151
+ Elem : & schema.Resource {
152
+ Schema : map [string ]* schema.Schema {
153
+ "auth" : {
154
+ Type : schema .TypeList ,
155
+ Required : true ,
156
+ MaxItems : 1 ,
157
+ Elem : & schema.Resource {
158
+ Schema : map [string ]* schema.Schema {
159
+ "type" : {
160
+ Type : schema .TypeString ,
161
+ Required : true ,
162
+ },
163
+ "json_config" : {
164
+ Type : schema .TypeMap ,
165
+ Required : true ,
166
+ },
167
+ },
168
+ },
169
+ },
170
+ },
171
+ },
172
+ },
173
+ },
174
+ },
175
+ },
138
176
},
139
177
},
140
178
},
@@ -239,6 +277,8 @@ func flattenContextSpec(spec cfClient.ContextSpec) []interface{} {
239
277
m [normalizeFieldName (currentContextType )] = flattenContextConfig (spec )
240
278
case contextYaml , contextSecretYaml :
241
279
m [normalizeFieldName (currentContextType )] = flattenContextYaml (spec )
280
+ case contextGoogleStorage :
281
+ m [normalizeFieldName (currentContextType )] = flattenStorageContextConfig (spec )
242
282
default :
243
283
log .Printf ("[DEBUG] Invalid context type = %v" , currentContextType )
244
284
return nil
@@ -256,6 +296,40 @@ func flattenContextConfig(spec cfClient.ContextSpec) []interface{} {
256
296
return res
257
297
}
258
298
299
+ func flattenStorageContextConfig (spec cfClient.ContextSpec ) []interface {} {
300
+ //google.[0].data[0].auth[0].[type, json]
301
+
302
+ var res = make ([]interface {}, 0 )
303
+ m := make (map [string ]interface {})
304
+
305
+ dataList := make ([]interface {}, 0 )
306
+ data := make (map [string ]interface {})
307
+
308
+ auth := make (map [string ]interface {})
309
+ auth ["json_config" ] = spec .Data ["auth" ].(map [string ]interface {})["jsonConfig" ]
310
+ auth ["type" ] = spec .Data ["type" ]
311
+
312
+ authList := make ([]interface {}, 0 )
313
+ authList = append (authList , auth )
314
+
315
+ data ["auth" ] = authList
316
+
317
+ dataList = append (dataList , data )
318
+
319
+ m ["data" ] = dataList
320
+ res = append (res , m )
321
+ return res
322
+
323
+ //contextData := context[0].(map[string]interface{})
324
+ //contextAuth := contextData["auth"].([]interface{})[0].(map[string]interface{})
325
+ //data := make(map[string]interface{})
326
+ //auth := make(map[string]interface{})
327
+ //auth["type"] = contextAuth["type"]
328
+ //auth["jsonConfig"] = contextAuth["json_config"]
329
+ //data["auth"] = auth
330
+ //return data
331
+ }
332
+
259
333
func flattenContextYaml (spec cfClient.ContextSpec ) []interface {} {
260
334
var res = make ([]interface {}, 0 )
261
335
m := make (map [string ]interface {})
@@ -268,11 +342,25 @@ func flattenContextYaml(spec cfClient.ContextSpec) []interface{} {
268
342
return res
269
343
}
270
344
345
+ func convertStorageContext (context []interface {}) map [string ]interface {} {
346
+ contextData := context [0 ].(map [string ]interface {})
347
+ contextAuth := contextData ["auth" ].([]interface {})[0 ].(map [string ]interface {})
348
+ data := make (map [string ]interface {})
349
+ auth := make (map [string ]interface {})
350
+ auth ["type" ] = contextAuth ["type" ]
351
+ auth ["jsonConfig" ] = contextAuth ["json_config" ]
352
+ data ["auth" ] = auth
353
+ return data
354
+ }
355
+
271
356
func mapResourceToContext (d * schema.ResourceData ) * cfClient.Context {
272
357
273
358
var normalizedContextType string
274
359
var normalizedContextData map [string ]interface {}
275
360
361
+ spec := d .Get ("spec" )
362
+ log .Println (spec )
363
+
276
364
if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextConfig ) + ".0.data" ); ok {
277
365
normalizedContextType = contextConfig
278
366
normalizedContextData = data .(map [string ]interface {})
@@ -285,6 +373,9 @@ func mapResourceToContext(d *schema.ResourceData) *cfClient.Context {
285
373
} else if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextSecretYaml ) + ".0.data" ); ok {
286
374
normalizedContextType = contextSecretYaml
287
375
yaml .Unmarshal ([]byte (data .(string )), & normalizedContextData )
376
+ } else if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextGoogleStorage ) + ".0.data" ); ok {
377
+ normalizedContextType = contextGoogleStorage
378
+ normalizedContextData = convertStorageContext (data .([]interface {}))
288
379
}
289
380
290
381
context := & cfClient.Context {
0 commit comments