Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌙 Add GCP Essential contact MQL resources #718

Merged
merged 3 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions resources/packs/gcp/essential_contacts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package gcp

import (
"context"

"go.mondoo.com/cnquery/resources/packs/core"
"google.golang.org/api/essentialcontacts/v1"
"google.golang.org/api/option"
)

func (g *mqlGcpProject) GetEssentialContacts() (interface{}, error) {
provider, err := gcpProvider(g.MotorRuntime.Motor.Provider)
if err != nil {
return nil, err
}

projectId, err := g.Id()
if err != nil {
return nil, err
}

client, err := provider.Client(essentialcontacts.CloudPlatformScope)
if err != nil {
return nil, err
}

ctx := context.Background()

contactSvc, err := essentialcontacts.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
return nil, err
}

contacts, err := contactSvc.Projects.Contacts.List("projects/" + projectId).Do()
if err != nil {
return nil, err
}

mqlContacts := make([]interface{}, 0, len(contacts.Contacts))
for _, c := range contacts.Contacts {
mqlC, err := g.MotorRuntime.CreateResource("gcp.essentialContact",
"resourcePath", c.Name,
"email", c.Email,
"languageTag", c.LanguageTag,
"name", parseResourceName(c.Name),
"notificationCategorySubscriptions", core.StrSliceToInterface(c.NotificationCategorySubscriptions),
"validated", parseTime(c.ValidateTime),
"validationState", c.ValidationState,
)
if err != nil {
return nil, err
}
mqlContacts = append(mqlContacts, mqlC)
}
return mqlContacts, nil
}

func (g *mqlGcpEssentialContact) id() (string, error) {
return g.ResourcePath()
}
20 changes: 20 additions & 0 deletions resources/packs/gcp/gcp.lr
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ gcp.project @defaults("name") {
pubsub() gcp.project.pubsubService
// KMS-related resources
kms() gcp.project.kmsService
// GCP Contacts for the project
essentialContacts() []gcp.essentialContact
}

// GCP Service
Expand Down Expand Up @@ -1251,3 +1253,21 @@ private gcp.project.kmsService.keyring.cryptokey.version.externalProtectionLevel
// Path to the external key material on the EKM when using EKM connection
ekmConnectionKeyPath string
}

// GCP Contact
private gcp.essentialContact {
// Full resource path
resourcePath string
// Email address to send notifications to
email string
// Preferred language for notifications, as a ISO 639-1 language code
languageTag string
// Name of the contact
name string
// Categories of notifications that the contact will receive communication for
notificationCategorySubscriptions []string
// Last time the validation state was updated
validated time
// Validity of the contact
validationState string
}
Loading