Skip to content

Commit

Permalink
Call syncassets even if motor connection fails.
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <ivan@mondoo.com>
  • Loading branch information
preslavgerchev authored and imilchev committed Nov 21, 2022
1 parent a8612fc commit 7ec9c8f
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions policy/scan/local_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,32 @@ func (s *LocalScanner) distributeJob(job *Job, ctx context.Context, upstreamConf
func (s *LocalScanner) RunAssetJob(job *AssetJob) {
log.Info().Msgf("connecting to asset %s", job.Asset.HumanName())

// run over all connections
connections, err := resolver.OpenAssetConnections(job.Ctx, job.Asset, job.GetCredential, job.DoRecord)
if err != nil {
job.Reporter.AddScanError(job.Asset, err)
return
}

var upstream *policy.Services
var err error
if job.UpstreamConfig.ApiEndpoint != "" && !job.UpstreamConfig.Incognito {
log.Debug().Msg("using API endpoint " + s.apiEndpoint)
upstream, err = policy.NewRemoteServices(s.apiEndpoint, s.plugins)
log.Debug().Msg("using API endpoint " + job.UpstreamConfig.ApiEndpoint)
upstream, err = policy.NewRemoteServices(job.UpstreamConfig.ApiEndpoint, job.UpstreamConfig.Plugins)
if err != nil {
log.Error().Err(err).Msg("could not connect to upstream")
}
}

// run over all connections
connections, err := resolver.OpenAssetConnections(job.Ctx, job.Asset, job.GetCredential, job.DoRecord)
if err != nil {
job.Reporter.AddScanError(job.Asset, err)
if upstream != nil {
_, err := upstream.SynchronizeAssets(job.Ctx, &policy.SynchronizeAssetsReq{
SpaceMrn: job.UpstreamConfig.SpaceMrn,
List: []*asset.Asset{job.Asset},
})
if err != nil {
log.Error().Err(err).Msgf("failed to synchronize asset %s", job.Asset.Mrn)
}
}
return
}

for c := range connections {
// We use a function since we want to close the motor once the current iteration finishes. If we directly
// use defer in the loop m.Close() for each connection will only be executed once the entire loop is
Expand Down Expand Up @@ -248,7 +258,7 @@ func (s *LocalScanner) RunAssetJob(job *AssetJob) {

if upstream != nil {
resp, err := upstream.SynchronizeAssets(job.Ctx, &policy.SynchronizeAssetsReq{
SpaceMrn: s.spaceMrn,
SpaceMrn: job.UpstreamConfig.SpaceMrn,
List: []*asset.Asset{job.Asset},
})
if err != nil {
Expand Down

0 comments on commit 7ec9c8f

Please sign in to comment.