This repository has been archived by the owner on Aug 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idp.go
73 lines (61 loc) · 2 KB
/
idp.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
63
64
65
66
67
68
69
70
71
72
73
// Copyright (C) 2019 The aws-exec-cmd Authors.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package idp
import (
"context"
"github.com/spf13/cobra"
"github.com/codeactual/aws-exec-cmd/internal/cage/cli/handler"
handler_cobra "github.com/codeactual/aws-exec-cmd/internal/cage/cli/handler/cobra"
"github.com/codeactual/aws-exec-cmd/internal/cage/cli/handler/mixin/aws/auth"
auth_idp "github.com/codeactual/aws-exec-cmd/internal/cage/cli/handler/mixin/aws/auth/idp"
cmd_mixin "github.com/codeactual/aws-exec-cmd/mixin"
)
// Handler defines the sub-command flags and logic.
type Handler struct {
handler.Session
Auth auth.Mixin
IdentityPool auth_idp.Mixin
Exec cmd_mixin.Exec
}
// Init defines the command, its environment variable prefix, etc.
//
// It implements cli/handler/cobra.Handler.
func (h *Handler) Init() handler_cobra.Init {
h.Exec = cmd_mixin.New()
return handler_cobra.Init{
Cmd: &cobra.Command{
Use: "idp",
Short: "Acquire credentials from a Cognito identity pool",
},
EnvPrefix: "AWS_EXEC_CMD",
Mixins: []handler.Mixin{
&h.Auth,
&h.Exec,
&h.IdentityPool,
},
}
}
// BindFlags binds the flags to Handler fields.
//
// It implements cli/handler/cobra.Handler.
func (h *Handler) BindFlags(cmd *cobra.Command) []string {
return []string{} // auth_idp.Mixin provides all of them
}
// Run performs the sub-command logic.
//
// It implements cli/handler/cobra.Handler.
func (h *Handler) Run(ctx context.Context, input handler.Input) {
creds, credsErr := h.Auth.Credentials(&h.IdentityPool)
h.ExitOnErr(credsErr, "failed to acquire credentials", 1)
h.Exec.Do(ctx, creds, input.Args)
}
// New returns a cobra command instance based on Handler.
func NewCommand() *cobra.Command {
return handler_cobra.NewHandler(&Handler{
Session: &handler.DefaultSession{},
})
}
var _ handler_cobra.Handler = (*Handler)(nil)