(c *cli.Context)
| 437 | } |
| 438 | |
| 439 | func startDsortHandler(c *cli.Context) (err error) { |
| 440 | var ( |
| 441 | id string |
| 442 | specPath = parseStrFlag(c, specFileFlag) |
| 443 | ) |
| 444 | if c.NArg() == 0 && specPath == "" { |
| 445 | return missingArgumentsError(c, "job specification") |
| 446 | } else if c.NArg() > 0 && specPath != "" { |
| 447 | return &errUsage{ |
| 448 | context: c, |
| 449 | message: "multiple job specifications provided, expected one", |
| 450 | helpData: c.Command, |
| 451 | helpTemplate: cli.CommandHelpTemplate, |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | var specBytes []byte |
| 456 | if specPath == "" { |
| 457 | // Specification provided as an argument. |
| 458 | specBytes = []byte(c.Args().First()) |
| 459 | } else { |
| 460 | // Specification provided as path to the file (flag). |
| 461 | var r io.Reader |
| 462 | if specPath == fileStdIO { |
| 463 | r = os.Stdin |
| 464 | } else { |
| 465 | f, err := os.Open(specPath) |
| 466 | if err != nil { |
| 467 | return err |
| 468 | } |
| 469 | defer f.Close() |
| 470 | r = f |
| 471 | } |
| 472 | |
| 473 | var b bytes.Buffer |
| 474 | // Read at most 1MB so we don't blow up when reading a malicious file. |
| 475 | if _, err := io.CopyN(&b, r, cos.MiB); err == nil { |
| 476 | return errors.New("file too big") |
| 477 | } else if err != io.EOF { |
| 478 | return err |
| 479 | } |
| 480 | specBytes = b.Bytes() |
| 481 | } |
| 482 | |
| 483 | var rs dsort.RequestSpec |
| 484 | if errj := jsoniter.Unmarshal(specBytes, &rs); errj != nil { |
| 485 | if erry := yaml.Unmarshal(specBytes, &rs); erry != nil { |
| 486 | return fmt.Errorf( |
| 487 | "failed to determine the type of the job specification, errs: (%v, %v)", |
| 488 | errj, erry, |
| 489 | ) |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | if id, err = api.StartDSort(defaultAPIParams, rs); err != nil { |
| 494 | return |
| 495 | } |
| 496 |
nothing calls this directly
no test coverage detected