2021-08-24 08:32:56 +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-08-24 08:32:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type AzurermStorageContainerEnumerator struct {
|
|
|
|
repository repository.StorageRespository
|
|
|
|
factory resource.ResourceFactory
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewAzurermStorageContainerEnumerator(repo repository.StorageRespository, factory resource.ResourceFactory) *AzurermStorageContainerEnumerator {
|
|
|
|
return &AzurermStorageContainerEnumerator{
|
|
|
|
repository: repo,
|
|
|
|
factory: factory,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *AzurermStorageContainerEnumerator) SupportedType() resource.ResourceType {
|
|
|
|
return azurerm.AzureStorageContainerResourceType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *AzurermStorageContainerEnumerator) Enumerate() ([]*resource.Resource, error) {
|
|
|
|
|
|
|
|
accounts, err := e.repository.ListAllStorageAccount()
|
|
|
|
if err != nil {
|
|
|
|
return nil, remoteerror.NewResourceListingErrorWithType(err, string(e.SupportedType()), azurerm.AzureStorageAccountResourceType)
|
|
|
|
}
|
|
|
|
|
|
|
|
results := make([]*resource.Resource, 0)
|
|
|
|
|
|
|
|
for _, account := range accounts {
|
|
|
|
containers, err := e.repository.ListAllStorageContainer(account)
|
|
|
|
if err != nil {
|
|
|
|
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, container := range containers {
|
|
|
|
results = append(
|
|
|
|
results,
|
|
|
|
e.factory.CreateAbstractResource(
|
|
|
|
string(e.SupportedType()),
|
|
|
|
container,
|
|
|
|
map[string]interface{}{},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return results, err
|
|
|
|
}
|