forked from snyk/driftctl
/
iam_group_enumerator.go
46 lines (38 loc) · 1.17 KB
/
iam_group_enumerator.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 aws
import (
"github.com/snyk/driftctl/enumeration/remote/aws/repository"
remoteerror "github.com/snyk/driftctl/enumeration/remote/error"
"github.com/snyk/driftctl/enumeration/resource"
"github.com/snyk/driftctl/enumeration/resource/aws"
)
type IamGroupEnumerator struct {
repository repository.IAMRepository
factory resource.ResourceFactory
}
func NewIamGroupEnumerator(repo repository.IAMRepository, factory resource.ResourceFactory) *IamGroupEnumerator {
return &IamGroupEnumerator{
repository: repo,
factory: factory,
}
}
func (e *IamGroupEnumerator) SupportedType() resource.ResourceType {
return aws.AwsIamGroupResourceType
}
func (e *IamGroupEnumerator) Enumerate() ([]*resource.Resource, error) {
groups, err := e.repository.ListAllGroups()
if err != nil {
return nil, remoteerror.NewResourceListingErrorWithType(err, string(e.SupportedType()), aws.AwsIamGroupResourceType)
}
results := make([]*resource.Resource, 0, len(groups))
for _, group := range groups {
results = append(
results,
e.factory.CreateAbstractResource(
string(e.SupportedType()),
*group.GroupName,
map[string]interface{}{},
),
)
}
return results, err
}