File
Blob: cmd/client/acme.go
| 1 | package client |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| 6 | "os" |
| 7 | "os/signal" |
| 8 | "syscall" |
| 9 | |
| 10 | clientruntime "go.miragespace.co/specter/internal/client" |
| 11 | "go.miragespace.co/specter/spec/acme" |
| 12 | |
| 13 | "github.com/urfave/cli/v3" |
| 14 | ) |
| 15 | |
| 16 | func cmdAcme(ctx context.Context, cmd *cli.Command) error { |
| 17 | hostname := cmd.Args().First() |
| 18 | if hostname == "" { |
| 19 | return fmt.Errorf("missing hostname in argument") |
| 20 | } |
| 21 | hostname, err := acme.Normalize(hostname) |
| 22 | if err != nil { |
| 23 | return err |
| 24 | } |
| 25 | |
| 26 | s := make(chan os.Signal, 1) |
| 27 | signal.Notify(s, syscall.SIGHUP) |
| 28 | defer signal.Stop(s) |
| 29 | |
| 30 | c, closeClient, err := clientruntime.OpenOwner(ctx, cmd.String("config"), runtimeOptions(cmd)) |
| 31 | if err != nil { |
| 32 | return err |
| 33 | } |
| 34 | defer closeClient() |
| 35 | |
| 36 | resp, err := c.GetAcmeInstruction(ctx, hostname) |
| 37 | if err != nil { |
| 38 | return fmt.Errorf("failed to query acme instruction: %w", err) |
| 39 | } |
| 40 | |
| 41 | fmt.Printf("\n") |
| 42 | c.FormatAcme(resp, os.Stdout) |
| 43 | |
| 44 | return nil |
| 45 | } |