-
Notifications
You must be signed in to change notification settings - Fork 33
Fix csbs policy Operation Def field type conversion #84
Fix csbs policy Operation Def field type conversion #84
Conversation
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.
Pull Request Test Coverage Report for Build 277
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see inline d comments
RetentionDurationDays int `json:"retention_duration_days"` | ||
Permanent bool `json:"permanent"` | ||
} | ||
err := json.Unmarshal(b, &s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if I don't miss anything, the struct s
and method json.Unmarshal
are the same. why to call it twice here when error occurring, or what issue are you going to fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The context is that Huawei Cloud API response for create backup policy has max_backups
, retention_duration_days
, permanent
as string type but get and list api response has them as int and bool. Also other clouds like OTC, Telefonica, Orange have return type as string for mentioned parameters. First unmarshal call tries to unmarshal for string type but if it fails, then we check for UnmarshalTypeError (which occurs if type conversion is not possible) and the we try to unmarshal again in a struct which has them as int and bool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@freesky-edward this solution is similar to #85
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Savasw ok, it's ok to me as a temporary solution. thanks for your update
What this PR does / why we need it: In HW Cloud, CSBS Get and List Policy Operation Def resp doesn't require type conversion, contrary to other clouds, so this PR handles that.
Which issue this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close that issue when PR gets merged): fixes #Special notes for your reviewer:
Release note: