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:
Anis Elleuch
2020-05-10 18:55:28 +01:00
committed by GitHub
parent b5ed42c845
commit 52a1d248b2
12 changed files with 116 additions and 684 deletions

View File

@@ -103,21 +103,9 @@ func (iamp Policy) isValid() error {
return err
}
}
return nil
}
// MarshalJSON - encodes Policy to JSON data.
func (iamp Policy) MarshalJSON() ([]byte, error) {
if err := iamp.isValid(); err != nil {
return nil, err
}
// subtype to avoid recursive call to MarshalJSON()
type subPolicy Policy
return json.Marshal(subPolicy(iamp))
}
func (iamp *Policy) dropDuplicateStatements() {
redo:
for i := range iamp.Statements {
@@ -153,30 +141,14 @@ func (iamp *Policy) UnmarshalJSON(data []byte) error {
}
p := Policy(sp)
if err := p.isValid(); err != nil {
return err
}
p.dropDuplicateStatements()
*iamp = p
return nil
}
// Validate - validates all statements are for given bucket or not.
func (iamp Policy) Validate() error {
if err := iamp.isValid(); err != nil {
return err
}
for _, statement := range iamp.Statements {
if err := statement.Validate(); err != nil {
return err
}
}
return nil
return iamp.isValid()
}
// ParseConfig - parses data in given reader to Iamp.