| 110 | } |
| 111 | |
| 112 | func (role *roleImpl) initRole(name string, channels base.Set, collections map[string]map[string]struct{}) error { |
| 113 | role.Name_ = name |
| 114 | // Grant the user the specified channels for all specified collections. If none are |
| 115 | // specified, grant to the default collection. |
| 116 | if len(collections) == 0 { |
| 117 | if err := role.initChannels(base.DefaultScope, base.DefaultCollection, channels); err != nil { |
| 118 | return err |
| 119 | } |
| 120 | } else { |
| 121 | for scopeName, scope := range collections { |
| 122 | for collectionName, _ := range scope { |
| 123 | if err := role.initChannels(scopeName, collectionName, channels); err != nil { |
| 124 | return err |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | return role.validate() |
| 130 | } |
| 131 | |
| 132 | // IsValidPrincipalName checks if the given user/role name would be valid. Valid names must be valid UTF-8, containing |
| 133 | // at least one alphanumeric (except for the guest user), and no colons, commas, backticks, or slashes. |