Exemplo n.º 1
0
func (e *EC2) awsApiCall(v url.Values) (*http.Response, error) {
	v.Set("Version", "2014-06-15")
	log.Debug("Making AWS API call with values:")
	utils.DumpVal(v)
	client := &http.Client{}
	finalEndpoint := fmt.Sprintf("%s?%s", e.Endpoint, v.Encode())
	req, err := http.NewRequest("GET", finalEndpoint, nil)
	if err != nil {
		return &http.Response{}, fmt.Errorf("error creating request from client")
	}
	req.Header.Add("Content-type", "application/json")

	awsauth.Sign4(req, awsauth.Credentials{
		AccessKeyID:     e.Auth.AccessKey,
		SecretAccessKey: e.Auth.SecretKey,
		SecurityToken:   e.Auth.SessionToken,
	})
	resp, err := client.Do(req)
	if err != nil {
		fmt.Printf("client encountered error while doing the request: %s", err.Error())
		return resp, fmt.Errorf("client encountered error while doing the request: %s", err)
	}

	if resp.StatusCode != http.StatusOK {
		return resp, newAwsApiResponseError(*resp)
	}
	return resp, nil
}
Exemplo n.º 2
0
// RoundTrip implementation
func (a AWSSigningTransport) RoundTrip(req *http.Request) (*http.Response, error) {
	return a.HTTPClient.Do(awsauth.Sign4(req, a.Credentials))
}