Skip to content

Commit

Permalink
Merge pull request #21 from lacework/james/fix-update-api-path
Browse files Browse the repository at this point in the history
Fix Update Operation for GCP CFG
  • Loading branch information
mjunglw authored Mar 18, 2020
2 parents ce9745f + 3508e78 commit 5f027ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions api/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,18 @@ func (c *Client) getIntegration(intgGuid string, response interface{}) error {

// UpdateGCPConfigIntegration updates a single integration on the server
func (c *Client) UpdateGCPConfigIntegration(data gcpIntegrationData) (response gcpIntegrationsResponse, err error) {
err = c.updateIntegration(data, &response)
err = c.updateIntegration(data.IntgGuid, data, &response)
return
}

func (c *Client) updateIntegration(data interface{}, response interface{}) error {
func (c *Client) updateIntegration(intgGuid string, data interface{}, response interface{}) error {
body, err := jsonReader(data)
if err != nil {
return err
}

err = c.RequestDecoder("PATCH", apiIntegrations, body, response)
apiPath := fmt.Sprintf(apiIntegrationByGUID, intgGuid)
err = c.RequestDecoder("PATCH", apiPath, body, response)
return err
}

Expand Down
4 changes: 3 additions & 1 deletion api/integrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ func TestGetGCPConfigIntegration(t *testing.T) {

func TestUpdateGCPConfigIntegration(t *testing.T) {
intgGUID := "12345"
apiPath := fmt.Sprintf("external/integrations/%s", intgGUID)

fakeAPI := NewLaceworkServer()
fakeAPI.MockAPI("external/integrations", func(w http.ResponseWriter, r *http.Request) {
fakeAPI.MockAPI(apiPath, func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, createGCPCFGJson(intgGUID))
})
defer fakeAPI.Close()
Expand All @@ -93,6 +94,7 @@ func TestUpdateGCPConfigIntegration(t *testing.T) {

data := api.NewGCPIntegrationData("integration_name", api.GcpProject)
assert.Equal(t, "GCP_CFG", data.Type, "a new GCP integration should match its type")
data.IntgGuid = intgGUID
data.Data.ID = "xxxxxxxxxx"
data.Data.Credentials.ClientId = "xxxxxxxxx"
data.Data.Credentials.ClientEmail = "[email protected]"
Expand Down

0 comments on commit 5f027ea

Please sign in to comment.