pangea-sdk

module
v3.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2023 License: MIT

README


Pangea Logo


documentation Slack


Pangea Go SDK

A Go SDK for integrating with Pangea Services.

Installation

To add Pangea Go SDK to your project, will need to run next command on your project root directory where you should have go.mod file:

go get github.com/pangeacyber/pangea-go/pangea-sdk

Usage

Examples

For the best example of how to set up and use the SDK in your code, look at the /examples folder in this repository. There you will find basic samples apps for each services supported on this SDK. Each service folder has a README.md with instructions to install, setup and run.

Getting started

Set up the SDK in your project in 3 steps:

  1. Pick your service. Full list of services available here.
  2. Initialize your client with your Token and Domain
  3. Use your client to call the service's endpoints

Let's walkthrough 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_mytokenvaluehere
$ 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.

Reporting issues and new features

If faced some issue using or testing this SDK or a new feature request feel free to open an issue clicking here. We would need you to provide some basic information like what SDK's version you are using, stack trace if you got it, framework used, and steps to reproduce the issue. Also feel free to contact Pangea support by email or send us a message on Slack

Contributing

Currently, the setup scripts only have support for Mac/ZSH environments. Future support is incoming.

To install our linters, simply run ./dev/setup_repo.sh These linters will run on every git commit operation.

Send a PR

If you would like to send a PR including a new feature or fixing a bug in code or an error in documents we will really appreciate it and after review and approval you will be included in our contributors list

Directories

Path Synopsis
internal
pangeatesting
go:build integration
go:build integration
service

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL