Ejemplo n.º 1
0
// GetAuthKeys get access key id and secret access key
func GetAuthKeys(url string) ([]byte, *probe.Error) {
	op := RPCOps{
		Method:  "Auth.Get",
		Request: rpc.Args{Request: ""},
	}
	req, perr := NewRequest(url, op, http.DefaultTransport)
	if perr != nil {
		return nil, perr.Trace()
	}
	resp, perr := req.Do()
	defer closeResp(resp)
	if perr != nil {
		return nil, perr.Trace()
	}
	var reply rpc.AuthReply
	if err := jsonrpc.DecodeClientResponse(resp.Body, &reply); err != nil {
		return nil, probe.NewError(err)
	}
	authConfig := &auth.Config{}
	authConfig.Version = "0.0.1"
	authConfig.Users = make(map[string]*auth.User)
	user := &auth.User{}
	user.Name = "testuser"
	user.AccessKeyID = reply.AccessKeyID
	user.SecretAccessKey = reply.SecretAccessKey
	authConfig.Users[reply.AccessKeyID] = user
	if err := auth.SaveConfig(authConfig); err != nil {
		return nil, err.Trace()
	}
	jsonRespBytes, err := json.MarshalIndent(reply, "", "\t")
	if err != nil {
		return nil, probe.NewError(err)
	}
	return jsonRespBytes, nil
}
Ejemplo n.º 2
0
func (s *MyRPCSuite) TestSysInfo(c *C) {
	op := controller.RPCOps{
		Method:  "SysInfo.Get",
		Request: rpc.Args{Request: ""},
	}
	req, err := controller.NewRequest(testRPCServer.URL+"/rpc", op, http.DefaultTransport)
	c.Assert(err, IsNil)
	c.Assert(req.Get("Content-Type"), Equals, "application/json")
	resp, err := req.Do()
	c.Assert(err, IsNil)
	c.Assert(resp.StatusCode, Equals, http.StatusOK)

	var reply rpc.SysInfoReply
	c.Assert(jsonrpc.DecodeClientResponse(resp.Body, &reply), IsNil)
	resp.Body.Close()
	c.Assert(reply, Not(DeepEquals), rpc.SysInfoReply{})
}
Ejemplo n.º 3
0
// GetSysInfo get system status of the server at given url
func GetSysInfo(url string) ([]byte, *probe.Error) {
	op := RPCOps{
		Method:  "SysInfo.Get",
		Request: rpc.Args{Request: ""},
	}
	req, perr := NewRequest(url, op, http.DefaultTransport)
	if perr != nil {
		return nil, perr.Trace()
	}
	resp, perr := req.Do()
	defer closeResp(resp)
	if perr != nil {
		return nil, perr.Trace()
	}
	var reply rpc.SysInfoReply
	if err := jsonrpc.DecodeClientResponse(resp.Body, &reply); err != nil {
		return nil, probe.NewError(err)
	}
	jsonRespBytes, err := json.MarshalIndent(reply, "", "\t")
	if err != nil {
		return nil, probe.NewError(err)
	}
	return jsonRespBytes, nil
}