driftctl/enumeration/remote/google/google_compute_health_check...

48 lines
1.3 KiB
Go
Raw Permalink Normal View History

2021-10-27 15:05:23 +00:00
package google
import (
remoteerror "github.com/snyk/driftctl/enumeration/remote/error"
"github.com/snyk/driftctl/enumeration/remote/google/repository"
"github.com/snyk/driftctl/enumeration/resource"
"github.com/snyk/driftctl/enumeration/resource/google"
2021-10-27 15:05:23 +00:00
)
type GoogleComputeHealthCheckEnumerator struct {
repository repository.AssetRepository
factory resource.ResourceFactory
}
func NewGoogleComputeHealthCheckEnumerator(repo repository.AssetRepository, factory resource.ResourceFactory) *GoogleComputeHealthCheckEnumerator {
return &GoogleComputeHealthCheckEnumerator{
repository: repo,
factory: factory,
}
}
func (e *GoogleComputeHealthCheckEnumerator) SupportedType() resource.ResourceType {
return google.GoogleComputeHealthCheckResourceType
}
func (e *GoogleComputeHealthCheckEnumerator) Enumerate() ([]*resource.Resource, error) {
checks, err := e.repository.SearchAllHealthChecks()
if err != nil {
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
}
results := make([]*resource.Resource, 0, len(checks))
for _, res := range checks {
results = append(
results,
e.factory.CreateAbstractResource(
string(e.SupportedType()),
trimResourceName(res.GetName()),
map[string]interface{}{
"name": res.GetDisplayName(),
2021-10-27 15:05:23 +00:00
},
),
)
}
return results, err
}