Skip to content

Commit

Permalink
backport fixes to v7 (#909)
Browse files Browse the repository at this point in the history
backports #905,
#906 and
#907 to v7
  • Loading branch information
chris-rock authored Feb 8, 2023
1 parent 8ee5cef commit 6ac7f91
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 72 deletions.
9 changes: 5 additions & 4 deletions apps/cnquery/cmd/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,10 +837,11 @@ func scanOktaCmd(commonCmdFlags commonFlagsFn, preRun commonPreRunFn, runFn runF

func scanGoogleWorkspaceCmd(commonCmdFlags commonFlagsFn, preRun commonPreRunFn, runFn runFn, docs CommandsDocs) *cobra.Command {
cmd := &cobra.Command{
Use: "googleworkspace",
Short: docs.GetShort("googleworkspace"),
Long: docs.GetLong("googleworkspace"),
Args: cobra.ExactArgs(0),
Use: "google-workspace",
Aliases: []string{"googleworkspace"},
Short: docs.GetShort("googleworkspace"),
Long: docs.GetLong("googleworkspace"),
Args: cobra.ExactArgs(0),
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlag("customer-id", cmd.Flags().Lookup("customer-id"))
viper.BindPFlag("impersonated-user-email", cmd.Flags().Lookup("impersonated-user-email"))
Expand Down
2 changes: 1 addition & 1 deletion motor/discovery/slack/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (r *Resolver) Resolve(ctx context.Context, root *asset.Asset, cc *providers
}
resolved = append(resolved, &asset.Asset{
PlatformIds: []string{identifier},
Name: "Slack organization " + teamName,
Name: "Slack team " + teamName,
Platform: pf,
Connections: []*providers.Config{cc}, // pass-in the current config
Labels: map[string]string{},
Expand Down
79 changes: 70 additions & 9 deletions motor/providers/google/platform.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,83 @@
package google

import "errors"
import (
"errors"

func (t *Provider) Identifier() (string, error) {
switch t.ResourceType() {
"go.mondoo.com/cnquery/motor/platform"
"go.mondoo.com/cnquery/motor/providers"
)

func (p *Provider) Identifier() (string, error) {
switch p.resourceType {
case Project:
return "//platformid.api.mondoo.app/runtime/gcp/projects/" + t.id, nil
return "//platformid.api.mondoo.app/runtime/gcp/projects/" + p.id, nil
case Workspace:
return "//platformid.api.mondoo.app/runtime/googleworkspace/customer/" + t.id, nil
return "//platformid.api.mondoo.app/runtime/googleworkspace/customer/" + p.id, nil
default:
return "", errors.New("unsupported resource type")
}
}

func (t *Provider) ResourceType() ResourceType {
return t.resourceType
func (p *Provider) ResourceType() ResourceType {
return p.resourceType
}

func (p *Provider) ResourceID() string {
return p.id
}

func (p *Provider) PlatformInfo() (*platform.Platform, error) {
// TODO: this is a hack and we need to find a better way to do this
if p.platformOverride != "" && p.platformOverride != "gcp" && p.platformOverride != "google-workspace" {
return &platform.Platform{
Name: p.platformOverride,
Title: getTitleForPlatformName(p.platformOverride),
Family: []string{"google"},
Kind: providers.Kind_KIND_GCP_OBJECT,
Runtime: providers.RUNTIME_GCP,
}, nil
}

switch p.resourceType {
case Project:
return &platform.Platform{
Name: "gcp",
Title: "Google Cloud Platform",
Family: []string{"google"},
Kind: providers.Kind_KIND_GCP_OBJECT,
Runtime: p.Runtime(),
}, nil
case Workspace:
return &platform.Platform{
Name: "google-workspace",
Title: "Google Workspace",
Family: []string{"google"},
Kind: providers.Kind_KIND_API,
Runtime: p.Runtime(),
}, nil
}

return nil, errors.New("unsupported resource type")
}

func (t *Provider) ResourceID() string {
return t.id
func getTitleForPlatformName(name string) string {
switch name {
case "gcp-project":
return "GCP Project"
case "gcp-compute-image":
return "GCP Compute Image"
case "gcp-compute-network":
return "GCP Compute Network"
case "gcp-compute-subnetwork":
return "GCP Compute Subnetwork"
case "gcp-compute-firewall":
return "GCP Compute Firewall"
case "gcp-gke-cluster":
return "GCP GKE Cluster"
case "gcp-storage-bucket":
return "GCP Storage Bucket"
case "gcp-bigquery-dataset":
return "GCP BigQuery Dataset"
}
return "Google Cloud Platform"
}
55 changes: 0 additions & 55 deletions motor/providers/google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import (
"os"

"github.com/rs/zerolog/log"
"github.com/spf13/afero"
"go.mondoo.com/cnquery/motor/platform"
"go.mondoo.com/cnquery/motor/providers"
"go.mondoo.com/cnquery/motor/providers/os/fsutil"
"go.mondoo.com/cnquery/motor/vault"
)

Expand Down Expand Up @@ -143,10 +140,6 @@ type Provider struct {
platformOverride string
}

func (p *Provider) FS() afero.Fs {
return &fsutil.NoFs{}
}

func (p *Provider) Close() {}

func (p *Provider) Capabilities() providers.Capabilities {
Expand Down Expand Up @@ -176,54 +169,6 @@ func (p *Provider) PlatformIdDetectors() []providers.PlatformIdDetector {
}
}

func (p *Provider) PlatformInfo() (*platform.Platform, error) {
if p.platformOverride != "" && p.platformOverride != "gcp" {
return &platform.Platform{
Name: p.platformOverride,
Title: getTitleForPlatformName(p.platformOverride),
Kind: providers.Kind_KIND_GCP_OBJECT,
Runtime: providers.RUNTIME_GCP,
}, nil
}

name := "gcp"
title := "Google Cloud Platform"

if p.resourceType == Workspace {
name = "googleworkspace"
title = "Google Workspace"
}

return &platform.Platform{
Name: name,
Title: title,
Kind: providers.Kind_KIND_API,
Runtime: p.Runtime(),
}, nil
}

func getTitleForPlatformName(name string) string {
switch name {
case "gcp-project":
return "GCP Project"
case "gcp-compute-image":
return "GCP Compute Image"
case "gcp-compute-network":
return "GCP Compute Network"
case "gcp-compute-subnetwork":
return "GCP Compute Subnetwork"
case "gcp-compute-firewall":
return "GCP Compute Firewall"
case "gcp-gke-cluster":
return "GCP GKE Cluster"
case "gcp-storage-bucket":
return "GCP Storage Bucket"
case "gcp-bigquery-dataset":
return "GCP BigQuery Dataset"
}
return "Google Cloud Platform"
}

func loadCredentialsFromEnv(envs ...string) ([]byte, error) {
for i := range envs {
val := os.Getenv(envs[i])
Expand Down
1 change: 1 addition & 0 deletions motor/providers/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ const (
RUNTIME_GITLAB = "gitlab" // api
RUNTIME_TERRAFORM = "terraform"
RUNTIME_OKTA = "okta"
RUNTIME_SLACK = "slack"
)
5 changes: 3 additions & 2 deletions motor/providers/slack/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import "go.mondoo.com/cnquery/motor/platform"

func (p *Provider) PlatformInfo() (*platform.Platform, error) {
return &platform.Platform{
Name: "slack",
Title: "Slack",
Name: "slack-team",
Title: "Slack Team",
Runtime: p.Runtime(),
Kind: p.Kind(),
Family: []string{"slack"},
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion motor/providers/slack/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (p *Provider) Kind() providers.Kind {
}

func (p *Provider) Runtime() string {
return ""
return providers.RUNTIME_SLACK
}

func (p *Provider) PlatformIdDetectors() []providers.PlatformIdDetector {
Expand Down

0 comments on commit 6ac7f91

Please sign in to comment.