-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
62 lines (49 loc) · 1.16 KB
/
main.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
55
56
57
58
59
60
61
62
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"github.com/poundifdef/certmaster/models"
"github.com/aws/aws-lambda-go/lambda"
"github.com/alexflint/go-arg"
)
type CreateCmd struct {
Config string `help:"File name for certificate creation config"`
JSON string `help:"JSON string for certificate creation config"`
}
type LambdaCmd struct {
}
var args struct {
Create *CreateCmd `arg:"subcommand:create" help:"Create a new certificate"`
Lambda *LambdaCmd `arg:"subcommand:lambda" help:"Run AWS Lambda function to create cert"`
}
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
arg.MustParse(&args)
switch {
case args.Create != nil:
jsonInput := args.Create.JSON
if args.Create.Config != "" {
data, err := os.ReadFile(args.Create.Config)
if err != nil {
panic(err)
}
jsonInput = string(data)
}
var request models.CertRequest
err := json.Unmarshal([]byte(jsonInput), &request)
if err != nil {
log.Fatal(err)
}
err = createCert(&request)
if err != nil {
log.Fatal(err)
}
case args.Lambda != nil:
lambda.Start(HandleLambdaEvent)
default:
fmt.Println("Run with --help for options")
os.Exit(1)
}
}