-
Notifications
You must be signed in to change notification settings - Fork 1
/
issue.go
54 lines (47 loc) · 1.23 KB
/
issue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"time"
"github.com/RealImage/bifrost/cafiles"
"github.com/RealImage/bifrost/tinyca"
"github.com/urfave/cli/v2"
)
var (
notBefore cli.Timestamp
notAfter cli.Timestamp
issueCmd = &cli.Command{
Name: "issue",
Flags: []cli.Flag{
caCertFlag,
caKeyFlag,
&cli.TimestampFlag{
Name: "not-before",
Usage: "issue certificates valid from `TIMESTAMP`",
Aliases: []string{"before"},
EnvVars: []string{"NOT_BEFORE"},
Value: cli.NewTimestamp(time.Now()),
Destination: ¬Before,
},
&cli.TimestampFlag{
Name: "not-after",
Usage: "issue certificates valid until `TIMESTAMP`",
Aliases: []string{"after"},
EnvVars: []string{"NOT_AFTER"},
Value: cli.NewTimestamp(time.Now().AddDate(0, 0, 1)),
Destination: ¬After,
},
},
Action: func(cliCtx *cli.Context) error {
ctx := cliCtx.Context
cert, key, err := cafiles.GetCertKey(ctx, caCertUri, caPrivKeyUri)
if err != nil {
return cli.Exit(fmt.Sprintf("Error reading cert/key: %s", err), 1)
}
_, err = tinyca.New(cert, key)
if err != nil {
return cli.Exit(fmt.Sprintf("Error creating CA: %s", err), 1)
}
return nil
},
}
)