ListClient lists the rights for the given client ID in the context.
(ctx context.Context, id *ttnpb.ClientIdentifiers)
| 55 | |
| 56 | // ListClient lists the rights for the given client ID in the context. |
| 57 | func ListClient(ctx context.Context, id *ttnpb.ClientIdentifiers) (rights *ttnpb.Rights, err error) { |
| 58 | uid := unique.ID(ctx, id) |
| 59 | if inCtx, ok := fromContext(ctx); ok { |
| 60 | r, _ := inCtx.ClientRights.GetRights(uid) |
| 61 | return r, nil |
| 62 | } |
| 63 | if inCtx, ok := cacheFromContext(ctx); ok { |
| 64 | if r, ok := inCtx.ClientRights.GetRights(uid); ok { |
| 65 | return r, nil |
| 66 | } |
| 67 | } |
| 68 | defer func() { |
| 69 | if err == nil { |
| 70 | cacheInContext(ctx, func(r *Rights) { r.setClientRights(uid, rights) }) |
| 71 | } |
| 72 | }() |
| 73 | fetcher, ok := fetcherFromContext(ctx) |
| 74 | if !ok { |
| 75 | panic(errNoFetcher) |
| 76 | } |
| 77 | rights, err = fetcher.ClientRights(ctx, id) |
| 78 | if err != nil { |
| 79 | if errors.IsPermissionDenied(err) { |
| 80 | return &ttnpb.Rights{}, nil |
| 81 | } |
| 82 | return nil, err |
| 83 | } |
| 84 | return rights, nil |
| 85 | } |
| 86 | |
| 87 | // ListGateway lists the rights for the given gateway ID in the context. |
| 88 | func ListGateway(ctx context.Context, id *ttnpb.GatewayIdentifiers) (rights *ttnpb.Rights, err error) { |
no test coverage detected