AttachJWTNamespace attaches the namespace in the JWT claims to the context if present, otherwise it attaches the galaxy namespace.
(ctx context.Context)
| 448 | // AttachJWTNamespace attaches the namespace in the JWT claims to the context if present, otherwise |
| 449 | // it attaches the galaxy namespace. |
| 450 | func 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. |
| 467 | func AttachNamespace(ctx context.Context, namespace uint64) context.Context { |
no test coverage detected