Skip to content

Commit

Permalink
feat: prosast component data upload (#1639)
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-stewart committed Jun 10, 2024
1 parent 02bccca commit 635f2d3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
7 changes: 6 additions & 1 deletion api/component_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ type ComponentDataService struct {

const URL_TYPE_DEFAULT = "Default"
const URL_TYPE_SAST_TABLES = "SastTables"
const URL_TYPE_PROSAST = "ProSast"

var URL_TYPES = []string{URL_TYPE_DEFAULT, URL_TYPE_SAST_TABLES}
var URL_TYPES = []string{URL_TYPE_DEFAULT, URL_TYPE_SAST_TABLES, URL_TYPE_PROSAST}

type ComponentDataInitialRequest struct {
Name string `json:"name"`
Expand Down Expand Up @@ -70,6 +71,10 @@ func (svc *ComponentDataService) UploadSastTables(
return svc.doUploadFiles(name, []string{"sast"}, paths, URL_TYPE_SAST_TABLES)
}

func (svc *ComponentDataService) UploadProSast(name string, paths []string) (string, error) {
return svc.doUploadFiles(name, []string{"sast"}, paths, URL_TYPE_PROSAST)
}

func (svc *ComponentDataService) doUploadFiles(
name string, tags []string, paths []string, urlType string) (string, error) {
var hasValidType = false
Expand Down
30 changes: 30 additions & 0 deletions api/component_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,36 @@ func TestSastTablesUrlType(t *testing.T) {
assert.Equal(t, "SOME-GUID", guid)
}

func TestProSastUrlType(t *testing.T) {
fakeServer := lacework.MockServer()
fakeServer.MockToken("TOKEN")
defer fakeServer.Close()
fakeServer.MockAPI("ComponentData/requestUpload", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "POST", r.Method)
assert.NotNil(t, r.Body)
body := httpBodySniffer(r)
assert.Contains(t, body, api.URL_TYPE_PROSAST)
_, err := fmt.Fprint(w, generateInitialResponse())
assert.Nil(t, err)
})
fakeServer.MockAPI("ComponentData/completeUpload", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "POST", r.Method)
assert.NotNil(t, r.Body)
body := httpBodySniffer(r)
assert.Contains(t, body, api.URL_TYPE_PROSAST)
_, err := fmt.Fprint(w, generateCompleteResponse())
assert.Nil(t, err)
})
c, err := api.NewClient("test",
api.WithToken("TOKEN"),
api.WithURL(fakeServer.URL()),
)
assert.Nil(t, err)
guid, err := c.V2.ComponentData.UploadProSast("doc-set", []string{})
assert.Nil(t, err)
assert.Equal(t, "SOME-GUID", guid)
}

func TestDoWithExponentialBackoffAlwaysFailing(t *testing.T) {
waited := 0
err := api.DoWithExponentialBackoff(func() error {
Expand Down
5 changes: 2 additions & 3 deletions integration/resource_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package integration
import (
"encoding/json"
"fmt"
"strings"
"testing"

"github.com/lacework/go-sdk/api"
Expand Down Expand Up @@ -174,8 +173,8 @@ func TestResourceGroupDelete(t *testing.T) {
t.Run(i.String(), func(t *testing.T) {
// setup resource group
resourceGroupID, err := createResourceGroup(i.String())
if err != nil && !strings.Contains(err.Error(), "already exists in the account") {
assert.FailNow(t, err.Error())
if err != nil {
assert.FailNow(t, err.Error(), fmt.Sprintf("Manually delete resourceGroup CLI_TestCreateResourceGroup_%s", i.String()))
}

// delete resource group
Expand Down

0 comments on commit 635f2d3

Please sign in to comment.