forked from snyk/driftctl
/
apigatewayv2_authorizer_enumerator.go
56 lines (46 loc) · 1.52 KB
/
apigatewayv2_authorizer_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
47
48
49
50
51
52
53
54
55
56
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 ApiGatewayV2AuthorizerEnumerator struct {
repository repository.ApiGatewayV2Repository
factory resource.ResourceFactory
}
func NewApiGatewayV2AuthorizerEnumerator(repo repository.ApiGatewayV2Repository, factory resource.ResourceFactory) *ApiGatewayV2AuthorizerEnumerator {
return &ApiGatewayV2AuthorizerEnumerator{
repository: repo,
factory: factory,
}
}
func (e *ApiGatewayV2AuthorizerEnumerator) SupportedType() resource.ResourceType {
return aws.AwsApiGatewayV2AuthorizerResourceType
}
func (e *ApiGatewayV2AuthorizerEnumerator) Enumerate() ([]*resource.Resource, error) {
apis, err := e.repository.ListAllApis()
if err != nil {
return nil, remoteerror.NewResourceListingErrorWithType(err, string(e.SupportedType()), aws.AwsApiGatewayV2ApiResourceType)
}
results := make([]*resource.Resource, 0)
for _, api := range apis {
a := api
authorizers, err := e.repository.ListAllApiAuthorizers(*a.ApiId)
if err != nil {
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
}
for _, authorizer := range authorizers {
au := authorizer
results = append(
results,
e.factory.CreateAbstractResource(
string(e.SupportedType()),
*au.AuthorizerId,
map[string]interface{}{},
),
)
}
}
return results, err
}