newBuiltinMetricsSQL is the resolver for the built-in /metrics-sql API. It executes a metrics SQL query provided dynamically through the args. It errors if the user identified by the attributes is not an admin.
(ctx context.Context, opts *runtime.ResolverOptions)
| 46 | // It executes a metrics SQL query provided dynamically through the args. |
| 47 | // It errors if the user identified by the attributes is not an admin. |
| 48 | func newBuiltinMetricsSQL(ctx context.Context, opts *runtime.ResolverOptions) (runtime.Resolver, error) { |
| 49 | // Only admins can run arbitrary SQL queries. |
| 50 | if !opts.Claims.SkipChecks && !opts.Claims.Admin() { |
| 51 | return nil, errors.New("must be an admin to run arbitrary SQL queries") |
| 52 | } |
| 53 | |
| 54 | // Decode the args |
| 55 | args := &builtinMetricsSQLArgs{} |
| 56 | if err := mapstructure.Decode(opts.Args, args); err != nil { |
| 57 | return nil, err |
| 58 | } |
| 59 | |
| 60 | // Rewrite to the metrics SQL resolver |
| 61 | return newMetricsSQL(ctx, &runtime.ResolverOptions{ |
| 62 | Runtime: opts.Runtime, |
| 63 | InstanceID: opts.InstanceID, |
| 64 | Properties: map[string]any{ |
| 65 | "sql": args.SQL, |
| 66 | }, |
| 67 | Args: map[string]any{ |
| 68 | "priority": args.Priority, |
| 69 | }, |
| 70 | Claims: opts.Claims, |
| 71 | ForExport: opts.ForExport, |
| 72 | }) |
| 73 | } |
nothing calls this directly
no test coverage detected