@@ -239,7 +239,7 @@ func flattenContextSpec(spec cfClient.ContextSpec) []interface{} {
239239 case contextYaml , contextSecretYaml :
240240 m [normalizeFieldName (currentContextType )] = flattenContextYaml (spec )
241241 case contextGoogleStorage :
242- m [normalizeFieldName (currentContextType )] = flattenStorageContextConfig (spec )
242+ m [normalizeFieldName (currentContextType )] = context . FlattenStorageContextConfig (spec )
243243 default :
244244 log .Printf ("[DEBUG] Invalid context type = %v" , currentContextType )
245245 return nil
@@ -257,40 +257,6 @@ func flattenContextConfig(spec cfClient.ContextSpec) []interface{} {
257257 return res
258258}
259259
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-
294260func flattenContextYaml (spec cfClient.ContextSpec ) []interface {} {
295261 var res = make ([]interface {}, 0 )
296262 m := make (map [string ]interface {})
@@ -303,25 +269,11 @@ func flattenContextYaml(spec cfClient.ContextSpec) []interface{} {
303269 return res
304270}
305271
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-
317272func mapResourceToContext (d * schema.ResourceData ) * cfClient.Context {
318273
319274 var normalizedContextType string
320275 var normalizedContextData map [string ]interface {}
321276
322- spec := d .Get ("spec" )
323- log .Println (spec )
324-
325277 if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextConfig ) + ".0.data" ); ok {
326278 normalizedContextType = contextConfig
327279 normalizedContextData = data .(map [string ]interface {})
@@ -330,16 +282,16 @@ func mapResourceToContext(d *schema.ResourceData) *cfClient.Context {
330282 normalizedContextData = data .(map [string ]interface {})
331283 } else if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextYaml ) + ".0.data" ); ok {
332284 normalizedContextType = contextYaml
333- yaml .Unmarshal ([]byte (data .(string )), & normalizedContextData )
285+ _ = yaml .Unmarshal ([]byte (data .(string )), & normalizedContextData )
334286 } else if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextSecretYaml ) + ".0.data" ); ok {
335287 normalizedContextType = contextSecretYaml
336- yaml .Unmarshal ([]byte (data .(string )), & normalizedContextData )
288+ _ = yaml .Unmarshal ([]byte (data .(string )), & normalizedContextData )
337289 } else if data , ok := d .GetOk ("spec.0." + normalizeFieldName (contextGoogleStorage ) + ".0.data" ); ok {
338290 normalizedContextType = contextGoogleStorage
339- normalizedContextData = convertStorageContext (data .([]interface {}))
291+ normalizedContextData = context . ConvertStorageContext (data .([]interface {}))
340292 }
341293
342- context := & cfClient.Context {
294+ return & cfClient.Context {
343295 Metadata : cfClient.ContextMetadata {
344296 Name : d .Get ("name" ).(string ),
345297 },
@@ -348,6 +300,4 @@ func mapResourceToContext(d *schema.ResourceData) *cfClient.Context {
348300 Data : normalizedContextData ,
349301 },
350302 }
351-
352- return context
353303}
0 commit comments