RequireApplication checks that context contains the required rights for the given application ID.
(ctx context.Context, id *ttnpb.ApplicationIdentifiers, required ...ttnpb.Right)
| 126 | // RequireApplication checks that context contains the required rights for the |
| 127 | // given application ID. |
| 128 | func RequireApplication(ctx context.Context, id *ttnpb.ApplicationIdentifiers, required ...ttnpb.Right) error { |
| 129 | uid := unique.ID(ctx, id) |
| 130 | rights, err := ListApplication(ctx, id) |
| 131 | if err != nil { |
| 132 | return err |
| 133 | } |
| 134 | if len(rights.GetRights()) == 0 { |
| 135 | return ErrNoApplicationRights.WithAttributes("uid", uid) |
| 136 | } |
| 137 | missing := ttnpb.RightsFrom(required...).Sub(rights).GetRights() |
| 138 | if len(missing) > 0 { |
| 139 | return ErrInsufficientApplicationRights.WithAttributes("uid", uid, "missing", rightsNames(missing...)) |
| 140 | } |
| 141 | return nil |
| 142 | } |
| 143 | |
| 144 | // RequireClient checks that context contains the required rights for the |
| 145 | // given client ID. |