mirror of
https://github.com/minio/minio.git
synced 2025-11-20 01:50:24 -05:00
Add more context aware error for policy parsing errors (#8726)
In existing functionality we simply return a generic error such as "MalformedPolicy" which indicates just a generic string "invalid resource" which is not very meaningful when there might be multiple types of errors during policy parsing. This PR ensures that we send these errors back to client to indicate the actual error, brings in two concrete types such as - iampolicy.Error - policy.Error Refer #8202
This commit is contained in:
@@ -18,7 +18,6 @@ package policy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
@@ -78,7 +77,7 @@ func (policy Policy) IsEmpty() bool {
|
||||
// isValid - checks if Policy is valid or not.
|
||||
func (policy Policy) isValid() error {
|
||||
if policy.Version != DefaultVersion && policy.Version != "" {
|
||||
return fmt.Errorf("invalid version '%v'", policy.Version)
|
||||
return Errorf("invalid version '%v'", policy.Version)
|
||||
}
|
||||
|
||||
for _, statement := range policy.Statements {
|
||||
@@ -108,7 +107,7 @@ func (policy Policy) isValid() error {
|
||||
continue
|
||||
}
|
||||
|
||||
return fmt.Errorf("duplicate principal %v, actions %v, resouces %v found in statements %v, %v",
|
||||
return Errorf("duplicate principal %v, actions %v, resouces %v found in statements %v, %v",
|
||||
principals, actions, resources, policy.Statements[i], statement)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user