MCPcopy
hub / github.com/smallstep/cli / GetTemplateData

Function GetTemplateData

flags/flags.go:613–643  ·  view source on GitHub ↗

GetTemplateData parses the set and set-file flags and returns a map to be used in certificate templates.

(ctx *cli.Context)

Source from the content-addressed store, hash-verified

611// GetTemplateData parses the set and set-file flags and returns a map to be
612// used in certificate templates.
613func 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.

Callers 4

signActionFunction · 0.92
createActionFunction · 0.92
tokenActionFunction · 0.92
ParseTemplateDataFunction · 0.85

Calls 2

ReadFileFunction · 0.92
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…