コード例 #1
0
ファイル: main.go プロジェクト: dylanmei/rsc
func main() {
	// 1. Retrieve login and endpoint information
	email := flag.String("e", "", "Login email")
	pwd := flag.String("p", "", "Login password")
	account := flag.Int("a", 0, "Account id")
	host := flag.String("h", "us-3.rightscale.com", "RightScale API host")
	insecure := flag.Bool("insecure", false, "Bypass certificate check, used for testing")
	cat := flag.String("cat", "", "Path to CAT file")
	flag.Parse()
	if *email == "" {
		fail("Login email required")
	}
	if *pwd == "" {
		fail("Login password required")
	}
	if *account == 0 {
		fail("Account id required")
	}
	if *host == "" {
		fail("Host required")
	}
	if *insecure {
		httpclient.NoCertCheck = true
	}
	if *cat == "" {
		fail("Path to CAT required")
	}
	if _, err := os.Stat(*cat); err != nil {
		fail("Can't find file %s", *cat)
	}

	// 2. Setup client using basic auth
	auth := rsapi.NewBasicAuthenticator(*email, *pwd, *account)
	ssAuth := rsapi.NewSSAuthenticator(auth, *account)
	client := ssd.New(*host, ssAuth)
	if err := client.CanAuthenticate(); err != nil {
		fail("invalid credentials: %s", err)
	}

	// 3. Make execution index call using expanded view
	file, err := os.Open(*cat)
	if err != nil {
		fail("Could not open %s", *cat)
	}
	name := filepath.Base(*cat)
	l := client.TemplateLocator(fmt.Sprintf("/designer/collections/%d/templates", *account))
	upload := rsapi.FileUpload{Name: name, Filename: name, Reader: file}
	t, err := l.Create(&upload)
	if err != nil {
		fail("failed to create template: %s", err)
	}
	created, err := t.Show(rsapi.ApiParams{})
	if err != nil {
		fail("failed to retrieve created template: %s", err)
	}
	fmt.Fprintf(osStdout, "%s created at %s by %s\n",
		created.Name, created.Timestamps.CreatedAt, created.CreatedBy.Name)
}
コード例 #2
0
ファイル: main.go プロジェクト: lopaka/rsc
func main() {
	// 1. Retrieve login and endpoint information
	email := flag.String("e", "", "Login email")
	pwd := flag.String("p", "", "Login password")
	account := flag.Int("a", 0, "Account id")
	host := flag.String("h", "us-3.rightscale.com", "RightScale API host")
	insecure := flag.Bool("insecure", false, "Use HTTP instead of HTTPS - used for testing")
	flag.Parse()
	if *email == "" {
		fail("Login email required")
	}
	if *pwd == "" {
		fail("Login password required")
	}
	if *account == 0 {
		fail("Account id required")
	}
	if *host == "" {
		fail("Host required")
	}

	// 2. Setup client using basic auth
	auth := rsapi.NewBasicAuthenticator(*email, *pwd, *account)
	ssAuth := rsapi.NewSSAuthenticator(auth, *account)
	client := ssm.New(*host, ssAuth)
	if *insecure {
		httpclient.Insecure = true
	}
	if err := client.CanAuthenticate(); err != nil {
		fail("invalid credentials: %s", err)
	}

	// 3. Make execution index call using expanded view
	l := client.ExecutionLocator(fmt.Sprintf("/projects/%d/executions", *account))
	execs, err := l.Index(rsapi.APIParams{})
	if err != nil {
		fail("failed to list executions: %s", err)
	}
	sort.Sort(ByName(execs))

	// 4. Print executions launch from
	w := new(tabwriter.Writer)
	w.Init(osStdout, 5, 0, 1, ' ', 0)
	fmt.Fprintln(w, "Name\tState\tBy\tLink")
	fmt.Fprintln(w, "-----\t-----\t-----\t-----")
	for _, e := range execs {
		link := fmt.Sprintf("https://%s/manager/#/exe/%s", ss.HostFromLogin(client.Host),
			e.Id)
		fmt.Fprintln(w, fmt.Sprintf("%s\t%s\t%s\t%s", e.Name, e.Status, e.CreatedBy.Email, link))
	}
	w.Flush()
}
コード例 #3
0
ファイル: client.go プロジェクト: dylanmei/sscat
func NewClient(apiHost, ssHost string, account int, token string) (*Client, error) {
	apiAuth := rsapi.NewOAuthAuthenticator(token, account)
	apiAuth.SetHost(apiHost)

	if err := apiAuth.CanAuthenticate(apiHost); err != nil {
		return nil, fmt.Errorf("invalid credentials: %s\n", err)
	}

	ssAuth := rsapi.NewSSAuthenticator(apiAuth, account)
	return &Client{
		account:  account,
		designer: ssd.New(ssHost, ssAuth),
		manager:  ssm.New(ssHost, ssAuth),
	}, nil
}