@@ -239,7 +239,7 @@ func flattenContextSpec(spec cfClient.ContextSpec) []interface{} {
239
239
case contextYaml , contextSecretYaml :
240
240
m [normalizeFieldName (currentContextType )] = flattenContextYaml (spec )
241
241
case contextGoogleStorage :
242
- m [normalizeFieldName (currentContextType )] = flattenStorageContextConfig (spec )
242
+ m [normalizeFieldName (currentContextType )] = context . FlattenStorageContextConfig (spec )
243
243
default :
244
244
log .Printf ("[DEBUG] Invalid context type = %v" , currentContextType )
245
245
return nil
@@ -257,40 +257,6 @@ func flattenContextConfig(spec cfClient.ContextSpec) []interface{} {
257
257
return res
258
258
}
259
259
260
- func flattenStorageContextConfig (spec cfClient.ContextSpec ) []interface {} {
261
- //google.[0].data[0].auth[0].[type, json]
262
-
263
- var res = make ([]interface {}, 0 )
264
- m := make (map [string ]interface {})
265
-
266
- dataList := make ([]interface {}, 0 )
267
- data := make (map [string ]interface {})
268
-
269
- auth := make (map [string ]interface {})
270
- auth ["json_config" ] = spec .Data ["auth" ].(map [string ]interface {})["jsonConfig" ]
271
- auth ["type" ] = spec .Data ["type" ]
272
-
273
- authList := make ([]interface {}, 0 )
274
- authList = append (authList , auth )
275
-
276
- data ["auth" ] = authList
277
-
278
- dataList = append (dataList , data )
279
-
280
- m ["data" ] = dataList
281
- res = append (res , m )
282
- return res
283
-
284
- //contextData := context[0].(map[string]interface{})
285
- //contextAuth := contextData["auth"].([]interface{})[0].(map[string]interface{})
286
- //data := make(map[string]interface{})
287
- //auth := make(map[string]interface{})
288
- //auth["type"] = contextAuth["type"]
289
- //auth["jsonConfig"] = contextAuth["json_config"]
290
- //data["auth"] = auth
291
- //return data
292
- }
293
-
294
260
func flattenContextYaml (spec cfClient.ContextSpec ) []interface {} {
295
261
var res = make ([]interface {}, 0 )
296
262
m := make (map [string ]interface {})
@@ -303,25 +269,11 @@ func flattenContextYaml(spec cfClient.ContextSpec) []interface{} {
303
269
return res
304
270
}
305
271
306
- func convertStorageContext (context []interface {}) map [string ]interface {} {
307
- contextData := context [0 ].(map [string ]interface {})
308
- contextAuth := contextData ["auth" ].([]interface {})[0 ].(map [string ]interface {})
309
- data := make (map [string ]interface {})
310
- auth := make (map [string ]interface {})
311
- auth ["type" ] = contextAuth ["type" ]
312
- auth ["jsonConfig" ] = contextAuth ["json_config" ]
313
- data ["auth" ] = auth
314
- return data
315
- }
316
-
317
272
func mapResourceToContext (d * schema.ResourceData ) * cfClient.Context {
318
273
319
274
var normalizedContextType string
320
275
var normalizedContextData map [string ]interface {}
321
276
322
- spec := d .Get ("spec" )
323
- log .Println (spec )
324
-
325
277
if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextConfig ) + ".0.data" ); ok {
326
278
normalizedContextType = contextConfig
327
279
normalizedContextData = data .(map [string ]interface {})
@@ -330,16 +282,16 @@ func mapResourceToContext(d *schema.ResourceData) *cfClient.Context {
330
282
normalizedContextData = data .(map [string ]interface {})
331
283
} else if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextYaml ) + ".0.data" ); ok {
332
284
normalizedContextType = contextYaml
333
- yaml .Unmarshal ([]byte (data .(string )), & normalizedContextData )
285
+ _ = yaml .Unmarshal ([]byte (data .(string )), & normalizedContextData )
334
286
} else if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextSecretYaml ) + ".0.data" ); ok {
335
287
normalizedContextType = contextSecretYaml
336
- yaml .Unmarshal ([]byte (data .(string )), & normalizedContextData )
288
+ _ = yaml .Unmarshal ([]byte (data .(string )), & normalizedContextData )
337
289
} else if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextGoogleStorage ) + ".0.data" ); ok {
338
290
normalizedContextType = contextGoogleStorage
339
- normalizedContextData = convertStorageContext (data .([]interface {}))
291
+ normalizedContextData = context . ConvertStorageContext (data .([]interface {}))
340
292
}
341
293
342
- context := & cfClient.Context {
294
+ return & cfClient.Context {
343
295
Metadata : cfClient.ContextMetadata {
344
296
Name : d .Get ("name" ).(string ),
345
297
},
@@ -348,6 +300,4 @@ func mapResourceToContext(d *schema.ResourceData) *cfClient.Context {
348
300
Data : normalizedContextData ,
349
301
},
350
302
}
351
-
352
- return context
353
303
}
0 commit comments