in internal/resources/providers/azurelib/inventory/storage_provider.go [73:151]
func NewStorageAccountProvider(log *clog.Logger, diagnosticSettingsClient *armmonitor.DiagnosticSettingsClient, credentials azcore.TokenCredential) StorageAccountProviderAPI {
// We wrap the client, so we can mock it in tests
wrapper := &storageAccountAzureClientWrapper{
AssetDiagnosticSettings: func(ctx context.Context, resourceURI string, options *armmonitor.DiagnosticSettingsClientListOptions) ([]armmonitor.DiagnosticSettingsClientListResponse, error) {
pager := diagnosticSettingsClient.NewListPager(resourceURI, options)
return readPager(ctx, pager)
},
AssetBlobContainers: func(ctx context.Context, subID string, clientOptions *arm.ClientOptions, resourceGroupName, storageAccountName string, options *armstorage.BlobContainersClientListOptions) ([]armstorage.BlobContainersClientListResponse, error) {
cl, err := armstorage.NewBlobContainersClient(subID, credentials, clientOptions)
if err != nil {
return nil, err
}
return readPager(ctx, cl.NewListPager(resourceGroupName, storageAccountName, options))
},
AssetBlobServices: func(ctx context.Context, subID string, clientOptions *arm.ClientOptions, resourceGroupName, storageAccountName string, options *armstorage.BlobServicesClientListOptions) ([]armstorage.BlobServicesClientListResponse, error) {
cl, err := armstorage.NewBlobServicesClient(subID, credentials, clientOptions)
if err != nil {
return nil, err
}
return readPager(ctx, cl.NewListPager(resourceGroupName, storageAccountName, options))
},
AssetFileServices: func(ctx context.Context, subID string, clientOptions *arm.ClientOptions, resourceGroupName, storageAccountName string, options *armstorage.FileServicesClientListOptions) (armstorage.FileServicesClientListResponse, error) {
cl, err := armstorage.NewFileServicesClient(subID, credentials, clientOptions)
if err != nil {
return armstorage.FileServicesClientListResponse{}, err
}
return cl.List(ctx, resourceGroupName, storageAccountName, options)
},
AssetFileShares: func(ctx context.Context, subID string, clientOptions *arm.ClientOptions, resourceGroupName, storageAccountName string, options *armstorage.FileSharesClientListOptions) ([]armstorage.FileSharesClientListResponse, error) {
cl, err := armstorage.NewFileSharesClient(subID, credentials, clientOptions)
if err != nil {
return nil, err
}
return readPager(ctx, cl.NewListPager(resourceGroupName, storageAccountName, options))
},
AssetQueues: func(ctx context.Context, subID string, clientOptions *arm.ClientOptions, resourceGroupName, storageAccountName string, options *armstorage.QueueClientListOptions) ([]armstorage.QueueClientListResponse, error) {
cl, err := armstorage.NewQueueClient(subID, credentials, clientOptions)
if err != nil {
return nil, err
}
return readPager(ctx, cl.NewListPager(resourceGroupName, storageAccountName, options))
},
AssetQueueServices: func(ctx context.Context, subID string, clientOptions *arm.ClientOptions, resourceGroupName, storageAccountName string, options *armstorage.QueueServicesClientListOptions) (armstorage.QueueServicesClientListResponse, error) {
cl, err := armstorage.NewQueueServicesClient(subID, credentials, clientOptions)
if err != nil {
return armstorage.QueueServicesClientListResponse{}, err
}
return cl.List(ctx, resourceGroupName, storageAccountName, options)
},
AssetTables: func(ctx context.Context, subID string, clientOptions *arm.ClientOptions, resourceGroupName, storageAccountName string, options *armstorage.TableClientListOptions) ([]armstorage.TableClientListResponse, error) {
cl, err := armstorage.NewTableClient(subID, credentials, clientOptions)
if err != nil {
return nil, err
}
return readPager(ctx, cl.NewListPager(resourceGroupName, storageAccountName, options))
},
AssetTableServices: func(ctx context.Context, subID string, clientOptions *arm.ClientOptions, resourceGroupName, storageAccountName string, options *armstorage.TableServicesClientListOptions) (armstorage.TableServicesClientListResponse, error) {
cl, err := armstorage.NewTableServicesClient(subID, credentials, clientOptions)
if err != nil {
return armstorage.TableServicesClientListResponse{}, err
}
return cl.List(ctx, resourceGroupName, storageAccountName, options)
},
AssetAccountStorage: func(ctx context.Context, subID string, clientOptions *arm.ClientOptions) ([]armstorage.AccountsClientListResponse, error) {
accountsClient, err := armstorage.NewAccountsClient(subID, credentials, clientOptions)
if err != nil {
return nil, err
}
return readPager(ctx, accountsClient.NewListPager(&armstorage.AccountsClientListOptions{}))
},
}
return &storageAccountProvider{
log: log,
client: wrapper,
diagnosticSettingsCache: cycle.NewCache[[]AzureAsset](log),
}
}