-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
46 lines (36 loc) · 821 Bytes
/
app.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
package app
import (
"context"
"errors"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ssm"
"github.com/hairyhenderson/go-which"
"github.com/urfave/cli/v2"
)
type App struct {
ec2 *ec2.Client
ssm *ssm.Client
region string
}
type appKey int
const (
appCLI appKey = iota
)
func New(c *cli.Context) error {
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
return err
}
// check session-manager-plugin
if !which.Found("session-manager-plugin") {
return errors.New("you need to install session-manager-plugin command")
}
app := &App{
ec2: ec2.NewFromConfig(cfg),
ssm: ssm.NewFromConfig(cfg),
region: cfg.Region,
}
c.Context = context.WithValue(c.Context, appCLI, app)
return nil
}