From c5d87f33a5335b1f83eba7c00b082ef2e5b59742 Mon Sep 17 00:00:00 2001 From: Ivan Milchev Date: Tue, 25 Apr 2023 12:46:56 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20add=20user-friendly=20err=20when?= =?UTF-8?q?=20using=20unauthenticated=20cnquery=20(#1165)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/packs/core/asset_advisories.go | 4 ++-- resources/packs/core/core.go | 4 ++++ resources/packs/core/mondoo_eol.go | 4 ++-- resources/packs/core/platform_advisories.go | 4 ++-- resources/packs/core/platform_eol.go | 4 ++-- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/resources/packs/core/asset_advisories.go b/resources/packs/core/asset_advisories.go index ecbbd7aec7..c2756c948e 100644 --- a/resources/packs/core/asset_advisories.go +++ b/resources/packs/core/asset_advisories.go @@ -14,8 +14,8 @@ import ( func (a *mqlAsset) GetVulnerabilityReport() (interface{}, error) { r := a.MotorRuntime mcc := r.UpstreamConfig - if mcc == nil { - return nil, errors.New("mondoo upstream configuration is missing") + if mcc == nil || mcc.ApiEndpoint == "" { + return nil, errors.New(MissingUpstreamErr) } // get asset information diff --git a/resources/packs/core/core.go b/resources/packs/core/core.go index 58e25976f5..ecd6101704 100644 --- a/resources/packs/core/core.go +++ b/resources/packs/core/core.go @@ -2,6 +2,10 @@ package core import "go.mondoo.com/cnquery/resources/packs/core/info" +const MissingUpstreamErr = `To use this resource, you must authenticate with the Mondoo Platform. +To learn how, read: +https://mondoo.com/docs/cnspec/cnspec-adv-install/registration/` + var Registry = info.Registry func init() { diff --git a/resources/packs/core/mondoo_eol.go b/resources/packs/core/mondoo_eol.go index 1b3390142b..c4d28aa2f6 100644 --- a/resources/packs/core/mondoo_eol.go +++ b/resources/packs/core/mondoo_eol.go @@ -22,8 +22,8 @@ func (p *mqlMondooEol) GetDate() (*time.Time, error) { r := p.MotorRuntime mcc := r.UpstreamConfig - if mcc == nil { - return nil, errors.New("mondoo upstream configuration is missing") + if mcc == nil || mcc.ApiEndpoint == "" { + return nil, errors.New(MissingUpstreamErr) } // get new advisory report diff --git a/resources/packs/core/platform_advisories.go b/resources/packs/core/platform_advisories.go index e59135d93e..d630796fc2 100644 --- a/resources/packs/core/platform_advisories.go +++ b/resources/packs/core/platform_advisories.go @@ -52,8 +52,8 @@ func newAdvisoryScannerHttpClient(mondooapi string, plugins []ranger.ClientPlugi func (p *mqlPlatform) GetVulnerabilityReport() (interface{}, error) { r := p.MotorRuntime mcc := r.UpstreamConfig - if mcc == nil { - return nil, errors.New("mondoo upstream configuration is missing") + if mcc == nil || mcc.ApiEndpoint == "" { + return nil, errors.New(MissingUpstreamErr) } // get platform information diff --git a/resources/packs/core/platform_eol.go b/resources/packs/core/platform_eol.go index 7357a7732f..06f56c0b3e 100644 --- a/resources/packs/core/platform_eol.go +++ b/resources/packs/core/platform_eol.go @@ -78,8 +78,8 @@ func (p *mqlPlatformEol) init(args *resources.Args) (*resources.Args, PlatformEo r := p.MotorRuntime mcc := r.UpstreamConfig - if mcc == nil { - return nil, nil, errors.New("mondoo upstream configuration is missing") + if mcc == nil || mcc.ApiEndpoint == "" { + return nil, nil, errors.New(MissingUpstreamErr) } // get new advisory report