Skip to content

Commit

Permalink
🐛 fix dict parsing for gcp buckets (#3267)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock authored Feb 11, 2024
1 parent c32aa49 commit 2defef5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 71 deletions.
50 changes: 25 additions & 25 deletions providers/gcp/resources/gcp.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ resources:
name:
- gcp
refs:
- title: Creating and managing Folders
- title: Creating and managing Folders
url: https://cloud.google.com/resource-manager/docs/creating-managing-folders
gcp.folders:
fields:
Expand All @@ -151,7 +151,7 @@ resources:
name:
- gcp
refs:
- title: Creating and managing Folders
- title: Creating and managing Folders
url: https://cloud.google.com/resource-manager/docs/creating-managing-folders
gcp.organization:
fields:
Expand All @@ -168,7 +168,7 @@ resources:
name:
- gcp
refs:
- title: Resource hierarchy
- title: Resource hierarchy
url: https://cloud.google.com/resource-manager/docs/cloud-platform-resource-hierarchy
gcp.project:
fields:
Expand Down Expand Up @@ -206,7 +206,7 @@ resources:
name:
- gcp
refs:
- title: Creating and managing projects
- title: Creating and managing projects
url: https://cloud.google.com/resource-manager/docs/creating-managing-projects
gcp.project.apiKey:
fields:
Expand All @@ -226,7 +226,7 @@ resources:
name:
- gcp
refs:
- title: API Keys Overview
- title: API Keys Overview
url: https://cloud.google.com/api-keys/docs/overview
gcp.project.apiKey.restrictions:
fields:
Expand All @@ -242,7 +242,7 @@ resources:
name:
- gcp
refs:
- title: Adding restrictions to API keys
- title: Adding restrictions to API keys
url: https://cloud.google.com/api-keys/docs/add-restrictions-api-keys
gcp.project.bigqueryService:
fields:
Expand All @@ -254,7 +254,7 @@ resources:
name:
- gcp
refs:
- title: BigQuery documentation
- title: BigQuery documentation
url: https://cloud.google.com/bigquery/docs
gcp.project.bigqueryService.dataset:
fields:
Expand All @@ -278,7 +278,7 @@ resources:
name:
- gcp
refs:
- title: Introduction to datasets
- title: Introduction to datasets
url: https://cloud.google.com/bigquery/docs/datasets-intro
gcp.project.bigqueryService.dataset.accessEntry:
fields:
Expand All @@ -296,7 +296,7 @@ resources:
name:
- gcp
refs:
- title: Control access to resources
- title: Control access to resources
url: https://cloud.google.com/bigquery/docs/control-access-to-resources-iam
gcp.project.bigqueryService.model:
fields:
Expand All @@ -318,7 +318,7 @@ resources:
name:
- gcp
refs:
- title: Introduction to BigQuery ML
- title: Introduction to BigQuery ML
url: https://cloud.google.com/bigquery/docs/bqml-introduction
gcp.project.bigqueryService.routine:
fields:
Expand All @@ -336,7 +336,7 @@ resources:
name:
- gcp
refs:
- title: Manage routines
- title: Manage routines
url: https://cloud.google.com/bigquery/docs/routines
gcp.project.bigqueryService.table:
fields:
Expand Down Expand Up @@ -371,7 +371,7 @@ resources:
name:
- gcp
refs:
- title: Introduction to tables
- title: Introduction to tables
url: https://cloud.google.com/bigquery/docs/tables-intro
gcp.project.cloudFunction:
fields:
Expand Down Expand Up @@ -414,7 +414,7 @@ resources:
name:
- gcp
refs:
- title: Cloud Functions
- title: Cloud Functions
url: https://cloud.google.com/functions
gcp.project.cloudRunService:
fields:
Expand All @@ -429,7 +429,7 @@ resources:
name:
- gcp
refs:
- title: What is Cloud Run
- title: What is Cloud Run
url: https://cloud.google.com/run/docs/overview/what-is-cloud-run
gcp.project.cloudRunService.condition:
fields:
Expand All @@ -445,7 +445,7 @@ resources:
name:
- gcp
refs:
- title: Condition
- title: Condition
url: https://cloud.google.com/run/docs/reference/rest/v1/Condition
gcp.project.cloudRunService.container:
fields:
Expand All @@ -467,7 +467,7 @@ resources:
name:
- gcp
refs:
- title: Container
- title: Container
url: https://cloud.google.com/run/docs/reference/rest/v1/Container
gcp.project.cloudRunService.container.probe:
fields:
Expand All @@ -484,7 +484,7 @@ resources:
name:
- gcp
refs:
- title: Container
- title: Container
url: https://cloud.google.com/run/docs/reference/rest/v1/Container
gcp.project.cloudRunService.job:
fields:
Expand Down Expand Up @@ -516,7 +516,7 @@ resources:
name:
- gcp
refs:
- title: Cloud Run Jobs
- title: Cloud Run Jobs
url: https://cloud.google.com/run/docs/overview/what-is-cloud-run#jobs
gcp.project.cloudRunService.job.executionTemplate:
fields:
Expand All @@ -532,7 +532,7 @@ resources:
name:
- gcp
refs:
- title: Create jobs
- title: Create jobs
url: https://cloud.google.com/run/docs/create-jobs
gcp.project.cloudRunService.job.executionTemplate.taskTemplate:
fields:
Expand All @@ -553,7 +553,7 @@ resources:
name:
- gcp
refs:
- title: Create jobs
- title: Create jobs
url: https://cloud.google.com/run/docs/create-jobs
gcp.project.cloudRunService.operation:
fields:
Expand Down Expand Up @@ -599,7 +599,7 @@ resources:
name:
- gcp
refs:
- title: Cloud Run services
- title: Cloud Run services
url: https://cloud.google.com/run/docs/resource-model#services
gcp.project.cloudRunService.service.revisionTemplate:
fields:
Expand All @@ -624,7 +624,7 @@ resources:
name:
- gcp
refs:
- title: Rollbacks, gradual rollouts, and traffic migration
- title: Rollbacks, gradual rollouts, and traffic migration
url: https://cloud.google.com/run/docs/rollouts-rollbacks-traffic-migration
gcp.project.computeService:
fields:
Expand Down Expand Up @@ -2384,7 +2384,7 @@ resources:
name:
- gcp
refs:
- title: Creating and managing projects
- title: Creating and managing projects
url: https://cloud.google.com/resource-manager/docs/creating-managing-projects
gcp.recommendation:
fields:
Expand All @@ -2405,7 +2405,7 @@ resources:
name:
- gcp
refs:
- title: Recommendations
- title: Recommendations
url: https://cloud.google.com/recommender/docs/key-concepts
gcp.resourcemanager.binding:
fields:
Expand All @@ -2418,7 +2418,7 @@ resources:
name:
- gcp
refs:
- title: Creating and managing projects
- title: Creating and managing projects
url: https://cloud.google.com/resource-manager/docs/creating-managing-projects
gcp.service:
fields:
Expand Down
57 changes: 11 additions & 46 deletions providers/gcp/resources/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import (
"context"
"fmt"
"strconv"
"time"

"go.mondoo.com/cnquery/v10/llx"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/plugin"
"go.mondoo.com/cnquery/v10/providers-sdk/v1/util/convert"
"go.mondoo.com/cnquery/v10/providers/gcp/connection"
"go.mondoo.com/cnquery/v10/types"

"google.golang.org/api/cloudresourcemanager/v3"
"google.golang.org/api/iam/v1"
"google.golang.org/api/option"
Expand Down Expand Up @@ -82,56 +80,23 @@ func (g *mqlGcpProjectStorageService) buckets() ([]interface{}, error) {
}

res := make([]interface{}, 0, len(buckets.Items))
for _, bucket := range buckets.Items {
for i := range buckets.Items {
bucket := buckets.Items[i]
created := parseTime(bucket.TimeCreated)
updated := parseTime(bucket.Updated)

iamConfigurationDict := map[string]interface{}{}

if bucket.IamConfiguration != nil {
iamConfiguration := bucket.IamConfiguration

if iamConfiguration.BucketPolicyOnly != nil {
var parsedLockTime time.Time
if iamConfiguration.BucketPolicyOnly.LockedTime != "" {
parsedLockTime, err = time.Parse(time.RFC3339, iamConfiguration.BucketPolicyOnly.LockedTime)
if err != nil {
return nil, err
}
}

iamConfigurationDict["BucketPolicyOnly"] = map[string]interface{}{
"enabled": iamConfiguration.BucketPolicyOnly.Enabled,
"lockedTime": parsedLockTime,
}
}

if iamConfiguration.UniformBucketLevelAccess != nil {
var parsedLockTime time.Time
if iamConfiguration.UniformBucketLevelAccess.LockedTime != "" {
parsedLockTime, err = time.Parse(time.RFC3339, iamConfiguration.UniformBucketLevelAccess.LockedTime)
if err != nil {
return nil, err
}
}

iamConfigurationDict["UniformBucketLevelAccess"] = map[string]interface{}{
"enabled": iamConfiguration.UniformBucketLevelAccess.Enabled,
"lockedTime": parsedLockTime,
}
}

iamConfigurationDict["publicAccessPrevention"] = iamConfiguration.PublicAccessPrevention
var iamConfigurationDict map[string]interface{}
iamConfigurationDict, err = convert.JsonToDict(bucket.IamConfiguration)
if err != nil {
return nil, err
}

var retentionPolicy interface{}
if bucket.RetentionPolicy != nil {
retentionPolicy = map[string]interface{}{
"retentionPeriod": bucket.RetentionPolicy.RetentionPeriod,
"effectiveTime": parseTime(bucket.RetentionPolicy.EffectiveTime),
"isLocked": bucket.RetentionPolicy.IsLocked,
}
var retentionPolicy map[string]interface{}
retentionPolicy, err = convert.JsonToDict(bucket.RetentionPolicy)
if err != nil {
return nil, err
}

mqlInstance, err := CreateResource(g.MqlRuntime, "gcp.project.storageService.bucket", map[string]*llx.RawData{
"id": llx.StringData(bucket.Id),
"projectId": llx.StringData(projectId),
Expand Down

0 comments on commit 2defef5

Please sign in to comment.