mirror of
https://github.com/minio/minio.git
synced 2025-11-24 03:27:44 -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 iampolicy
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
@@ -66,7 +65,7 @@ func (r Resource) Match(resource string, conditionValues map[string][]string) bo
|
||||
// MarshalJSON - encodes Resource to JSON data.
|
||||
func (r Resource) MarshalJSON() ([]byte, error) {
|
||||
if !r.IsValid() {
|
||||
return nil, fmt.Errorf("invalid resource %v", r)
|
||||
return nil, Errorf("invalid resource %v", r)
|
||||
}
|
||||
|
||||
return json.Marshal(r.String())
|
||||
@@ -96,7 +95,7 @@ func (r *Resource) UnmarshalJSON(data []byte) error {
|
||||
// Validate - validates Resource is for given bucket or not.
|
||||
func (r Resource) Validate() error {
|
||||
if !r.IsValid() {
|
||||
return fmt.Errorf("invalid resource")
|
||||
return Errorf("invalid resource")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -104,14 +103,14 @@ func (r Resource) Validate() error {
|
||||
// parseResource - parses string to Resource.
|
||||
func parseResource(s string) (Resource, error) {
|
||||
if !strings.HasPrefix(s, ResourceARNPrefix) {
|
||||
return Resource{}, fmt.Errorf("invalid resource '%v'", s)
|
||||
return Resource{}, Errorf("invalid resource '%v'", s)
|
||||
}
|
||||
|
||||
pattern := strings.TrimPrefix(s, ResourceARNPrefix)
|
||||
tokens := strings.SplitN(pattern, "/", 2)
|
||||
bucketName := tokens[0]
|
||||
if bucketName == "" {
|
||||
return Resource{}, fmt.Errorf("invalid resource format '%v'", s)
|
||||
return Resource{}, Errorf("invalid resource format '%v'", s)
|
||||
}
|
||||
|
||||
return Resource{
|
||||
|
||||
Reference in New Issue
Block a user