mirror of
https://github.com/minio/minio.git
synced 2025-11-25 03:56:17 -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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user