aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/aws/aws-sdk-go/private/protocol/rest
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/aws/aws-sdk-go/private/protocol/rest')
-rw-r--r--vendor/github.com/aws/aws-sdk-go/private/protocol/rest/build.go295
-rw-r--r--vendor/github.com/aws/aws-sdk-go/private/protocol/rest/payload.go45
-rw-r--r--vendor/github.com/aws/aws-sdk-go/private/protocol/rest/unmarshal.go225
3 files changed, 0 insertions, 565 deletions
diff --git a/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/build.go b/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/build.go
deleted file mode 100644
index b34f525..0000000
--- a/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/build.go
+++ /dev/null
@@ -1,295 +0,0 @@
-// Package rest provides RESTful serialization of AWS requests and responses.
-package rest
-
-import (
- "bytes"
- "encoding/base64"
- "fmt"
- "io"
- "net/http"
- "net/url"
- "path"
- "reflect"
- "strconv"
- "strings"
- "time"
-
- "github.com/aws/aws-sdk-go/aws"
- "github.com/aws/aws-sdk-go/aws/awserr"
- "github.com/aws/aws-sdk-go/aws/request"
- "github.com/aws/aws-sdk-go/private/protocol"
-)
-
-// Whether the byte value can be sent without escaping in AWS URLs
-var noEscape [256]bool
-
-var errValueNotSet = fmt.Errorf("value not set")
-
-func init() {
- for i := 0; i < len(noEscape); i++ {
- // AWS expects every character except these to be escaped
- noEscape[i] = (i >= 'A' && i <= 'Z') ||
- (i >= 'a' && i <= 'z') ||
- (i >= '0' && i <= '9') ||
- i == '-' ||
- i == '.' ||
- i == '_' ||
- i == '~'
- }
-}
-
-// BuildHandler is a named request handler for building rest protocol requests
-var BuildHandler = request.NamedHandler{Name: "awssdk.rest.Build", Fn: Build}
-
-// Build builds the REST component of a service request.
-func Build(r *request.Request) {
- if r.ParamsFilled() {
- v := reflect.ValueOf(r.Params).Elem()
- buildLocationElements(r, v, false)
- buildBody(r, v)
- }
-}
-
-// BuildAsGET builds the REST component of a service request with the ability to hoist
-// data from the body.
-func BuildAsGET(r *request.Request) {
- if r.ParamsFilled() {
- v := reflect.ValueOf(r.Params).Elem()
- buildLocationElements(r, v, true)
- buildBody(r, v)
- }
-}
-
-func buildLocationElements(r *request.Request, v reflect.Value, buildGETQuery bool) {
- query := r.HTTPRequest.URL.Query()
-
- // Setup the raw path to match the base path pattern. This is needed
- // so that when the path is mutated a custom escaped version can be
- // stored in RawPath that will be used by the Go client.
- r.HTTPRequest.URL.RawPath = r.HTTPRequest.URL.Path
-
- for i := 0; i < v.NumField(); i++ {
- m := v.Field(i)
- if n := v.Type().Field(i).Name; n[0:1] == strings.ToLower(n[0:1]) {
- continue
- }
-
- if m.IsValid() {
- field := v.Type().Field(i)
- name := field.Tag.Get("locationName")
- if name == "" {
- name = field.Name
- }
- if kind := m.Kind(); kind == reflect.Ptr {
- m = m.Elem()
- } else if kind == reflect.Interface {
- if !m.Elem().IsValid() {
- continue
- }
- }
- if !m.IsValid() {
- continue
- }
- if field.Tag.Get("ignore") != "" {
- continue
- }
-
- var err error
- switch field.Tag.Get("location") {
- case "headers": // header maps
- err = buildHeaderMap(&r.HTTPRequest.Header, m, field.Tag)
- case "header":
- err = buildHeader(&r.HTTPRequest.Header, m, name, field.Tag)
- case "uri":
- err = buildURI(r.HTTPRequest.URL, m, name, field.Tag)
- case "querystring":
- err = buildQueryString(query, m, name, field.Tag)
- default:
- if buildGETQuery {
- err = buildQueryString(query, m, name, field.Tag)
- }
- }
- r.Error = err
- }
- if r.Error != nil {
- return
- }
- }
-
- r.HTTPRequest.URL.RawQuery = query.Encode()
- if !aws.BoolValue(r.Config.DisableRestProtocolURICleaning) {
- cleanPath(r.HTTPRequest.URL)
- }
-}
-
-func buildBody(r *request.Request, v reflect.Value) {
- if field, ok := v.Type().FieldByName("_"); ok {
- if payloadName := field.Tag.Get("payload"); payloadName != "" {
- pfield, _ := v.Type().FieldByName(payloadName)
- if ptag := pfield.Tag.Get("type"); ptag != "" && ptag != "structure" {
- payload := reflect.Indirect(v.FieldByName(payloadName))
- if payload.IsValid() && payload.Interface() != nil {
- switch reader := payload.Interface().(type) {
- case io.ReadSeeker:
- r.SetReaderBody(reader)
- case []byte:
- r.SetBufferBody(reader)
- case string:
- r.SetStringBody(reader)
- default:
- r.Error = awserr.New("SerializationError",
- "failed to encode REST request",
- fmt.Errorf("unknown payload type %s", payload.Type()))
- }
- }
- }
- }
- }
-}
-
-func buildHeader(header *http.Header, v reflect.Value, name string, tag reflect.StructTag) error {
- str, err := convertType(v, tag)
- if err == errValueNotSet {
- return nil
- } else if err != nil {
- return awserr.New("SerializationError", "failed to encode REST request", err)
- }
-
- header.Add(name, str)
-
- return nil
-}
-
-func buildHeaderMap(header *http.Header, v reflect.Value, tag reflect.StructTag) error {
- prefix := tag.Get("locationName")
- for _, key := range v.MapKeys() {
- str, err := convertType(v.MapIndex(key), tag)
- if err == errValueNotSet {
- continue
- } else if err != nil {
- return awserr.New("SerializationError", "failed to encode REST request", err)
-
- }
-
- header.Add(prefix+key.String(), str)
- }
- return nil
-}
-
-func buildURI(u *url.URL, v reflect.Value, name string, tag reflect.StructTag) error {
- value, err := convertType(v, tag)
- if err == errValueNotSet {
- return nil
- } else if err != nil {
- return awserr.New("SerializationError", "failed to encode REST request", err)
- }
-
- u.Path = strings.Replace(u.Path, "{"+name+"}", value, -1)
- u.Path = strings.Replace(u.Path, "{"+name+"+}", value, -1)
-
- u.RawPath = strings.Replace(u.RawPath, "{"+name+"}", EscapePath(value, true), -1)
- u.RawPath = strings.Replace(u.RawPath, "{"+name+"+}", EscapePath(value, false), -1)
-
- return nil
-}
-
-func buildQueryString(query url.Values, v reflect.Value, name string, tag reflect.StructTag) error {
- switch value := v.Interface().(type) {
- case []*string:
- for _, item := range value {
- query.Add(name, *item)
- }
- case map[string]*string:
- for key, item := range value {
- query.Add(key, *item)
- }
- case map[string][]*string:
- for key, items := range value {
- for _, item := range items {
- query.Add(key, *item)
- }
- }
- default:
- str, err := convertType(v, tag)
- if err == errValueNotSet {
- return nil
- } else if err != nil {
- return awserr.New("SerializationError", "failed to encode REST request", err)
- }
- query.Set(name, str)
- }
-
- return nil
-}
-
-func cleanPath(u *url.URL) {
- hasSlash := strings.HasSuffix(u.Path, "/")
-
- // clean up path, removing duplicate `/`
- u.Path = path.Clean(u.Path)
- u.RawPath = path.Clean(u.RawPath)
-
- if hasSlash && !strings.HasSuffix(u.Path, "/") {
- u.Path += "/"
- u.RawPath += "/"
- }
-}
-
-// EscapePath escapes part of a URL path in Amazon style
-func EscapePath(path string, encodeSep bool) string {
- var buf bytes.Buffer
- for i := 0; i < len(path); i++ {
- c := path[i]
- if noEscape[c] || (c == '/' && !encodeSep) {
- buf.WriteByte(c)
- } else {
- fmt.Fprintf(&buf, "%%%02X", c)
- }
- }
- return buf.String()
-}
-
-func convertType(v reflect.Value, tag reflect.StructTag) (str string, err error) {
- v = reflect.Indirect(v)
- if !v.IsValid() {
- return "", errValueNotSet
- }
-
- switch value := v.Interface().(type) {
- case string:
- str = value
- case []byte:
- str = base64.StdEncoding.EncodeToString(value)
- case bool:
- str = strconv.FormatBool(value)
- case int64:
- str = strconv.FormatInt(value, 10)
- case float64:
- str = strconv.FormatFloat(value, 'f', -1, 64)
- case time.Time:
- format := tag.Get("timestampFormat")
- if len(format) == 0 {
- format = protocol.RFC822TimeFormatName
- if tag.Get("location") == "querystring" {
- format = protocol.ISO8601TimeFormatName
- }
- }
- str = protocol.FormatTime(format, value)
- case aws.JSONValue:
- if len(value) == 0 {
- return "", errValueNotSet
- }
- escaping := protocol.NoEscape
- if tag.Get("location") == "header" {
- escaping = protocol.Base64Escape
- }
- str, err = protocol.EncodeJSONValue(value, escaping)
- if err != nil {
- return "", fmt.Errorf("unable to encode JSONValue, %v", err)
- }
- default:
- err := fmt.Errorf("unsupported value for param %v (%s)", v.Interface(), v.Type())
- return "", err
- }
- return str, nil
-}
diff --git a/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/payload.go b/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/payload.go
deleted file mode 100644
index 4366de2..0000000
--- a/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/payload.go
+++ /dev/null
@@ -1,45 +0,0 @@
-package rest
-
-import "reflect"
-
-// PayloadMember returns the payload field member of i if there is one, or nil.
-func PayloadMember(i interface{}) interface{} {
- if i == nil {
- return nil
- }
-
- v := reflect.ValueOf(i).Elem()
- if !v.IsValid() {
- return nil
- }
- if field, ok := v.Type().FieldByName("_"); ok {
- if payloadName := field.Tag.Get("payload"); payloadName != "" {
- field, _ := v.Type().FieldByName(payloadName)
- if field.Tag.Get("type") != "structure" {
- return nil
- }
-
- payload := v.FieldByName(payloadName)
- if payload.IsValid() || (payload.Kind() == reflect.Ptr && !payload.IsNil()) {
- return payload.Interface()
- }
- }
- }
- return nil
-}
-
-// PayloadType returns the type of a payload field member of i if there is one, or "".
-func PayloadType(i interface{}) string {
- v := reflect.Indirect(reflect.ValueOf(i))
- if !v.IsValid() {
- return ""
- }
- if field, ok := v.Type().FieldByName("_"); ok {
- if payloadName := field.Tag.Get("payload"); payloadName != "" {
- if member, ok := v.Type().FieldByName(payloadName); ok {
- return member.Tag.Get("type")
- }
- }
- }
- return ""
-}
diff --git a/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/unmarshal.go b/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/unmarshal.go
deleted file mode 100644
index 33fd53b..0000000
--- a/vendor/github.com/aws/aws-sdk-go/private/protocol/rest/unmarshal.go
+++ /dev/null
@@ -1,225 +0,0 @@
-package rest
-
-import (
- "bytes"
- "encoding/base64"
- "fmt"
- "io"
- "io/ioutil"
- "net/http"
- "reflect"
- "strconv"
- "strings"
- "time"
-
- "github.com/aws/aws-sdk-go/aws"
- "github.com/aws/aws-sdk-go/aws/awserr"
- "github.com/aws/aws-sdk-go/aws/request"
- "github.com/aws/aws-sdk-go/private/protocol"
-)
-
-// UnmarshalHandler is a named request handler for unmarshaling rest protocol requests
-var UnmarshalHandler = request.NamedHandler{Name: "awssdk.rest.Unmarshal", Fn: Unmarshal}
-
-// UnmarshalMetaHandler is a named request handler for unmarshaling rest protocol request metadata
-var UnmarshalMetaHandler = request.NamedHandler{Name: "awssdk.rest.UnmarshalMeta", Fn: UnmarshalMeta}
-
-// Unmarshal unmarshals the REST component of a response in a REST service.
-func Unmarshal(r *request.Request) {
- if r.DataFilled() {
- v := reflect.Indirect(reflect.ValueOf(r.Data))
- unmarshalBody(r, v)
- }
-}
-
-// UnmarshalMeta unmarshals the REST metadata of a response in a REST service
-func UnmarshalMeta(r *request.Request) {
- r.RequestID = r.HTTPResponse.Header.Get("X-Amzn-Requestid")
- if r.RequestID == "" {
- // Alternative version of request id in the header
- r.RequestID = r.HTTPResponse.Header.Get("X-Amz-Request-Id")
- }
- if r.DataFilled() {
- v := reflect.Indirect(reflect.ValueOf(r.Data))
- unmarshalLocationElements(r, v)
- }
-}
-
-func unmarshalBody(r *request.Request, v reflect.Value) {
- if field, ok := v.Type().FieldByName("_"); ok {
- if payloadName := field.Tag.Get("payload"); payloadName != "" {
- pfield, _ := v.Type().FieldByName(payloadName)
- if ptag := pfield.Tag.Get("type"); ptag != "" && ptag != "structure" {
- payload := v.FieldByName(payloadName)
- if payload.IsValid() {
- switch payload.Interface().(type) {
- case []byte:
- defer r.HTTPResponse.Body.Close()
- b, err := ioutil.ReadAll(r.HTTPResponse.Body)
- if err != nil {
- r.Error = awserr.New("SerializationError", "failed to decode REST response", err)
- } else {
- payload.Set(reflect.ValueOf(b))
- }
- case *string:
- defer r.HTTPResponse.Body.Close()
- b, err := ioutil.ReadAll(r.HTTPResponse.Body)
- if err != nil {
- r.Error = awserr.New("SerializationError", "failed to decode REST response", err)
- } else {
- str := string(b)
- payload.Set(reflect.ValueOf(&str))
- }
- default:
- switch payload.Type().String() {
- case "io.ReadCloser":
- payload.Set(reflect.ValueOf(r.HTTPResponse.Body))
- case "io.ReadSeeker":
- b, err := ioutil.ReadAll(r.HTTPResponse.Body)
- if err != nil {
- r.Error = awserr.New("SerializationError",
- "failed to read response body", err)
- return
- }
- payload.Set(reflect.ValueOf(ioutil.NopCloser(bytes.NewReader(b))))
- default:
- io.Copy(ioutil.Discard, r.HTTPResponse.Body)
- defer r.HTTPResponse.Body.Close()
- r.Error = awserr.New("SerializationError",
- "failed to decode REST response",
- fmt.Errorf("unknown payload type %s", payload.Type()))
- }
- }
- }
- }
- }
- }
-}
-
-func unmarshalLocationElements(r *request.Request, v reflect.Value) {
- for i := 0; i < v.NumField(); i++ {
- m, field := v.Field(i), v.Type().Field(i)
- if n := field.Name; n[0:1] == strings.ToLower(n[0:1]) {
- continue
- }
-
- if m.IsValid() {
- name := field.Tag.Get("locationName")
- if name == "" {
- name = field.Name
- }
-
- switch field.Tag.Get("location") {
- case "statusCode":
- unmarshalStatusCode(m, r.HTTPResponse.StatusCode)
- case "header":
- err := unmarshalHeader(m, r.HTTPResponse.Header.Get(name), field.Tag)
- if err != nil {
- r.Error = awserr.New("SerializationError", "failed to decode REST response", err)
- break
- }
- case "headers":
- prefix := field.Tag.Get("locationName")
- err := unmarshalHeaderMap(m, r.HTTPResponse.Header, prefix)
- if err != nil {
- r.Error = awserr.New("SerializationError", "failed to decode REST response", err)
- break
- }
- }
- }
- if r.Error != nil {
- return
- }
- }
-}
-
-func unmarshalStatusCode(v reflect.Value, statusCode int) {
- if !v.IsValid() {
- return
- }
-
- switch v.Interface().(type) {
- case *int64:
- s := int64(statusCode)
- v.Set(reflect.ValueOf(&s))
- }
-}
-
-func unmarshalHeaderMap(r reflect.Value, headers http.Header, prefix string) error {
- switch r.Interface().(type) {
- case map[string]*string: // we only support string map value types
- out := map[string]*string{}
- for k, v := range headers {
- k = http.CanonicalHeaderKey(k)
- if strings.HasPrefix(strings.ToLower(k), strings.ToLower(prefix)) {
- out[k[len(prefix):]] = &v[0]
- }
- }
- r.Set(reflect.ValueOf(out))
- }
- return nil
-}
-
-func unmarshalHeader(v reflect.Value, header string, tag reflect.StructTag) error {
- isJSONValue := tag.Get("type") == "jsonvalue"
- if isJSONValue {
- if len(header) == 0 {
- return nil
- }
- } else if !v.IsValid() || (header == "" && v.Elem().Kind() != reflect.String) {
- return nil
- }
-
- switch v.Interface().(type) {
- case *string:
- v.Set(reflect.ValueOf(&header))
- case []byte:
- b, err := base64.StdEncoding.DecodeString(header)
- if err != nil {
- return err
- }
- v.Set(reflect.ValueOf(&b))
- case *bool:
- b, err := strconv.ParseBool(header)
- if err != nil {
- return err
- }
- v.Set(reflect.ValueOf(&b))
- case *int64:
- i, err := strconv.ParseInt(header, 10, 64)
- if err != nil {
- return err
- }
- v.Set(reflect.ValueOf(&i))
- case *float64:
- f, err := strconv.ParseFloat(header, 64)
- if err != nil {
- return err
- }
- v.Set(reflect.ValueOf(&f))
- case *time.Time:
- format := tag.Get("timestampFormat")
- if len(format) == 0 {
- format = protocol.RFC822TimeFormatName
- }
- t, err := protocol.ParseTime(format, header)
- if err != nil {
- return err
- }
- v.Set(reflect.ValueOf(&t))
- case aws.JSONValue:
- escaping := protocol.NoEscape
- if tag.Get("location") == "header" {
- escaping = protocol.Base64Escape
- }
- m, err := protocol.DecodeJSONValue(header, escaping)
- if err != nil {
- return err
- }
- v.Set(reflect.ValueOf(m))
- default:
- err := fmt.Errorf("Unsupported value for param %v (%s)", v.Interface(), v.Type())
- return err
- }
- return nil
-}