drud/go-pantheon

Name: go-pantheon

Owner: DRUD

Description: A golang package for interacting with the Pantheon Systems Terminus API

Created: 2017-05-23 20:19:29.0

Updated: 2018-04-07 05:38:38.0

Pushed: 2018-02-13 19:28:31.0

Homepage: null

Size: 111

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Go Report Card CircleCI Build

go-pantheon

go-pantheon is a GO client library for accessing the Patheon Systems Terminus API.

This is not an official Pantheon Systems project.

Usage

You'll need to get a machine token from Pantheon. Please see Creating and Revoking Machine Tokens from Pantheon documentation for instructions on how to manage your machine tokens. It is recommended you set this value as an environment variable. The following examples will assume your token has been set as an environment variable named TERMINUS_API_TOKEN.

You can import go-pantheon for use in Go by importing the following package:

rt "github.com/drud/go-pantheon/pkg/pantheon"
Authentication

To use go-pantheon, you construct a new session, then use the various services on the client to access the Terminus API. For example:

reate a new session for your API token.
ion := pantheon.NewAuthSession(os.Getenv("TERMINUS_API_TOKEN"))

The session object is responsible for managing API sessions and requesting new session tokens as needed. To prevent requesting new sessions to often, it supports reading and writing session state to disk.

ionLocation := "/home/user/.go-pantheon/savedsession"

ion := pantheon.NewAuthSession(os.Getenv("TERMINUS_API_TOKEN"))


rite a session to disk.
:= session.Write(sessionLocation)
rr != nil {
log.Fatal(err)


ead a previously saved session.
:= session.Read(sessionLocation)
rr != nil {
log.Fatal(err)

Using the API

The following code shows how you would interact with the API to do the following tasks:

  1. Get a site list for the currently authed user.
  2. Get an environment list for the first site found
  3. Get a list of backups for the “live” environment.
  4. Get a S3 download URL for a database backup from the live environment.
et a list of all sites the authenticated user has access to.
List := &pantheon.SiteList{}
= session.Request("GET", SiteList)

et a list of environments for a given site.
 := SiteList.Sites[0]
ronmentList := pantheon.NewEnvironmentList(site.ID)
= session.Request("GET", environmentList)

et a list of all backups for the live.
:= environmentList.Environments["live"]
= pantheon.NewBackupList(site.ID, env.Name)
= session.Request("GET", bl)

et a database backup for the live site.
ckup := &pantheon.Backup{}
en(bl.Backups) > 0 {
for _, backup := range bl.Backups {
    if backup.ArchiveType == "database" {
        // Get a time-limited backup URL from Pantheon. This requires a POST of the backup type to their API.
        dbBackup = &backup
        err = session.Request("POST", dbBackup)
        if err != nil {
            log.Fatal(err)
        }
        break
    }
}


rint the download URL.
Println(dbBackup.DownloadURL)

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.