Skip to content

Commit

Permalink
🧹 apply runtime env labels for discovered assets (#794)
Browse files Browse the repository at this point in the history
* apply runtimeenv labels for discovered assets

Signed-off-by: Ivan Milchev <[email protected]>

* address comments

Signed-off-by: Ivan Milchev <[email protected]>

---------

Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev authored Oct 4, 2023
1 parent a027278 commit 634de0b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions policy/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,25 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstream *up
return nil, false, nil
}

runtimeEnv := execruntime.Detect()
var runtimeLabels map[string]string
// If the runtime is an automated environment and the root asset is CI/CD, then we are doing a
// CI/CD scan and we need to apply the runtime labels to the assets
if runtimeEnv != nil &&
runtimeEnv.IsAutomatedEnv() &&
job.Inventory.Spec.Assets[0].Category == inventory.AssetCategory_CATEGORY_CICD {
runtimeLabels = runtimeEnv.Labels()
}

justAssets := []*inventory.Asset{}
for _, asset := range assets {
asset.asset.KindString = asset.asset.GetPlatform().Kind
for k, v := range runtimeLabels {
if asset.asset.Labels == nil {
asset.asset.Labels = map[string]string{}
}
asset.asset.Labels[k] = v
}
justAssets = append(justAssets, asset.asset)
}

Expand Down

0 comments on commit 634de0b

Please sign in to comment.