Giter VIP home page Giter VIP logo

trustar-golang's Introduction

trustar-golang

Build Status GoDoc MIT License Go Report Card PRs Welcome

Golang SDK for the TruSTAR API

API Documentation

See https://docs.trustar.co/api/index.html for the official documentation to the TruSTAR API.

Example

Get reports from an enclave

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)
}

Roadmap

Implemented endpoints can be found in TODO.md

Disclaimer

This project is currently in alpha status. Breaking changes are possible and the project has not been thoroughly tested.

Acknowledgements

The overall design of this client is based upon logpacker/PayPal-Go-SDK

License

MIT © 2019 Jake Warren

trustar-golang's People

Contributors

jakewarren avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.