driftctl/enumeration/remote/aws/vpc_security_group_enumerat...

49 lines
1.3 KiB
Go
Raw Normal View History

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"
resourceaws "github.com/snyk/driftctl/enumeration/resource/aws"
"github.com/aws/aws-sdk-go/aws"
)
type VPCSecurityGroupEnumerator struct {
repository repository.EC2Repository
factory resource.ResourceFactory
}
func NewVPCSecurityGroupEnumerator(repo repository.EC2Repository, factory resource.ResourceFactory) *VPCSecurityGroupEnumerator {
return &VPCSecurityGroupEnumerator{
repo,
factory,
}
}
func (e *VPCSecurityGroupEnumerator) SupportedType() resource.ResourceType {
return resourceaws.AwsSecurityGroupResourceType
}
2021-08-09 14:03:04 +00:00
func (e *VPCSecurityGroupEnumerator) Enumerate() ([]*resource.Resource, error) {
securityGroups, _, err := e.repository.ListAllSecurityGroups()
if err != nil {
2021-08-03 10:34:36 +00:00
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
}
2021-08-09 14:03:04 +00:00
results := make([]*resource.Resource, 0, len(securityGroups))
for _, item := range securityGroups {
results = append(
results,
e.factory.CreateAbstractResource(
string(e.SupportedType()),
aws.StringValue(item.GroupId),
map[string]interface{}{},
),
)
}
return results, nil
}