driftctl/enumeration/remote/aws/classic_loadbalancer_enumer...

47 lines
1.2 KiB
Go
Raw Normal View History

2022-04-07 07:51:32 +00:00
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"
2022-04-07 07:51:32 +00:00
)
type ClassicLoadBalancerEnumerator struct {
repository repository.ELBRepository
factory resource.ResourceFactory
}
func NewClassicLoadBalancerEnumerator(repo repository.ELBRepository, factory resource.ResourceFactory) *ClassicLoadBalancerEnumerator {
return &ClassicLoadBalancerEnumerator{
repository: repo,
factory: factory,
}
}
func (e *ClassicLoadBalancerEnumerator) SupportedType() resource.ResourceType {
return aws.AwsClassicLoadBalancerResourceType
}
func (e *ClassicLoadBalancerEnumerator) Enumerate() ([]*resource.Resource, error) {
loadBalancers, err := e.repository.ListAllLoadBalancers()
if err != nil {
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
}
results := make([]*resource.Resource, 0, len(loadBalancers))
for _, lb := range loadBalancers {
results = append(
results,
e.factory.CreateAbstractResource(
string(e.SupportedType()),
*lb.LoadBalancerName,
map[string]interface{}{},
),
)
}
return results, nil
}