Skip to content

Commit

Permalink
implement gcp project essential contacts
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev committed Jan 4, 2023
1 parent e0ec1be commit bd5745d
Show file tree
Hide file tree
Showing 4 changed files with 433 additions and 1 deletion.
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) GetContacts() (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.contact",
"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 *mqlGcpContact) 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 Contancts for the project
contacts() []gcp.contact
}

// 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.contact {
// 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

0 comments on commit bd5745d

Please sign in to comment.