Skip to content

Commit

Permalink
Add SOS support (#155)
Browse files Browse the repository at this point in the history
Co-authored-by: David Wayman <[email protected]>
Co-authored-by: Kenan Yildirim <[email protected]>
  • Loading branch information
3 people authored Mar 18, 2024
1 parent 9867e58 commit ef744d1
Show file tree
Hide file tree
Showing 22 changed files with 2,300 additions and 48 deletions.
2 changes: 2 additions & 0 deletions examples/.examples-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go-sdk-examples:
- intel
- redact
- vault
- share
image: golang:${GO_VERSION}
before_script:
- export PANGEA_AUDIT_CONFIG_ID="${PANGEA_AUDIT_CONFIG_ID_1_LVE_AWS}"
Expand All @@ -31,6 +32,7 @@ go-sdk-examples:
- export PANGEA_URL_INTEL_TOKEN="${PANGEA_INTEGRATION_TOKEN_LVE_AWS}"
- export PANGEA_USER_INTEL_TOKEN="${PANGEA_INTEGRATION_TOKEN_LVE_AWS}"
- export PANGEA_VAULT_TOKEN="${PANGEA_INTEGRATION_TOKEN_LVE_AWS}"
- export PANGEA_SHARE_TOKEN="${PANGEA_INTEGRATION_TOKEN_LVE_AWS}"
script:
- cd examples/${EXAMPLE_FOLDER}
- bash ../../dev/run_examples.sh
Expand Down
30 changes: 21 additions & 9 deletions examples/file_scan/file_scan_async_crowdstrike.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,28 @@ func main() {
}
fmt.Println("Accepted error received (as expected).")

fmt.Println("Sleep some time before polling.")
// multiple polling attempts may be required
time.Sleep(time.Duration(20 * time.Second))
var pr *pangea.PangeaResponse[any]
i := 0
maxRetry := 24

fmt.Println("File Scan poll result...")
pr, err := client.PollResultByError(ctx, *ae)
if err != nil {
log.Fatal(err)
fmt.Println("Let's try to poll result...")
for i < maxRetry {
// Wait for result
time.Sleep(time.Duration(10 * time.Second))

pr, err = client.PollResultByError(ctx, *ae)
if err == nil {
break
}
i++
fmt.Printf("Result is not ready yet. Retry: %d\n", i)
}

fmt.Println("File Scan poll result success.")
fmt.Println(pangea.Stringify(pr.Result))
if i == maxRetry {
log.Fatal("Result still not ready")
} else {
r := (*pr.Result).(*file_scan.FileScanResult)
fmt.Println("File Scan success.")
fmt.Println(pangea.Stringify(r))
}
}
30 changes: 21 additions & 9 deletions examples/file_scan/file_scan_async_reversinglabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,28 @@ func main() {
}
fmt.Println("Accepted error received (as expected).")

fmt.Println("Sleep some time before polling.")
// multiple polling attempts may be required
time.Sleep(time.Duration(20 * time.Second))
var pr *pangea.PangeaResponse[any]
i := 0
maxRetry := 24

fmt.Println("File Scan poll result...")
pr, err := client.PollResultByError(ctx, *ae)
if err != nil {
log.Fatal(err)
fmt.Println("Let's try to poll result...")
for i < maxRetry {
// Wait for result
time.Sleep(time.Duration(10 * time.Second))

pr, err = client.PollResultByError(ctx, *ae)
if err == nil {
break
}
i++
fmt.Printf("Result is not ready yet. Retry: %d\n", i)
}

fmt.Println("File Scan poll result success.")
fmt.Println(pangea.Stringify(pr.Result))
if i == maxRetry {
log.Fatal("Result still not ready")
} else {
r := (*pr.Result).(*file_scan.FileScanResult)
fmt.Println("File Scan success.")
fmt.Println(pangea.Stringify(r))
}
}
61 changes: 61 additions & 0 deletions examples/share/folder_create_and_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"context"
"fmt"
"log"
"os"
"time"

"github.com/pangeacyber/pangea-go/pangea-sdk/v3/pangea"
"github.com/pangeacyber/pangea-go/pangea-sdk/v3/service/share"
)

func main() {
var t = time.Now().Format("20060102_150405")
var path = "/sdk_example/delete/" + t

// Load pangea token from environment variables
token := os.Getenv("PANGEA_SHARE_TOKEN")
if token == "" {
log.Fatal("Unauthorized: No token present.")
}

ctx, cancelFn := context.WithTimeout(context.Background(), 60*time.Second)
defer cancelFn()

// create a new store client with pangea token and domain
client := share.New(&pangea.Config{
Token: token,
Domain: os.Getenv("PANGEA_DOMAIN"),
})

// Create a FolderCreateRequest and set the path of the folder to be created
input := &share.FolderCreateRequest{
Path: path,
}

fmt.Printf("Let's create a folder: %s\n", path)
// Send the CreateRequest
out, err := client.FolderCreate(ctx, input)
if err != nil {
log.Fatalf("unexpected error: %v", err)
}

id := out.Result.Object.ID
fmt.Printf("Folder created. ID: %s.\n", id)

fmt.Printf("Let's create this folder now\n")
// Create a DeleteRequest and set the ID of the item to be deleted
input2 := &share.DeleteRequest{
ID: id,
}

// Send the DeleteRequest
rDel, err := client.Delete(ctx, input2)
if err != nil {
log.Fatalf("unexpected error: %v", err)
}

fmt.Printf("Folder deleted. Deleted %d items.\n", rDel.Result.Count)
}
16 changes: 16 additions & 0 deletions examples/share/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module examples/share

go 1.19

require github.com/pangeacyber/pangea-go/pangea-sdk/v3 v3.7.0

require (
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/rs/zerolog v1.31.0 // indirect
golang.org/x/sys v0.15.0 // indirect
)

replace github.com/pangeacyber/pangea-go/pangea-sdk/v3 v3.7.0 => ../../pangea-sdk/v3
30 changes: 30 additions & 0 deletions examples/share/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.7.5 h1:bJj+Pj19UZMIweq/iie+1u5YCdGrnxCT9yvm0e+Nd5M=
github.com/hashicorp/go-retryablehttp v0.7.5/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Loading

0 comments on commit ef744d1

Please sign in to comment.