/
handle.go
62 lines (58 loc) · 1.57 KB
/
handle.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 grants
import (
"time"
"github.com/common-fate/clio"
"github.com/common-fate/common-fate/accesshandler/pkg/types"
ahTypes "github.com/common-fate/common-fate/accesshandler/pkg/types"
"github.com/common-fate/common-fate/pkg/config"
"github.com/common-fate/common-fate/pkg/service/requestroutersvc"
"github.com/common-fate/common-fate/pkg/targetgroupgranter"
"github.com/common-fate/ddb"
"github.com/common-fate/iso8601"
openapi_types "github.com/deepmap/oapi-codegen/pkg/types"
"github.com/joho/godotenv"
"github.com/sethvargo/go-envconfig"
"github.com/urfave/cli/v2"
)
var Handle = cli.Command{
Name: "handle",
Action: func(c *cli.Context) error {
ctx := c.Context
var cfg config.TargetGroupGranterConfig
_ = godotenv.Load("../../../../.env")
err := envconfig.Process(ctx, &cfg)
if err != nil {
panic(err)
}
db, err := ddb.New(ctx, cfg.DynamoTable)
if err != nil {
panic(err)
}
granter := targetgroupgranter.Granter{
Cfg: cfg,
DB: db,
RequestRouter: &requestroutersvc.Service{
DB: db,
},
}
out, err := granter.HandleRequest(ctx, targetgroupgranter.InputEvent{
Grant: types.Grant{
Subject: openapi_types.Email("josh@commonfate.io"),
Start: iso8601.New(time.Now().Add(time.Second * 2)),
End: iso8601.New(time.Now().Add(time.Hour)),
Provider: "josh-example",
ID: ahTypes.NewGrantID(),
With: ahTypes.Grant_With{
AdditionalProperties: map[string]string{
"vault": "test",
},
},
},
})
if err != nil {
return err
}
clio.Infow("complete", "out", out)
return nil
},
}