MCPcopy Create free account
hub / github.com/rilldata/rill / RevokeMagicAuthToken

Method RevokeMagicAuthToken

admin/server/magic_tokens.go:227–258  ·  view source on GitHub ↗
(ctx context.Context, req *adminv1.RevokeMagicAuthTokenRequest)

Source from the content-addressed store, hash-verified

225}
226
227func (s *Server) RevokeMagicAuthToken(ctx context.Context, req *adminv1.RevokeMagicAuthTokenRequest) (*adminv1.RevokeMagicAuthTokenResponse, error) {
228 observability.AddRequestAttributes(ctx,
229 attribute.String("args.token_id", req.TokenId),
230 )
231
232 tkn, err := s.admin.DB.FindMagicAuthToken(ctx, req.TokenId, false)
233 if err != nil {
234 return nil, err
235 }
236
237 proj, err := s.admin.DB.FindProject(ctx, tkn.ProjectID)
238 if err != nil {
239 return nil, err
240 }
241
242 claims := auth.GetClaims(ctx)
243 projPerms := claims.ProjectPermissions(ctx, proj.OrganizationID, proj.ID)
244 if !projPerms.ManageMagicAuthTokens {
245 // If they don't have manage permissions, they can only revoke tokens they created themselves.
246 isCreator := tkn.CreatedByUserID != nil && *tkn.CreatedByUserID == claims.OwnerID()
247 if !projPerms.CreateMagicAuthTokens || !isCreator {
248 return nil, status.Error(codes.PermissionDenied, "not allowed to revoke this magic auth token")
249 }
250 }
251
252 err = s.admin.DB.DeleteMagicAuthToken(ctx, tkn.ID)
253 if err != nil {
254 return nil, err
255 }
256
257 return &adminv1.RevokeMagicAuthTokenResponse{}, nil
258}
259
260func (s *Server) magicAuthTokensToPB(tkns []*database.MagicAuthTokenWithUser, org *database.Organization, proj *database.Project) ([]*adminv1.MagicAuthToken, error) {
261 var pbs []*adminv1.MagicAuthToken

Callers

nothing calls this directly

Calls 9

AddRequestAttributesFunction · 0.92
GetClaimsFunction · 0.92
StringMethod · 0.65
FindMagicAuthTokenMethod · 0.65
FindProjectMethod · 0.65
ProjectPermissionsMethod · 0.65
OwnerIDMethod · 0.65
DeleteMagicAuthTokenMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected