MCPcopy
hub / github.com/minio/minio-go / UnmarshalJSON

Method UnmarshalJSON

pkg/policy/bucket-policy.go:90–112  ·  view source on GitHub ↗

UnmarshalJSON is a custom json unmarshaler for Principal field, the reason is that Principal can take a json struct represented by User string but it can also take a string.

(data []byte)

Source from the content-addressed store, hash-verified

88// the reason is that Principal can take a json struct represented by
89// User string but it can also take a string.
90func (u *User) UnmarshalJSON(data []byte) error {
91 // Try to unmarshal data in a struct equal to User,
92 // to avoid infinite recursive call of this function
93 type AliasUser User
94 var au AliasUser
95 err := json.Unmarshal(data, &au)
96 if err == nil {
97 *u = User(au)
98 return nil
99 }
100 // Data type is not known, check if it is a json string
101 // which contains a star, which is permitted in the spec
102 var str string
103 err = json.Unmarshal(data, &str)
104 if err == nil {
105 if str != "*" {
106 return errors.New("unrecognized Principal field")
107 }
108 *u = User{AWS: set.CreateStringSet("*")}
109 return nil
110 }
111 return err
112}
113
114// Statement - minio policy statement
115type Statement struct {

Callers

nothing calls this directly

Calls 2

CreateStringSetFunction · 0.92
UserStruct · 0.85

Tested by

no test coverage detected