MCPcopy
hub / github.com/dgraph-io/dgraph / AttachJWTNamespace

Function AttachJWTNamespace

x/x.go:450–464  ·  view source on GitHub ↗

AttachJWTNamespace attaches the namespace in the JWT claims to the context if present, otherwise it attaches the galaxy namespace.

(ctx context.Context)

Source from the content-addressed store, hash-verified

448// AttachJWTNamespace attaches the namespace in the JWT claims to the context if present, otherwise
449// it attaches the galaxy namespace.
450func AttachJWTNamespace(ctx context.Context) context.Context {
451 if !WorkerConfig.AclEnabled {
452 return AttachNamespace(ctx, RootNamespace)
453 }
454
455 ns, err := ExtractNamespaceFrom(ctx)
456 if err == nil {
457 // Attach the namespace only if we got one from JWT.
458 // This preserves any namespace directly present in the context which is needed for
459 // requests originating from dgraph internal code like server.go::GetGQLSchema() where
460 // context is created by hand.
461 ctx = AttachNamespace(ctx, ns)
462 }
463 return ctx
464}
465
466// AttachNamespace adds given namespace to the metadata of the context.
467func AttachNamespace(ctx context.Context, namespace uint64) context.Context {

Callers 7

RunDQLMethod · 0.92
alterMethod · 0.92
QueryNoGrpcMethod · 0.92
resolveWithAdminServerFunction · 0.92
UpdateGraphQLSchemaMethod · 0.92
ResolveMethod · 0.92
ServeHTTPMethod · 0.92

Calls 2

AttachNamespaceFunction · 0.85
ExtractNamespaceFromFunction · 0.85

Tested by

no test coverage detected