예제 #1
0
파일: queue.go 프로젝트: justinbarry/GoAWS
// Note: 0 is a valid timeout!!
func (self *Queue) Peek(id *aws.Signer, vt int) (body []byte, msgid string, err os.Error) {
	var resp *http.Response
	parms := http.Values{}
	parms.Set("Action", "ReceiveMessage")
	if vt >= 0 {
		parms.Set("VisibilityTimeout", strconv.Itoa(vt))
	}
	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	if err == nil {
		resp, err = self.conn.Request(req)
		if err == nil {
			defer resp.Body.Close()
		}
		if err == nil && resp.StatusCode != http.StatusOK {
			err = os.NewError("Unexpected response")
		}
		if err == nil {
			msg := message{}
			err = xml.Unmarshal(resp.Body, &msg)
			if err == nil {
				body, msgid = msg.Body, msg.ReceiptHandle
			}
		}
	}
	return
}
예제 #2
0
파일: service.go 프로젝트: abneptis/GoAWS
func (self *Service) ListQueues(id *aws.Signer, prefix string) (mq []string, err os.Error) {
	var resp *http.Response
	parms := http.Values{}
	parms.Set("Action", "ListQueues")
	if prefix != "" {
		parms.Set("QueueNamePrefix", prefix)
	}

	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	resp, err = self.conn.Request(req)
	if err == nil {
		defer resp.Body.Close()
		xresp := listQueuesResponse{}
		if resp.StatusCode == http.StatusOK {
			err = xml.Unmarshal(resp.Body, &xresp)
		} else {
			err = os.NewError("Unexpected response code")
		}
		if err == nil {
			mq = xresp.QueueURL
		}

	}
	return
}
예제 #3
0
파일: service.go 프로젝트: abneptis/GoAWS
func (self *Service) DescribeInstances(id *aws.Signer, filter http.Values, ic chan Instance) (err os.Error) {
	if filter == nil {
		filter = http.Values{}
	}
	filter.Set("Action", "DescribeInstances")
	req := aws.NewRequest(self.URL, "GET", nil, filter)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	if err != nil {
		return
	}
	resp, err := self.conn.Request(req)
	if err == nil {
		defer resp.Body.Close()
		xresp := describeInstancesResponse{}
		err := xml.Unmarshal(resp.Body, &xresp)
		if err == nil {
			log.Printf("XRESP == %+v", xresp)
		} else {
			log.Printf("XERR == %+v", err)
		}
		ob, _ := http.DumpResponse(resp, true)
		os.Stdout.Write(ob)
	}

	return
}
예제 #4
0
파일: service.go 프로젝트: abneptis/GoAWS
// 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
}
예제 #5
0
파일: client.go 프로젝트: abneptis/riak
func getBucketRequest(c Client, name string, getprops, getkeys bool) (req *http.Request) {
	hdrs := http.Header{"Content-Type": []string{"application/json"}}
	qry := http.Values{}
	if !getprops {
		qry.Set("props", "false")
	}
	if getkeys {
		qry.Set("keys", "true")
	}

	req = c.request("GET", c.bucketPath(name), hdrs, qry)
	return
}
예제 #6
0
파일: escape.go 프로젝트: justinbarry/GoAWS
// (2011-06-21) - The standard go http.Values.Escape
// works properly for SQS  and S3, but it should be
// noted that at least SDB requiers more to be escaped
// than is officially standard.
//
// Sorted Escape also sorts the keys before joining them (needed
// for canonicalization).
func SortedEscape(v http.Values) (out string) {
	keys := []string{}
	for k, _ := range v {
		keys = append(keys, k)
	}
	sort.SortStrings(keys)
	for k := range keys {
		if k > 0 {
			out += "&"
		}
		// out += http.URLEscape(keys[k]) + "=" + http.URLEscape(v.Get(keys[k]))
		out += escape(keys[k]) + "=" + escape(v.Get(keys[k]))
	}
	return
}
예제 #7
0
파일: client.go 프로젝트: abneptis/riak
func (self Client) request(method string, p string, hdrs http.Header, vals http.Values) (req *http.Request) {
	req = &http.Request{
		Method: method,
		Host:   self.RootURL.Host,
		URL:    &http.URL{Path: path.Join(self.RootURL.Path, p)},
		Header: hdrs,
	}
	if method == "GET" {
		req.URL.RawQuery = vals.Encode()
	}
	// TODO: Deletes?
	if method == "POST" || method == "PUT" {
		req.Header.Set("X-Riak-ClientId", self.ClientId)
	}
	return
}
예제 #8
0
// Constructs a basic http.Request based off of a fully-qualified URL
func NewRequest(url *http.URL, method string, hdrs http.Header, params http.Values) (req *http.Request) {
	req = &http.Request{
		Method: method,
		URL: &http.URL{
			Path:     url.Path,
			RawQuery: url.RawQuery,
		},
		Host:   url.Host,
		Header: hdrs,
		Form:   params,
	}
	if req.URL.RawQuery != "" {
		req.URL.RawQuery += "&"
	}
	req.URL.RawQuery += params.Encode()
	return
}
예제 #9
0
파일: service.go 프로젝트: abneptis/GoAWS
// Create a queue, returning the Queue object.
func (self *Service) CreateQueue(id *aws.Signer, name string, dvtimeout int) (mq *Queue, err os.Error) {
	var resp *http.Response
	parms := http.Values{}
	parms.Set("Action", "CreateQueue")
	parms.Set("QueueName", name)
	parms.Set("DefaultVisibilityTimeout", strconv.Itoa(dvtimeout))

	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	if err == nil {
		resp, err = self.conn.Request(req)
		if err == nil {
			defer resp.Body.Close()
			if resp.StatusCode == http.StatusOK {
				xmlresp := createQueueResponse{}
				err = xml.Unmarshal(resp.Body, &xmlresp)
				if err == nil {
					var qrl *http.URL
					qrl, err = http.ParseURL(xmlresp.QueueURL)
					if err == nil {
						mq = NewQueue(qrl)
					}
				}
			} else {
				err = os.NewError("Unexpected response")
			}
		}
	}

	return
}
예제 #10
0
파일: queue.go 프로젝트: justinbarry/GoAWS
// Note: 0 is a valid timeout!!
func (self *Queue) Delete(id *aws.Signer, mid string) (err os.Error) {
	var resp *http.Response
	parms := http.Values{}
	parms.Set("Action", "DeleteMessage")
	parms.Set("ReceiptHandle", mid)
	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	if err == nil {
		resp, err = self.conn.Request(req)
		if err == nil {
			defer resp.Body.Close()
		}
		if resp.StatusCode != http.StatusOK {
			err = os.NewError("Unexpected response")
		}
	}
	return
}
예제 #11
0
파일: queue.go 프로젝트: justinbarry/GoAWS
func (self *Queue) Push(id *aws.Signer, body []byte) (err os.Error) {
	var resp *http.Response
	parms := http.Values{}
	parms.Set("Action", "SendMessage")
	parms.Set("MessageBody", string(body))
	req := aws.NewRequest(self.URL, "GET", nil, parms)
	err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_VERSION, 15)
	if err == nil {
		resp, err = self.conn.Request(req)
		if err == nil {
			defer resp.Body.Close()
			if resp.StatusCode != http.StatusOK {
				err = os.NewError("Unexpected response")
			}
		}
	}
	return
}
예제 #12
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
}
예제 #13
0
파일: service.go 프로젝트: abneptis/GoAWS
func (self *Service) DescribeLoadBalancers(id *aws.Signer) (lbs []LoadBalancerDescription, err os.Error) {
	parms := http.Values{}
	parms.Set("Action", "DescribeLoadBalancers")
	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 {
		qr := LoadBalancerQueryResult{}
		defer resp.Body.Close()
		err = xml.Unmarshal(resp.Body, &qr)
		if err == nil {
			lbs = qr.LoadBalancerDescription
		}
	}

	return
}
예제 #14
0
파일: service.go 프로젝트: abneptis/GoAWS
func (self *Service) CreateLoadBalancer(id *aws.Signer, name string, zones []string, listeners []Listener) (err os.Error) {
	parms := http.Values{}
	parms.Set("Action", "CreateLoadBalancer")
	parms.Set("LoadBalancerName", name)
	for zi := range zones {
		parms.Set(Sprintf("AvailabilityZones.members.%d", zi+1), zones[zi])
	}
	for li := range listeners {
		listeners[li].SetValues(parms, li+1)
	}
	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 {
		defer resp.Body.Close()
		ob, _ := http.DumpResponse(resp, true)
		os.Stdout.Write(ob)
	}
	return

}
예제 #15
0
파일: domain.go 프로젝트: justinbarry/GoAWS
func (self *Domain) Select(id *aws.Signer, what, where string, consist bool, items chan<- Item) (err os.Error) {
	var resp *http.Response

	vl := http.Values{}

	vl.Set("Action", "Select")
	if where != "" {
		where = " where " + where
	}
	vl.Set("SelectExpression", fmt.Sprintf("select %s from %s%s", what, self.Name, where))

	if consist {
		vl.Set("ConsistentRead", "true")
	}
	done := false
	nextToken := ""
	for err == nil && !done {
		vl.Del("NextToken")
		if nextToken != "" {
			vl.Set("NextToken", nextToken)
		}
		req := aws.NewRequest(self.URL, "GET", nil, vl)
		err = id.SignRequestV2(req, aws.Canonicalize, DEFAULT_API_VERSION, 0)
		if err == nil {
			resp, err = self.conn.Request(req)
		}
		if err == nil {
			ob, _ := http.DumpResponse(resp, true)
			os.Stdout.Write(ob)
			xresp := selectresponse{}
			err = xml.Unmarshal(resp.Body, &xresp)
			if err == nil {
				fmt.Printf("XML == %+v", xresp)
				for i := range xresp.Items {
					items <- xresp.Items[i]
				}
				nextToken = xresp.NextToken
				done = (nextToken == "")
			}
			resp.Body.Close()
		}
	}
	return
}
예제 #16
0
파일: service.go 프로젝트: abneptis/GoAWS
func (self Listener) SetValues(v http.Values, i int) {
	v.Set(Sprintf("Listeners.members.%d.LoadBalancerPort", i), strconv.Itoa(self.LoadBalancerPort))
	v.Set(Sprintf("Listeners.members.%d.InstancePort", i), strconv.Itoa(self.InstancePort))
	v.Set(Sprintf("Listeners.members.%d.Protocol", i), self.Protocol)
}