Skip to content

Instantly share code, notes, and snippets.

@dylanmei
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylanmei/c60c5be7fa1cd2e4baef to your computer and use it in GitHub Desktop.
Save dylanmei/c60c5be7fa1cd2e4baef to your computer and use it in GitHub Desktop.
RSC SS Upload Example
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/rightscale/rsc/rsapi"
"github.com/rightscale/rsc/ss/ssd"
)
const account int = <account>
const token string = "<refresh-token>"
func main() {
auth := rsapi.NewOAuthAuthenticator(token, account)
auth.SetHost("us-3.rightscale.com") // SS/OAuth doesn't work without manually setting this
fmt.Println("Authenticating...")
if err := auth.CanAuthenticate("selfservice-3.rightscale.com"); err != nil {
fmt.Printf("invalid credentials: %s\n", err)
return
}
client := ssd.New("selfservice-3.rightscale.com", rsapi.NewSSAuthenticator(auth, account))
locator := client.TemplateLocator(fmt.Sprintf("/designer/collections/%d/templates", account))
path := "test.cat"
file, err := os.Open(path)
if err != nil {
fmt.Printf("Could not open %s\n", path)
return
}
defer file.Close()
name := filepath.Base(path)
fmt.Println("Uploading...")
upload := rsapi.FileUpload{Name: name, Filename: name, Reader: file}
t, err := locator.Create(&upload)
if err != nil {
fmt.Printf("failed to create template: %s\n", err)
return
}
fmt.Println("Done.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment