Safely access maps in storage transfer (#3185)

<!-- This change is generated by MagicModules. -->
/cc @rileykarson
This commit is contained in:
The Magician 2019-03-06 13:02:01 -08:00 committed by Riley Karson
parent 11bb321219
commit cc1c019166

View File

@ -491,12 +491,23 @@ func expandDates(dates []interface{}) *storagetransfer.Date {
return nil return nil
} }
date := dates[0].([]interface{}) dateElem := dates[0].([]interface{})
return &storagetransfer.Date{ date := &storagetransfer.Date{}
Day: int64(extractFirstMapConfig(date)["day"].(int)),
Month: int64(extractFirstMapConfig(date)["month"].(int)), dateMap := extractFirstMapConfig(dateElem)
Year: int64(extractFirstMapConfig(date)["year"].(int)), if v, ok := dateMap["day"]; ok {
date.Day = int64(v.(int))
} }
if v, ok := dateMap["month"]; ok {
date.Month = int64(v.(int))
}
if v, ok := dateMap["year"]; ok {
date.Year = int64(v.(int))
}
return date
} }
func flattenDate(date *storagetransfer.Date) []map[string]interface{} { func flattenDate(date *storagetransfer.Date) []map[string]interface{} {
@ -514,13 +525,27 @@ func expandTimeOfDays(times []interface{}) *storagetransfer.TimeOfDay {
return nil return nil
} }
time := times[0].([]interface{}) timeElem := times[0].([]interface{})
return &storagetransfer.TimeOfDay{ time := &storagetransfer.TimeOfDay{}
Hours: int64(extractFirstMapConfig(time)["hours"].(int)),
Minutes: int64(extractFirstMapConfig(time)["minutes"].(int)), timeMap := extractFirstMapConfig(timeElem)
Seconds: int64(extractFirstMapConfig(time)["seconds"].(int)), if v, ok := timeMap["hours"]; ok {
Nanos: int64(extractFirstMapConfig(time)["nanos"].(int)), time.Hours = int64(v.(int))
} }
if v, ok := timeMap["minutes"]; ok {
time.Minutes = int64(v.(int))
}
if v, ok := timeMap["seconds"]; ok {
time.Seconds = int64(v.(int))
}
if v, ok := timeMap["nanos"]; ok {
time.Nanos = int64(v.(int))
}
return time
} }
func flattenTimeOfDay(timeOfDay *storagetransfer.TimeOfDay) []map[string]interface{} { func flattenTimeOfDay(timeOfDay *storagetransfer.TimeOfDay) []map[string]interface{} {