MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / RequireApplication

Function RequireApplication

pkg/auth/rights/require.go:128–142  ·  view source on GitHub ↗

RequireApplication checks that context contains the required rights for the given application ID.

(ctx context.Context, id *ttnpb.ApplicationIdentifiers, required ...ttnpb.Right)

Source from the content-addressed store, hash-verified

126// RequireApplication checks that context contains the required rights for the
127// given application ID.
128func 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.

Callers 15

ClaimMethod · 0.92
getEndDevicesMethod · 0.92
requireRightsFunction · 0.92
TestRequireFunction · 0.92
GetMethod · 0.92
SetMethod · 0.92
DeleteMethod · 0.92
GetMethod · 0.92
SetMethod · 0.92
ProvisionMethod · 0.92
DeleteMethod · 0.92

Calls 7

IDFunction · 0.92
RightsFromFunction · 0.92
ListApplicationFunction · 0.85
rightsNamesFunction · 0.85
SubMethod · 0.80
GetRightsMethod · 0.45
WithAttributesMethod · 0.45

Tested by 3

requireRightsFunction · 0.74
TestRequireFunction · 0.74