示例#1
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()
}
示例#2
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
}
示例#3
0
			Ω(res).Should(Equal(expected))
		})
	})
})

var _ = Describe("ParseCommand", func() {
	var cmd, hrefPrefix string
	var values rsapi.ActionCommands
	var api *rsapi.API

	var parsed *rsapi.ParsedCommand
	var parseErr error

	BeforeEach(func() {
		values = nil
		ssm := ssm.New("", nil)
		api = ssm.API
	})

	JustBeforeEach(func() {
		parsed, parseErr = api.ParseCommand(cmd, hrefPrefix, values)
	})

	Describe("with array of maps with one element", func() {
		BeforeEach(func() {
			cmd = "run"
			runCmd := rsapi.ActionCommand{
				Href: "/api/manager/projects/42/executions/54",
				Params: []string{
					"name=Tip CWF",
					"configuration_options[][name]=environment_name",