-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(integration): move CRUD gcp config code
BREAKING CHANGE: The `NewGCPIntegrationData()` has been changed and renamed to the new standard, users must switch to use `NewGCPIntegration()` Signed-off-by: Salim Afiune Maya <[email protected]>
- Loading branch information
Showing
2 changed files
with
153 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// | ||
// Author:: Salim Afiune Maya (<[email protected]>) | ||
// Copyright:: Copyright 2020, Lacework Inc. | ||
// License:: Apache License, Version 2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package api | ||
|
||
// gcpResourceLevel determines Project or Organization level integration | ||
type gcpResourceLevel int | ||
|
||
const ( | ||
// Project level integration with GCP | ||
GcpProjectIntegration gcpResourceLevel = iota | ||
|
||
// Organization level integration with GCP | ||
GcpOrganizationIntegration | ||
) | ||
|
||
var gcpResourceLevels = map[gcpResourceLevel]string{ | ||
GcpProjectIntegration: "PROJECT", | ||
GcpOrganizationIntegration: "ORGANIZATION", | ||
} | ||
|
||
func (g gcpResourceLevel) String() string { | ||
return gcpResourceLevels[g] | ||
} | ||
|
||
// NewGcpIntegration returns an instance of gcpIntegration | ||
// | ||
// Basic usage: Initialize a new gcpIntegration struct, then | ||
// use the new instance to do CRUD operations | ||
// | ||
// gcp, err := api.NewGcpIntegration("abc", | ||
// api.GcpIntegrationData{ | ||
// ID: "1234", | ||
// Credentials: api.GcpCredentials{ | ||
// ClientId: "id", | ||
// ClientEmail: "email", | ||
// PrivateKeyId: "key_id", | ||
// PrivateKey: "key", | ||
// }, | ||
// }, | ||
// ) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// | ||
// integrationResponse, err := api.CreateGcpConfigIntegration(gcp) | ||
// if err != nil { | ||
// return err | ||
// } | ||
// | ||
func NewGcpIntegration(name string, data GcpIntegrationData) gcpIntegration { | ||
return gcpIntegration{ | ||
commonIntegrationData: commonIntegrationData{ | ||
Name: name, | ||
Type: GcpCfgIntegration.String(), | ||
Enabled: 1, | ||
}, | ||
Data: data, | ||
} | ||
} | ||
|
||
// CreateGcpConfigIntegration creates a single GCP_CFG integration on the Lacework Server | ||
func (c *Client) CreateGcpConfigIntegration(data gcpIntegration) (response gcpIntegrationsResponse, err error) { | ||
err = c.createIntegration(data, &response) | ||
return | ||
} | ||
|
||
// GetGcpConfigIntegration gets a single integration matching the integration guid available on the server | ||
func (c *Client) GetGcpConfigIntegration(intgGuid string) (response gcpIntegrationsResponse, err error) { | ||
err = c.getIntegration(intgGuid, &response) | ||
return | ||
} | ||
|
||
// UpdateGcpConfigIntegration updates a single integration on the server | ||
func (c *Client) UpdateGcpConfigIntegration(data gcpIntegration) (response gcpIntegrationsResponse, err error) { | ||
err = c.updateIntegration(data.IntgGuid, data, &response) | ||
return | ||
} | ||
|
||
// DeleteGcpConfigIntegration gets a single integration matching the integration guid available on the server | ||
func (c *Client) DeleteGcpConfigIntegration(intgGuid string) (response gcpIntegrationsResponse, err error) { | ||
err = c.deleteIntegration(intgGuid, &response) | ||
return | ||
} | ||
|
||
func (c *Client) GetGcpIntegrations() (response gcpIntegrationsResponse, err error) { | ||
return | ||
} | ||
|
||
type gcpIntegrationsResponse struct { | ||
Data []gcpIntegration `json:"data"` | ||
Ok bool `json:"ok"` | ||
Message string `json:"message"` | ||
} | ||
|
||
type gcpIntegration struct { | ||
commonIntegrationData | ||
Data GcpIntegrationData `json:"DATA"` | ||
} | ||
|
||
type GcpIntegrationData struct { | ||
ID string `json:"ID"` | ||
IdType string `json:"ID_TYPE"` | ||
IssueGrouping string `json:"ISSUE_GROUPING,omitempty"` | ||
Credentials GcpCredentials `json:"CREDENTIALS"` | ||
SubscriptionName string `json:"SUBSCRIPTION_NAME,omitempty"` | ||
} | ||
|
||
type GcpCredentials struct { | ||
ClientId string `json:"CLIENT_ID"` | ||
ClientEmail string `json:"CLIENT_EMAIL"` | ||
PrivateKeyId string `json:"PRIVATE_KEY_ID"` | ||
PrivateKey string `json:"PRIVATE_KEY"` | ||
} |