RequireClient checks that context contains the required rights for the given client ID.
(ctx context.Context, id *ttnpb.ClientIdentifiers, required ...ttnpb.Right)
| 144 | // RequireClient checks that context contains the required rights for the |
| 145 | // given client ID. |
| 146 | func RequireClient(ctx context.Context, id *ttnpb.ClientIdentifiers, required ...ttnpb.Right) (err error) { |
| 147 | uid := unique.ID(ctx, id) |
| 148 | rights, err := ListClient(ctx, id) |
| 149 | if err != nil { |
| 150 | return err |
| 151 | } |
| 152 | if len(rights.GetRights()) == 0 { |
| 153 | return ErrNoClientRights.WithAttributes("uid", uid) |
| 154 | } |
| 155 | missing := ttnpb.RightsFrom(required...).Sub(rights).GetRights() |
| 156 | if len(missing) > 0 { |
| 157 | return ErrInsufficientClientRights.WithAttributes("uid", uid, "missing", rightsNames(missing...)) |
| 158 | } |
| 159 | return nil |
| 160 | } |
| 161 | |
| 162 | // RequireGateway checks that context contains the required rights for the |
| 163 | // given gateway ID. |