Skip to content

Commit

Permalink
🧹 add user-friendly err when using unauthenticated cnquery (#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
imilchev authored Apr 25, 2023
1 parent 3c1daf5 commit c5d87f3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions resources/packs/core/asset_advisories.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions resources/packs/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions resources/packs/core/mondoo_eol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions resources/packs/core/platform_advisories.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions resources/packs/core/platform_eol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c5d87f3

Please sign in to comment.