(ctx context.Context, m schema.Mutation)
| 30 | } |
| 31 | |
| 32 | func resolveExport(ctx context.Context, m schema.Mutation) (*resolve.Resolved, bool) { |
| 33 | glog.Info("Got export request through GraphQL admin API") |
| 34 | |
| 35 | input, err := getExportInput(m) |
| 36 | if err != nil { |
| 37 | return resolve.EmptyResult(m, err), false |
| 38 | } |
| 39 | |
| 40 | format := worker.DefaultExportFormat |
| 41 | if input.Format != "" { |
| 42 | format = worker.NormalizeExportFormat(input.Format) |
| 43 | if format == "" { |
| 44 | return resolve.EmptyResult(m, errors.Errorf("invalid export format: %v", input.Format)), false |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | validateAndGetNs := func(inputNs int64) (uint64, error) { |
| 49 | ns, err := x.ExtractNamespace(ctx) |
| 50 | if err != nil { |
| 51 | return 0, err |
| 52 | } |
| 53 | if input.Namespace == notSet { |
| 54 | // If namespace parameter is not set, use the namespace from the context. |
| 55 | return ns, nil |
| 56 | } |
| 57 | switch ns { |
| 58 | case x.RootNamespace: |
| 59 | if input.Namespace < 0 { // export all namespaces. |
| 60 | return math.MaxUint64, nil |
| 61 | } |
| 62 | return uint64(inputNs), nil |
| 63 | default: |
| 64 | if input.Namespace != notSet && uint64(input.Namespace) != ns { |
| 65 | return 0, errors.Errorf("not allowed to export namespace %#x", input.Namespace) |
| 66 | } |
| 67 | } |
| 68 | return ns, nil |
| 69 | } |
| 70 | |
| 71 | var exportNs uint64 |
| 72 | if exportNs, err = validateAndGetNs(input.Namespace); err != nil { |
| 73 | return resolve.EmptyResult(m, err), false |
| 74 | } |
| 75 | |
| 76 | req := &pb.ExportRequest{ |
| 77 | Format: format, |
| 78 | Namespace: exportNs, |
| 79 | Destination: input.Destination, |
| 80 | AccessKey: input.AccessKey, |
| 81 | SecretKey: input.SecretKey, |
| 82 | SessionToken: input.SessionToken, |
| 83 | Anonymous: input.Anonymous, |
| 84 | } |
| 85 | taskId, err := worker.Tasks.Enqueue(req) |
| 86 | if err != nil { |
| 87 | return resolve.EmptyResult(m, err), false |
| 88 | } |
| 89 |
nothing calls this directly
no test coverage detected