grants

package
v0.15.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = cli.Command{
	Name:        "grants",
	Action:      cli.ShowSubcommandHelp,
	Description: "Administer grants",
	Subcommands: []*cli.Command{&CreateCommand, &Handle},
}
View Source
var CreateCommand = cli.Command{
	Name: "create",
	Flags: []cli.Flag{
		&cli.StringFlag{Name: "subject", Required: true},
		&cli.StringFlag{Name: "provider", Required: true},
		&cli.StringSliceFlag{Name: "with", Usage: "key:value"},
	},
	Action: func(c *cli.Context) error {
		ctx := c.Context
		// Read from the .env file
		var cfg config.Config
		_ = godotenv.Load()
		err := envconfig.Process(ctx, &cfg)
		if err != nil {
			return err
		}

		awscfg, err := cfaws.ConfigFromContextOrDefault(ctx)
		if err != nil {
			return err
		}
		sfnClient := sfn.NewFromConfig(awscfg)
		if err != nil {
			return err
		}
		m := map[string]string{}

		for _, kv := range c.StringSlice("with") {
			s := strings.Split(kv, ":")
			m[s[0]] = s[1]
		}
		grant := ahTypes.CreateGrant{
			Subject:  openapi_types.Email(c.String("subject")),
			Start:    iso8601.New(time.Now().Add(time.Second * 2)),
			End:      iso8601.New(time.Now().Add(time.Second * 5)),
			Provider: c.String("provider"),
			Id:       ahTypes.NewGrantID(),
			With: ahTypes.CreateGrant_With{
				AdditionalProperties: m,
			},
		}
		in := targetgroupgranter.WorkflowInput{Grant: grant}

		clio.Infow("constructed workflow input", "input", in, "cfg", cfg)

		inJson, err := json.Marshal(in)
		if err != nil {
			return err
		}

		sei := &sfn.StartExecutionInput{
			StateMachineArn: aws.String(cfg.StateMachineARN),
			Input:           aws.String(string(inJson)),
			Name:            &grant.Id,
		}

		out, err := sfnClient.StartExecution(ctx, sei)
		if err != nil {
			return err
		}
		clio.Infow("execution created", "out", out)
		return nil
	},
}
View Source
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
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL