From 752dabd45602b79878f00e530cdb0815f5ab567b Mon Sep 17 00:00:00 2001 From: Sapan Date: Mon, 12 Nov 2018 17:32:10 +0530 Subject: [PATCH] Fix csbs policy Operation Def field type conversion In HW Cloud, CSBS Get and List Policy Operation Def resp doesn't require type conversion, contrary to other clouds, so this commit handles that. --- openstack/csbs/v1/policies/results.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/openstack/csbs/v1/policies/results.go b/openstack/csbs/v1/policies/results.go index 31598336a..d679f0e1f 100644 --- a/openstack/csbs/v1/policies/results.go +++ b/openstack/csbs/v1/policies/results.go @@ -100,9 +100,31 @@ func (r *OperationDefinitionResp) UnmarshalJSON(b []byte) error { RetentionDurationDays string `json:"retention_duration_days"` Permanent string `json:"permanent"` } + err := json.Unmarshal(b, &s) + if err != nil { - return err + switch err.(type) { + case *json.UnmarshalTypeError: //check if type error occurred (handles if no type conversion is required for cloud like Huawei) + + var s struct { + tmp + MaxBackups int `json:"max_backups"` + RetentionDurationDays int `json:"retention_duration_days"` + Permanent bool `json:"permanent"` + } + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + *r = OperationDefinitionResp(s.tmp) + r.MaxBackups = s.MaxBackups + r.RetentionDurationDays = s.RetentionDurationDays + r.Permanent = s.Permanent + return nil + default: + return err + } } *r = OperationDefinitionResp(s.tmp)