-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
41 lines (32 loc) · 1.18 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
package main
import (
"context"
"encoding/json"
"fmt"
kingpin "github.com/alecthomas/kingpin/v2"
"github.com/aws/aws-lambda-go/lambda"
"github.com/hamstah/awstools/common"
)
var (
configFilenameTemplate = kingpin.Flag("config-filename-template", "Filename of the configuration file.").Default("%s.json").String()
eventFilename = kingpin.Flag("event-filename", "Filename with the event payload. Will process the event and exit if present.").String()
identityURLMaxAge = kingpin.Flag("identity-url-max-age", "Maximum age of the identity URL signature.").Default("10s").Duration()
)
func main() {
kingpin.CommandLine.Name = "lambda-sign-ssh-key"
kingpin.CommandLine.Help = "Signs SSH keys."
sessionFlags := common.HandleFlags()
handler := Handler(sessionFlags, *configFilenameTemplate, *identityURLMaxAge)
if *eventFilename == "" {
lambda.Start(handler)
} else {
event := SignSSHKeyEvent{}
err := common.LoadJSON(*eventFilename, &event)
common.FatalOnError(err)
response, err := handler(context.Background(), event)
common.FatalOnError(err)
bytes, err := json.MarshalIndent(response, "", " ")
common.FatalOnError(err)
fmt.Println(string(bytes))
}
}