2021-10-07 13:18:47 +00:00
|
|
|
package azurerm
|
|
|
|
|
|
|
|
import (
|
2021-12-06 13:29:39 +00:00
|
|
|
"github.com/snyk/driftctl/pkg/remote/azurerm/repository"
|
|
|
|
remoteerror "github.com/snyk/driftctl/pkg/remote/error"
|
|
|
|
"github.com/snyk/driftctl/pkg/resource"
|
|
|
|
"github.com/snyk/driftctl/pkg/resource/azurerm"
|
2021-10-07 13:18:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type AzurermPostgresqlServerEnumerator struct {
|
|
|
|
repository repository.PostgresqlRespository
|
|
|
|
factory resource.ResourceFactory
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAzurermPostgresqlServerEnumerator(repo repository.PostgresqlRespository, factory resource.ResourceFactory) *AzurermPostgresqlServerEnumerator {
|
|
|
|
return &AzurermPostgresqlServerEnumerator{
|
|
|
|
repository: repo,
|
|
|
|
factory: factory,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *AzurermPostgresqlServerEnumerator) SupportedType() resource.ResourceType {
|
|
|
|
return azurerm.AzurePostgresqlServerResourceType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *AzurermPostgresqlServerEnumerator) Enumerate() ([]*resource.Resource, error) {
|
|
|
|
servers, err := e.repository.ListAllServers()
|
|
|
|
if err != nil {
|
|
|
|
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
|
|
|
|
}
|
|
|
|
|
|
|
|
results := make([]*resource.Resource, 0)
|
|
|
|
for _, server := range servers {
|
|
|
|
results = append(
|
|
|
|
results,
|
|
|
|
e.factory.CreateAbstractResource(
|
|
|
|
string(e.SupportedType()),
|
|
|
|
*server.ID,
|
|
|
|
map[string]interface{}{
|
|
|
|
"name": *server.Name,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return results, err
|
|
|
|
}
|