Пример #1
0
func (t *GetTemplate) Execute(client *aws.Client) (*GetTemplateResponse, error) {
	v := Values{
		"Action":    "GetTemplate",
		"StackName": t.StackName,
		"Version":   "2010-05-15",
	}

	ep, e := endpoint(client)
	if e != nil {
		return nil, e
	}
	req, e := http.NewRequest("GET", ep+"?"+v.Encode(), nil)
	if e != nil {
		return nil, e
	}
	client.SignAwsRequestV2(req, time.Now())
	rsp, e := httpClient.Do(req)
	if e != nil {
		return nil, e
	}
	defer rsp.Body.Close()

	b, e := ioutil.ReadAll(rsp.Body)
	if e != nil {
		return nil, e
	}
	xmlRsp := &GetTemplateResponse{}
	e = xml.Unmarshal(b, xmlRsp)
	if e != nil {
		e = fmt.Errorf(e.Error() + ": " + string(b) + " status=" + rsp.Status)
	}
	return xmlRsp, e
}
Пример #2
0
func (p *PutMetricData) Execute(client *aws.Client) error {
	q := p.query()
	theUrl := endpoint(client) + "?" + q
	req, e := http.NewRequest("POST", theUrl, nil)
	if e != nil {
		return e
	}
	now := time.Now()
	client.SignAwsRequestV2(req, now)
	rsp, e := http.DefaultClient.Do(req)
	if e != nil {
		return e
	}
	b, e := ioutil.ReadAll(rsp.Body)
	if e != nil {
		return e
	}
	if rsp.Status[0] != '2' {
		return fmt.Errorf("expected status 2xx, got %s. %s", rsp.Status, string(b))
	}
	return nil
}
Пример #3
0
func (a *GetSessionToken) Execute(client *aws.Client) (*GetSessionTokenResponse, error) {
	params, err := aws.ParamsForAction(a)
	if err != nil {
		return nil, err
	}
	req, err := http.NewRequest("GET", "https://sts.amazonaws.com/?"+params.Encode(), nil)
	tim := time.Now().UTC()
	client.SignAwsRequestV2(req, tim)
	for k, v := range req.Header {
		log.Printf("%s: %s", k, v)
	}
	rsp, err := http.DefaultClient.Do(req)
	if err != nil {
		return nil, err
	}
	defer rsp.Body.Close()
	if rsp.Status[0] != '2' {
		b, _ := ioutil.ReadAll(rsp.Body)
		return nil, fmt.Errorf("expected status 2xx, got %s. %s", rsp.Status, string(b))
	}
	var r *GetSessionTokenResponse
	return r, xml.NewDecoder(rsp.Body).Decode(&r)
}