in internal/resources/fetching/fetchers/azure/batch_fetcher.go [61:114]
func (f *AzureBatchAssetFetcher) Fetch(ctx context.Context, cycleMetadata cycle.Metadata) error {
f.log.Info("Starting AzureBatchAssetFetcher.Fetch")
subscriptions, err := f.provider.GetSubscriptions(ctx, cycleMetadata)
if err != nil {
return fmt.Errorf("failed to fetch governance info: %w", err)
}
var errAgg error
assets := []inventory.AzureAsset{}
for _, assetGroup := range AzureBatchAssetGroups {
r, err := f.provider.ListAllAssetTypesByName(ctx, assetGroup, slices.Collect(maps.Keys(AzureBatchAssets)))
if err != nil {
f.log.Errorf("AzureBatchAssetFetcher.Fetch failed to fetch asset group %s: %s", assetGroup, err.Error())
errAgg = errors.Join(errAgg, err)
continue
}
assets = append(assets, r...)
}
subscriptionGroups := lo.GroupBy(assets, func(item inventory.AzureAsset) string {
return item.SubscriptionId
})
for _, sub := range subscriptions {
assetGroups := lo.GroupBy(subscriptionGroups[sub.ShortID], func(item inventory.AzureAsset) string {
return item.Type
})
for assetType, pair := range AzureBatchAssets {
batchAssets := assetGroups[assetType]
if batchAssets == nil {
batchAssets = []inventory.AzureAsset{} // Use empty array instead of nil
}
select {
case <-ctx.Done():
err := ctx.Err()
f.log.Infof("AzureBatchAssetFetcher.Fetch context err: %s", err.Error())
errAgg = errors.Join(errAgg, err)
return errAgg
case f.resourceCh <- fetching.ResourceInfo{
CycleMetadata: cycleMetadata,
Resource: &AzureBatchResource{
// Every asset in the list has the same type and subtype
typePair: pair,
Subscription: sub,
Assets: batchAssets,
},
}:
}
}
}
return errAgg
}