/
api_gateway_integration_enumerator.go
59 lines (49 loc) · 1.66 KB
/
api_gateway_integration_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
57
58
59
package aws
import (
"strings"
"github.com/cloudskiff/driftctl/pkg/remote/aws/repository"
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
"github.com/cloudskiff/driftctl/pkg/resource"
"github.com/cloudskiff/driftctl/pkg/resource/aws"
)
type ApiGatewayIntegrationEnumerator struct {
repository repository.ApiGatewayRepository
factory resource.ResourceFactory
}
func NewApiGatewayIntegrationEnumerator(repo repository.ApiGatewayRepository, factory resource.ResourceFactory) *ApiGatewayIntegrationEnumerator {
return &ApiGatewayIntegrationEnumerator{
repository: repo,
factory: factory,
}
}
func (e *ApiGatewayIntegrationEnumerator) SupportedType() resource.ResourceType {
return aws.AwsApiGatewayIntegrationResourceType
}
func (e *ApiGatewayIntegrationEnumerator) Enumerate() ([]*resource.Resource, error) {
apis, err := e.repository.ListAllRestApis()
if err != nil {
return nil, remoteerror.NewResourceListingErrorWithType(err, string(e.SupportedType()), aws.AwsApiGatewayRestApiResourceType)
}
results := make([]*resource.Resource, 0)
for _, api := range apis {
a := api
resources, err := e.repository.ListAllRestApiResources(*a.Id)
if err != nil {
return nil, remoteerror.NewResourceListingErrorWithType(err, string(e.SupportedType()), aws.AwsApiGatewayResourceResourceType)
}
for _, resource := range resources {
r := resource
for httpMethod := range r.ResourceMethods {
results = append(
results,
e.factory.CreateAbstractResource(
string(e.SupportedType()),
strings.Join([]string{"agi", *a.Id, *r.Id, httpMethod}, "-"),
map[string]interface{}{},
),
)
}
}
}
return results, err
}