Skip to content

Commit

Permalink
add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
orouz committed Mar 31, 2024
1 parent 495ff4d commit 0a66e87
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/resources/providers/gcplib/inventory/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ func (p *ProviderInitializer) Init(ctx context.Context, log *logp.Logger, gcpCon
}

func (p *Provider) ListAllAssetTypesByName(ctx context.Context, assetTypes []string) ([]*ExtendedGcpAsset, error) {
p.log.Infof("Listing GCP asset types: %v in %v", assetTypes, p.config.Parent)

wg := sync.WaitGroup{}
var resourceAssets []*assetpb.Asset
var policyAssets []*assetpb.Asset
Expand All @@ -194,6 +192,7 @@ func (p *Provider) ListAllAssetTypesByName(ctx context.Context, assetTypes []str
AssetTypes: assetTypes,
ContentType: assetpb.ContentType_RESOURCE,
}
p.log.Infof("Listing GCP resources for asset types: %v in %v", assetTypes, p.config.Parent)
resourceAssets = getAllAssets(p.log, p.inventory.ListAssets(ctx, request))
wg.Done()
}()
Expand All @@ -204,6 +203,7 @@ func (p *Provider) ListAllAssetTypesByName(ctx context.Context, assetTypes []str
AssetTypes: assetTypes,
ContentType: assetpb.ContentType_IAM_POLICY,
}
p.log.Infof("Listing GCP policies for asset types: %v in %v", assetTypes, p.config.Parent)
policyAssets = getAllAssets(p.log, p.inventory.ListAssets(ctx, request))
wg.Done()
}()
Expand All @@ -217,6 +217,7 @@ func (p *Provider) ListAllAssetTypesByName(ctx context.Context, assetTypes []str
// Enrich network assets with dns policy
p.enrichNetworkAssets(ctx, extendedAssets)

p.log.Infof("Listed %d assets for asset types: %v", len(extendedAssets), assetTypes)
return extendedAssets, nil
}

Expand Down Expand Up @@ -312,7 +313,7 @@ func (p *Provider) enrichNetworkAssets(ctx context.Context, assets []*ExtendedGc
p.log.Infof("no %s assets were listed", ComputeNetworkAssetType)
return
}

p.log.Infof("Listing GCP dns policies for %v", p.config.Parent)
dnsPolicyAssets := getAllAssets(p.log, p.inventory.ListAssets(ctx, &assetpb.ListAssetsRequest{
Parent: p.config.Parent,
AssetTypes: []string{DnsPolicyAssetType},
Expand All @@ -323,7 +324,7 @@ func (p *Provider) enrichNetworkAssets(ctx context.Context, assets []*ExtendedGc
p.log.Infof("no %s assets were listed, return original assets", DnsPolicyAssetType)
return
}

p.log.Infof("Listed %d %s assets", len(dnsPolicyAssets), DnsPolicyAssetType)
dnsPolicies := decodeDnsPolicies(dnsPolicyAssets)

p.log.Infof("attempting to enrich %d %s assets with dns policy", len(assets), ComputeNetworkAssetType)
Expand Down Expand Up @@ -470,12 +471,13 @@ func extendWithECS(ctx context.Context, crm *ResourceManagerWrapper, cache map[s
}

func (p *Provider) ListProjectsAncestorsPolicies(ctx context.Context) ([]*ProjectPoliciesAsset, error) {
p.log.Infof("Listing GCP project policies for %v", p.config.Parent)
projects := getAllAssets(p.log, p.inventory.ListAssets(ctx, &assetpb.ListAssetsRequest{
ContentType: assetpb.ContentType_IAM_POLICY,
Parent: p.config.Parent,
AssetTypes: []string{CrmProjectAssetType},
}))

p.log.Infof("Listed %d project policies", len(projects))
return lo.Map(projects, func(project *assetpb.Asset, _ int) *ProjectPoliciesAsset {
projectAsset := extendWithECS(ctx, p.crm, p.crmCache, []*assetpb.Asset{project})[0]
// Skip first ancestor it as we already got it
Expand All @@ -493,11 +495,13 @@ func getAncestorsAssets(ctx context.Context, p *Provider, ancestors []string) []
if strings.HasPrefix(parent, "organizations") {
assetType = CrmOrgAssetType
}
p.log.Infof("Listing GCP ancestor policies for %v", parent)
assets := getAllAssets(p.log, p.inventory.ListAssets(ctx, &assetpb.ListAssetsRequest{
ContentType: assetpb.ContentType_IAM_POLICY,
Parent: parent,
AssetTypes: []string{assetType},
}))
p.log.Infof("Listed %d ancestor policies", len(assets))
return extendWithECS(ctx, p.crm, p.crmCache, assets)
}))
}
Expand Down

0 comments on commit 0a66e87

Please sign in to comment.