-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
get.go
51 lines (42 loc) · 1.45 KB
/
get.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
package irsa
import (
"context"
"github.com/pkg/errors"
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
)
// GetOptions holds the configuration for the IRSA get action
type GetOptions struct {
Name string
Namespace string
}
func (m *Manager) Get(ctx context.Context, options GetOptions) ([]*api.ClusterIAMServiceAccount, error) {
remoteServiceAccounts, err := m.stackManager.GetIAMServiceAccounts(ctx)
if err != nil {
return nil, errors.Wrap(err, "getting iamserviceaccounts")
}
if options.Namespace != "" {
remoteServiceAccounts = filterByNamespace(remoteServiceAccounts, options.Namespace)
}
if options.Name != "" {
remoteServiceAccounts = filterByName(remoteServiceAccounts, options.Name)
}
return remoteServiceAccounts, nil
}
func filterByNamespace(serviceAccounts []*api.ClusterIAMServiceAccount, namespace string) []*api.ClusterIAMServiceAccount {
var serviceAccountsMatching []*api.ClusterIAMServiceAccount
for _, sa := range serviceAccounts {
if sa.Namespace == namespace {
serviceAccountsMatching = append(serviceAccountsMatching, sa)
}
}
return serviceAccountsMatching
}
func filterByName(serviceAccounts []*api.ClusterIAMServiceAccount, name string) []*api.ClusterIAMServiceAccount {
var serviceAccountsMatching []*api.ClusterIAMServiceAccount
for _, sa := range serviceAccounts {
if sa.Name == name {
serviceAccountsMatching = append(serviceAccountsMatching, sa)
}
}
return serviceAccountsMatching
}