-
Notifications
You must be signed in to change notification settings - Fork 9
/
client.go
53 lines (44 loc) · 1.19 KB
/
client.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
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package eks
import (
"context"
"github.com/aws/aws-sdk-go-v2/service/eks"
"github.com/aws/aws-sdk-go-v2/service/iam"
awsprovider "namespacelabs.dev/foundation/internal/providers/aws"
"namespacelabs.dev/foundation/std/cfg"
)
type Session struct {
cfg cfg.Configuration
sesh *awsprovider.Session
eks *eks.Client
iam *iam.Client
}
func NewSession(ctx context.Context, cfg cfg.Configuration) (*Session, error) {
sesh, err := awsprovider.MustConfiguredSession(ctx, cfg)
if err != nil {
return nil, err
}
return &Session{
cfg: cfg,
sesh: sesh,
eks: eks.NewFromConfig(sesh.Config()),
iam: iam.NewFromConfig(sesh.Config()),
}, nil
}
func NewOptionalSession(ctx context.Context, cfg cfg.Configuration) (*Session, error) {
sesh, err := awsprovider.ConfiguredSession(ctx, cfg)
if err != nil {
return nil, err
}
if sesh == nil {
return nil, err
}
return &Session{
cfg: cfg,
sesh: sesh,
eks: eks.NewFromConfig(sesh.Config()),
iam: iam.NewFromConfig(sesh.Config()),
}, nil
}