Pangea Go SDK
A Go SDK for integrating with Pangea services. Supports Go v1.18 and above.
Installation
GA releases
$ go get github.com/pangeacyber/pangea-go/pangea-sdk/v3
Beta releases
Pre-release versions may be available with the beta
denotation in the version
number. These releases serve to preview beta services and APIs. Per Semantic
Versioning, they are considered unstable and do not carry the same compatibility
guarantees as stable releases. Beta changelog.
$ go get github.com/pangeacyber/pangea-go/pangea-sdk/v3@v3.8.0-beta.2
Usage
Set up the SDK in your project in 3 steps:
- Pick your service. Full list of services available here.
- Initialize your client with your
Token
and Domain
- Use your client to call the service's endpoints
Let's walk through an example using:
We need two things to initialize your client: a Token
and Domain
. These can
be found on the service overview page. For the Secure Audit Log service, go to
https://console.pangea.cloud/service/audit and take a look at the
"Configuration Details" box where it has "Default Token" and "Domain" listed.
Go ahead and set the token and domain as environment variables in our terminal.
$ export PANGEA_AUDIT_TOKEN=pts_tokenvaluehere
$ export PANGEA_DOMAIN=aws.us.pangea.cloud
Now let's add the SDK to our code.
Import statements:
import (
"context"
"fmt"
"log"
"os"
"github.com/pangeacyber/pangea-go/pangea-sdk/v3/pangea"
"github.com/pangeacyber/pangea-go/pangea-sdk/v3/service/audit"
)
Initialize your client:
// Initialize the Secure Audit Log client.
auditcli, err := audit.New(&pangea.Config{
Token: os.Getenv("PANGEA_AUDIT_TOKEN"), // NEVER hardcode your token here, always use env vars
Domain: os.Getenv("PANGEA_DOMAIN"),
})
if err != nil {
log.Fatal("failed to create Audit client")
}
IMPORTANT! Never hardcode your token. Use environment variables to avoid committing secrets in your codebase.
Make a call to the /v1/log
endpoint using the SDK
// Set up our parameters
ctx := context.Background()
event := &audit.StandardEvent{
Message: "Hello, World!",
}
// Call the /v1/log endpoint
resp, err := auditcli.Log(ctx, event, true)
if err != nil {
log.Fatal(err)
}
// Print the response
event := (resp.Result.EventEnvelope.Event).(*audit.StandardEvent)
fmt.Printf("Logged event: %s", pangea.Stringify(e))
Full code for the above example available in the examples directory.