mirror of
https://github.com/minio/minio.git
synced 2025-11-26 20:38:20 -05:00
policy: Do not return an error for invalid value during parsing (#9442)
s3:HardwareInfo was removed recently. Users having that admin action stored in the backend will have an issue starting the server. To fix this, we need to avoid returning an error in Marshal/Unmarshal when they encounter an invalid action and validate only in specific location. Currently the validation is done and in ParseConfig().
This commit is contained in:
@@ -107,6 +107,16 @@ func (actionSet ActionSet) ToSlice() []Action {
|
||||
return actions
|
||||
}
|
||||
|
||||
// ToAdminSlice - returns slice of admin actions from the action set.
|
||||
func (actionSet ActionSet) ToAdminSlice() []AdminAction {
|
||||
actions := []AdminAction{}
|
||||
for action := range actionSet {
|
||||
actions = append(actions, AdminAction(action))
|
||||
}
|
||||
|
||||
return actions
|
||||
}
|
||||
|
||||
// UnmarshalJSON - decodes JSON data to ActionSet.
|
||||
func (actionSet *ActionSet) UnmarshalJSON(data []byte) error {
|
||||
var sset set.StringSet
|
||||
@@ -120,17 +130,32 @@ func (actionSet *ActionSet) UnmarshalJSON(data []byte) error {
|
||||
|
||||
*actionSet = make(ActionSet)
|
||||
for _, s := range sset.ToSlice() {
|
||||
action, err := parseAction(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
actionSet.Add(action)
|
||||
actionSet.Add(Action(s))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateAdmin checks if all actions are valid Admin actions
|
||||
func (actionSet ActionSet) ValidateAdmin() error {
|
||||
for _, action := range actionSet.ToAdminSlice() {
|
||||
if !action.IsValid() {
|
||||
return Errorf("unsupported admin action '%v'", action)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Validate checks if all actions are valid
|
||||
func (actionSet ActionSet) Validate() error {
|
||||
for _, action := range actionSet.ToSlice() {
|
||||
if !action.IsValid() {
|
||||
return Errorf("unsupported action '%v'", action)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewActionSet - creates new action set.
|
||||
func NewActionSet(actions ...Action) ActionSet {
|
||||
actionSet := make(ActionSet)
|
||||
|
||||
Reference in New Issue
Block a user