Exemplo n.º 1
0
// Returns a list of bucket names known by the endpoint.  Depending on the
// endpoint used, your list may be global or regional in nature.
func ListBuckets(id cryptools.NamedSigner, ep *awsconn.Endpoint) (out []string, err os.Error) {
	hreq, err := NewQueryRequest(id, ep, "GET", "", "", "", "", nil, nil)
	if err != nil {
		return
	}

	result := &listBucketsResult{}
	etype := &errorResponse{}
	err = ep.SendParsable(hreq, result, etype)

	if err != nil {
		return
	}

	out = make([]string, len(result.Buckets.Bucket))
	for i := range result.Buckets.Bucket {
		out[i] = result.Buckets.Bucket[i].Name
	}
	return
}
Exemplo n.º 2
0
func newQuery(id cryptools.NamedSigner, endpoint awsconn.Endpoint,
	domain, action string,
	params map[string]string) (hreq *http.Request, err os.Error) {

	if params == nil {
		params = make(map[string]string)
	}
	req := &Request{
		//Method: method,
		Host: endpoint.GetURL().Host,
		URL: &http.URL{
			Scheme: endpoint.GetURL().Scheme,
			Host:   endpoint.GetURL().Host,
			Path:   endpoint.GetURL().Path,
		},
	}
	if req.URL.Path == "" {
		req.URL.Path = "/"
	}
	if _, ok := params["Version"]; !ok {
		params["Version"] = DEFAULT_VERSION
	}
	if _, ok := params["SignatureVersion"]; !ok {
		params["SignatureVersion"] = DEFAULT_SIGNATURE_VERSION
	}
	if _, ok := params["SignatureMethod"]; !ok {
		params["SignatureMethod"] = DEFAULT_SIGNATURE_METHOD
	}
	if _, ok := params["Timestamp"]; !ok {
		params["Timestamp"] = time.UTC().Format("2006-01-02T15:04:05-07:00")
	}
	// ListDomains, Select don't require a DomainName attribute
	if domain != "" {
		params["DomainName"] = domain
	}
	params["Action"] = action
	params["AWSAccessKeyId"] = id.SignerName()

	req.Form = maptools.StringStringToStringStrings(params)
	if len(http.EncodeQuery(req.Form)) > 512 {
		req.Method = "POST"
	} else {
		req.Method = "GET"
	}

	if _, ok := params["Signature"]; !ok {
		err = req.Sign(id)
	}
	if err == nil {
		hreq = (*http.Request)(req)
	}
	return
}
Exemplo n.º 3
0
func calculateCobrandingURL(id cryptools.NamedSigner, endpoint *awsconn.Endpoint, params map[string]string) (hreq *http.Request, err os.Error) {

	if params == nil {
		params = make(map[string]string)
	}
	req := &Request{
		//Method: method,
		Host: endpoint.GetURL().Host,
		URL: &http.URL{
			Scheme: endpoint.GetURL().Scheme,
			Host:   endpoint.GetURL().Host,
			Path:   endpoint.GetURL().Path,
		},
	}
	if req.URL.Path == "" {
		req.URL.Path = "/"
	}
	if _, ok := params["Version"]; !ok {
		params["Version"] = DEFAULT_VERSION
	}
	if _, ok := params["SignatureVersion"]; !ok {
		params["SignatureVersion"] = DEFAULT_SIGNATURE_VERSION
	}
	if _, ok := params["SignatureMethod"]; !ok {
		params["SignatureMethod"] = DEFAULT_SIGNATURE_METHOD
	}
	// Timestamp is only mandatory on certain contexts.
	//if _, ok := params["Timestamp"]; ! ok { params["Timestamp"] = time.UTC().Format("2006-01-02T15:04:05-07:00")}
	// ListDomains, Select don't require a DomainName attribute
	params["callerKey"] = id.SignerName()

	req.Form = maptools.StringStringToStringStrings(params)
	req.Method = "GET"

	if _, ok := params["Signature"]; !ok {
		err = req.Sign(id)
	}
	if err == nil {
		hreq = (*http.Request)(req)
	}
	return
}
Exemplo n.º 4
0
// Constructs a query request object;  This complex type implements
// both the Canonicalization and Signing methods necessary to access
// S3.
//
// For the most part, users are expected to use the exposed bucket/endpoint/obj
// functions
//
// If Expiration is < 1 year (in seconds), the expiration is assumed to
// mean seconds-from-now (local clock based).
func NewQueryRequest(id cryptools.NamedSigner, endpoint *awsconn.Endpoint,
	method, bucket, key, ctype, cmd5 string,
	params, hdrs map[string]string) (req *http.Request, err os.Error) {
	req = &http.Request{
		Method: method,
		Host:   endpoint.GetURL().Host,
		URL: &http.URL{
			Scheme: endpoint.GetURL().Scheme,
			Host:   endpoint.GetURL().Host,
			Path:   endpoint.GetURL().Path,
		},
		Header: hdrs,
		Form:   maptools.StringStringToStringStrings(params),
	}
	if req.Header == nil {
		req.Header = make(map[string]string)
	}
	if ctype != "" {
		req.Header["Content-Type"] = ctype
	}
	if cmd5 != "" {
		req.Header["Content-Md5"] = cmd5
	}
	if bucket != "" {
		req.URL.Path = "/" + bucket
		if key != "" {
			req.URL.Path += "/" + key
		}
	}
	req.Form["AWSAccessKeyId"] = []string{id.SignerName()}
	if len(req.Form["Expires"]) == 0 {
		req.Form["Expires"] = []string{strconv.Itoa64(time.Seconds() + 30)}
	}
	if len(req.Form["Signature"]) == 0 {
		sig, err := cryptools.SignString64(id, base64.StdEncoding, cryptools.SignableString(CanonicalString(req)))
		if err != nil {
			return
		}
		req.Form["Signature"] = []string{sig}
	}
	return
}