(ctx *cli.Context)
| 67 | } |
| 68 | |
| 69 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…