MCPcopy Index your code
hub / github.com/smallstep/cli / rootAction

Function rootAction

command/ca/root.go:69–108  ·  view source on GitHub ↗
(ctx *cli.Context)

Source from the content-addressed store, hash-verified

67}
68
69func rootAction(ctx *cli.Context) error {
70 if err := errs.MinMaxNumberOfArguments(ctx, 0, 1); err != nil {
71 return err
72 }
73
74 caURL, err := flags.ParseCaURL(ctx)
75 if err != nil {
76 return err
77 }
78
79 fingerprint := strings.TrimSpace(ctx.String("fingerprint"))
80 if fingerprint == "" {
81 return errs.RequiredFlag(ctx, "fingerprint")
82 }
83
84 client, err := ca.NewClient(caURL, ca.WithInsecure())
85 if err != nil {
86 return err
87 }
88
89 // Root already validates the certificate
90 resp, err := client.Root(fingerprint)
91 if err != nil {
92 return errors.Wrap(err, "error downloading root certificate")
93 }
94
95 if rootFile := ctx.Args().Get(0); rootFile != "" {
96 if _, err := pemutil.Serialize(resp.RootPEM.Certificate, pemutil.ToFile(rootFile, 0600)); err != nil {
97 return err
98 }
99 ui.Printf("The root certificate has been saved in %s.\n", rootFile)
100 } else {
101 block, err := pemutil.Serialize(resp.RootPEM.Certificate)
102 if err != nil {
103 return err
104 }
105 fmt.Print(string(pem.EncodeToMemory(block)))
106 }
107 return nil
108}

Callers

nothing calls this directly

Calls 3

ParseCaURLFunction · 0.92
RootMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…