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)
| 88 | // the reason is that Principal can take a json struct represented by |
| 89 | // User string but it can also take a string. |
| 90 | func (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 |
| 115 | type Statement struct { |
nothing calls this directly
no test coverage detected