GetTemplateData parses the set and set-file flags and returns a map to be used in certificate templates.
(ctx *cli.Context)
| 611 | // GetTemplateData parses the set and set-file flags and returns a map to be |
| 612 | // used in certificate templates. |
| 613 | func GetTemplateData(ctx *cli.Context) (map[string]interface{}, error) { |
| 614 | data := make(map[string]interface{}) |
| 615 | if path := ctx.String("set-file"); path != "" { |
| 616 | b, err := utils.ReadFile(path) |
| 617 | if err != nil { |
| 618 | return nil, err |
| 619 | } |
| 620 | if err := json.Unmarshal(b, &data); err != nil { |
| 621 | return nil, errors.Wrapf(err, "error unmarshaling %s", path) |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | keyValues := ctx.StringSlice("set") |
| 626 | for _, s := range keyValues { |
| 627 | i := strings.Index(s, "=") |
| 628 | if i == -1 { |
| 629 | return nil, errs.InvalidFlagValue(ctx, "set", s, "") |
| 630 | } |
| 631 | key, value := s[:i], s[i+1:] |
| 632 | |
| 633 | // If the value is not json, use the raw string. |
| 634 | var v interface{} |
| 635 | if err := json.Unmarshal([]byte(value), &v); err == nil { |
| 636 | data[key] = v |
| 637 | } else { |
| 638 | data[key] = value |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | return data, nil |
| 643 | } |
| 644 | |
| 645 | // ParseCaURL gets and parses the ca-url from the command context. |
| 646 | // - Require non-empty value. |
no test coverage detected
searching dependent graphs…