Golang SDK for the TruSTAR API
See https://docs.trustar.co/api/index.html for the official documentation to the TruSTAR API.
package main
import (
"net/url"
"os"
"strconv"
"strings"
"time"
"github.com/davecgh/go-spew/spew"
trustar "github.com/jakewarren/trustar-golang"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func main() {
log.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Caller().Timestamp().Logger()
// set the list of enclave IDs we want to pull from
enclaveIDs := []string{"abc-123-def"}
// initialize the client with our API auth information
c, err := trustar.NewClient("TruSTAR API Key goes here", "TruSTAR API Secret goes here", trustar.APIBaseLive)
if err != nil {
log.Fatal().Err(err).Msg("error creating client")
}
// acquire the access token
_, err = c.GetAccessToken()
if err != nil {
log.Fatal().Err(err).Msg("error while getting access token")
}
t := time.Now().Add(-24 * time.Hour)
// build the request and send it
query := url.Values{}
query.Add("from", strconv.FormatInt(timeToMsEpoch(t), 10)) // request reports from the past 24 hours
query.Add("enclaveIds", strings.Join(enclaveIDs, ","))
reports, err := c.GetReports(query)
// print out the reports we received
spew.Dump(reports)
}
// convert time.Time to milliseconds epoch string
func timeToMsEpoch(t time.Time) int64 {
return t.UnixNano() / int64(time.Millisecond)
}
Implemented endpoints can be found in TODO.md
This project is currently in alpha status. Breaking changes are possible and the project has not been thoroughly tested.
The overall design of this client is based upon logpacker/PayPal-Go-SDK
MIT © 2019 Jake Warren