Пример #1
0
func (self *Domain) GetAttribute(s *aws.Signer, item string, attrs AttributeList, consist bool) (a []Attribute, err os.Error) {
	var resp *http.Response

	vl := attrs.Values(ATTRIBUTE_LIST)

	vl.Set("Action", "GetAttributes")
	vl.Set("DomainName", self.Name)
	vl.Set("ItemName", item)

	if consist {
		vl.Set("ConsistentRead", "true")
	}

	req := aws.NewRequest(self.URL, "GET", nil, vl)
	err = s.SignRequestV2(req, aws.Canonicalize, DEFAULT_API_VERSION, 0)
	if err == nil {
		resp, err = self.conn.Request(req)
	}
	if err == nil {
		defer resp.Body.Close()
		err = aws.CodeToError(resp.StatusCode)
	}
	if err == nil {
		var response getattributesresponse
		ob, _ := http.DumpResponse(resp, true)
		os.Stdout.Write(ob)
		err = xml.Unmarshal(resp.Body, &response)
		if err == nil {
			a = response.Attributes
		}
	}
	return
}
Пример #2
0
// Users note: amazon will only return an error if the request is bad,
// thus an error will not be raised when deleting a non-existent LB.
func (self *Service) DeleteLoadBalancer(id *aws.Signer, name string) (err os.Error) {
	parms := http.Values{}
	parms.Set("Action", "DeleteLoadBalancer")
	parms.Set("LoadBalancerName", name)
	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 0)
	if err != nil {
		return
	}
	resp, err := self.conn.Request(req)
	if err != nil {
		return
	}
	defer resp.Body.Close()
	if resp.StatusCode != 200 {
		err = aws.CodeToError(resp.StatusCode)
	}
	qr := LoadBalancerQueryResult{}
	err = xml.Unmarshal(resp.Body, &qr)
	if err == nil {
		if qr.ErrorCode != "" {
			err = os.NewError(qr.ErrorCode)
		}
	}
	return
}
Пример #3
0
// Performs a HEAD request on the bucket and returns the response object.
// The body is CLOSED, and it is an error to try and read from it.
func (self *Bucket) HeadKey(id *aws.Signer, key string) (resp *http.Response, err os.Error) {
	hreq := aws.NewRequest(self.key_url(key), "HEAD", nil, nil)
	err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15)
	if err == nil {
		resp, err = self.conn.Request(hreq)
	}
	if err == nil {
		resp.Body.Close()
		err = aws.CodeToError(resp.StatusCode)
	}
	return
}
Пример #4
0
func (self *Bucket) PutKeyBytes(id *aws.Signer, key string, buff []byte, hdr http.Header) (err os.Error) {
	var resp *http.Response
	hreq := aws.NewRequest(self.key_url(key), "PUT", hdr, nil)
	hreq.ContentLength = int64(len(buff))
	hreq.Body = ioutil.NopCloser(bytes.NewBuffer(buff))
	err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15)
	if err == nil {
		resp, err = self.conn.Request(hreq)
		if err == nil {
			defer resp.Body.Close()
			err = aws.CodeToError(resp.StatusCode)
		}
	}
	return
}
Пример #5
0
// Deletes the named key from the bucket.  To delete a bucket, see *Service.DeleteBucket()
func (self *Bucket) Delete(id *aws.Signer, key string) (err os.Error) {
	var resp *http.Response
	if key == "" {
		return os.NewError("Key cannot be empty!")
	}
	hreq := aws.NewRequest(self.key_url(key), "DELETE", nil, nil)
	err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15)
	if err == nil {
		resp, err = self.conn.Request(hreq)
	}
	if err == nil {
		defer resp.Body.Close()
		if resp.StatusCode != http.StatusNoContent {
			err = aws.CodeToError(resp.StatusCode)
		}
	}

	return
}
Пример #6
0
// NB: Length is required as we do not buffer the reader
// NB(2): We do NOT close your reader (hence the io.Reader),
// we wrap it with a NopCloser.
func (self *Bucket) PutKeyReader(id *aws.Signer, key string, r io.Reader, l int64, hdr http.Header) (err os.Error) {
	var resp *http.Response
	hreq := aws.NewRequest(self.key_url(key), "PUT", hdr, nil)
	hreq.ContentLength = l
	hreq.Body = ioutil.NopCloser(io.LimitReader(r, l))
	err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15)
	if err == nil {
		resp, err = self.conn.Request(hreq)
		if err == nil {
			defer resp.Body.Close()
			err = aws.CodeToError(resp.StatusCode)
		}
		if err == aws.ErrorUnexpectedResponse {
			ob, _ := http.DumpResponse(resp, true)
			os.Stdout.Write(ob)
		}
	}
	return
}
Пример #7
0
// Walks a bucket and writes the resulting strings to the channel.
// * There is currently NO (correct) way to abort a running walk.
func (self *Bucket) ListKeys(id *aws.Signer,
	prefix, delim, marker string, out chan<- string) (err os.Error) {
	var done bool
	var resp *http.Response
	var last string
	form := http.Values{"prefix": []string{prefix},
		"delimeter": []string{delim},
		"marker":    []string{marker}}
	for err == nil && !done {
		result := listBucketResult{}
		result.Prefix = prefix
		result.Marker = marker
		if last != "" {
			form.Set("marker", last)
		}

		hreq := aws.NewRequest(self.key_url("/"), "GET", nil, form)
		err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15)

		if err == nil {
			resp, err = self.conn.Request(hreq)
		}
		if err == nil {
			err = aws.CodeToError(resp.StatusCode)
			if err == nil {
				err = xml.Unmarshal(resp.Body, &result)
				if err == nil {
					for i := range result.Contents {
						out <- result.Contents[i].Key
					}
					if len(result.Contents) > 0 {
						last = result.Contents[len(result.Contents)-1].Key
					}
					done = !result.IsTruncated
				}
			}
			resp.Body.Close()
		}
	}
	close(out)
	return
}
Пример #8
0
// Opens the named key and copys it to the named io.Writer IFF the response.Status is 200.
// Also returns the http headers for convenience (regardless of status code, as long as a  resp is generated).
func (self *Bucket) GetKey(id *aws.Signer, key string, w io.Writer) (hdr http.Header, err os.Error) {
	var resp *http.Response
	hreq := aws.NewRequest(self.key_url(key), "GET", nil, nil)
	err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15)
	if err == nil {
		resp, err = self.conn.Request(hreq)
	}
	if err == nil {
		defer resp.Body.Close()
		err = aws.CodeToError(resp.StatusCode)
		hdr = resp.Header
		if err == nil {
			_, err2 := io.Copy(w, resp.Body)
			if err == nil {
				err = err2
			}
		}
	}
	return
}
Пример #9
0
// Will put an open file descriptor to the named key.  Size is determined
// by statting the fd (so a partially read file will not work).
// TODO: ACL's & content-type/headers support
func (self *Bucket) PutFile(id *aws.Signer, key string, fp *os.File) (err os.Error) {
	var resp *http.Response
	if fp == nil {
		return os.NewError("invalid file descriptor")
	}
	fi, err := fp.Stat()
	if err == nil {
		fsize := fi.Size
		hdr := http.Header{}
		hreq := aws.NewRequest(self.key_url(key), "PUT", hdr, nil)
		hreq.ContentLength = fsize
		hreq.Body = fp
		err = id.SignRequestV1(hreq, aws.CanonicalizeS3, 15)
		if err == nil {
			resp, err = self.conn.Request(hreq)
			if err == nil {
				defer resp.Body.Close()
				err = aws.CodeToError(resp.StatusCode)
			}
		}
	}
	return
}
Пример #10
0
func (self *Domain) DeleteAttribute(s *aws.Signer, item string, attrs, expected AttributeList) (err os.Error) {
	var resp *http.Response

	vl := attrs.Values(ATTRIBUTE_LIST)

	for k, v := range expected.Values(EXPECTED_LIST) {
		vl[k] = v
	}

	vl.Set("Action", "DeleteAttribute")
	vl.Set("DomainName", self.Name)
	vl.Set("ItemName", item)

	req := aws.NewRequest(self.URL, "GET", nil, vl)
	err = s.SignRequestV2(req, aws.Canonicalize, DEFAULT_API_VERSION, 0)
	if err == nil {
		resp, err = self.conn.Request(req)
	}
	if err == nil {
		defer resp.Body.Close()
		err = aws.CodeToError(resp.StatusCode)
	}
	return
}