Last active
August 29, 2015 14:25
-
-
Save dylanmei/c60c5be7fa1cd2e4baef to your computer and use it in GitHub Desktop.
RSC SS Upload Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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