|
1 | 1 | package ca |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "crypto/x509" |
5 | | - "crypto/x509/pkix" |
6 | | - "net" |
7 | | - "net/netip" |
8 | | - |
9 | | - "github.com/android-sms-gateway/cli/internal/core/codes" |
10 | | - "github.com/urfave/cli/v2" |
| 4 | + "github.com/android-sms-gateway/cli/internal/commands/ca/common" |
| 5 | + "github.com/android-sms-gateway/client-go/ca" |
11 | 6 | ) |
12 | 7 |
|
13 | | -var webhooks = &cli.Command{ |
14 | | - Name: "webhooks", |
15 | | - Aliases: []string{"wh"}, |
16 | | - Usage: "Issue a new certificate for receiving webhooks to local IP address", |
17 | | - Args: true, |
18 | | - ArgsUsage: "IP address", |
19 | | - Flags: []cli.Flag{ |
20 | | - &cli.StringFlag{ |
21 | | - Name: "out", |
22 | | - Usage: "Certificate output file", |
23 | | - Required: false, |
24 | | - Value: "server.crt", |
25 | | - }, |
26 | | - &cli.StringFlag{ |
27 | | - Name: "keyout", |
28 | | - Usage: "Private key output file", |
29 | | - Required: false, |
30 | | - Value: "server.key", |
31 | | - }, |
32 | | - }, |
33 | | - Action: func(c *cli.Context) error { |
34 | | - ip := c.Args().Get(0) |
35 | | - if ip == "" { |
36 | | - return cli.Exit("IP address is empty", codes.ParamsError) |
37 | | - } |
38 | | - |
39 | | - netipAddr, err := netip.ParseAddr(ip) |
40 | | - if err != nil { |
41 | | - return cli.Exit(err.Error(), codes.ParamsError) |
42 | | - } |
43 | | - |
44 | | - if !netipAddr.IsPrivate() { |
45 | | - return cli.Exit("IP address is not private", codes.ParamsError) |
46 | | - } |
47 | | - |
48 | | - csrTemplate := x509.CertificateRequest{ |
49 | | - Subject: pkix.Name{ |
50 | | - CommonName: netipAddr.String(), |
51 | | - }, |
52 | | - IPAddresses: []net.IP{netipAddr.AsSlice()}, |
53 | | - } |
54 | | - |
55 | | - return requestCertificate(c, csrTemplate) |
56 | | - }, |
57 | | -} |
| 8 | +var webhooks = common.NewIPCertificateCommand( |
| 9 | + "webhooks", |
| 10 | + "Issue a new certificate for receiving webhooks to local IP address", |
| 11 | + []string{"wh"}, |
| 12 | + ca.CSRTypeWebhook, |
| 13 | +) |
0 commit comments