Prune dependencies (#1917)
When running `dep prune` explicitly, the following message show up: ``` dep prune Pruning is now performed automatically by dep ensure. ``` However, after the explicit `dep prune`, there are still many files deleted. (Guess `dep ensure` is not complete yet). This fix did a `dep prune` to clean up unneeded files. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
fcc32a79d4
commit
c7321fabc2
10332 changed files with 0 additions and 4102992 deletions
894
vendor/github.com/aws/aws-sdk-go/private/model/api/api.go
generated
vendored
894
vendor/github.com/aws/aws-sdk-go/private/model/api/api.go
generated
vendored
|
@ -1,894 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
// Package api represents API abstractions for rendering service generated files.
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/template"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// An API defines a service API's definition. and logic to serialize the definition.
|
||||
type API struct {
|
||||
Metadata Metadata
|
||||
Operations map[string]*Operation
|
||||
Shapes map[string]*Shape
|
||||
Waiters []Waiter
|
||||
Documentation string
|
||||
Examples Examples
|
||||
|
||||
// Set to true to avoid removing unused shapes
|
||||
NoRemoveUnusedShapes bool
|
||||
|
||||
// Set to true to avoid renaming to 'Input/Output' postfixed shapes
|
||||
NoRenameToplevelShapes bool
|
||||
|
||||
// Set to true to ignore service/request init methods (for testing)
|
||||
NoInitMethods bool
|
||||
|
||||
// Set to true to ignore String() and GoString methods (for generated tests)
|
||||
NoStringerMethods bool
|
||||
|
||||
// Set to true to not generate API service name constants
|
||||
NoConstServiceNames bool
|
||||
|
||||
// Set to true to not generate validation shapes
|
||||
NoValidataShapeMethods bool
|
||||
|
||||
// Set to true to not generate struct field accessors
|
||||
NoGenStructFieldAccessors bool
|
||||
|
||||
SvcClientImportPath string
|
||||
|
||||
initialized bool
|
||||
imports map[string]bool
|
||||
name string
|
||||
path string
|
||||
|
||||
BaseCrosslinkURL string
|
||||
|
||||
HasEventStream bool `json:"-"`
|
||||
}
|
||||
|
||||
// A Metadata is the metadata about an API's definition.
|
||||
type Metadata struct {
|
||||
APIVersion string
|
||||
EndpointPrefix string
|
||||
SigningName string
|
||||
ServiceAbbreviation string
|
||||
ServiceFullName string
|
||||
SignatureVersion string
|
||||
JSONVersion string
|
||||
TargetPrefix string
|
||||
Protocol string
|
||||
UID string
|
||||
EndpointsID string
|
||||
ServiceID string
|
||||
|
||||
NoResolveEndpoint bool
|
||||
}
|
||||
|
||||
var serviceAliases map[string]string
|
||||
|
||||
func Bootstrap() error {
|
||||
b, err := ioutil.ReadFile(filepath.Join("..", "models", "customizations", "service-aliases.json"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return json.Unmarshal(b, &serviceAliases)
|
||||
}
|
||||
|
||||
// PackageName name of the API package
|
||||
func (a *API) PackageName() string {
|
||||
return strings.ToLower(a.StructName())
|
||||
}
|
||||
|
||||
// InterfacePackageName returns the package name for the interface.
|
||||
func (a *API) InterfacePackageName() string {
|
||||
return a.PackageName() + "iface"
|
||||
}
|
||||
|
||||
var stripServiceNamePrefixes = []string{
|
||||
"Amazon",
|
||||
"AWS",
|
||||
}
|
||||
|
||||
// StructName returns the struct name for a given API.
|
||||
func (a *API) StructName() string {
|
||||
if len(a.name) != 0 {
|
||||
return a.name
|
||||
}
|
||||
|
||||
name := a.Metadata.ServiceAbbreviation
|
||||
if len(name) == 0 {
|
||||
name = a.Metadata.ServiceFullName
|
||||
}
|
||||
|
||||
name = strings.TrimSpace(name)
|
||||
|
||||
// Strip out prefix names not reflected in service client symbol names.
|
||||
for _, prefix := range stripServiceNamePrefixes {
|
||||
if strings.HasPrefix(name, prefix) {
|
||||
name = name[len(prefix):]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Replace all Non-letter/number values with space
|
||||
runes := []rune(name)
|
||||
for i := 0; i < len(runes); i++ {
|
||||
if r := runes[i]; !(unicode.IsNumber(r) || unicode.IsLetter(r)) {
|
||||
runes[i] = ' '
|
||||
}
|
||||
}
|
||||
name = string(runes)
|
||||
|
||||
// Title case name so its readable as a symbol.
|
||||
name = strings.Title(name)
|
||||
|
||||
// Strip out spaces.
|
||||
name = strings.Replace(name, " ", "", -1)
|
||||
|
||||
// Swap out for alias name if one is defined.
|
||||
if alias, ok := serviceAliases[strings.ToLower(name)]; ok {
|
||||
name = alias
|
||||
}
|
||||
|
||||
a.name = name
|
||||
return a.name
|
||||
}
|
||||
|
||||
// UseInitMethods returns if the service's init method should be rendered.
|
||||
func (a *API) UseInitMethods() bool {
|
||||
return !a.NoInitMethods
|
||||
}
|
||||
|
||||
// NiceName returns the human friendly API name.
|
||||
func (a *API) NiceName() string {
|
||||
if a.Metadata.ServiceAbbreviation != "" {
|
||||
return a.Metadata.ServiceAbbreviation
|
||||
}
|
||||
return a.Metadata.ServiceFullName
|
||||
}
|
||||
|
||||
// ProtocolPackage returns the package name of the protocol this API uses.
|
||||
func (a *API) ProtocolPackage() string {
|
||||
switch a.Metadata.Protocol {
|
||||
case "json":
|
||||
return "jsonrpc"
|
||||
case "ec2":
|
||||
return "ec2query"
|
||||
default:
|
||||
return strings.Replace(a.Metadata.Protocol, "-", "", -1)
|
||||
}
|
||||
}
|
||||
|
||||
// OperationNames returns a slice of API operations supported.
|
||||
func (a *API) OperationNames() []string {
|
||||
i, names := 0, make([]string, len(a.Operations))
|
||||
for n := range a.Operations {
|
||||
names[i] = n
|
||||
i++
|
||||
}
|
||||
sort.Strings(names)
|
||||
return names
|
||||
}
|
||||
|
||||
// OperationList returns a slice of API operation pointers
|
||||
func (a *API) OperationList() []*Operation {
|
||||
list := make([]*Operation, len(a.Operations))
|
||||
for i, n := range a.OperationNames() {
|
||||
list[i] = a.Operations[n]
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// OperationHasOutputPlaceholder returns if any of the API operation input
|
||||
// or output shapes are place holders.
|
||||
func (a *API) OperationHasOutputPlaceholder() bool {
|
||||
for _, op := range a.Operations {
|
||||
if op.OutputRef.Shape.Placeholder {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ShapeNames returns a slice of names for each shape used by the API.
|
||||
func (a *API) ShapeNames() []string {
|
||||
i, names := 0, make([]string, len(a.Shapes))
|
||||
for n := range a.Shapes {
|
||||
names[i] = n
|
||||
i++
|
||||
}
|
||||
sort.Strings(names)
|
||||
return names
|
||||
}
|
||||
|
||||
// ShapeList returns a slice of shape pointers used by the API.
|
||||
//
|
||||
// Will exclude error shapes from the list of shapes returned.
|
||||
func (a *API) ShapeList() []*Shape {
|
||||
list := make([]*Shape, 0, len(a.Shapes))
|
||||
for _, n := range a.ShapeNames() {
|
||||
// Ignore error shapes in list
|
||||
if s := a.Shapes[n]; !s.IsError {
|
||||
list = append(list, s)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// ShapeListErrors returns a list of the errors defined by the API model
|
||||
func (a *API) ShapeListErrors() []*Shape {
|
||||
list := []*Shape{}
|
||||
for _, n := range a.ShapeNames() {
|
||||
// Ignore error shapes in list
|
||||
if s := a.Shapes[n]; s.IsError {
|
||||
list = append(list, s)
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// resetImports resets the import map to default values.
|
||||
func (a *API) resetImports() {
|
||||
a.imports = map[string]bool{
|
||||
"github.com/aws/aws-sdk-go/aws": true,
|
||||
}
|
||||
}
|
||||
|
||||
// importsGoCode returns the generated Go import code.
|
||||
func (a *API) importsGoCode() string {
|
||||
if len(a.imports) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
corePkgs, extPkgs := []string{}, []string{}
|
||||
for i := range a.imports {
|
||||
if strings.Contains(i, ".") {
|
||||
extPkgs = append(extPkgs, i)
|
||||
} else {
|
||||
corePkgs = append(corePkgs, i)
|
||||
}
|
||||
}
|
||||
sort.Strings(corePkgs)
|
||||
sort.Strings(extPkgs)
|
||||
|
||||
code := "import (\n"
|
||||
for _, i := range corePkgs {
|
||||
code += fmt.Sprintf("\t%q\n", i)
|
||||
}
|
||||
if len(corePkgs) > 0 {
|
||||
code += "\n"
|
||||
}
|
||||
for _, i := range extPkgs {
|
||||
code += fmt.Sprintf("\t%q\n", i)
|
||||
}
|
||||
code += ")\n\n"
|
||||
return code
|
||||
}
|
||||
|
||||
// A tplAPI is the top level template for the API
|
||||
var tplAPI = template.Must(template.New("api").Parse(`
|
||||
{{ range $_, $o := .OperationList }}
|
||||
{{ $o.GoCode }}
|
||||
|
||||
{{ end }}
|
||||
|
||||
{{ range $_, $s := .ShapeList }}
|
||||
{{ if and $s.IsInternal (eq $s.Type "structure") }}{{ $s.GoCode }}{{ end }}
|
||||
|
||||
{{ end }}
|
||||
|
||||
{{ range $_, $s := .ShapeList }}
|
||||
{{ if $s.IsEnum }}{{ $s.GoCode }}{{ end }}
|
||||
|
||||
{{ end }}
|
||||
`))
|
||||
|
||||
// APIGoCode renders the API in Go code. Returning it as a string
|
||||
func (a *API) APIGoCode() string {
|
||||
a.resetImports()
|
||||
a.imports["github.com/aws/aws-sdk-go/aws/awsutil"] = true
|
||||
a.imports["github.com/aws/aws-sdk-go/aws/request"] = true
|
||||
if a.OperationHasOutputPlaceholder() {
|
||||
a.imports["github.com/aws/aws-sdk-go/private/protocol/"+a.ProtocolPackage()] = true
|
||||
a.imports["github.com/aws/aws-sdk-go/private/protocol"] = true
|
||||
}
|
||||
|
||||
for _, op := range a.Operations {
|
||||
if op.AuthType == "none" {
|
||||
a.imports["github.com/aws/aws-sdk-go/aws/credentials"] = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
err := tplAPI.Execute(&buf, a)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
code := a.importsGoCode() + strings.TrimSpace(buf.String())
|
||||
return code
|
||||
}
|
||||
|
||||
var noCrossLinkServices = map[string]struct{}{
|
||||
"apigateway": {},
|
||||
"budgets": {},
|
||||
"cloudsearch": {},
|
||||
"cloudsearchdomain": {},
|
||||
"elastictranscoder": {},
|
||||
"es": {},
|
||||
"glacier": {},
|
||||
"importexport": {},
|
||||
"iot": {},
|
||||
"iot-data": {},
|
||||
"machinelearning": {},
|
||||
"rekognition": {},
|
||||
"sdb": {},
|
||||
"swf": {},
|
||||
}
|
||||
|
||||
// HasCrosslinks will return whether or not a service has crosslinking .
|
||||
func HasCrosslinks(service string) bool {
|
||||
_, ok := noCrossLinkServices[service]
|
||||
return !ok
|
||||
}
|
||||
|
||||
// GetCrosslinkURL returns the crosslinking URL for the shape based on the name and
|
||||
// uid provided. Empty string is returned if no crosslink link could be determined.
|
||||
func GetCrosslinkURL(baseURL, uid string, params ...string) string {
|
||||
if uid == "" || baseURL == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
if !HasCrosslinks(strings.ToLower(ServiceIDFromUID(uid))) {
|
||||
return ""
|
||||
}
|
||||
|
||||
return strings.Join(append([]string{baseURL, "goto", "WebAPI", uid}, params...), "/")
|
||||
}
|
||||
|
||||
// ServiceIDFromUID will parse the service id from the uid and return
|
||||
// the service id that was found.
|
||||
func ServiceIDFromUID(uid string) string {
|
||||
found := 0
|
||||
i := len(uid) - 1
|
||||
for ; i >= 0; i-- {
|
||||
if uid[i] == '-' {
|
||||
found++
|
||||
}
|
||||
// Terminate after the date component is found, e.g. es-2017-11-11
|
||||
if found == 3 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return uid[0:i]
|
||||
}
|
||||
|
||||
// APIName returns the API's service name.
|
||||
func (a *API) APIName() string {
|
||||
return a.name
|
||||
}
|
||||
|
||||
var tplServiceDoc = template.Must(template.New("service docs").Funcs(template.FuncMap{
|
||||
"GetCrosslinkURL": GetCrosslinkURL,
|
||||
}).
|
||||
Parse(`
|
||||
// Package {{ .PackageName }} provides the client and types for making API
|
||||
// requests to {{ .Metadata.ServiceFullName }}.
|
||||
{{ if .Documentation -}}
|
||||
//
|
||||
{{ .Documentation }}
|
||||
{{ end -}}
|
||||
{{ $crosslinkURL := GetCrosslinkURL $.BaseCrosslinkURL $.Metadata.UID -}}
|
||||
{{ if $crosslinkURL -}}
|
||||
//
|
||||
// See {{ $crosslinkURL }} for more information on this service.
|
||||
{{ end -}}
|
||||
//
|
||||
// See {{ .PackageName }} package documentation for more information.
|
||||
// https://docs.aws.amazon.com/sdk-for-go/api/service/{{ .PackageName }}/
|
||||
//
|
||||
// Using the Client
|
||||
//
|
||||
// To contact {{ .Metadata.ServiceFullName }} with the SDK use the New function to create
|
||||
// a new service client. With that client you can make API requests to the service.
|
||||
// These clients are safe to use concurrently.
|
||||
//
|
||||
// See the SDK's documentation for more information on how to use the SDK.
|
||||
// https://docs.aws.amazon.com/sdk-for-go/api/
|
||||
//
|
||||
// See aws.Config documentation for more information on configuring SDK clients.
|
||||
// https://docs.aws.amazon.com/sdk-for-go/api/aws/#Config
|
||||
//
|
||||
// See the {{ .Metadata.ServiceFullName }} client {{ .StructName }} for more
|
||||
// information on creating client for this service.
|
||||
// https://docs.aws.amazon.com/sdk-for-go/api/service/{{ .PackageName }}/#New
|
||||
`))
|
||||
|
||||
var serviceIDRegex = regexp.MustCompile("[^a-zA-Z0-9 ]+")
|
||||
var prefixDigitRegex = regexp.MustCompile("^[0-9]+")
|
||||
|
||||
// ServiceID will return a unique identifier specific to a service.
|
||||
func ServiceID(a *API) string {
|
||||
if len(a.Metadata.ServiceID) > 0 {
|
||||
return a.Metadata.ServiceID
|
||||
}
|
||||
|
||||
name := a.Metadata.ServiceAbbreviation
|
||||
if len(name) == 0 {
|
||||
name = a.Metadata.ServiceFullName
|
||||
}
|
||||
|
||||
name = strings.Replace(name, "Amazon", "", -1)
|
||||
name = strings.Replace(name, "AWS", "", -1)
|
||||
name = serviceIDRegex.ReplaceAllString(name, "")
|
||||
name = prefixDigitRegex.ReplaceAllString(name, "")
|
||||
name = strings.TrimSpace(name)
|
||||
return name
|
||||
}
|
||||
|
||||
// A tplService defines the template for the service generated code.
|
||||
var tplService = template.Must(template.New("service").Funcs(template.FuncMap{
|
||||
"ServiceNameConstValue": ServiceName,
|
||||
"ServiceNameValue": func(a *API) string {
|
||||
if !a.NoConstServiceNames {
|
||||
return "ServiceName"
|
||||
}
|
||||
return fmt.Sprintf("%q", ServiceName(a))
|
||||
},
|
||||
"EndpointsIDConstValue": func(a *API) string {
|
||||
if a.NoConstServiceNames {
|
||||
return fmt.Sprintf("%q", a.Metadata.EndpointsID)
|
||||
}
|
||||
if a.Metadata.EndpointsID == ServiceName(a) {
|
||||
return "ServiceName"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%q", a.Metadata.EndpointsID)
|
||||
},
|
||||
"EndpointsIDValue": func(a *API) string {
|
||||
if a.NoConstServiceNames {
|
||||
return fmt.Sprintf("%q", a.Metadata.EndpointsID)
|
||||
}
|
||||
|
||||
return "EndpointsID"
|
||||
},
|
||||
"ServiceIDVar": func(a *API) string {
|
||||
if a.NoConstServiceNames {
|
||||
return fmt.Sprintf("%q", ServiceID(a))
|
||||
}
|
||||
|
||||
return "ServiceID"
|
||||
},
|
||||
"ServiceID": ServiceID,
|
||||
}).Parse(`
|
||||
// {{ .StructName }} provides the API operation methods for making requests to
|
||||
// {{ .Metadata.ServiceFullName }}. See this package's package overview docs
|
||||
// for details on the service.
|
||||
//
|
||||
// {{ .StructName }} methods are safe to use concurrently. It is not safe to
|
||||
// modify mutate any of the struct's properties though.
|
||||
type {{ .StructName }} struct {
|
||||
*client.Client
|
||||
}
|
||||
|
||||
{{ if .UseInitMethods }}// Used for custom client initialization logic
|
||||
var initClient func(*client.Client)
|
||||
|
||||
// Used for custom request initialization logic
|
||||
var initRequest func(*request.Request)
|
||||
{{ end }}
|
||||
|
||||
|
||||
{{ if not .NoConstServiceNames -}}
|
||||
// Service information constants
|
||||
const (
|
||||
ServiceName = "{{ ServiceNameConstValue . }}" // Name of service.
|
||||
EndpointsID = {{ EndpointsIDConstValue . }} // ID to lookup a service endpoint with.
|
||||
ServiceID = "{{ ServiceID . }}" // ServiceID is a unique identifer of a specific service.
|
||||
)
|
||||
{{- end }}
|
||||
|
||||
// New creates a new instance of the {{ .StructName }} client with a session.
|
||||
// If additional configuration is needed for the client instance use the optional
|
||||
// aws.Config parameter to add your extra config.
|
||||
//
|
||||
// Example:
|
||||
// // Create a {{ .StructName }} client from just a session.
|
||||
// svc := {{ .PackageName }}.New(mySession)
|
||||
//
|
||||
// // Create a {{ .StructName }} client with additional configuration
|
||||
// svc := {{ .PackageName }}.New(mySession, aws.NewConfig().WithRegion("us-west-2"))
|
||||
func New(p client.ConfigProvider, cfgs ...*aws.Config) *{{ .StructName }} {
|
||||
{{ if .Metadata.NoResolveEndpoint -}}
|
||||
var c client.Config
|
||||
if v, ok := p.(client.ConfigNoResolveEndpointProvider); ok {
|
||||
c = v.ClientConfigNoResolveEndpoint(cfgs...)
|
||||
} else {
|
||||
c = p.ClientConfig({{ EndpointsIDValue . }}, cfgs...)
|
||||
}
|
||||
{{- else -}}
|
||||
c := p.ClientConfig({{ EndpointsIDValue . }}, cfgs...)
|
||||
{{- end }}
|
||||
|
||||
{{- if .Metadata.SigningName }}
|
||||
if c.SigningNameDerived || len(c.SigningName) == 0{
|
||||
c.SigningName = "{{ .Metadata.SigningName }}"
|
||||
}
|
||||
{{- end }}
|
||||
return newClient(*c.Config, c.Handlers, c.Endpoint, c.SigningRegion, c.SigningName)
|
||||
}
|
||||
|
||||
// newClient creates, initializes and returns a new service client instance.
|
||||
func newClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegion, signingName string) *{{ .StructName }} {
|
||||
svc := &{{ .StructName }}{
|
||||
Client: client.New(
|
||||
cfg,
|
||||
metadata.ClientInfo{
|
||||
ServiceName: {{ ServiceNameValue . }},
|
||||
ServiceID : {{ ServiceIDVar . }},
|
||||
SigningName: signingName,
|
||||
SigningRegion: signingRegion,
|
||||
Endpoint: endpoint,
|
||||
APIVersion: "{{ .Metadata.APIVersion }}",
|
||||
{{ if .Metadata.JSONVersion -}}
|
||||
JSONVersion: "{{ .Metadata.JSONVersion }}",
|
||||
{{- end }}
|
||||
{{ if .Metadata.TargetPrefix -}}
|
||||
TargetPrefix: "{{ .Metadata.TargetPrefix }}",
|
||||
{{- end }}
|
||||
},
|
||||
handlers,
|
||||
),
|
||||
}
|
||||
|
||||
// Handlers
|
||||
svc.Handlers.Sign.PushBackNamed({{if eq .Metadata.SignatureVersion "v2"}}v2{{else}}v4{{end}}.SignRequestHandler)
|
||||
{{- if eq .Metadata.SignatureVersion "v2" }}
|
||||
svc.Handlers.Sign.PushBackNamed(corehandlers.BuildContentLengthHandler)
|
||||
{{- end }}
|
||||
svc.Handlers.Build.PushBackNamed({{ .ProtocolPackage }}.BuildHandler)
|
||||
svc.Handlers.Unmarshal.PushBackNamed({{ .ProtocolPackage }}.UnmarshalHandler)
|
||||
svc.Handlers.UnmarshalMeta.PushBackNamed({{ .ProtocolPackage }}.UnmarshalMetaHandler)
|
||||
svc.Handlers.UnmarshalError.PushBackNamed({{ .ProtocolPackage }}.UnmarshalErrorHandler)
|
||||
{{ if .HasEventStream }}
|
||||
svc.Handlers.UnmarshalStream.PushBackNamed({{ .ProtocolPackage }}.UnmarshalHandler)
|
||||
{{ end }}
|
||||
|
||||
{{ if .UseInitMethods }}// Run custom client initialization if present
|
||||
if initClient != nil {
|
||||
initClient(svc.Client)
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
return svc
|
||||
}
|
||||
|
||||
// newRequest creates a new request for a {{ .StructName }} operation and runs any
|
||||
// custom request initialization.
|
||||
func (c *{{ .StructName }}) newRequest(op *request.Operation, params, data interface{}) *request.Request {
|
||||
req := c.NewRequest(op, params, data)
|
||||
|
||||
{{ if .UseInitMethods }}// Run custom request initialization if present
|
||||
if initRequest != nil {
|
||||
initRequest(req)
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
return req
|
||||
}
|
||||
`))
|
||||
|
||||
// ServicePackageDoc generates the contents of the doc file for the service.
|
||||
//
|
||||
// Will also read in the custom doc templates for the service if found.
|
||||
func (a *API) ServicePackageDoc() string {
|
||||
a.imports = map[string]bool{}
|
||||
|
||||
var buf bytes.Buffer
|
||||
if err := tplServiceDoc.Execute(&buf, a); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// ServiceGoCode renders service go code. Returning it as a string.
|
||||
func (a *API) ServiceGoCode() string {
|
||||
a.resetImports()
|
||||
a.imports["github.com/aws/aws-sdk-go/aws/client"] = true
|
||||
a.imports["github.com/aws/aws-sdk-go/aws/client/metadata"] = true
|
||||
a.imports["github.com/aws/aws-sdk-go/aws/request"] = true
|
||||
if a.Metadata.SignatureVersion == "v2" {
|
||||
a.imports["github.com/aws/aws-sdk-go/private/signer/v2"] = true
|
||||
a.imports["github.com/aws/aws-sdk-go/aws/corehandlers"] = true
|
||||
} else {
|
||||
a.imports["github.com/aws/aws-sdk-go/aws/signer/v4"] = true
|
||||
}
|
||||
a.imports["github.com/aws/aws-sdk-go/private/protocol/"+a.ProtocolPackage()] = true
|
||||
|
||||
var buf bytes.Buffer
|
||||
err := tplService.Execute(&buf, a)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
code := a.importsGoCode() + buf.String()
|
||||
return code
|
||||
}
|
||||
|
||||
// ExampleGoCode renders service example code. Returning it as a string.
|
||||
func (a *API) ExampleGoCode() string {
|
||||
exs := []string{}
|
||||
imports := map[string]bool{}
|
||||
for _, o := range a.OperationList() {
|
||||
o.imports = map[string]bool{}
|
||||
exs = append(exs, o.Example())
|
||||
for k, v := range o.imports {
|
||||
imports[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
code := fmt.Sprintf("import (\n%q\n%q\n%q\n\n%q\n%q\n%q\n",
|
||||
"bytes",
|
||||
"fmt",
|
||||
"time",
|
||||
"github.com/aws/aws-sdk-go/aws",
|
||||
"github.com/aws/aws-sdk-go/aws/session",
|
||||
path.Join(a.SvcClientImportPath, a.PackageName()),
|
||||
)
|
||||
for k := range imports {
|
||||
code += fmt.Sprintf("%q\n", k)
|
||||
}
|
||||
code += ")\n\n"
|
||||
code += "var _ time.Duration\nvar _ bytes.Buffer\n\n"
|
||||
code += strings.Join(exs, "\n\n")
|
||||
return code
|
||||
}
|
||||
|
||||
// A tplInterface defines the template for the service interface type.
|
||||
var tplInterface = template.Must(template.New("interface").Parse(`
|
||||
// {{ .StructName }}API provides an interface to enable mocking the
|
||||
// {{ .PackageName }}.{{ .StructName }} service client's API operation,
|
||||
// paginators, and waiters. This make unit testing your code that calls out
|
||||
// to the SDK's service client's calls easier.
|
||||
//
|
||||
// The best way to use this interface is so the SDK's service client's calls
|
||||
// can be stubbed out for unit testing your code with the SDK without needing
|
||||
// to inject custom request handlers into the SDK's request pipeline.
|
||||
//
|
||||
// // myFunc uses an SDK service client to make a request to
|
||||
// // {{.Metadata.ServiceFullName}}. {{ $opts := .OperationList }}{{ $opt := index $opts 0 }}
|
||||
// func myFunc(svc {{ .InterfacePackageName }}.{{ .StructName }}API) bool {
|
||||
// // Make svc.{{ $opt.ExportedName }} request
|
||||
// }
|
||||
//
|
||||
// func main() {
|
||||
// sess := session.New()
|
||||
// svc := {{ .PackageName }}.New(sess)
|
||||
//
|
||||
// myFunc(svc)
|
||||
// }
|
||||
//
|
||||
// In your _test.go file:
|
||||
//
|
||||
// // Define a mock struct to be used in your unit tests of myFunc.
|
||||
// type mock{{ .StructName }}Client struct {
|
||||
// {{ .InterfacePackageName }}.{{ .StructName }}API
|
||||
// }
|
||||
// func (m *mock{{ .StructName }}Client) {{ $opt.ExportedName }}(input {{ $opt.InputRef.GoTypeWithPkgName }}) ({{ $opt.OutputRef.GoTypeWithPkgName }}, error) {
|
||||
// // mock response/functionality
|
||||
// }
|
||||
//
|
||||
// func TestMyFunc(t *testing.T) {
|
||||
// // Setup Test
|
||||
// mockSvc := &mock{{ .StructName }}Client{}
|
||||
//
|
||||
// myfunc(mockSvc)
|
||||
//
|
||||
// // Verify myFunc's functionality
|
||||
// }
|
||||
//
|
||||
// It is important to note that this interface will have breaking changes
|
||||
// when the service model is updated and adds new API operations, paginators,
|
||||
// and waiters. Its suggested to use the pattern above for testing, or using
|
||||
// tooling to generate mocks to satisfy the interfaces.
|
||||
type {{ .StructName }}API interface {
|
||||
{{ range $_, $o := .OperationList }}
|
||||
{{ $o.InterfaceSignature }}
|
||||
{{ end }}
|
||||
{{ range $_, $w := .Waiters }}
|
||||
{{ $w.InterfaceSignature }}
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
var _ {{ .StructName }}API = (*{{ .PackageName }}.{{ .StructName }})(nil)
|
||||
`))
|
||||
|
||||
// InterfaceGoCode returns the go code for the service's API operations as an
|
||||
// interface{}. Assumes that the interface is being created in a different
|
||||
// package than the service API's package.
|
||||
func (a *API) InterfaceGoCode() string {
|
||||
a.resetImports()
|
||||
a.imports = map[string]bool{
|
||||
"github.com/aws/aws-sdk-go/aws": true,
|
||||
"github.com/aws/aws-sdk-go/aws/request": true,
|
||||
path.Join(a.SvcClientImportPath, a.PackageName()): true,
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
err := tplInterface.Execute(&buf, a)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
code := a.importsGoCode() + strings.TrimSpace(buf.String())
|
||||
return code
|
||||
}
|
||||
|
||||
// NewAPIGoCodeWithPkgName returns a string of instantiating the API prefixed
|
||||
// with its package name. Takes a string depicting the Config.
|
||||
func (a *API) NewAPIGoCodeWithPkgName(cfg string) string {
|
||||
return fmt.Sprintf("%s.New(%s)", a.PackageName(), cfg)
|
||||
}
|
||||
|
||||
// computes the validation chain for all input shapes
|
||||
func (a *API) addShapeValidations() {
|
||||
for _, o := range a.Operations {
|
||||
resolveShapeValidations(o.InputRef.Shape)
|
||||
}
|
||||
}
|
||||
|
||||
// Updates the source shape and all nested shapes with the validations that
|
||||
// could possibly be needed.
|
||||
func resolveShapeValidations(s *Shape, ancestry ...*Shape) {
|
||||
for _, a := range ancestry {
|
||||
if a == s {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
children := []string{}
|
||||
for _, name := range s.MemberNames() {
|
||||
ref := s.MemberRefs[name]
|
||||
|
||||
if s.IsRequired(name) && !s.Validations.Has(ref, ShapeValidationRequired) {
|
||||
s.Validations = append(s.Validations, ShapeValidation{
|
||||
Name: name, Ref: ref, Type: ShapeValidationRequired,
|
||||
})
|
||||
}
|
||||
|
||||
if ref.Shape.Min != 0 && !s.Validations.Has(ref, ShapeValidationMinVal) {
|
||||
s.Validations = append(s.Validations, ShapeValidation{
|
||||
Name: name, Ref: ref, Type: ShapeValidationMinVal,
|
||||
})
|
||||
}
|
||||
|
||||
switch ref.Shape.Type {
|
||||
case "map", "list", "structure":
|
||||
children = append(children, name)
|
||||
}
|
||||
}
|
||||
|
||||
ancestry = append(ancestry, s)
|
||||
for _, name := range children {
|
||||
ref := s.MemberRefs[name]
|
||||
// Since this is a grab bag we will just continue since
|
||||
// we can't validate because we don't know the valued shape.
|
||||
if ref.JSONValue {
|
||||
continue
|
||||
}
|
||||
|
||||
nestedShape := ref.Shape.NestedShape()
|
||||
|
||||
var v *ShapeValidation
|
||||
if len(nestedShape.Validations) > 0 {
|
||||
v = &ShapeValidation{
|
||||
Name: name, Ref: ref, Type: ShapeValidationNested,
|
||||
}
|
||||
} else {
|
||||
resolveShapeValidations(nestedShape, ancestry...)
|
||||
if len(nestedShape.Validations) > 0 {
|
||||
v = &ShapeValidation{
|
||||
Name: name, Ref: ref, Type: ShapeValidationNested,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if v != nil && !s.Validations.Has(v.Ref, v.Type) {
|
||||
s.Validations = append(s.Validations, *v)
|
||||
}
|
||||
}
|
||||
ancestry = ancestry[:len(ancestry)-1]
|
||||
}
|
||||
|
||||
// A tplAPIErrors is the top level template for the API
|
||||
var tplAPIErrors = template.Must(template.New("api").Parse(`
|
||||
const (
|
||||
{{ range $_, $s := $.ShapeListErrors }}
|
||||
// {{ $s.ErrorCodeName }} for service response error code
|
||||
// {{ printf "%q" $s.ErrorName }}.
|
||||
{{ if $s.Docstring -}}
|
||||
//
|
||||
{{ $s.Docstring }}
|
||||
{{ end -}}
|
||||
{{ $s.ErrorCodeName }} = {{ printf "%q" $s.ErrorName }}
|
||||
{{ end }}
|
||||
)
|
||||
`))
|
||||
|
||||
func (a *API) APIErrorsGoCode() string {
|
||||
var buf bytes.Buffer
|
||||
err := tplAPIErrors.Execute(&buf, a)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return strings.TrimSpace(buf.String())
|
||||
}
|
||||
|
||||
// removeOperation removes an operation, its input/output shapes, as well as
|
||||
// any references/shapes that are unique to this operation.
|
||||
func (a *API) removeOperation(name string) {
|
||||
fmt.Println("removing operation,", name)
|
||||
op := a.Operations[name]
|
||||
|
||||
delete(a.Operations, name)
|
||||
delete(a.Examples, name)
|
||||
|
||||
a.removeShape(op.InputRef.Shape)
|
||||
a.removeShape(op.OutputRef.Shape)
|
||||
}
|
||||
|
||||
// removeShape removes the given shape, and all form member's reference target
|
||||
// shapes. Will also remove member reference targeted shapes if those shapes do
|
||||
// not have any additional references.
|
||||
func (a *API) removeShape(s *Shape) {
|
||||
fmt.Println("removing shape,", s.ShapeName)
|
||||
|
||||
delete(a.Shapes, s.ShapeName)
|
||||
|
||||
for name, ref := range s.MemberRefs {
|
||||
a.removeShapeRef(ref)
|
||||
delete(s.MemberRefs, name)
|
||||
}
|
||||
|
||||
for _, ref := range []*ShapeRef{&s.MemberRef, &s.KeyRef, &s.ValueRef} {
|
||||
if ref.Shape == nil {
|
||||
continue
|
||||
}
|
||||
a.removeShapeRef(ref)
|
||||
*ref = ShapeRef{}
|
||||
}
|
||||
}
|
||||
|
||||
// removeShapeRef removes the shape reference from its target shape. If the
|
||||
// reference was the last reference to the target shape, the shape will also be
|
||||
// removed.
|
||||
func (a *API) removeShapeRef(ref *ShapeRef) {
|
||||
if ref.Shape == nil {
|
||||
return
|
||||
}
|
||||
|
||||
ref.Shape.removeRef(ref)
|
||||
if len(ref.Shape.refs) == 0 {
|
||||
a.removeShape(ref.Shape)
|
||||
}
|
||||
}
|
71
vendor/github.com/aws/aws-sdk-go/private/model/api/api_test.go
generated
vendored
71
vendor/github.com/aws/aws-sdk-go/private/model/api/api_test.go
generated
vendored
|
@ -1,71 +0,0 @@
|
|||
// +build go1.8,codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAPI_StructName(t *testing.T) {
|
||||
origAliases := serviceAliases
|
||||
defer func() { serviceAliases = origAliases }()
|
||||
|
||||
cases := map[string]struct {
|
||||
Aliases map[string]string
|
||||
Metadata Metadata
|
||||
StructName string
|
||||
}{
|
||||
"FullName": {
|
||||
Metadata: Metadata{
|
||||
ServiceFullName: "Amazon Service Name-100",
|
||||
},
|
||||
StructName: "ServiceName100",
|
||||
},
|
||||
"Abbreviation": {
|
||||
Metadata: Metadata{
|
||||
ServiceFullName: "Amazon Service Name-100",
|
||||
ServiceAbbreviation: "AWS SN100",
|
||||
},
|
||||
StructName: "SN100",
|
||||
},
|
||||
"Lowercase Name": {
|
||||
Metadata: Metadata{
|
||||
EndpointPrefix: "other",
|
||||
ServiceFullName: "AWS Lowercase service",
|
||||
ServiceAbbreviation: "lowercase",
|
||||
},
|
||||
StructName: "Lowercase",
|
||||
},
|
||||
"Lowercase Name Mixed": {
|
||||
Metadata: Metadata{
|
||||
EndpointPrefix: "other",
|
||||
ServiceFullName: "AWS Lowercase service",
|
||||
ServiceAbbreviation: "lowercase name Goes heRe",
|
||||
},
|
||||
StructName: "LowercaseNameGoesHeRe",
|
||||
},
|
||||
"Alias": {
|
||||
Aliases: map[string]string{
|
||||
"elasticloadbalancing": "ELB",
|
||||
},
|
||||
Metadata: Metadata{
|
||||
ServiceFullName: "Elastic Load Balancing",
|
||||
},
|
||||
StructName: "ELB",
|
||||
},
|
||||
}
|
||||
|
||||
for k, c := range cases {
|
||||
t.Run(k, func(t *testing.T) {
|
||||
serviceAliases = c.Aliases
|
||||
|
||||
a := API{
|
||||
Metadata: c.Metadata,
|
||||
}
|
||||
|
||||
if e, o := c.StructName, a.StructName(); e != o {
|
||||
t.Errorf("expect %v structName, got %v", e, o)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
180
vendor/github.com/aws/aws-sdk-go/private/model/api/customization_passes.go
generated
vendored
180
vendor/github.com/aws/aws-sdk-go/private/model/api/customization_passes.go
generated
vendored
|
@ -1,180 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type service struct {
|
||||
srcName string
|
||||
dstName string
|
||||
|
||||
serviceVersion string
|
||||
}
|
||||
|
||||
var mergeServices = map[string]service{
|
||||
"dynamodbstreams": {
|
||||
dstName: "dynamodb",
|
||||
srcName: "streams.dynamodb",
|
||||
},
|
||||
"wafregional": {
|
||||
dstName: "waf",
|
||||
srcName: "waf-regional",
|
||||
serviceVersion: "2015-08-24",
|
||||
},
|
||||
}
|
||||
|
||||
// customizationPasses Executes customization logic for the API by package name.
|
||||
func (a *API) customizationPasses() {
|
||||
var svcCustomizations = map[string]func(*API){
|
||||
"s3": s3Customizations,
|
||||
"cloudfront": cloudfrontCustomizations,
|
||||
"rds": rdsCustomizations,
|
||||
|
||||
// Disable endpoint resolving for services that require customer
|
||||
// to provide endpoint them selves.
|
||||
"cloudsearchdomain": disableEndpointResolving,
|
||||
"iotdataplane": disableEndpointResolving,
|
||||
}
|
||||
|
||||
for k := range mergeServices {
|
||||
svcCustomizations[k] = mergeServicesCustomizations
|
||||
}
|
||||
|
||||
if fn := svcCustomizations[a.PackageName()]; fn != nil {
|
||||
fn(a)
|
||||
}
|
||||
}
|
||||
|
||||
// s3Customizations customizes the API generation to replace values specific to S3.
|
||||
func s3Customizations(a *API) {
|
||||
var strExpires *Shape
|
||||
|
||||
var keepContentMD5Ref = map[string]struct{}{
|
||||
"PutObjectInput": struct{}{},
|
||||
"UploadPartInput": struct{}{},
|
||||
}
|
||||
|
||||
for name, s := range a.Shapes {
|
||||
// Remove ContentMD5 members unless specified otherwise.
|
||||
if _, keep := keepContentMD5Ref[name]; !keep {
|
||||
if _, have := s.MemberRefs["ContentMD5"]; have {
|
||||
delete(s.MemberRefs, "ContentMD5")
|
||||
}
|
||||
}
|
||||
|
||||
// Generate getter methods for API operation fields used by customizations.
|
||||
for _, refName := range []string{"Bucket", "SSECustomerKey", "CopySourceSSECustomerKey"} {
|
||||
if ref, ok := s.MemberRefs[refName]; ok {
|
||||
ref.GenerateGetter = true
|
||||
}
|
||||
}
|
||||
|
||||
// Expires should be a string not time.Time since the format is not
|
||||
// enforced by S3, and any value can be set to this field outside of the SDK.
|
||||
if strings.HasSuffix(name, "Output") {
|
||||
if ref, ok := s.MemberRefs["Expires"]; ok {
|
||||
if strExpires == nil {
|
||||
newShape := *ref.Shape
|
||||
strExpires = &newShape
|
||||
strExpires.Type = "string"
|
||||
strExpires.refs = []*ShapeRef{}
|
||||
}
|
||||
ref.Shape.removeRef(ref)
|
||||
ref.Shape = strExpires
|
||||
ref.Shape.refs = append(ref.Shape.refs, &s.MemberRef)
|
||||
}
|
||||
}
|
||||
}
|
||||
s3CustRemoveHeadObjectModeledErrors(a)
|
||||
}
|
||||
|
||||
// S3 HeadObject API call incorrect models NoSuchKey as valid
|
||||
// error code that can be returned. This operation does not
|
||||
// return error codes, all error codes are derived from HTTP
|
||||
// status codes.
|
||||
//
|
||||
// aws/aws-sdk-go#1208
|
||||
func s3CustRemoveHeadObjectModeledErrors(a *API) {
|
||||
op, ok := a.Operations["HeadObject"]
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
op.Documentation += `
|
||||
//
|
||||
// See http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html#RESTErrorResponses
|
||||
// for more information on returned errors.`
|
||||
op.ErrorRefs = []ShapeRef{}
|
||||
}
|
||||
|
||||
// cloudfrontCustomizations customized the API generation to replace values
|
||||
// specific to CloudFront.
|
||||
func cloudfrontCustomizations(a *API) {
|
||||
// MaxItems members should always be integers
|
||||
for _, s := range a.Shapes {
|
||||
if ref, ok := s.MemberRefs["MaxItems"]; ok {
|
||||
ref.ShapeName = "Integer"
|
||||
ref.Shape = a.Shapes["Integer"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// mergeServicesCustomizations references any duplicate shapes from DynamoDB
|
||||
func mergeServicesCustomizations(a *API) {
|
||||
info := mergeServices[a.PackageName()]
|
||||
|
||||
p := strings.Replace(a.path, info.srcName, info.dstName, -1)
|
||||
|
||||
if info.serviceVersion != "" {
|
||||
index := strings.LastIndex(p, "/")
|
||||
files, _ := ioutil.ReadDir(p[:index])
|
||||
if len(files) > 1 {
|
||||
panic("New version was introduced")
|
||||
}
|
||||
p = p[:index] + "/" + info.serviceVersion
|
||||
}
|
||||
|
||||
file := filepath.Join(p, "api-2.json")
|
||||
|
||||
serviceAPI := API{}
|
||||
serviceAPI.Attach(file)
|
||||
serviceAPI.Setup()
|
||||
|
||||
for n := range a.Shapes {
|
||||
if _, ok := serviceAPI.Shapes[n]; ok {
|
||||
a.Shapes[n].resolvePkg = "github.com/aws/aws-sdk-go/service/" + info.dstName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// rdsCustomizations are customization for the service/rds. This adds non-modeled fields used for presigning.
|
||||
func rdsCustomizations(a *API) {
|
||||
inputs := []string{
|
||||
"CopyDBSnapshotInput",
|
||||
"CreateDBInstanceReadReplicaInput",
|
||||
"CopyDBClusterSnapshotInput",
|
||||
"CreateDBClusterInput",
|
||||
}
|
||||
for _, input := range inputs {
|
||||
if ref, ok := a.Shapes[input]; ok {
|
||||
ref.MemberRefs["SourceRegion"] = &ShapeRef{
|
||||
Documentation: docstring(`SourceRegion is the source region where the resource exists. This is not sent over the wire and is only used for presigning. This value should always have the same region as the source ARN.`),
|
||||
ShapeName: "String",
|
||||
Shape: a.Shapes["String"],
|
||||
Ignore: true,
|
||||
}
|
||||
ref.MemberRefs["DestinationRegion"] = &ShapeRef{
|
||||
Documentation: docstring(`DestinationRegion is used for presigning the request to a given region.`),
|
||||
ShapeName: "String",
|
||||
Shape: a.Shapes["String"],
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func disableEndpointResolving(a *API) {
|
||||
a.Metadata.NoResolveEndpoint = true
|
||||
}
|
411
vendor/github.com/aws/aws-sdk-go/private/model/api/docstring.go
generated
vendored
411
vendor/github.com/aws/aws-sdk-go/private/model/api/docstring.go
generated
vendored
|
@ -1,411 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
xhtml "golang.org/x/net/html"
|
||||
)
|
||||
|
||||
type apiDocumentation struct {
|
||||
*API
|
||||
Operations map[string]string
|
||||
Service string
|
||||
Shapes map[string]shapeDocumentation
|
||||
}
|
||||
|
||||
type shapeDocumentation struct {
|
||||
Base string
|
||||
Refs map[string]string
|
||||
}
|
||||
|
||||
// AttachDocs attaches documentation from a JSON filename.
|
||||
func (a *API) AttachDocs(filename string) {
|
||||
d := apiDocumentation{API: a}
|
||||
|
||||
f, err := os.Open(filename)
|
||||
defer f.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = json.NewDecoder(f).Decode(&d)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
d.setup()
|
||||
|
||||
}
|
||||
|
||||
func (d *apiDocumentation) setup() {
|
||||
d.API.Documentation = docstring(d.Service)
|
||||
|
||||
for op, doc := range d.Operations {
|
||||
d.API.Operations[op].Documentation = docstring(doc)
|
||||
}
|
||||
|
||||
for shape, info := range d.Shapes {
|
||||
if sh := d.API.Shapes[shape]; sh != nil {
|
||||
sh.Documentation = docstring(info.Base)
|
||||
}
|
||||
|
||||
for ref, doc := range info.Refs {
|
||||
if doc == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
parts := strings.Split(ref, "$")
|
||||
if len(parts) != 2 {
|
||||
fmt.Fprintf(os.Stderr, "Shape Doc %s has unexpected reference format, %q\n", shape, ref)
|
||||
continue
|
||||
}
|
||||
if sh := d.API.Shapes[parts[0]]; sh != nil {
|
||||
if m := sh.MemberRefs[parts[1]]; m != nil {
|
||||
m.Documentation = docstring(doc)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var reNewline = regexp.MustCompile(`\r?\n`)
|
||||
var reMultiSpace = regexp.MustCompile(`\s+`)
|
||||
var reComments = regexp.MustCompile(`<!--.*?-->`)
|
||||
var reFullnameBlock = regexp.MustCompile(`<fullname>(.+?)<\/fullname>`)
|
||||
var reFullname = regexp.MustCompile(`<fullname>(.*?)</fullname>`)
|
||||
var reExamples = regexp.MustCompile(`<examples?>.+?<\/examples?>`)
|
||||
var reEndNL = regexp.MustCompile(`\n+$`)
|
||||
|
||||
// docstring rewrites a string to insert godocs formatting.
|
||||
func docstring(doc string) string {
|
||||
doc = strings.TrimSpace(doc)
|
||||
if doc == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
doc = reNewline.ReplaceAllString(doc, "")
|
||||
doc = reMultiSpace.ReplaceAllString(doc, " ")
|
||||
doc = reComments.ReplaceAllString(doc, "")
|
||||
|
||||
var fullname string
|
||||
parts := reFullnameBlock.FindStringSubmatch(doc)
|
||||
if len(parts) > 1 {
|
||||
fullname = parts[1]
|
||||
}
|
||||
// Remove full name block from doc string
|
||||
doc = reFullname.ReplaceAllString(doc, "")
|
||||
|
||||
doc = reExamples.ReplaceAllString(doc, "")
|
||||
doc = generateDoc(doc)
|
||||
doc = reEndNL.ReplaceAllString(doc, "")
|
||||
doc = html.UnescapeString(doc)
|
||||
|
||||
// Replace doc with full name if doc is empty.
|
||||
doc = strings.TrimSpace(doc)
|
||||
if len(doc) == 0 {
|
||||
doc = fullname
|
||||
}
|
||||
|
||||
return commentify(doc)
|
||||
}
|
||||
|
||||
const (
|
||||
indent = " "
|
||||
)
|
||||
|
||||
// style is what we want to prefix a string with.
|
||||
// For instance, <li>Foo</li><li>Bar</li>, will generate
|
||||
// * Foo
|
||||
// * Bar
|
||||
var style = map[string]string{
|
||||
"ul": indent + "* ",
|
||||
"li": indent + "* ",
|
||||
"code": indent,
|
||||
"pre": indent,
|
||||
}
|
||||
|
||||
// commentify converts a string to a Go comment
|
||||
func commentify(doc string) string {
|
||||
if len(doc) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
lines := strings.Split(doc, "\n")
|
||||
out := make([]string, 0, len(lines))
|
||||
for i := 0; i < len(lines); i++ {
|
||||
line := lines[i]
|
||||
|
||||
if i > 0 && line == "" && lines[i-1] == "" {
|
||||
continue
|
||||
}
|
||||
out = append(out, line)
|
||||
}
|
||||
|
||||
if len(out) > 0 {
|
||||
out[0] = "// " + out[0]
|
||||
return strings.Join(out, "\n// ")
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// wrap returns a rewritten version of text to have line breaks
|
||||
// at approximately length characters. Line breaks will only be
|
||||
// inserted into whitespace.
|
||||
func wrap(text string, length int, isIndented bool) string {
|
||||
var buf bytes.Buffer
|
||||
var last rune
|
||||
var lastNL bool
|
||||
var col int
|
||||
|
||||
for _, c := range text {
|
||||
switch c {
|
||||
case '\r': // ignore this
|
||||
continue // and also don't track `last`
|
||||
case '\n': // ignore this too, but reset col
|
||||
if col >= length || last == '\n' {
|
||||
buf.WriteString("\n")
|
||||
}
|
||||
buf.WriteString("\n")
|
||||
col = 0
|
||||
case ' ', '\t': // opportunity to split
|
||||
if col >= length {
|
||||
buf.WriteByte('\n')
|
||||
col = 0
|
||||
if isIndented {
|
||||
buf.WriteString(indent)
|
||||
col += 3
|
||||
}
|
||||
} else {
|
||||
// We only want to write a leading space if the col is greater than zero.
|
||||
// This will provide the proper spacing for documentation.
|
||||
buf.WriteRune(c)
|
||||
col++ // count column
|
||||
}
|
||||
default:
|
||||
buf.WriteRune(c)
|
||||
col++
|
||||
}
|
||||
lastNL = c == '\n'
|
||||
_ = lastNL
|
||||
last = c
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
type tagInfo struct {
|
||||
tag string
|
||||
key string
|
||||
val string
|
||||
txt string
|
||||
raw string
|
||||
closingTag bool
|
||||
}
|
||||
|
||||
// generateDoc will generate the proper doc string for html encoded or plain text doc entries.
|
||||
func generateDoc(htmlSrc string) string {
|
||||
tokenizer := xhtml.NewTokenizer(strings.NewReader(htmlSrc))
|
||||
tokens := buildTokenArray(tokenizer)
|
||||
scopes := findScopes(tokens)
|
||||
return walk(scopes)
|
||||
}
|
||||
|
||||
func buildTokenArray(tokenizer *xhtml.Tokenizer) []tagInfo {
|
||||
tokens := []tagInfo{}
|
||||
for tt := tokenizer.Next(); tt != xhtml.ErrorToken; tt = tokenizer.Next() {
|
||||
switch tt {
|
||||
case xhtml.TextToken:
|
||||
txt := string(tokenizer.Text())
|
||||
if len(tokens) == 0 {
|
||||
info := tagInfo{
|
||||
raw: txt,
|
||||
}
|
||||
tokens = append(tokens, info)
|
||||
}
|
||||
tn, _ := tokenizer.TagName()
|
||||
key, val, _ := tokenizer.TagAttr()
|
||||
info := tagInfo{
|
||||
tag: string(tn),
|
||||
key: string(key),
|
||||
val: string(val),
|
||||
txt: txt,
|
||||
}
|
||||
tokens = append(tokens, info)
|
||||
case xhtml.StartTagToken:
|
||||
tn, _ := tokenizer.TagName()
|
||||
key, val, _ := tokenizer.TagAttr()
|
||||
info := tagInfo{
|
||||
tag: string(tn),
|
||||
key: string(key),
|
||||
val: string(val),
|
||||
}
|
||||
tokens = append(tokens, info)
|
||||
case xhtml.SelfClosingTagToken, xhtml.EndTagToken:
|
||||
tn, _ := tokenizer.TagName()
|
||||
key, val, _ := tokenizer.TagAttr()
|
||||
info := tagInfo{
|
||||
tag: string(tn),
|
||||
key: string(key),
|
||||
val: string(val),
|
||||
closingTag: true,
|
||||
}
|
||||
tokens = append(tokens, info)
|
||||
}
|
||||
}
|
||||
return tokens
|
||||
}
|
||||
|
||||
// walk is used to traverse each scoped block. These scoped
|
||||
// blocks will act as blocked text where we do most of our
|
||||
// text manipulation.
|
||||
func walk(scopes [][]tagInfo) string {
|
||||
doc := ""
|
||||
// Documentation will be chunked by scopes.
|
||||
// Meaning, for each scope will be divided by one or more newlines.
|
||||
for _, scope := range scopes {
|
||||
indentStr, isIndented := priorityIndentation(scope)
|
||||
block := ""
|
||||
href := ""
|
||||
after := false
|
||||
level := 0
|
||||
lastTag := ""
|
||||
for _, token := range scope {
|
||||
if token.closingTag {
|
||||
endl := closeTag(token, level)
|
||||
block += endl
|
||||
level--
|
||||
lastTag = ""
|
||||
} else if token.txt == "" {
|
||||
if token.val != "" {
|
||||
href, after = formatText(token, "")
|
||||
}
|
||||
if level == 1 && isIndented {
|
||||
block += indentStr
|
||||
}
|
||||
level++
|
||||
lastTag = token.tag
|
||||
} else {
|
||||
if token.txt != " " {
|
||||
str, _ := formatText(token, lastTag)
|
||||
block += str
|
||||
if after {
|
||||
block += href
|
||||
after = false
|
||||
}
|
||||
} else {
|
||||
fmt.Println(token.tag)
|
||||
str, _ := formatText(tagInfo{}, lastTag)
|
||||
block += str
|
||||
}
|
||||
}
|
||||
}
|
||||
if !isIndented {
|
||||
block = strings.TrimPrefix(block, " ")
|
||||
}
|
||||
block = wrap(block, 72, isIndented)
|
||||
doc += block
|
||||
}
|
||||
return doc
|
||||
}
|
||||
|
||||
// closeTag will divide up the blocks of documentation to be formated properly.
|
||||
func closeTag(token tagInfo, level int) string {
|
||||
switch token.tag {
|
||||
case "pre", "li", "div":
|
||||
return "\n"
|
||||
case "p", "h1", "h2", "h3", "h4", "h5", "h6":
|
||||
return "\n\n"
|
||||
case "code":
|
||||
// indented code is only at the 0th level.
|
||||
if level == 0 {
|
||||
return "\n"
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// formatText will format any sort of text based off of a tag. It will also return
|
||||
// a boolean to add the string after the text token.
|
||||
func formatText(token tagInfo, lastTag string) (string, bool) {
|
||||
switch token.tag {
|
||||
case "a":
|
||||
if token.val != "" {
|
||||
return fmt.Sprintf(" (%s)", token.val), true
|
||||
}
|
||||
}
|
||||
|
||||
// We don't care about a single space nor no text.
|
||||
if len(token.txt) == 0 || token.txt == " " {
|
||||
return "", false
|
||||
}
|
||||
|
||||
// Here we want to indent code blocks that are newlines
|
||||
if lastTag == "code" {
|
||||
// Greater than one, because we don't care about newlines in the beginning
|
||||
block := ""
|
||||
if lines := strings.Split(token.txt, "\n"); len(lines) > 1 {
|
||||
for _, line := range lines {
|
||||
block += indent + line
|
||||
}
|
||||
block += "\n"
|
||||
return block, false
|
||||
}
|
||||
}
|
||||
return token.txt, false
|
||||
}
|
||||
|
||||
// This is a parser to check what type of indention is needed.
|
||||
func priorityIndentation(blocks []tagInfo) (string, bool) {
|
||||
if len(blocks) == 0 {
|
||||
return "", false
|
||||
}
|
||||
|
||||
v, ok := style[blocks[0].tag]
|
||||
return v, ok
|
||||
}
|
||||
|
||||
// Divides into scopes based off levels.
|
||||
// For instance,
|
||||
// <p>Testing<code>123</code></p><ul><li>Foo</li></ul>
|
||||
// This has 2 scopes, the <p> and <ul>
|
||||
func findScopes(tokens []tagInfo) [][]tagInfo {
|
||||
level := 0
|
||||
scope := []tagInfo{}
|
||||
scopes := [][]tagInfo{}
|
||||
for _, token := range tokens {
|
||||
// we will clear empty tagged tokens from the array
|
||||
txt := strings.TrimSpace(token.txt)
|
||||
tag := strings.TrimSpace(token.tag)
|
||||
if len(txt) == 0 && len(tag) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
scope = append(scope, token)
|
||||
|
||||
// If it is a closing tag then we check what level
|
||||
// we are on. If it is 0, then that means we have found a
|
||||
// scoped block.
|
||||
if token.closingTag {
|
||||
level--
|
||||
if level == 0 {
|
||||
scopes = append(scopes, scope)
|
||||
scope = []tagInfo{}
|
||||
}
|
||||
// Check opening tags and increment the level
|
||||
} else if token.txt == "" {
|
||||
level++
|
||||
}
|
||||
}
|
||||
// In this case, we did not run into a closing tag. This would mean
|
||||
// we have plaintext for documentation.
|
||||
if len(scopes) == 0 {
|
||||
scopes = append(scopes, scope)
|
||||
}
|
||||
return scopes
|
||||
}
|
100
vendor/github.com/aws/aws-sdk-go/private/model/api/docstring_test.go
generated
vendored
100
vendor/github.com/aws/aws-sdk-go/private/model/api/docstring_test.go
generated
vendored
|
@ -1,100 +0,0 @@
|
|||
// +build 1.6,codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNonHTMLDocGen(t *testing.T) {
|
||||
doc := "Testing 1 2 3"
|
||||
expected := "// Testing 1 2 3\n"
|
||||
doc = docstring(doc)
|
||||
|
||||
if expected != doc {
|
||||
t.Errorf("Expected %s, but received %s", expected, doc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListsHTMLDocGen(t *testing.T) {
|
||||
doc := "<ul><li>Testing 1 2 3</li> <li>FooBar</li></ul>"
|
||||
expected := "// * Testing 1 2 3\n// * FooBar\n"
|
||||
doc = docstring(doc)
|
||||
|
||||
if expected != doc {
|
||||
t.Errorf("Expected %s, but received %s", expected, doc)
|
||||
}
|
||||
|
||||
doc = "<ul> <li>Testing 1 2 3</li> <li>FooBar</li> </ul>"
|
||||
expected = "// * Testing 1 2 3\n// * FooBar\n"
|
||||
doc = docstring(doc)
|
||||
|
||||
if expected != doc {
|
||||
t.Errorf("Expected %s, but received %s", expected, doc)
|
||||
}
|
||||
|
||||
// Test leading spaces
|
||||
doc = " <ul> <li>Testing 1 2 3</li> <li>FooBar</li> </ul>"
|
||||
doc = docstring(doc)
|
||||
if expected != doc {
|
||||
t.Errorf("Expected %s, but received %s", expected, doc)
|
||||
}
|
||||
|
||||
// Paragraph check
|
||||
doc = "<ul> <li> <p>Testing 1 2 3</p> </li><li> <p>FooBar</p></li></ul>"
|
||||
expected = "// * Testing 1 2 3\n// \n// * FooBar\n"
|
||||
doc = docstring(doc)
|
||||
if expected != doc {
|
||||
t.Errorf("Expected %s, but received %s", expected, doc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInlineCodeHTMLDocGen(t *testing.T) {
|
||||
doc := "<ul> <li><code>Testing</code>: 1 2 3</li> <li>FooBar</li> </ul>"
|
||||
expected := "// * Testing: 1 2 3\n// * FooBar\n"
|
||||
doc = docstring(doc)
|
||||
|
||||
if expected != doc {
|
||||
t.Errorf("Expected %s, but received %s", expected, doc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInlineCodeInParagraphHTMLDocGen(t *testing.T) {
|
||||
doc := "<p><code>Testing</code>: 1 2 3</p>"
|
||||
expected := "// Testing: 1 2 3\n"
|
||||
doc = docstring(doc)
|
||||
|
||||
if expected != doc {
|
||||
t.Errorf("Expected %s, but received %s", expected, doc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyPREInlineCodeHTMLDocGen(t *testing.T) {
|
||||
doc := "<pre><code>Testing</code></pre>"
|
||||
expected := "// Testing\n"
|
||||
doc = docstring(doc)
|
||||
|
||||
if expected != doc {
|
||||
t.Errorf("Expected %s, but received %s", expected, doc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParagraph(t *testing.T) {
|
||||
doc := "<p>Testing 1 2 3</p>"
|
||||
expected := "// Testing 1 2 3\n"
|
||||
doc = docstring(doc)
|
||||
|
||||
if expected != doc {
|
||||
t.Errorf("Expected %s, but received %s", expected, doc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComplexListParagraphCode(t *testing.T) {
|
||||
doc := "<ul> <li><p><code>FOO</code> Bar</p></li><li><p><code>Xyz</code> ABC</p></li></ul>"
|
||||
expected := "// * FOO Bar\n// \n// * Xyz ABC\n"
|
||||
doc = docstring(doc)
|
||||
|
||||
if expected != doc {
|
||||
t.Errorf("Expected %s, but received %s", expected, doc)
|
||||
}
|
||||
}
|
537
vendor/github.com/aws/aws-sdk-go/private/model/api/eventstream.go
generated
vendored
537
vendor/github.com/aws/aws-sdk-go/private/model/api/eventstream.go
generated
vendored
|
@ -1,537 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
// EventStreamAPI provides details about the event stream async API and
|
||||
// associated EventStream shapes.
|
||||
type EventStreamAPI struct {
|
||||
Name string
|
||||
Operation *Operation
|
||||
Shape *Shape
|
||||
Inbound *EventStream
|
||||
Outbound *EventStream
|
||||
}
|
||||
|
||||
// EventStream represents a single eventstream group (input/output) and the
|
||||
// modeled events that are known for the stream.
|
||||
type EventStream struct {
|
||||
Name string
|
||||
Shape *Shape
|
||||
Events []*Event
|
||||
}
|
||||
|
||||
// Event is a single EventStream event that can be sent or received in an
|
||||
// EventStream.
|
||||
type Event struct {
|
||||
Name string
|
||||
Shape *Shape
|
||||
For *EventStream
|
||||
}
|
||||
|
||||
// ShapeDoc returns the docstring for the EventStream API.
|
||||
func (esAPI *EventStreamAPI) ShapeDoc() string {
|
||||
tmpl := template.Must(template.New("eventStreamShapeDoc").Parse(`
|
||||
{{- $.Name }} provides handling of EventStreams for
|
||||
the {{ $.Operation.ExportedName }} API.
|
||||
{{- if $.Inbound }}
|
||||
|
||||
Use this type to receive {{ $.Inbound.Name }} events. The events
|
||||
can be read from the Events channel member.
|
||||
|
||||
The events that can be received are:
|
||||
{{ range $_, $event := $.Inbound.Events }}
|
||||
* {{ $event.Shape.ShapeName }}
|
||||
{{- end }}
|
||||
|
||||
{{- end }}
|
||||
|
||||
{{- if $.Outbound }}
|
||||
|
||||
Use this type to send {{ $.Outbound.Name }} events. The events
|
||||
can be sent with the Send method.
|
||||
|
||||
The events that can be sent are:
|
||||
{{ range $_, $event := $.Outbound.Events -}}
|
||||
* {{ $event.Shape.ShapeName }}
|
||||
{{- end }}
|
||||
|
||||
{{- end }}`))
|
||||
|
||||
var w bytes.Buffer
|
||||
if err := tmpl.Execute(&w, esAPI); err != nil {
|
||||
panic(fmt.Sprintf("failed to generate eventstream shape template for %v, %v", esAPI.Name, err))
|
||||
}
|
||||
|
||||
return commentify(w.String())
|
||||
}
|
||||
|
||||
func eventStreamAPIShapeRefDoc(refName string) string {
|
||||
return commentify(fmt.Sprintf("Use %s to use the API's stream.", refName))
|
||||
}
|
||||
|
||||
func (a *API) setupEventStreams() {
|
||||
const eventStreamMemberName = "EventStream"
|
||||
|
||||
for _, op := range a.Operations {
|
||||
outbound := setupEventStream(op.InputRef.Shape)
|
||||
inbound := setupEventStream(op.OutputRef.Shape)
|
||||
|
||||
if outbound == nil && inbound == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if outbound != nil {
|
||||
panic(fmt.Sprintf("Outbound stream support not implemented, %s, %s",
|
||||
outbound.Name, outbound.Shape.ShapeName))
|
||||
}
|
||||
|
||||
switch a.Metadata.Protocol {
|
||||
case `rest-json`, `rest-xml`, `json`:
|
||||
default:
|
||||
panic(fmt.Sprintf("EventStream not supported for protocol %v",
|
||||
a.Metadata.Protocol))
|
||||
}
|
||||
|
||||
eventStreamAPI := &EventStreamAPI{
|
||||
Name: op.ExportedName + eventStreamMemberName,
|
||||
Operation: op,
|
||||
Outbound: outbound,
|
||||
Inbound: inbound,
|
||||
}
|
||||
|
||||
streamShape := &Shape{
|
||||
API: a,
|
||||
ShapeName: eventStreamAPI.Name,
|
||||
Documentation: eventStreamAPI.ShapeDoc(),
|
||||
Type: "structure",
|
||||
EventStreamAPI: eventStreamAPI,
|
||||
}
|
||||
streamShapeRef := &ShapeRef{
|
||||
API: a,
|
||||
ShapeName: streamShape.ShapeName,
|
||||
Shape: streamShape,
|
||||
Documentation: eventStreamAPIShapeRefDoc(eventStreamMemberName),
|
||||
}
|
||||
streamShape.refs = []*ShapeRef{streamShapeRef}
|
||||
eventStreamAPI.Shape = streamShape
|
||||
|
||||
if _, ok := op.OutputRef.Shape.MemberRefs[eventStreamMemberName]; ok {
|
||||
panic(fmt.Sprintf("shape ref already exists, %s.%s",
|
||||
op.OutputRef.Shape.ShapeName, eventStreamMemberName))
|
||||
}
|
||||
op.OutputRef.Shape.MemberRefs[eventStreamMemberName] = streamShapeRef
|
||||
op.OutputRef.Shape.EventStreamsMemberName = eventStreamMemberName
|
||||
if _, ok := a.Shapes[streamShape.ShapeName]; ok {
|
||||
panic("shape already exists, " + streamShape.ShapeName)
|
||||
}
|
||||
a.Shapes[streamShape.ShapeName] = streamShape
|
||||
|
||||
a.HasEventStream = true
|
||||
}
|
||||
}
|
||||
|
||||
func setupEventStream(topShape *Shape) *EventStream {
|
||||
var eventStream *EventStream
|
||||
for refName, ref := range topShape.MemberRefs {
|
||||
if !ref.Shape.IsEventStream {
|
||||
continue
|
||||
}
|
||||
if eventStream != nil {
|
||||
panic(fmt.Sprintf("multiple shape ref eventstreams, %s, prev: %s",
|
||||
refName, eventStream.Name))
|
||||
}
|
||||
|
||||
eventStream = &EventStream{
|
||||
Name: ref.Shape.ShapeName,
|
||||
Shape: ref.Shape,
|
||||
}
|
||||
for _, eventRefName := range ref.Shape.MemberNames() {
|
||||
eventRef := ref.Shape.MemberRefs[eventRefName]
|
||||
if !eventRef.Shape.IsEvent {
|
||||
panic(fmt.Sprintf("unexpected non-event member reference %s.%s",
|
||||
ref.Shape.ShapeName, eventRefName))
|
||||
}
|
||||
|
||||
updateEventPayloadRef(eventRef.Shape)
|
||||
|
||||
eventRef.Shape.EventFor = append(eventRef.Shape.EventFor, eventStream)
|
||||
eventStream.Events = append(eventStream.Events, &Event{
|
||||
Name: eventRefName,
|
||||
Shape: eventRef.Shape,
|
||||
For: eventStream,
|
||||
})
|
||||
}
|
||||
|
||||
// Remove the eventstream references as they will be added elsewhere.
|
||||
ref.Shape.removeRef(ref)
|
||||
delete(topShape.MemberRefs, refName)
|
||||
delete(topShape.API.Shapes, ref.Shape.ShapeName)
|
||||
}
|
||||
|
||||
return eventStream
|
||||
}
|
||||
|
||||
func updateEventPayloadRef(parent *Shape) {
|
||||
refName := parent.PayloadRefName()
|
||||
if len(refName) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
payloadRef := parent.MemberRefs[refName]
|
||||
|
||||
if payloadRef.Shape.Type == "blob" {
|
||||
return
|
||||
}
|
||||
|
||||
if len(payloadRef.LocationName) != 0 {
|
||||
return
|
||||
}
|
||||
|
||||
payloadRef.LocationName = refName
|
||||
}
|
||||
|
||||
func renderEventStreamAPIShape(w io.Writer, s *Shape) error {
|
||||
// Imports needed by the EventStream APIs.
|
||||
s.API.imports["bytes"] = true
|
||||
s.API.imports["io"] = true
|
||||
s.API.imports["sync"] = true
|
||||
s.API.imports["sync/atomic"] = true
|
||||
s.API.imports["github.com/aws/aws-sdk-go/private/protocol/eventstream"] = true
|
||||
s.API.imports["github.com/aws/aws-sdk-go/private/protocol/eventstream/eventstreamapi"] = true
|
||||
|
||||
return eventStreamAPIShapeTmpl.Execute(w, s)
|
||||
}
|
||||
|
||||
// EventStreamReaderInterfaceName returns the interface name for the
|
||||
// EventStream's reader interface.
|
||||
func EventStreamReaderInterfaceName(s *Shape) string {
|
||||
return s.ShapeName + "Reader"
|
||||
}
|
||||
|
||||
// Template for an EventStream API Shape that will provide read/writing events
|
||||
// across the EventStream. This is a special shape that's only public members
|
||||
// are the Events channel and a Close and Err method.
|
||||
//
|
||||
// Executed in the context of a Shape.
|
||||
var eventStreamAPIShapeTmpl = func() *template.Template {
|
||||
t := template.Must(
|
||||
template.New("eventStreamAPIShapeTmpl").
|
||||
Funcs(template.FuncMap{}).
|
||||
Parse(eventStreamAPITmplDef),
|
||||
)
|
||||
|
||||
template.Must(
|
||||
t.AddParseTree(
|
||||
"eventStreamAPIReaderTmpl", eventStreamAPIReaderTmpl.Tree),
|
||||
)
|
||||
|
||||
return t
|
||||
}()
|
||||
|
||||
const eventStreamAPITmplDef = `
|
||||
{{ $.Documentation }}
|
||||
type {{ $.ShapeName }} struct {
|
||||
{{- if $.EventStreamAPI.Inbound }}
|
||||
// Reader is the EventStream reader for the {{ $.EventStreamAPI.Inbound.Name }}
|
||||
// events. This value is automatically set by the SDK when the API call is made
|
||||
// Use this member when unit testing your code with the SDK to mock out the
|
||||
// EventStream Reader.
|
||||
//
|
||||
// Must not be nil.
|
||||
Reader {{ $.ShapeName }}Reader
|
||||
|
||||
{{ end -}}
|
||||
|
||||
{{- if $.EventStreamAPI.Outbound }}
|
||||
// Writer is the EventStream reader for the {{ $.EventStreamAPI.Inbound.Name }}
|
||||
// events. This value is automatically set by the SDK when the API call is made
|
||||
// Use this member when unit testing your code with the SDK to mock out the
|
||||
// EventStream Writer.
|
||||
//
|
||||
// Must not be nil.
|
||||
Writer *{{ $.ShapeName }}Writer
|
||||
|
||||
{{ end -}}
|
||||
|
||||
// StreamCloser is the io.Closer for the EventStream connection. For HTTP
|
||||
// EventStream this is the response Body. The stream will be closed when
|
||||
// the Close method of the EventStream is called.
|
||||
StreamCloser io.Closer
|
||||
}
|
||||
|
||||
// Close closes the EventStream. This will also cause the Events channel to be
|
||||
// closed. You can use the closing of the Events channel to terminate your
|
||||
// application's read from the API's EventStream.
|
||||
{{- if $.EventStreamAPI.Inbound }}
|
||||
//
|
||||
// Will close the underlying EventStream reader. For EventStream over HTTP
|
||||
// connection this will also close the HTTP connection.
|
||||
{{ end -}}
|
||||
//
|
||||
// Close must be called when done using the EventStream API. Not calling Close
|
||||
// may result in resource leaks.
|
||||
func (es *{{ $.ShapeName }}) Close() (err error) {
|
||||
{{- if $.EventStreamAPI.Inbound }}
|
||||
es.Reader.Close()
|
||||
{{ end -}}
|
||||
{{- if $.EventStreamAPI.Outbound }}
|
||||
es.Writer.Close()
|
||||
{{ end -}}
|
||||
|
||||
return es.Err()
|
||||
}
|
||||
|
||||
// Err returns any error that occurred while reading EventStream Events from
|
||||
// the service API's response. Returns nil if there were no errors.
|
||||
func (es *{{ $.ShapeName }}) Err() error {
|
||||
{{- if $.EventStreamAPI.Outbound }}
|
||||
if err := es.Writer.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
{{ end -}}
|
||||
|
||||
{{- if $.EventStreamAPI.Inbound }}
|
||||
if err := es.Reader.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
{{ end -}}
|
||||
|
||||
es.StreamCloser.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
{{ if $.EventStreamAPI.Inbound }}
|
||||
// Events returns a channel to read EventStream Events from the
|
||||
// {{ $.EventStreamAPI.Operation.ExportedName }} API.
|
||||
//
|
||||
// These events are:
|
||||
// {{ range $_, $event := $.EventStreamAPI.Inbound.Events }}
|
||||
// * {{ $event.Shape.ShapeName }}
|
||||
{{- end }}
|
||||
func (es *{{ $.ShapeName }}) Events() <-chan {{ $.EventStreamAPI.Inbound.Name }}Event {
|
||||
return es.Reader.Events()
|
||||
}
|
||||
|
||||
{{ template "eventStreamAPIReaderTmpl" $ }}
|
||||
{{ end }}
|
||||
|
||||
{{ if $.EventStreamAPI.Outbound }}
|
||||
// TODO writer helper method.
|
||||
{{ end }}
|
||||
|
||||
`
|
||||
|
||||
var eventStreamAPIReaderTmpl = template.Must(template.New("eventStreamAPIReaderTmpl").
|
||||
Funcs(template.FuncMap{}).
|
||||
Parse(`
|
||||
// {{ $.EventStreamAPI.Inbound.Name }}Event groups together all EventStream
|
||||
// events read from the {{ $.EventStreamAPI.Operation.ExportedName }} API.
|
||||
//
|
||||
// These events are:
|
||||
// {{ range $_, $event := $.EventStreamAPI.Inbound.Events }}
|
||||
// * {{ $event.Shape.ShapeName }}
|
||||
{{- end }}
|
||||
type {{ $.EventStreamAPI.Inbound.Name }}Event interface {
|
||||
event{{ $.EventStreamAPI.Name }}()
|
||||
}
|
||||
|
||||
// {{ $.ShapeName }}Reader provides the interface for reading EventStream
|
||||
// Events from the {{ $.EventStreamAPI.Operation.ExportedName }} API. The
|
||||
// default implementation for this interface will be {{ $.ShapeName }}.
|
||||
//
|
||||
// The reader's Close method must allow multiple concurrent calls.
|
||||
//
|
||||
// These events are:
|
||||
// {{ range $_, $event := $.EventStreamAPI.Inbound.Events }}
|
||||
// * {{ $event.Shape.ShapeName }}
|
||||
{{- end }}
|
||||
type {{ $.ShapeName }}Reader interface {
|
||||
// Returns a channel of events as they are read from the event stream.
|
||||
Events() <-chan {{ $.EventStreamAPI.Inbound.Name }}Event
|
||||
|
||||
// Close will close the underlying event stream reader. For event stream over
|
||||
// HTTP this will also close the HTTP connection.
|
||||
Close() error
|
||||
|
||||
// Returns any error that has occured while reading from the event stream.
|
||||
Err() error
|
||||
}
|
||||
|
||||
type read{{ $.ShapeName }} struct {
|
||||
eventReader *eventstreamapi.EventReader
|
||||
stream chan {{ $.EventStreamAPI.Inbound.Name }}Event
|
||||
errVal atomic.Value
|
||||
|
||||
done chan struct{}
|
||||
closeOnce sync.Once
|
||||
}
|
||||
|
||||
func newRead{{ $.ShapeName }}(
|
||||
reader io.ReadCloser,
|
||||
unmarshalers request.HandlerList,
|
||||
logger aws.Logger,
|
||||
logLevel aws.LogLevelType,
|
||||
) *read{{ $.ShapeName }} {
|
||||
r := &read{{ $.ShapeName }}{
|
||||
stream: make(chan {{ $.EventStreamAPI.Inbound.Name }}Event),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
|
||||
r.eventReader = eventstreamapi.NewEventReader(
|
||||
reader,
|
||||
protocol.HandlerPayloadUnmarshal{
|
||||
Unmarshalers: unmarshalers,
|
||||
},
|
||||
r.unmarshalerForEventType,
|
||||
)
|
||||
r.eventReader.UseLogger(logger, logLevel)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// Close will close the underlying event stream reader. For EventStream over
|
||||
// HTTP this will also close the HTTP connection.
|
||||
func (r *read{{ $.ShapeName }}) Close() error {
|
||||
r.closeOnce.Do(r.safeClose)
|
||||
|
||||
return r.Err()
|
||||
}
|
||||
|
||||
func (r *read{{ $.ShapeName }}) safeClose() {
|
||||
close(r.done)
|
||||
err := r.eventReader.Close()
|
||||
if err != nil {
|
||||
r.errVal.Store(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *read{{ $.ShapeName }}) Err() error {
|
||||
if v := r.errVal.Load(); v != nil {
|
||||
return v.(error)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *read{{ $.ShapeName }}) Events() <-chan {{ $.EventStreamAPI.Inbound.Name }}Event {
|
||||
return r.stream
|
||||
}
|
||||
|
||||
func (r *read{{ $.ShapeName }}) readEventStream() {
|
||||
defer close(r.stream)
|
||||
|
||||
for {
|
||||
event, err := r.eventReader.ReadEvent()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
return
|
||||
}
|
||||
select {
|
||||
case <-r.done:
|
||||
// If closed already ignore the error
|
||||
return
|
||||
default:
|
||||
}
|
||||
r.errVal.Store(err)
|
||||
return
|
||||
}
|
||||
|
||||
select {
|
||||
case r.stream <- event.({{ $.EventStreamAPI.Inbound.Name }}Event):
|
||||
case <-r.done:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *read{{ $.ShapeName }}) unmarshalerForEventType(
|
||||
eventType string,
|
||||
) (eventstreamapi.Unmarshaler, error) {
|
||||
switch eventType {
|
||||
{{- range $_, $event := $.EventStreamAPI.Inbound.Events }}
|
||||
case {{ printf "%q" $event.Name }}:
|
||||
return &{{ $event.Shape.ShapeName }}{}, nil
|
||||
{{ end -}}
|
||||
default:
|
||||
return nil, fmt.Errorf(
|
||||
"unknown event type name, %s, for {{ $.ShapeName }}", eventType)
|
||||
}
|
||||
}
|
||||
`))
|
||||
|
||||
// Template for the EventStream API Output shape that contains the EventStream
|
||||
// member.
|
||||
//
|
||||
// Executed in the context of a Shape.
|
||||
var eventStreamAPILoopMethodTmpl = template.Must(
|
||||
template.New("eventStreamAPILoopMethodTmpl").Parse(`
|
||||
func (s *{{ $.ShapeName }}) runEventStreamLoop(r *request.Request) {
|
||||
if r.Error != nil {
|
||||
return
|
||||
}
|
||||
|
||||
{{- $esMemberRef := index $.MemberRefs $.EventStreamsMemberName }}
|
||||
{{- if $esMemberRef.Shape.EventStreamAPI.Inbound }}
|
||||
reader := newRead{{ $esMemberRef.ShapeName }}(
|
||||
r.HTTPResponse.Body,
|
||||
r.Handlers.UnmarshalStream,
|
||||
r.Config.Logger,
|
||||
r.Config.LogLevel.Value(),
|
||||
)
|
||||
go reader.readEventStream()
|
||||
|
||||
eventStream := &{{ $esMemberRef.ShapeName }} {
|
||||
StreamCloser: r.HTTPResponse.Body,
|
||||
Reader: reader,
|
||||
}
|
||||
{{ end -}}
|
||||
|
||||
s.{{ $.EventStreamsMemberName }} = eventStream
|
||||
}
|
||||
`))
|
||||
|
||||
// Template for an EventStream Event shape. This is a normal API shape that is
|
||||
// decorated as an EventStream Event.
|
||||
//
|
||||
// Executed in the context of a Shape.
|
||||
var eventStreamEventShapeTmpl = template.Must(template.New("eventStreamEventShapeTmpl").Parse(`
|
||||
{{ range $_, $eventstream := $.EventFor }}
|
||||
// The {{ $.ShapeName }} is and event in the {{ $eventstream.Name }} group of events.
|
||||
func (s *{{ $.ShapeName }}) event{{ $eventstream.Name }}() {}
|
||||
{{ end }}
|
||||
|
||||
// UnmarshalEvent unmarshals the EventStream Message into the {{ $.ShapeName }} value.
|
||||
// This method is only used internally within the SDK's EventStream handling.
|
||||
func (s *{{ $.ShapeName }}) UnmarshalEvent(
|
||||
payloadUnmarshaler protocol.PayloadUnmarshaler,
|
||||
msg eventstream.Message,
|
||||
) error {
|
||||
{{- range $fieldIdx, $fieldName := $.MemberNames }}
|
||||
{{- $fieldRef := index $.MemberRefs $fieldName -}}
|
||||
{{ if $fieldRef.IsEventHeader }}
|
||||
// TODO handle event header, {{ $fieldName }}
|
||||
{{- else if (and ($fieldRef.IsEventPayload) (eq $fieldRef.Shape.Type "blob")) }}
|
||||
s.{{ $fieldName }} = make([]byte, len(msg.Payload))
|
||||
copy(s.{{ $fieldName }}, msg.Payload)
|
||||
{{- else }}
|
||||
if err := payloadUnmarshaler.UnmarshalPayload(
|
||||
bytes.NewReader(msg.Payload), s,
|
||||
); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal payload, %v", err)
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
return nil
|
||||
}
|
||||
`))
|
||||
|
||||
var eventStreamTestTmpl = template.Must(template.New("eventStreamTestTmpl").Parse(`
|
||||
`))
|
318
vendor/github.com/aws/aws-sdk-go/private/model/api/example.go
generated
vendored
318
vendor/github.com/aws/aws-sdk-go/private/model/api/example.go
generated
vendored
|
@ -1,318 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/aws/aws-sdk-go/private/util"
|
||||
)
|
||||
|
||||
type Examples map[string][]Example
|
||||
|
||||
// ExamplesDefinition is the structural representation of the examples-1.json file
|
||||
type ExamplesDefinition struct {
|
||||
*API `json:"-"`
|
||||
Examples Examples `json:"examples"`
|
||||
}
|
||||
|
||||
// Example is a single entry within the examples-1.json file.
|
||||
type Example struct {
|
||||
API *API `json:"-"`
|
||||
Operation *Operation `json:"-"`
|
||||
OperationName string `json:"-"`
|
||||
Index string `json:"-"`
|
||||
Builder examplesBuilder `json:"-"`
|
||||
VisitedErrors map[string]struct{} `json:"-"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
ID string `json:"id"`
|
||||
Comments Comments `json:"comments"`
|
||||
Input map[string]interface{} `json:"input"`
|
||||
Output map[string]interface{} `json:"output"`
|
||||
}
|
||||
|
||||
type Comments struct {
|
||||
Input map[string]interface{} `json:"input"`
|
||||
Output map[string]interface{} `json:"output"`
|
||||
}
|
||||
|
||||
var exampleFuncMap = template.FuncMap{
|
||||
"commentify": commentify,
|
||||
"wrap": wrap,
|
||||
"generateExampleInput": generateExampleInput,
|
||||
"generateTypes": generateTypes,
|
||||
}
|
||||
|
||||
var exampleCustomizations = map[string]template.FuncMap{}
|
||||
|
||||
var exampleTmpls = template.Must(template.New("example").Funcs(exampleFuncMap).Parse(`
|
||||
{{ generateTypes . }}
|
||||
{{ commentify (wrap .Title 80 false) }}
|
||||
//
|
||||
{{ commentify (wrap .Description 80 false) }}
|
||||
func Example{{ .API.StructName }}_{{ .MethodName }}() {
|
||||
svc := {{ .API.PackageName }}.New(session.New())
|
||||
input := &{{ .Operation.InputRef.Shape.GoTypeWithPkgNameElem }} {
|
||||
{{ generateExampleInput . -}}
|
||||
}
|
||||
|
||||
result, err := svc.{{ .OperationName }}(input)
|
||||
if err != nil {
|
||||
if aerr, ok := err.(awserr.Error); ok {
|
||||
switch aerr.Code() {
|
||||
{{ range $_, $ref := .Operation.ErrorRefs -}}
|
||||
{{ if not ($.HasVisitedError $ref) -}}
|
||||
case {{ .API.PackageName }}.{{ $ref.Shape.ErrorCodeName }}:
|
||||
fmt.Println({{ .API.PackageName }}.{{ $ref.Shape.ErrorCodeName }}, aerr.Error())
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
default:
|
||||
fmt.Println(aerr.Error())
|
||||
}
|
||||
} else {
|
||||
// Print the error, cast err to awserr.Error to get the Code and
|
||||
// Message from an error.
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(result)
|
||||
}
|
||||
`))
|
||||
|
||||
// Names will return the name of the example. This will also be the name of the operation
|
||||
// that is to be tested.
|
||||
func (exs Examples) Names() []string {
|
||||
names := make([]string, 0, len(exs))
|
||||
for k := range exs {
|
||||
names = append(names, k)
|
||||
}
|
||||
|
||||
sort.Strings(names)
|
||||
return names
|
||||
}
|
||||
|
||||
func (exs Examples) GoCode() string {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
for _, opName := range exs.Names() {
|
||||
examples := exs[opName]
|
||||
for _, ex := range examples {
|
||||
buf.WriteString(util.GoFmt(ex.GoCode()))
|
||||
buf.WriteString("\n")
|
||||
}
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// ExampleCode will generate the example code for the given Example shape.
|
||||
// TODO: Can delete
|
||||
func (ex Example) GoCode() string {
|
||||
var buf bytes.Buffer
|
||||
m := exampleFuncMap
|
||||
if fMap, ok := exampleCustomizations[ex.API.PackageName()]; ok {
|
||||
m = fMap
|
||||
}
|
||||
tmpl := exampleTmpls.Funcs(m)
|
||||
if err := tmpl.ExecuteTemplate(&buf, "example", &ex); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return strings.TrimSpace(buf.String())
|
||||
}
|
||||
|
||||
func generateExampleInput(ex Example) string {
|
||||
if ex.Operation.HasInput() {
|
||||
return ex.Builder.BuildShape(&ex.Operation.InputRef, ex.Input, false)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// generateTypes will generate no types for default examples, but customizations may
|
||||
// require their own defined types.
|
||||
func generateTypes(ex Example) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// correctType will cast the value to the correct type when printing the string.
|
||||
// This is due to the json decoder choosing numbers to be floats, but the shape may
|
||||
// actually be an int. To counter this, we pass the shape's type and properly do the
|
||||
// casting here.
|
||||
func correctType(memName string, t string, value interface{}) string {
|
||||
if value == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
v := ""
|
||||
switch value.(type) {
|
||||
case string:
|
||||
v = value.(string)
|
||||
case int:
|
||||
v = fmt.Sprintf("%d", value.(int))
|
||||
case float64:
|
||||
if t == "integer" || t == "long" || t == "int64" {
|
||||
v = fmt.Sprintf("%d", int(value.(float64)))
|
||||
} else {
|
||||
v = fmt.Sprintf("%f", value.(float64))
|
||||
}
|
||||
case bool:
|
||||
v = fmt.Sprintf("%t", value.(bool))
|
||||
}
|
||||
|
||||
return convertToCorrectType(memName, t, v)
|
||||
}
|
||||
|
||||
func convertToCorrectType(memName, t, v string) string {
|
||||
return fmt.Sprintf("%s: %s,\n", memName, getValue(t, v))
|
||||
}
|
||||
|
||||
func getValue(t, v string) string {
|
||||
if t[0] == '*' {
|
||||
t = t[1:]
|
||||
}
|
||||
switch t {
|
||||
case "string":
|
||||
return fmt.Sprintf("aws.String(%q)", v)
|
||||
case "integer", "long", "int64":
|
||||
return fmt.Sprintf("aws.Int64(%s)", v)
|
||||
case "float", "float64", "double":
|
||||
return fmt.Sprintf("aws.Float64(%s)", v)
|
||||
case "boolean":
|
||||
return fmt.Sprintf("aws.Bool(%s)", v)
|
||||
default:
|
||||
panic("Unsupported type: " + t)
|
||||
}
|
||||
}
|
||||
|
||||
// AttachExamples will create a new ExamplesDefinition from the examples file
|
||||
// and reference the API object.
|
||||
func (a *API) AttachExamples(filename string) {
|
||||
p := ExamplesDefinition{API: a}
|
||||
|
||||
f, err := os.Open(filename)
|
||||
defer f.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = json.NewDecoder(f).Decode(&p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
p.setup()
|
||||
}
|
||||
|
||||
var examplesBuilderCustomizations = map[string]examplesBuilder{
|
||||
"wafregional": wafregionalExamplesBuilder{},
|
||||
}
|
||||
|
||||
func (p *ExamplesDefinition) setup() {
|
||||
var builder examplesBuilder
|
||||
ok := false
|
||||
if builder, ok = examplesBuilderCustomizations[p.API.PackageName()]; !ok {
|
||||
builder = defaultExamplesBuilder{}
|
||||
}
|
||||
|
||||
keys := p.Examples.Names()
|
||||
for _, n := range keys {
|
||||
examples := p.Examples[n]
|
||||
for i, e := range examples {
|
||||
n = p.ExportableName(n)
|
||||
e.OperationName = n
|
||||
e.API = p.API
|
||||
e.Index = fmt.Sprintf("shared%02d", i)
|
||||
|
||||
e.Builder = builder
|
||||
|
||||
e.VisitedErrors = map[string]struct{}{}
|
||||
op := p.API.Operations[e.OperationName]
|
||||
e.OperationName = p.ExportableName(e.OperationName)
|
||||
e.Operation = op
|
||||
p.Examples[n][i] = e
|
||||
}
|
||||
}
|
||||
|
||||
p.API.Examples = p.Examples
|
||||
}
|
||||
|
||||
var exampleHeader = template.Must(template.New("exampleHeader").Parse(`
|
||||
import (
|
||||
{{ .Builder.Imports .API }}
|
||||
)
|
||||
|
||||
var _ time.Duration
|
||||
var _ strings.Reader
|
||||
var _ aws.Config
|
||||
|
||||
func parseTime(layout, value string) *time.Time {
|
||||
t, err := time.Parse(layout, value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
`))
|
||||
|
||||
type exHeader struct {
|
||||
Builder examplesBuilder
|
||||
API *API
|
||||
}
|
||||
|
||||
// ExamplesGoCode will return a code representation of the entry within the
|
||||
// examples.json file.
|
||||
func (a *API) ExamplesGoCode() string {
|
||||
var buf bytes.Buffer
|
||||
var builder examplesBuilder
|
||||
ok := false
|
||||
if builder, ok = examplesBuilderCustomizations[a.PackageName()]; !ok {
|
||||
builder = defaultExamplesBuilder{}
|
||||
}
|
||||
|
||||
if err := exampleHeader.ExecuteTemplate(&buf, "exampleHeader", &exHeader{builder, a}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
code := a.Examples.GoCode()
|
||||
if len(code) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
buf.WriteString(code)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// TODO: In the operation docuentation where we list errors, this needs to be done
|
||||
// there as well.
|
||||
func (ex *Example) HasVisitedError(errRef *ShapeRef) bool {
|
||||
errName := errRef.Shape.ErrorCodeName()
|
||||
_, ok := ex.VisitedErrors[errName]
|
||||
ex.VisitedErrors[errName] = struct{}{}
|
||||
return ok
|
||||
}
|
||||
|
||||
func parseTimeString(ref *ShapeRef, memName, v string) string {
|
||||
if ref.Location == "header" {
|
||||
return fmt.Sprintf("%s: parseTime(%q, %q),\n", memName, "Mon, 2 Jan 2006 15:04:05 GMT", v)
|
||||
} else {
|
||||
switch ref.API.Metadata.Protocol {
|
||||
case "json", "rest-json":
|
||||
return fmt.Sprintf("%s: parseTime(%q, %q),\n", memName, "2006-01-02T15:04:05Z", v)
|
||||
case "rest-xml", "ec2", "query":
|
||||
return fmt.Sprintf("%s: parseTime(%q, %q),\n", memName, "2006-01-02T15:04:05Z", v)
|
||||
default:
|
||||
panic("Unsupported time type: " + ref.API.Metadata.Protocol)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (ex *Example) MethodName() string {
|
||||
return fmt.Sprintf("%s_%s", ex.OperationName, ex.Index)
|
||||
}
|
322
vendor/github.com/aws/aws-sdk-go/private/model/api/example_test.go
generated
vendored
322
vendor/github.com/aws/aws-sdk-go/private/model/api/example_test.go
generated
vendored
|
@ -1,322 +0,0 @@
|
|||
// +build 1.6,codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func buildAPI() *API {
|
||||
a := &API{}
|
||||
|
||||
stringShape := &Shape{
|
||||
API: a,
|
||||
ShapeName: "string",
|
||||
Type: "string",
|
||||
}
|
||||
stringShapeRef := &ShapeRef{
|
||||
API: a,
|
||||
ShapeName: "string",
|
||||
Shape: stringShape,
|
||||
}
|
||||
|
||||
intShape := &Shape{
|
||||
API: a,
|
||||
ShapeName: "int",
|
||||
Type: "int",
|
||||
}
|
||||
intShapeRef := &ShapeRef{
|
||||
API: a,
|
||||
ShapeName: "int",
|
||||
Shape: intShape,
|
||||
}
|
||||
|
||||
nestedComplexShape := &Shape{
|
||||
API: a,
|
||||
ShapeName: "NestedComplexShape",
|
||||
MemberRefs: map[string]*ShapeRef{
|
||||
"NestedField": stringShapeRef,
|
||||
},
|
||||
Type: "structure",
|
||||
}
|
||||
|
||||
nestedComplexShapeRef := &ShapeRef{
|
||||
API: a,
|
||||
ShapeName: "NestedComplexShape",
|
||||
Shape: nestedComplexShape,
|
||||
}
|
||||
|
||||
nestedListShape := &Shape{
|
||||
API: a,
|
||||
ShapeName: "NestedListShape",
|
||||
MemberRef: *nestedComplexShapeRef,
|
||||
Type: "list",
|
||||
}
|
||||
|
||||
nestedListShapeRef := &ShapeRef{
|
||||
API: a,
|
||||
ShapeName: "NestedListShape",
|
||||
Shape: nestedListShape,
|
||||
}
|
||||
|
||||
complexShape := &Shape{
|
||||
API: a,
|
||||
ShapeName: "ComplexShape",
|
||||
MemberRefs: map[string]*ShapeRef{
|
||||
"Field": stringShapeRef,
|
||||
"List": nestedListShapeRef,
|
||||
},
|
||||
Type: "structure",
|
||||
}
|
||||
|
||||
complexShapeRef := &ShapeRef{
|
||||
API: a,
|
||||
ShapeName: "ComplexShape",
|
||||
Shape: complexShape,
|
||||
}
|
||||
|
||||
listShape := &Shape{
|
||||
API: a,
|
||||
ShapeName: "ListShape",
|
||||
MemberRef: *complexShapeRef,
|
||||
Type: "list",
|
||||
}
|
||||
|
||||
listShapeRef := &ShapeRef{
|
||||
API: a,
|
||||
ShapeName: "ListShape",
|
||||
Shape: listShape,
|
||||
}
|
||||
|
||||
listsShape := &Shape{
|
||||
API: a,
|
||||
ShapeName: "ListsShape",
|
||||
MemberRef: *listShapeRef,
|
||||
Type: "list",
|
||||
}
|
||||
|
||||
listsShapeRef := &ShapeRef{
|
||||
API: a,
|
||||
ShapeName: "ListsShape",
|
||||
Shape: listsShape,
|
||||
}
|
||||
|
||||
input := &Shape{
|
||||
API: a,
|
||||
ShapeName: "FooInput",
|
||||
MemberRefs: map[string]*ShapeRef{
|
||||
"BarShape": stringShapeRef,
|
||||
"ComplexField": complexShapeRef,
|
||||
"ListField": listShapeRef,
|
||||
"ListsField": listsShapeRef,
|
||||
},
|
||||
Type: "structure",
|
||||
}
|
||||
output := &Shape{
|
||||
API: a,
|
||||
ShapeName: "FooOutput",
|
||||
MemberRefs: map[string]*ShapeRef{
|
||||
"BazShape": intShapeRef,
|
||||
"ComplexField": complexShapeRef,
|
||||
"ListField": listShapeRef,
|
||||
"ListsField": listsShapeRef,
|
||||
},
|
||||
Type: "structure",
|
||||
}
|
||||
|
||||
inputRef := ShapeRef{
|
||||
API: a,
|
||||
ShapeName: "FooInput",
|
||||
Shape: input,
|
||||
}
|
||||
outputRef := ShapeRef{
|
||||
API: a,
|
||||
ShapeName: "Foooutput",
|
||||
Shape: output,
|
||||
}
|
||||
|
||||
operations := map[string]*Operation{
|
||||
"Foo": {
|
||||
API: a,
|
||||
Name: "Foo",
|
||||
ExportedName: "Foo",
|
||||
InputRef: inputRef,
|
||||
OutputRef: outputRef,
|
||||
},
|
||||
}
|
||||
|
||||
a.Operations = operations
|
||||
a.Shapes = map[string]*Shape{
|
||||
"FooInput": input,
|
||||
"FooOutput": output,
|
||||
}
|
||||
a.Metadata = Metadata{
|
||||
ServiceAbbreviation: "FooService",
|
||||
}
|
||||
|
||||
a.Setup()
|
||||
return a
|
||||
}
|
||||
|
||||
func TestExampleGeneration(t *testing.T) {
|
||||
example := `
|
||||
{
|
||||
"version": "1.0",
|
||||
"examples": {
|
||||
"Foo": [
|
||||
{
|
||||
"input": {
|
||||
"BarShape": "Hello world",
|
||||
"ComplexField": {
|
||||
"Field": "bar",
|
||||
"List": [
|
||||
{
|
||||
"NestedField": "qux"
|
||||
}
|
||||
]
|
||||
},
|
||||
"ListField": [
|
||||
{
|
||||
"Field": "baz"
|
||||
}
|
||||
],
|
||||
"ListsField": [
|
||||
[
|
||||
{
|
||||
"Field": "baz"
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"output": {
|
||||
"BazShape": 1
|
||||
},
|
||||
"comments": {
|
||||
"input": {
|
||||
},
|
||||
"output": {
|
||||
}
|
||||
},
|
||||
"description": "Foo bar baz qux",
|
||||
"title": "I pity the foo"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
`
|
||||
a := buildAPI()
|
||||
def := &ExamplesDefinition{}
|
||||
err := json.Unmarshal([]byte(example), def)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
def.API = a
|
||||
|
||||
def.setup()
|
||||
expected := `
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/fooservice"
|
||||
)
|
||||
|
||||
var _ time.Duration
|
||||
var _ strings.Reader
|
||||
var _ aws.Config
|
||||
|
||||
func parseTime(layout, value string) *time.Time {
|
||||
t, err := time.Parse(layout, value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
// I pity the foo
|
||||
//
|
||||
// Foo bar baz qux
|
||||
func ExampleFooService_Foo_shared00() {
|
||||
svc := fooservice.New(session.New())
|
||||
input := &fooservice.FooInput{
|
||||
BarShape: aws.String("Hello world"),
|
||||
ComplexField: &fooservice.ComplexShape{
|
||||
Field: aws.String("bar"),
|
||||
List: []*fooservice.NestedComplexShape{
|
||||
{
|
||||
NestedField: aws.String("qux"),
|
||||
},
|
||||
},
|
||||
},
|
||||
ListField: []*fooservice.ComplexShape{
|
||||
{
|
||||
Field: aws.String("baz"),
|
||||
},
|
||||
},
|
||||
ListsField: [][]*fooservice.ComplexShape{
|
||||
{
|
||||
{
|
||||
Field: aws.String("baz"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
result, err := svc.Foo(input)
|
||||
if err != nil {
|
||||
if aerr, ok := err.(awserr.Error); ok {
|
||||
switch aerr.Code() {
|
||||
default:
|
||||
fmt.Println(aerr.Error())
|
||||
}
|
||||
} else {
|
||||
// Print the error, cast err to awserr.Error to get the Code and
|
||||
// Message from an error.
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(result)
|
||||
}
|
||||
`
|
||||
if expected != a.ExamplesGoCode() {
|
||||
t.Log([]byte(expected))
|
||||
t.Log([]byte(a.ExamplesGoCode()))
|
||||
t.Errorf("Expected:\n%s\nReceived:\n%s\n", expected, a.ExamplesGoCode())
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildShape(t *testing.T) {
|
||||
a := buildAPI()
|
||||
cases := []struct {
|
||||
defs map[string]interface{}
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
defs: map[string]interface{}{
|
||||
"barShape": "Hello World",
|
||||
},
|
||||
expected: "BarShape: aws.String(\"Hello World\"),\n",
|
||||
},
|
||||
{
|
||||
defs: map[string]interface{}{
|
||||
"BarShape": "Hello World",
|
||||
},
|
||||
expected: "BarShape: aws.String(\"Hello World\"),\n",
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
ref := a.Operations["Foo"].InputRef
|
||||
shapeStr := defaultExamplesBuilder{}.BuildShape(&ref, c.defs, false)
|
||||
if c.expected != shapeStr {
|
||||
t.Errorf("Expected:\n%s\nReceived:\n%s", c.expected, shapeStr)
|
||||
}
|
||||
}
|
||||
}
|
222
vendor/github.com/aws/aws-sdk-go/private/model/api/examples_builder.go
generated
vendored
222
vendor/github.com/aws/aws-sdk-go/private/model/api/examples_builder.go
generated
vendored
|
@ -1,222 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type examplesBuilder interface {
|
||||
BuildShape(*ShapeRef, map[string]interface{}, bool) string
|
||||
BuildList(string, string, *ShapeRef, []interface{}) string
|
||||
BuildComplex(string, string, *ShapeRef, map[string]interface{}) string
|
||||
Imports(*API) string
|
||||
}
|
||||
|
||||
type defaultExamplesBuilder struct{}
|
||||
|
||||
// BuildShape will recursively build the referenced shape based on the json object
|
||||
// provided.
|
||||
// isMap will dictate how the field name is specified. If isMap is true, we will expect
|
||||
// the member name to be quotes like "Foo".
|
||||
func (builder defaultExamplesBuilder) BuildShape(ref *ShapeRef, shapes map[string]interface{}, isMap bool) string {
|
||||
order := make([]string, len(shapes))
|
||||
for k := range shapes {
|
||||
order = append(order, k)
|
||||
}
|
||||
sort.Strings(order)
|
||||
|
||||
ret := ""
|
||||
for _, name := range order {
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
shape := shapes[name]
|
||||
|
||||
// If the shape isn't a map, we want to export the value, since every field
|
||||
// defined in our shapes are exported.
|
||||
if len(name) > 0 && !isMap && strings.ToLower(name[0:1]) == name[0:1] {
|
||||
name = strings.Title(name)
|
||||
}
|
||||
|
||||
memName := name
|
||||
passRef := ref.Shape.MemberRefs[name]
|
||||
|
||||
if isMap {
|
||||
memName = fmt.Sprintf("%q", memName)
|
||||
passRef = &ref.Shape.ValueRef
|
||||
}
|
||||
|
||||
switch v := shape.(type) {
|
||||
case map[string]interface{}:
|
||||
ret += builder.BuildComplex(name, memName, passRef, v)
|
||||
case []interface{}:
|
||||
ret += builder.BuildList(name, memName, passRef, v)
|
||||
default:
|
||||
ret += builder.BuildScalar(name, memName, passRef, v, ref.Shape.Payload == name)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// BuildList will construct a list shape based off the service's definition
|
||||
// of that list.
|
||||
func (builder defaultExamplesBuilder) BuildList(name, memName string, ref *ShapeRef, v []interface{}) string {
|
||||
ret := ""
|
||||
|
||||
if len(v) == 0 || ref == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
passRef := &ref.Shape.MemberRef
|
||||
ret += fmt.Sprintf("%s: %s {\n", memName, builder.GoType(ref, false))
|
||||
ret += builder.buildListElements(passRef, v)
|
||||
ret += "},\n"
|
||||
return ret
|
||||
}
|
||||
|
||||
func (builder defaultExamplesBuilder) buildListElements(ref *ShapeRef, v []interface{}) string {
|
||||
if len(v) == 0 || ref == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
ret := ""
|
||||
format := ""
|
||||
isComplex := false
|
||||
isList := false
|
||||
|
||||
// get format for atomic type. If it is not an atomic type,
|
||||
// get the element.
|
||||
switch v[0].(type) {
|
||||
case string:
|
||||
format = "%s"
|
||||
case bool:
|
||||
format = "%t"
|
||||
case float64:
|
||||
switch ref.Shape.Type {
|
||||
case "integer", "int64", "long":
|
||||
format = "%d"
|
||||
default:
|
||||
format = "%f"
|
||||
}
|
||||
case []interface{}:
|
||||
isList = true
|
||||
case map[string]interface{}:
|
||||
isComplex = true
|
||||
}
|
||||
|
||||
for _, elem := range v {
|
||||
if isComplex {
|
||||
ret += fmt.Sprintf("{\n%s\n},\n", builder.BuildShape(ref, elem.(map[string]interface{}), ref.Shape.Type == "map"))
|
||||
} else if isList {
|
||||
ret += fmt.Sprintf("{\n%s\n},\n", builder.buildListElements(&ref.Shape.MemberRef, elem.([]interface{})))
|
||||
} else {
|
||||
switch ref.Shape.Type {
|
||||
case "integer", "int64", "long":
|
||||
elem = int(elem.(float64))
|
||||
}
|
||||
ret += fmt.Sprintf("%s,\n", getValue(ref.Shape.Type, fmt.Sprintf(format, elem)))
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// BuildScalar will build atomic Go types.
|
||||
func (builder defaultExamplesBuilder) BuildScalar(name, memName string, ref *ShapeRef, shape interface{}, isPayload bool) string {
|
||||
if ref == nil || ref.Shape == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
switch v := shape.(type) {
|
||||
case bool:
|
||||
return convertToCorrectType(memName, ref.Shape.Type, fmt.Sprintf("%t", v))
|
||||
case int:
|
||||
if ref.Shape.Type == "timestamp" {
|
||||
return parseTimeString(ref, memName, fmt.Sprintf("%d", v))
|
||||
}
|
||||
return convertToCorrectType(memName, ref.Shape.Type, fmt.Sprintf("%d", v))
|
||||
case float64:
|
||||
dataType := ref.Shape.Type
|
||||
if dataType == "integer" || dataType == "int64" || dataType == "long" {
|
||||
return convertToCorrectType(memName, ref.Shape.Type, fmt.Sprintf("%d", int(shape.(float64))))
|
||||
}
|
||||
return convertToCorrectType(memName, ref.Shape.Type, fmt.Sprintf("%f", v))
|
||||
case string:
|
||||
t := ref.Shape.Type
|
||||
switch t {
|
||||
case "timestamp":
|
||||
return parseTimeString(ref, memName, fmt.Sprintf("%s", v))
|
||||
case "blob":
|
||||
if (ref.Streaming || ref.Shape.Streaming) && isPayload {
|
||||
return fmt.Sprintf("%s: aws.ReadSeekCloser(strings.NewReader(%q)),\n", memName, v)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s: []byte(%q),\n", memName, v)
|
||||
default:
|
||||
return convertToCorrectType(memName, t, v)
|
||||
}
|
||||
default:
|
||||
panic(fmt.Errorf("Unsupported scalar type: %v", reflect.TypeOf(v)))
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (builder defaultExamplesBuilder) BuildComplex(name, memName string, ref *ShapeRef, v map[string]interface{}) string {
|
||||
switch ref.Shape.Type {
|
||||
case "structure":
|
||||
return fmt.Sprintf(`%s: &%s{
|
||||
%s
|
||||
},
|
||||
`, memName, builder.GoType(ref, true), builder.BuildShape(ref, v, false))
|
||||
case "map":
|
||||
return fmt.Sprintf(`%s: %s{
|
||||
%s
|
||||
},
|
||||
`, name, builder.GoType(ref, false), builder.BuildShape(ref, v, true))
|
||||
default:
|
||||
panic(fmt.Sprintf("Expected complex type but recieved %q", ref.Shape.Type))
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func (builder defaultExamplesBuilder) GoType(ref *ShapeRef, elem bool) string {
|
||||
if ref.Shape.Type != "structure" && ref.Shape.Type != "list" && ref.Shape.Type != "map" {
|
||||
return ref.GoTypeWithPkgName()
|
||||
}
|
||||
|
||||
prefix := ""
|
||||
if ref.Shape.Type == "list" {
|
||||
ref = &ref.Shape.MemberRef
|
||||
prefix = "[]"
|
||||
}
|
||||
|
||||
name := ref.GoTypeWithPkgName()
|
||||
if elem {
|
||||
name = ref.GoTypeElem()
|
||||
if !strings.Contains(name, ".") {
|
||||
name = strings.Join([]string{ref.API.PackageName(), name}, ".")
|
||||
}
|
||||
}
|
||||
|
||||
return prefix + name
|
||||
}
|
||||
|
||||
func (builder defaultExamplesBuilder) Imports(a *API) string {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
buf.WriteString(`"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
`)
|
||||
|
||||
buf.WriteString(fmt.Sprintf("\"%s/%s\"", "github.com/aws/aws-sdk-go/service", a.PackageName()))
|
||||
return buf.String()
|
||||
}
|
28
vendor/github.com/aws/aws-sdk-go/private/model/api/examples_builder_customizations.go
generated
vendored
28
vendor/github.com/aws/aws-sdk-go/private/model/api/examples_builder_customizations.go
generated
vendored
|
@ -1,28 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type wafregionalExamplesBuilder struct {
|
||||
defaultExamplesBuilder
|
||||
}
|
||||
|
||||
func (builder wafregionalExamplesBuilder) Imports(a *API) string {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
buf.WriteString(`"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/waf"
|
||||
`)
|
||||
|
||||
buf.WriteString(fmt.Sprintf("\"%s/%s\"", "github.com/aws/aws-sdk-go/service", a.PackageName()))
|
||||
return buf.String()
|
||||
}
|
14
vendor/github.com/aws/aws-sdk-go/private/model/api/exportable_name.go
generated
vendored
14
vendor/github.com/aws/aws-sdk-go/private/model/api/exportable_name.go
generated
vendored
|
@ -1,14 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
import "strings"
|
||||
|
||||
// ExportableName a name which is exportable as a value or name in Go code
|
||||
func (a *API) ExportableName(name string) string {
|
||||
if name == "" {
|
||||
return name
|
||||
}
|
||||
|
||||
return strings.ToUpper(name[0:1]) + name[1:]
|
||||
}
|
495
vendor/github.com/aws/aws-sdk-go/private/model/api/list_of_shame.go
generated
vendored
495
vendor/github.com/aws/aws-sdk-go/private/model/api/list_of_shame.go
generated
vendored
|
@ -1,495 +0,0 @@
|
|||
package api
|
||||
|
||||
// shamelist is used to not rename certain operation's input and output shapes.
|
||||
// We need to maintain backwards compatibility with pre-existing services. Since
|
||||
// not generating unique input/output shapes is not desired, we will generate
|
||||
// unique input/output shapes for new operations.
|
||||
var shamelist = map[string]map[string]struct {
|
||||
input bool
|
||||
output bool
|
||||
}{
|
||||
"APIGateway": {
|
||||
"CreateApiKey": {
|
||||
output: true,
|
||||
},
|
||||
"CreateAuthorizer": {
|
||||
output: true,
|
||||
},
|
||||
"CreateBasePathMapping": {
|
||||
output: true,
|
||||
},
|
||||
"CreateDeployment": {
|
||||
output: true,
|
||||
},
|
||||
"CreateDocumentationPart": {
|
||||
output: true,
|
||||
},
|
||||
"CreateDocumentationVersion": {
|
||||
output: true,
|
||||
},
|
||||
"CreateDomainName": {
|
||||
output: true,
|
||||
},
|
||||
"CreateModel": {
|
||||
output: true,
|
||||
},
|
||||
"CreateResource": {
|
||||
output: true,
|
||||
},
|
||||
"CreateRestApi": {
|
||||
output: true,
|
||||
},
|
||||
"CreateStage": {
|
||||
output: true,
|
||||
},
|
||||
"CreateUsagePlan": {
|
||||
output: true,
|
||||
},
|
||||
"CreateUsagePlanKey": {
|
||||
output: true,
|
||||
},
|
||||
"GenerateClientCertificate": {
|
||||
output: true,
|
||||
},
|
||||
"GetAccount": {
|
||||
output: true,
|
||||
},
|
||||
"GetApiKey": {
|
||||
output: true,
|
||||
},
|
||||
"GetAuthorizer": {
|
||||
output: true,
|
||||
},
|
||||
"GetBasePathMapping": {
|
||||
output: true,
|
||||
},
|
||||
"GetClientCertificate": {
|
||||
output: true,
|
||||
},
|
||||
"GetDeployment": {
|
||||
output: true,
|
||||
},
|
||||
"GetDocumentationPart": {
|
||||
output: true,
|
||||
},
|
||||
"GetDocumentationVersion": {
|
||||
output: true,
|
||||
},
|
||||
"GetDomainName": {
|
||||
output: true,
|
||||
},
|
||||
"GetIntegration": {
|
||||
output: true,
|
||||
},
|
||||
"GetIntegrationResponse": {
|
||||
output: true,
|
||||
},
|
||||
"GetMethod": {
|
||||
output: true,
|
||||
},
|
||||
"GetMethodResponse": {
|
||||
output: true,
|
||||
},
|
||||
"GetModel": {
|
||||
output: true,
|
||||
},
|
||||
"GetResource": {
|
||||
output: true,
|
||||
},
|
||||
"GetRestApi": {
|
||||
output: true,
|
||||
},
|
||||
"GetSdkType": {
|
||||
output: true,
|
||||
},
|
||||
"GetStage": {
|
||||
output: true,
|
||||
},
|
||||
"GetUsage": {
|
||||
output: true,
|
||||
},
|
||||
"GetUsagePlan": {
|
||||
output: true,
|
||||
},
|
||||
"GetUsagePlanKey": {
|
||||
output: true,
|
||||
},
|
||||
"ImportRestApi": {
|
||||
output: true,
|
||||
},
|
||||
"PutIntegration": {
|
||||
output: true,
|
||||
},
|
||||
"PutIntegrationResponse": {
|
||||
output: true,
|
||||
},
|
||||
"PutMethod": {
|
||||
output: true,
|
||||
},
|
||||
"PutMethodResponse": {
|
||||
output: true,
|
||||
},
|
||||
"PutRestApi": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateAccount": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateApiKey": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateAuthorizer": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateBasePathMapping": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateClientCertificate": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateDeployment": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateDocumentationPart": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateDocumentationVersion": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateDomainName": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateIntegration": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateIntegrationResponse": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateMethod": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateMethodResponse": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateModel": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateResource": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateRestApi": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateStage": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateUsage": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateUsagePlan": {
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
"AutoScaling": {
|
||||
"ResumeProcesses": {
|
||||
input: true,
|
||||
},
|
||||
"SuspendProcesses": {
|
||||
input: true,
|
||||
},
|
||||
},
|
||||
"CognitoIdentity": {
|
||||
"CreateIdentityPool": {
|
||||
output: true,
|
||||
},
|
||||
"DescribeIdentity": {
|
||||
output: true,
|
||||
},
|
||||
"DescribeIdentityPool": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateIdentityPool": {
|
||||
input: true,
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
"DirectConnect": {
|
||||
"AllocateConnectionOnInterconnect": {
|
||||
output: true,
|
||||
},
|
||||
"AllocateHostedConnection": {
|
||||
output: true,
|
||||
},
|
||||
"AllocatePrivateVirtualInterface": {
|
||||
output: true,
|
||||
},
|
||||
"AllocatePublicVirtualInterface": {
|
||||
output: true,
|
||||
},
|
||||
"AssociateConnectionWithLag": {
|
||||
output: true,
|
||||
},
|
||||
"AssociateHostedConnection": {
|
||||
output: true,
|
||||
},
|
||||
"AssociateVirtualInterface": {
|
||||
output: true,
|
||||
},
|
||||
"CreateConnection": {
|
||||
output: true,
|
||||
},
|
||||
"CreateInterconnect": {
|
||||
output: true,
|
||||
},
|
||||
"CreateLag": {
|
||||
output: true,
|
||||
},
|
||||
"CreatePrivateVirtualInterface": {
|
||||
output: true,
|
||||
},
|
||||
"CreatePublicVirtualInterface": {
|
||||
output: true,
|
||||
},
|
||||
"DeleteConnection": {
|
||||
output: true,
|
||||
},
|
||||
"DeleteLag": {
|
||||
output: true,
|
||||
},
|
||||
"DescribeConnections": {
|
||||
output: true,
|
||||
},
|
||||
"DescribeConnectionsOnInterconnect": {
|
||||
output: true,
|
||||
},
|
||||
"DescribeHostedConnections": {
|
||||
output: true,
|
||||
},
|
||||
"DescribeLoa": {
|
||||
output: true,
|
||||
},
|
||||
"DisassociateConnectionFromLag": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateLag": {
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
"EC2": {
|
||||
"AttachVolume": {
|
||||
output: true,
|
||||
},
|
||||
"CreateSnapshot": {
|
||||
output: true,
|
||||
},
|
||||
"CreateVolume": {
|
||||
output: true,
|
||||
},
|
||||
"DetachVolume": {
|
||||
output: true,
|
||||
},
|
||||
"RunInstances": {
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
"EFS": {
|
||||
"CreateFileSystem": {
|
||||
output: true,
|
||||
},
|
||||
"CreateMountTarget": {
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
"ElastiCache": {
|
||||
"AddTagsToResource": {
|
||||
output: true,
|
||||
},
|
||||
"ListTagsForResource": {
|
||||
output: true,
|
||||
},
|
||||
"ModifyCacheParameterGroup": {
|
||||
output: true,
|
||||
},
|
||||
"RemoveTagsFromResource": {
|
||||
output: true,
|
||||
},
|
||||
"ResetCacheParameterGroup": {
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
"ElasticBeanstalk": {
|
||||
"ComposeEnvironments": {
|
||||
output: true,
|
||||
},
|
||||
"CreateApplication": {
|
||||
output: true,
|
||||
},
|
||||
"CreateApplicationVersion": {
|
||||
output: true,
|
||||
},
|
||||
"CreateConfigurationTemplate": {
|
||||
output: true,
|
||||
},
|
||||
"CreateEnvironment": {
|
||||
output: true,
|
||||
},
|
||||
"DescribeEnvironments": {
|
||||
output: true,
|
||||
},
|
||||
"TerminateEnvironment": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateApplication": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateApplicationVersion": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateConfigurationTemplate": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateEnvironment": {
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
"Glacier": {
|
||||
"DescribeJob": {
|
||||
output: true,
|
||||
},
|
||||
"UploadArchive": {
|
||||
output: true,
|
||||
},
|
||||
"CompleteMultipartUpload": {
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
"IAM": {
|
||||
"GetContextKeysForCustomPolicy": {
|
||||
output: true,
|
||||
},
|
||||
"GetContextKeysForPrincipalPolicy": {
|
||||
output: true,
|
||||
},
|
||||
"SimulateCustomPolicy": {
|
||||
output: true,
|
||||
},
|
||||
"SimulatePrincipalPolicy": {
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
"Kinesis": {
|
||||
"DisableEnhancedMonitoring": {
|
||||
output: true,
|
||||
},
|
||||
"EnableEnhancedMonitoring": {
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
"KMS": {
|
||||
"ListGrants": {
|
||||
output: true,
|
||||
},
|
||||
"ListRetirableGrants": {
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
"Lambda": {
|
||||
"CreateAlias": {
|
||||
output: true,
|
||||
},
|
||||
"CreateEventSourceMapping": {
|
||||
output: true,
|
||||
},
|
||||
"CreateFunction": {
|
||||
output: true,
|
||||
},
|
||||
"DeleteEventSourceMapping": {
|
||||
output: true,
|
||||
},
|
||||
"GetAlias": {
|
||||
output: true,
|
||||
},
|
||||
"GetEventSourceMapping": {
|
||||
output: true,
|
||||
},
|
||||
"GetFunctionConfiguration": {
|
||||
output: true,
|
||||
},
|
||||
"PublishVersion": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateAlias": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateEventSourceMapping": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateFunctionCode": {
|
||||
output: true,
|
||||
},
|
||||
"UpdateFunctionConfiguration": {
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
"RDS": {
|
||||
"ModifyDBClusterParameterGroup": {
|
||||
output: true,
|
||||
},
|
||||
"ModifyDBParameterGroup": {
|
||||
output: true,
|
||||
},
|
||||
"ResetDBClusterParameterGroup": {
|
||||
output: true,
|
||||
},
|
||||
"ResetDBParameterGroup": {
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
"Redshift": {
|
||||
"DescribeLoggingStatus": {
|
||||
output: true,
|
||||
},
|
||||
"DisableLogging": {
|
||||
output: true,
|
||||
},
|
||||
"EnableLogging": {
|
||||
output: true,
|
||||
},
|
||||
"ModifyClusterParameterGroup": {
|
||||
output: true,
|
||||
},
|
||||
"ResetClusterParameterGroup": {
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
"S3": {
|
||||
"GetBucketNotification": {
|
||||
input: true,
|
||||
output: true,
|
||||
},
|
||||
"GetBucketNotificationConfiguration": {
|
||||
input: true,
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
"SWF": {
|
||||
"CountClosedWorkflowExecutions": {
|
||||
output: true,
|
||||
},
|
||||
"CountOpenWorkflowExecutions": {
|
||||
output: true,
|
||||
},
|
||||
"CountPendingActivityTasks": {
|
||||
output: true,
|
||||
},
|
||||
"CountPendingDecisionTasks": {
|
||||
output: true,
|
||||
},
|
||||
"ListClosedWorkflowExecutions": {
|
||||
output: true,
|
||||
},
|
||||
"ListOpenWorkflowExecutions": {
|
||||
output: true,
|
||||
},
|
||||
},
|
||||
}
|
62
vendor/github.com/aws/aws-sdk-go/private/model/api/load.go
generated
vendored
62
vendor/github.com/aws/aws-sdk-go/private/model/api/load.go
generated
vendored
|
@ -1,62 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Attach opens a file by name, and unmarshal its JSON data.
|
||||
// Will proceed to setup the API if not already done so.
|
||||
func (a *API) Attach(filename string) {
|
||||
a.path = filepath.Dir(filename)
|
||||
f, err := os.Open(filename)
|
||||
defer f.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := json.NewDecoder(f).Decode(a); err != nil {
|
||||
panic(fmt.Errorf("failed to decode %s, err: %v", filename, err))
|
||||
}
|
||||
}
|
||||
|
||||
// AttachString will unmarshal a raw JSON string, and setup the
|
||||
// API if not already done so.
|
||||
func (a *API) AttachString(str string) {
|
||||
json.Unmarshal([]byte(str), a)
|
||||
|
||||
if !a.initialized {
|
||||
a.Setup()
|
||||
}
|
||||
}
|
||||
|
||||
// Setup initializes the API.
|
||||
func (a *API) Setup() {
|
||||
a.setMetadataEndpointsKey()
|
||||
a.writeShapeNames()
|
||||
a.resolveReferences()
|
||||
a.fixStutterNames()
|
||||
a.renameExportable()
|
||||
if !a.NoRenameToplevelShapes {
|
||||
a.renameToplevelShapes()
|
||||
}
|
||||
|
||||
a.renameCollidingFields()
|
||||
a.updateTopLevelShapeReferences()
|
||||
a.createInputOutputShapes()
|
||||
a.setupEventStreams()
|
||||
a.customizationPasses()
|
||||
|
||||
if !a.NoRemoveUnusedShapes {
|
||||
a.removeUnusedShapes()
|
||||
}
|
||||
|
||||
if !a.NoValidataShapeMethods {
|
||||
a.addShapeValidations()
|
||||
}
|
||||
|
||||
a.initialized = true
|
||||
}
|
32
vendor/github.com/aws/aws-sdk-go/private/model/api/load_test.go
generated
vendored
32
vendor/github.com/aws/aws-sdk-go/private/model/api/load_test.go
generated
vendored
|
@ -1,32 +0,0 @@
|
|||
// +build 1.6,codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestResolvedReferences(t *testing.T) {
|
||||
json := `{
|
||||
"operations": {
|
||||
"OperationName": {
|
||||
"input": { "shape": "TestName" }
|
||||
}
|
||||
},
|
||||
"shapes": {
|
||||
"TestName": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"memberName1": { "shape": "OtherTest" },
|
||||
"memberName2": { "shape": "OtherTest" }
|
||||
}
|
||||
},
|
||||
"OtherTest": { "type": "string" }
|
||||
}
|
||||
}`
|
||||
a := API{}
|
||||
a.AttachString(json)
|
||||
if len(a.Shapes["OtherTest"].refs) != 2 {
|
||||
t.Errorf("Expected %d, but received %d", 2, len(a.Shapes["OtherTest"].refs))
|
||||
}
|
||||
}
|
510
vendor/github.com/aws/aws-sdk-go/private/model/api/operation.go
generated
vendored
510
vendor/github.com/aws/aws-sdk-go/private/model/api/operation.go
generated
vendored
|
@ -1,510 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
// An Operation defines a specific API Operation.
|
||||
type Operation struct {
|
||||
API *API `json:"-"`
|
||||
ExportedName string
|
||||
Name string
|
||||
Documentation string
|
||||
HTTP HTTPInfo
|
||||
InputRef ShapeRef `json:"input"`
|
||||
OutputRef ShapeRef `json:"output"`
|
||||
ErrorRefs []ShapeRef `json:"errors"`
|
||||
Paginator *Paginator
|
||||
Deprecated bool `json:"deprecated"`
|
||||
AuthType string `json:"authtype"`
|
||||
imports map[string]bool
|
||||
}
|
||||
|
||||
// A HTTPInfo defines the method of HTTP request for the Operation.
|
||||
type HTTPInfo struct {
|
||||
Method string
|
||||
RequestURI string
|
||||
ResponseCode uint
|
||||
}
|
||||
|
||||
// HasInput returns if the Operation accepts an input paramater
|
||||
func (o *Operation) HasInput() bool {
|
||||
return o.InputRef.ShapeName != ""
|
||||
}
|
||||
|
||||
// HasOutput returns if the Operation accepts an output parameter
|
||||
func (o *Operation) HasOutput() bool {
|
||||
return o.OutputRef.ShapeName != ""
|
||||
}
|
||||
|
||||
// GetSigner returns the signer that should be used for a API request.
|
||||
func (o *Operation) GetSigner() string {
|
||||
if o.AuthType == "v4-unsigned-body" {
|
||||
o.API.imports["github.com/aws/aws-sdk-go/aws/signer/v4"] = true
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
|
||||
switch o.AuthType {
|
||||
case "none":
|
||||
buf.WriteString("req.Config.Credentials = credentials.AnonymousCredentials")
|
||||
case "v4-unsigned-body":
|
||||
buf.WriteString("req.Handlers.Sign.Remove(v4.SignRequestHandler)\n")
|
||||
buf.WriteString("handler := v4.BuildNamedHandler(\"v4.CustomSignerHandler\", v4.WithUnsignedPayload)\n")
|
||||
buf.WriteString("req.Handlers.Sign.PushFrontNamed(handler)")
|
||||
}
|
||||
|
||||
buf.WriteString("\n")
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// tplOperation defines a template for rendering an API Operation
|
||||
var tplOperation = template.Must(template.New("operation").Funcs(template.FuncMap{
|
||||
"GetCrosslinkURL": GetCrosslinkURL,
|
||||
"EnableStopOnSameToken": enableStopOnSameToken,
|
||||
}).Parse(`
|
||||
const op{{ .ExportedName }} = "{{ .Name }}"
|
||||
|
||||
// {{ .ExportedName }}Request generates a "aws/request.Request" representing the
|
||||
// client's request for the {{ .ExportedName }} operation. The "output" return
|
||||
// value will be populated with the request's response once the request completes
|
||||
// successfuly.
|
||||
//
|
||||
// Use "Send" method on the returned Request to send the API call to the service.
|
||||
// the "output" return value is not valid until after Send returns without error.
|
||||
//
|
||||
// See {{ .ExportedName }} for more information on using the {{ .ExportedName }}
|
||||
// API call, and error handling.
|
||||
//
|
||||
// This method is useful when you want to inject custom logic or configuration
|
||||
// into the SDK's request lifecycle. Such as custom headers, or retry logic.
|
||||
//
|
||||
//
|
||||
// // Example sending a request using the {{ .ExportedName }}Request method.
|
||||
// req, resp := client.{{ .ExportedName }}Request(params)
|
||||
//
|
||||
// err := req.Send()
|
||||
// if err == nil { // resp is now filled
|
||||
// fmt.Println(resp)
|
||||
// }
|
||||
{{ $crosslinkURL := GetCrosslinkURL $.API.BaseCrosslinkURL $.API.Metadata.UID $.ExportedName -}}
|
||||
{{ if ne $crosslinkURL "" -}}
|
||||
//
|
||||
// See also, {{ $crosslinkURL }}
|
||||
{{ end -}}
|
||||
func (c *{{ .API.StructName }}) {{ .ExportedName }}Request(` +
|
||||
`input {{ .InputRef.GoType }}) (req *request.Request, output {{ .OutputRef.GoType }}) {
|
||||
{{ if (or .Deprecated (or .InputRef.Deprecated .OutputRef.Deprecated)) }}if c.Client.Config.Logger != nil {
|
||||
c.Client.Config.Logger.Log("This operation, {{ .ExportedName }}, has been deprecated")
|
||||
}
|
||||
op := &request.Operation{ {{ else }} op := &request.Operation{ {{ end }}
|
||||
Name: op{{ .ExportedName }},
|
||||
{{ if ne .HTTP.Method "" }}HTTPMethod: "{{ .HTTP.Method }}",
|
||||
{{ end }}HTTPPath: {{ if ne .HTTP.RequestURI "" }}"{{ .HTTP.RequestURI }}"{{ else }}"/"{{ end }},
|
||||
{{ if .Paginator }}Paginator: &request.Paginator{
|
||||
InputTokens: {{ .Paginator.InputTokensString }},
|
||||
OutputTokens: {{ .Paginator.OutputTokensString }},
|
||||
LimitToken: "{{ .Paginator.LimitKey }}",
|
||||
TruncationToken: "{{ .Paginator.MoreResults }}",
|
||||
},
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
if input == nil {
|
||||
input = &{{ .InputRef.GoTypeElem }}{}
|
||||
}
|
||||
|
||||
output = &{{ .OutputRef.GoTypeElem }}{}
|
||||
req = c.newRequest(op, input, output)
|
||||
{{ if eq .OutputRef.Shape.Placeholder true -}}
|
||||
req.Handlers.Unmarshal.Remove({{ .API.ProtocolPackage }}.UnmarshalHandler)
|
||||
req.Handlers.Unmarshal.PushBackNamed(protocol.UnmarshalDiscardBodyHandler)
|
||||
{{ end -}}
|
||||
{{ if ne .AuthType "" }}{{ .GetSigner }}{{ end -}}
|
||||
{{ if .OutputRef.Shape.EventStreamsMemberName -}}
|
||||
req.Handlers.Send.Swap(client.LogHTTPResponseHandler.Name, client.LogHTTPResponseHeaderHandler)
|
||||
req.Handlers.Unmarshal.Swap({{ .API.ProtocolPackage }}.UnmarshalHandler.Name, rest.UnmarshalHandler)
|
||||
req.Handlers.Unmarshal.PushBack(output.runEventStreamLoop)
|
||||
{{ end -}}
|
||||
return
|
||||
}
|
||||
|
||||
// {{ .ExportedName }} API operation for {{ .API.Metadata.ServiceFullName }}.
|
||||
{{ if .Documentation -}}
|
||||
//
|
||||
{{ .Documentation }}
|
||||
{{ end -}}
|
||||
//
|
||||
// Returns awserr.Error for service API and SDK errors. Use runtime type assertions
|
||||
// with awserr.Error's Code and Message methods to get detailed information about
|
||||
// the error.
|
||||
//
|
||||
// See the AWS API reference guide for {{ .API.Metadata.ServiceFullName }}'s
|
||||
// API operation {{ .ExportedName }} for usage and error information.
|
||||
{{ if .ErrorRefs -}}
|
||||
//
|
||||
// Returned Error Codes:
|
||||
{{ range $_, $err := .ErrorRefs -}}
|
||||
// * {{ $err.Shape.ErrorCodeName }} "{{ $err.Shape.ErrorName}}"
|
||||
{{ if $err.Docstring -}}
|
||||
{{ $err.IndentedDocstring }}
|
||||
{{ end -}}
|
||||
//
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
{{ $crosslinkURL := GetCrosslinkURL $.API.BaseCrosslinkURL $.API.Metadata.UID $.ExportedName -}}
|
||||
{{ if ne $crosslinkURL "" -}}
|
||||
// See also, {{ $crosslinkURL }}
|
||||
{{ end -}}
|
||||
func (c *{{ .API.StructName }}) {{ .ExportedName }}(` +
|
||||
`input {{ .InputRef.GoType }}) ({{ .OutputRef.GoType }}, error) {
|
||||
req, out := c.{{ .ExportedName }}Request(input)
|
||||
return out, req.Send()
|
||||
}
|
||||
|
||||
// {{ .ExportedName }}WithContext is the same as {{ .ExportedName }} with the addition of
|
||||
// the ability to pass a context and additional request options.
|
||||
//
|
||||
// See {{ .ExportedName }} for details on how to use this API operation.
|
||||
//
|
||||
// The context must be non-nil and will be used for request cancellation. If
|
||||
// the context is nil a panic will occur. In the future the SDK may create
|
||||
// sub-contexts for http.Requests. See https://golang.org/pkg/context/
|
||||
// for more information on using Contexts.
|
||||
func (c *{{ .API.StructName }}) {{ .ExportedName }}WithContext(` +
|
||||
`ctx aws.Context, input {{ .InputRef.GoType }}, opts ...request.Option) ` +
|
||||
`({{ .OutputRef.GoType }}, error) {
|
||||
req, out := c.{{ .ExportedName }}Request(input)
|
||||
req.SetContext(ctx)
|
||||
req.ApplyOptions(opts...)
|
||||
return out, req.Send()
|
||||
}
|
||||
|
||||
{{ if .Paginator }}
|
||||
// {{ .ExportedName }}Pages iterates over the pages of a {{ .ExportedName }} operation,
|
||||
// calling the "fn" function with the response data for each page. To stop
|
||||
// iterating, return false from the fn function.
|
||||
//
|
||||
// See {{ .ExportedName }} method for more information on how to use this operation.
|
||||
//
|
||||
// Note: This operation can generate multiple requests to a service.
|
||||
//
|
||||
// // Example iterating over at most 3 pages of a {{ .ExportedName }} operation.
|
||||
// pageNum := 0
|
||||
// err := client.{{ .ExportedName }}Pages(params,
|
||||
// func(page {{ .OutputRef.GoType }}, lastPage bool) bool {
|
||||
// pageNum++
|
||||
// fmt.Println(page)
|
||||
// return pageNum <= 3
|
||||
// })
|
||||
//
|
||||
func (c *{{ .API.StructName }}) {{ .ExportedName }}Pages(` +
|
||||
`input {{ .InputRef.GoType }}, fn func({{ .OutputRef.GoType }}, bool) bool) error {
|
||||
return c.{{ .ExportedName }}PagesWithContext(aws.BackgroundContext(), input, fn)
|
||||
}
|
||||
|
||||
// {{ .ExportedName }}PagesWithContext same as {{ .ExportedName }}Pages except
|
||||
// it takes a Context and allows setting request options on the pages.
|
||||
//
|
||||
// The context must be non-nil and will be used for request cancellation. If
|
||||
// the context is nil a panic will occur. In the future the SDK may create
|
||||
// sub-contexts for http.Requests. See https://golang.org/pkg/context/
|
||||
// for more information on using Contexts.
|
||||
func (c *{{ .API.StructName }}) {{ .ExportedName }}PagesWithContext(` +
|
||||
`ctx aws.Context, ` +
|
||||
`input {{ .InputRef.GoType }}, ` +
|
||||
`fn func({{ .OutputRef.GoType }}, bool) bool, ` +
|
||||
`opts ...request.Option) error {
|
||||
p := request.Pagination {
|
||||
{{ if EnableStopOnSameToken .API.PackageName -}}EndPageOnSameToken: true,
|
||||
{{ end -}}
|
||||
NewRequest: func() (*request.Request, error) {
|
||||
var inCpy {{ .InputRef.GoType }}
|
||||
if input != nil {
|
||||
tmp := *input
|
||||
inCpy = &tmp
|
||||
}
|
||||
req, _ := c.{{ .ExportedName }}Request(inCpy)
|
||||
req.SetContext(ctx)
|
||||
req.ApplyOptions(opts...)
|
||||
return req, nil
|
||||
},
|
||||
}
|
||||
|
||||
cont := true
|
||||
for p.Next() && cont {
|
||||
cont = fn(p.Page().({{ .OutputRef.GoType }}), !p.HasNextPage())
|
||||
}
|
||||
return p.Err()
|
||||
}
|
||||
{{ end }}
|
||||
`))
|
||||
|
||||
// GoCode returns a string of rendered GoCode for this Operation
|
||||
func (o *Operation) GoCode() string {
|
||||
var buf bytes.Buffer
|
||||
|
||||
if len(o.OutputRef.Shape.EventStreamsMemberName) != 0 {
|
||||
// TODO need better was of updating protocol unmarshalers
|
||||
o.API.imports["github.com/aws/aws-sdk-go/aws/client"] = true
|
||||
o.API.imports["github.com/aws/aws-sdk-go/private/protocol/rest"] = true
|
||||
}
|
||||
|
||||
err := tplOperation.Execute(&buf, o)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return strings.TrimSpace(buf.String())
|
||||
}
|
||||
|
||||
// tplInfSig defines the template for rendering an Operation's signature within an Interface definition.
|
||||
var tplInfSig = template.Must(template.New("opsig").Parse(`
|
||||
{{ .ExportedName }}({{ .InputRef.GoTypeWithPkgName }}) ({{ .OutputRef.GoTypeWithPkgName }}, error)
|
||||
{{ .ExportedName }}WithContext(aws.Context, {{ .InputRef.GoTypeWithPkgName }}, ...request.Option) ({{ .OutputRef.GoTypeWithPkgName }}, error)
|
||||
{{ .ExportedName }}Request({{ .InputRef.GoTypeWithPkgName }}) (*request.Request, {{ .OutputRef.GoTypeWithPkgName }})
|
||||
|
||||
{{ if .Paginator -}}
|
||||
{{ .ExportedName }}Pages({{ .InputRef.GoTypeWithPkgName }}, func({{ .OutputRef.GoTypeWithPkgName }}, bool) bool) error
|
||||
{{ .ExportedName }}PagesWithContext(aws.Context, {{ .InputRef.GoTypeWithPkgName }}, func({{ .OutputRef.GoTypeWithPkgName }}, bool) bool, ...request.Option) error
|
||||
{{- end }}
|
||||
`))
|
||||
|
||||
// InterfaceSignature returns a string representing the Operation's interface{}
|
||||
// functional signature.
|
||||
func (o *Operation) InterfaceSignature() string {
|
||||
var buf bytes.Buffer
|
||||
err := tplInfSig.Execute(&buf, o)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return strings.TrimSpace(buf.String())
|
||||
}
|
||||
|
||||
// tplExample defines the template for rendering an Operation example
|
||||
var tplExample = template.Must(template.New("operationExample").Parse(`
|
||||
func Example{{ .API.StructName }}_{{ .ExportedName }}() {
|
||||
sess := session.Must(session.NewSession())
|
||||
|
||||
svc := {{ .API.PackageName }}.New(sess)
|
||||
|
||||
{{ .ExampleInput }}
|
||||
resp, err := svc.{{ .ExportedName }}(params)
|
||||
|
||||
if err != nil {
|
||||
// Print the error, cast err to awserr.Error to get the Code and
|
||||
// Message from an error.
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// Pretty-print the response data.
|
||||
fmt.Println(resp)
|
||||
}
|
||||
`))
|
||||
|
||||
// Example returns a string of the rendered Go code for the Operation
|
||||
func (o *Operation) Example() string {
|
||||
var buf bytes.Buffer
|
||||
err := tplExample.Execute(&buf, o)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return strings.TrimSpace(buf.String())
|
||||
}
|
||||
|
||||
// ExampleInput return a string of the rendered Go code for an example's input parameters
|
||||
func (o *Operation) ExampleInput() string {
|
||||
if len(o.InputRef.Shape.MemberRefs) == 0 {
|
||||
if strings.Contains(o.InputRef.GoTypeElem(), ".") {
|
||||
o.imports["github.com/aws/aws-sdk-go/service/"+strings.Split(o.InputRef.GoTypeElem(), ".")[0]] = true
|
||||
return fmt.Sprintf("var params *%s", o.InputRef.GoTypeElem())
|
||||
}
|
||||
return fmt.Sprintf("var params *%s.%s",
|
||||
o.API.PackageName(), o.InputRef.GoTypeElem())
|
||||
}
|
||||
e := example{o, map[string]int{}}
|
||||
return "params := " + e.traverseAny(o.InputRef.Shape, false, false)
|
||||
}
|
||||
|
||||
// A example provides
|
||||
type example struct {
|
||||
*Operation
|
||||
visited map[string]int
|
||||
}
|
||||
|
||||
// traverseAny returns rendered Go code for the shape.
|
||||
func (e *example) traverseAny(s *Shape, required, payload bool) string {
|
||||
str := ""
|
||||
e.visited[s.ShapeName]++
|
||||
|
||||
switch s.Type {
|
||||
case "structure":
|
||||
str = e.traverseStruct(s, required, payload)
|
||||
case "list":
|
||||
str = e.traverseList(s, required, payload)
|
||||
case "map":
|
||||
str = e.traverseMap(s, required, payload)
|
||||
case "jsonvalue":
|
||||
str = "aws.JSONValue{\"key\": \"value\"}"
|
||||
if required {
|
||||
str += " // Required"
|
||||
}
|
||||
default:
|
||||
str = e.traverseScalar(s, required, payload)
|
||||
}
|
||||
|
||||
e.visited[s.ShapeName]--
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
var reType = regexp.MustCompile(`\b([A-Z])`)
|
||||
|
||||
// traverseStruct returns rendered Go code for a structure type shape.
|
||||
func (e *example) traverseStruct(s *Shape, required, payload bool) string {
|
||||
var buf bytes.Buffer
|
||||
|
||||
if s.resolvePkg != "" {
|
||||
e.imports[s.resolvePkg] = true
|
||||
buf.WriteString("&" + s.GoTypeElem() + "{")
|
||||
} else {
|
||||
buf.WriteString("&" + s.API.PackageName() + "." + s.GoTypeElem() + "{")
|
||||
}
|
||||
|
||||
if required {
|
||||
buf.WriteString(" // Required")
|
||||
}
|
||||
buf.WriteString("\n")
|
||||
|
||||
req := make([]string, len(s.Required))
|
||||
copy(req, s.Required)
|
||||
sort.Strings(req)
|
||||
|
||||
if e.visited[s.ShapeName] < 2 {
|
||||
for _, n := range req {
|
||||
m := s.MemberRefs[n].Shape
|
||||
p := n == s.Payload && (s.MemberRefs[n].Streaming || m.Streaming)
|
||||
buf.WriteString(n + ": " + e.traverseAny(m, true, p) + ",")
|
||||
if m.Type != "list" && m.Type != "structure" && m.Type != "map" {
|
||||
buf.WriteString(" // Required")
|
||||
}
|
||||
buf.WriteString("\n")
|
||||
}
|
||||
|
||||
for _, n := range s.MemberNames() {
|
||||
if s.IsRequired(n) {
|
||||
continue
|
||||
}
|
||||
m := s.MemberRefs[n].Shape
|
||||
p := n == s.Payload && (s.MemberRefs[n].Streaming || m.Streaming)
|
||||
buf.WriteString(n + ": " + e.traverseAny(m, false, p) + ",\n")
|
||||
}
|
||||
} else {
|
||||
buf.WriteString("// Recursive values...\n")
|
||||
}
|
||||
|
||||
buf.WriteString("}")
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// traverseMap returns rendered Go code for a map type shape.
|
||||
func (e *example) traverseMap(s *Shape, required, payload bool) string {
|
||||
var buf bytes.Buffer
|
||||
|
||||
t := ""
|
||||
if s.resolvePkg != "" {
|
||||
e.imports[s.resolvePkg] = true
|
||||
t = s.GoTypeElem()
|
||||
} else {
|
||||
t = reType.ReplaceAllString(s.GoTypeElem(), s.API.PackageName()+".$1")
|
||||
}
|
||||
buf.WriteString(t + "{")
|
||||
if required {
|
||||
buf.WriteString(" // Required")
|
||||
}
|
||||
buf.WriteString("\n")
|
||||
|
||||
if e.visited[s.ShapeName] < 2 {
|
||||
m := s.ValueRef.Shape
|
||||
buf.WriteString("\"Key\": " + e.traverseAny(m, true, false) + ",")
|
||||
if m.Type != "list" && m.Type != "structure" && m.Type != "map" {
|
||||
buf.WriteString(" // Required")
|
||||
}
|
||||
buf.WriteString("\n// More values...\n")
|
||||
} else {
|
||||
buf.WriteString("// Recursive values...\n")
|
||||
}
|
||||
buf.WriteString("}")
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// traverseList returns rendered Go code for a list type shape.
|
||||
func (e *example) traverseList(s *Shape, required, payload bool) string {
|
||||
var buf bytes.Buffer
|
||||
t := ""
|
||||
if s.resolvePkg != "" {
|
||||
e.imports[s.resolvePkg] = true
|
||||
t = s.GoTypeElem()
|
||||
} else {
|
||||
t = reType.ReplaceAllString(s.GoTypeElem(), s.API.PackageName()+".$1")
|
||||
}
|
||||
|
||||
buf.WriteString(t + "{")
|
||||
if required {
|
||||
buf.WriteString(" // Required")
|
||||
}
|
||||
buf.WriteString("\n")
|
||||
|
||||
if e.visited[s.ShapeName] < 2 {
|
||||
m := s.MemberRef.Shape
|
||||
buf.WriteString(e.traverseAny(m, true, false) + ",")
|
||||
if m.Type != "list" && m.Type != "structure" && m.Type != "map" {
|
||||
buf.WriteString(" // Required")
|
||||
}
|
||||
buf.WriteString("\n// More values...\n")
|
||||
} else {
|
||||
buf.WriteString("// Recursive values...\n")
|
||||
}
|
||||
buf.WriteString("}")
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// traverseScalar returns an AWS Type string representation initialized to a value.
|
||||
// Will panic if s is an unsupported shape type.
|
||||
func (e *example) traverseScalar(s *Shape, required, payload bool) string {
|
||||
str := ""
|
||||
switch s.Type {
|
||||
case "integer", "long":
|
||||
str = `aws.Int64(1)`
|
||||
case "float", "double":
|
||||
str = `aws.Float64(1.0)`
|
||||
case "string", "character":
|
||||
str = `aws.String("` + s.ShapeName + `")`
|
||||
case "blob":
|
||||
if payload {
|
||||
str = `bytes.NewReader([]byte("PAYLOAD"))`
|
||||
} else {
|
||||
str = `[]byte("PAYLOAD")`
|
||||
}
|
||||
case "boolean":
|
||||
str = `aws.Bool(true)`
|
||||
case "timestamp":
|
||||
str = `aws.Time(time.Now())`
|
||||
default:
|
||||
panic("unsupported shape " + s.Type)
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
100
vendor/github.com/aws/aws-sdk-go/private/model/api/pagination.go
generated
vendored
100
vendor/github.com/aws/aws-sdk-go/private/model/api/pagination.go
generated
vendored
|
@ -1,100 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Paginator keeps track of pagination configuration for an API operation.
|
||||
type Paginator struct {
|
||||
InputTokens interface{} `json:"input_token"`
|
||||
OutputTokens interface{} `json:"output_token"`
|
||||
LimitKey string `json:"limit_key"`
|
||||
MoreResults string `json:"more_results"`
|
||||
}
|
||||
|
||||
// InputTokensString returns output tokens formatted as a list
|
||||
func (p *Paginator) InputTokensString() string {
|
||||
str := p.InputTokens.([]string)
|
||||
return fmt.Sprintf("%#v", str)
|
||||
}
|
||||
|
||||
// OutputTokensString returns output tokens formatted as a list
|
||||
func (p *Paginator) OutputTokensString() string {
|
||||
str := p.OutputTokens.([]string)
|
||||
return fmt.Sprintf("%#v", str)
|
||||
}
|
||||
|
||||
// used for unmarshaling from the paginators JSON file
|
||||
type paginationDefinitions struct {
|
||||
*API
|
||||
Pagination map[string]Paginator
|
||||
}
|
||||
|
||||
// AttachPaginators attaches pagination configuration from filename to the API.
|
||||
func (a *API) AttachPaginators(filename string) {
|
||||
p := paginationDefinitions{API: a}
|
||||
|
||||
f, err := os.Open(filename)
|
||||
defer f.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = json.NewDecoder(f).Decode(&p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
p.setup()
|
||||
}
|
||||
|
||||
// setup runs post-processing on the paginator configuration.
|
||||
func (p *paginationDefinitions) setup() {
|
||||
for n, e := range p.Pagination {
|
||||
if e.InputTokens == nil || e.OutputTokens == nil {
|
||||
continue
|
||||
}
|
||||
paginator := e
|
||||
|
||||
switch t := paginator.InputTokens.(type) {
|
||||
case string:
|
||||
paginator.InputTokens = []string{t}
|
||||
case []interface{}:
|
||||
toks := []string{}
|
||||
for _, e := range t {
|
||||
s := e.(string)
|
||||
toks = append(toks, s)
|
||||
}
|
||||
paginator.InputTokens = toks
|
||||
}
|
||||
switch t := paginator.OutputTokens.(type) {
|
||||
case string:
|
||||
paginator.OutputTokens = []string{t}
|
||||
case []interface{}:
|
||||
toks := []string{}
|
||||
for _, e := range t {
|
||||
s := e.(string)
|
||||
toks = append(toks, s)
|
||||
}
|
||||
paginator.OutputTokens = toks
|
||||
}
|
||||
|
||||
if o, ok := p.Operations[n]; ok {
|
||||
o.Paginator = &paginator
|
||||
} else {
|
||||
panic("unknown operation for paginator " + n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func enableStopOnSameToken(service string) bool {
|
||||
switch service {
|
||||
case "cloudwatchlogs":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
147
vendor/github.com/aws/aws-sdk-go/private/model/api/param_filler.go
generated
vendored
147
vendor/github.com/aws/aws-sdk-go/private/model/api/param_filler.go
generated
vendored
|
@ -1,147 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/aws/aws-sdk-go/private/util"
|
||||
)
|
||||
|
||||
// A paramFiller provides string formatting for a shape and its types.
|
||||
type paramFiller struct {
|
||||
prefixPackageName bool
|
||||
}
|
||||
|
||||
// typeName returns the type name of a shape.
|
||||
func (f paramFiller) typeName(shape *Shape) string {
|
||||
if f.prefixPackageName && shape.Type == "structure" {
|
||||
return "*" + shape.API.PackageName() + "." + shape.GoTypeElem()
|
||||
}
|
||||
return shape.GoType()
|
||||
}
|
||||
|
||||
// ParamsStructFromJSON returns a JSON string representation of a structure.
|
||||
func ParamsStructFromJSON(value interface{}, shape *Shape, prefixPackageName bool) string {
|
||||
f := paramFiller{prefixPackageName: prefixPackageName}
|
||||
return util.GoFmt(f.paramsStructAny(value, shape))
|
||||
}
|
||||
|
||||
// paramsStructAny returns the string representation of any value.
|
||||
func (f paramFiller) paramsStructAny(value interface{}, shape *Shape) string {
|
||||
if value == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
switch shape.Type {
|
||||
case "structure":
|
||||
if value != nil {
|
||||
vmap := value.(map[string]interface{})
|
||||
return f.paramsStructStruct(vmap, shape)
|
||||
}
|
||||
case "list":
|
||||
vlist := value.([]interface{})
|
||||
return f.paramsStructList(vlist, shape)
|
||||
case "map":
|
||||
vmap := value.(map[string]interface{})
|
||||
return f.paramsStructMap(vmap, shape)
|
||||
case "string", "character":
|
||||
v := reflect.Indirect(reflect.ValueOf(value))
|
||||
if v.IsValid() {
|
||||
return fmt.Sprintf("aws.String(%#v)", v.Interface())
|
||||
}
|
||||
case "blob":
|
||||
v := reflect.Indirect(reflect.ValueOf(value))
|
||||
if v.IsValid() && shape.Streaming {
|
||||
return fmt.Sprintf("bytes.NewReader([]byte(%#v))", v.Interface())
|
||||
} else if v.IsValid() {
|
||||
return fmt.Sprintf("[]byte(%#v)", v.Interface())
|
||||
}
|
||||
case "boolean":
|
||||
v := reflect.Indirect(reflect.ValueOf(value))
|
||||
if v.IsValid() {
|
||||
return fmt.Sprintf("aws.Bool(%#v)", v.Interface())
|
||||
}
|
||||
case "integer", "long":
|
||||
v := reflect.Indirect(reflect.ValueOf(value))
|
||||
if v.IsValid() {
|
||||
return fmt.Sprintf("aws.Int64(%v)", v.Interface())
|
||||
}
|
||||
case "float", "double":
|
||||
v := reflect.Indirect(reflect.ValueOf(value))
|
||||
if v.IsValid() {
|
||||
return fmt.Sprintf("aws.Float64(%v)", v.Interface())
|
||||
}
|
||||
case "timestamp":
|
||||
v := reflect.Indirect(reflect.ValueOf(value))
|
||||
if v.IsValid() {
|
||||
return fmt.Sprintf("aws.Time(time.Unix(%d, 0))", int(v.Float()))
|
||||
}
|
||||
case "jsonvalue":
|
||||
v, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
panic("failed to marshal JSONValue, "+err.Error())
|
||||
}
|
||||
const tmpl = `func() aws.JSONValue {
|
||||
var m aws.JSONValue
|
||||
if err := json.Unmarshal([]byte(%q), &m); err != nil {
|
||||
panic("failed to unmarshal JSONValue, "+err.Error())
|
||||
}
|
||||
return m
|
||||
}()`
|
||||
return fmt.Sprintf(tmpl, string(v))
|
||||
default:
|
||||
panic("Unhandled type " + shape.Type)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// paramsStructStruct returns the string representation of a structure
|
||||
func (f paramFiller) paramsStructStruct(value map[string]interface{}, shape *Shape) string {
|
||||
out := "&" + f.typeName(shape)[1:] + "{\n"
|
||||
for _, n := range shape.MemberNames() {
|
||||
ref := shape.MemberRefs[n]
|
||||
name := findParamMember(value, n)
|
||||
|
||||
if val := f.paramsStructAny(value[name], ref.Shape); val != "" {
|
||||
out += fmt.Sprintf("%s: %s,\n", n, val)
|
||||
}
|
||||
}
|
||||
out += "}"
|
||||
return out
|
||||
}
|
||||
|
||||
// paramsStructMap returns the string representation of a map of values
|
||||
func (f paramFiller) paramsStructMap(value map[string]interface{}, shape *Shape) string {
|
||||
out := f.typeName(shape) + "{\n"
|
||||
keys := util.SortedKeys(value)
|
||||
for _, k := range keys {
|
||||
v := value[k]
|
||||
out += fmt.Sprintf("%q: %s,\n", k, f.paramsStructAny(v, shape.ValueRef.Shape))
|
||||
}
|
||||
out += "}"
|
||||
return out
|
||||
}
|
||||
|
||||
// paramsStructList returns the string representation of slice of values
|
||||
func (f paramFiller) paramsStructList(value []interface{}, shape *Shape) string {
|
||||
out := f.typeName(shape) + "{\n"
|
||||
for _, v := range value {
|
||||
out += fmt.Sprintf("%s,\n", f.paramsStructAny(v, shape.MemberRef.Shape))
|
||||
}
|
||||
out += "}"
|
||||
return out
|
||||
}
|
||||
|
||||
// findParamMember searches a map for a key ignoring case. Returns the map key if found.
|
||||
func findParamMember(value map[string]interface{}, key string) string {
|
||||
for actualKey := range value {
|
||||
if strings.ToLower(key) == strings.ToLower(actualKey) {
|
||||
return actualKey
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
355
vendor/github.com/aws/aws-sdk-go/private/model/api/passes.go
generated
vendored
355
vendor/github.com/aws/aws-sdk-go/private/model/api/passes.go
generated
vendored
|
@ -1,355 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// updateTopLevelShapeReferences moves resultWrapper, locationName, and
|
||||
// xmlNamespace traits from toplevel shape references to the toplevel
|
||||
// shapes for easier code generation
|
||||
func (a *API) updateTopLevelShapeReferences() {
|
||||
for _, o := range a.Operations {
|
||||
// these are for REST-XML services
|
||||
if o.InputRef.LocationName != "" {
|
||||
o.InputRef.Shape.LocationName = o.InputRef.LocationName
|
||||
}
|
||||
if o.InputRef.Location != "" {
|
||||
o.InputRef.Shape.Location = o.InputRef.Location
|
||||
}
|
||||
if o.InputRef.Payload != "" {
|
||||
o.InputRef.Shape.Payload = o.InputRef.Payload
|
||||
}
|
||||
if o.InputRef.XMLNamespace.Prefix != "" {
|
||||
o.InputRef.Shape.XMLNamespace.Prefix = o.InputRef.XMLNamespace.Prefix
|
||||
}
|
||||
if o.InputRef.XMLNamespace.URI != "" {
|
||||
o.InputRef.Shape.XMLNamespace.URI = o.InputRef.XMLNamespace.URI
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// writeShapeNames sets each shape's API and shape name values. Binding the
|
||||
// shape to its parent API.
|
||||
func (a *API) writeShapeNames() {
|
||||
for n, s := range a.Shapes {
|
||||
s.API = a
|
||||
s.ShapeName = n
|
||||
}
|
||||
}
|
||||
|
||||
func (a *API) resolveReferences() {
|
||||
resolver := referenceResolver{API: a, visited: map[*ShapeRef]bool{}}
|
||||
|
||||
for _, s := range a.Shapes {
|
||||
resolver.resolveShape(s)
|
||||
}
|
||||
|
||||
for _, o := range a.Operations {
|
||||
o.API = a // resolve parent reference
|
||||
|
||||
resolver.resolveReference(&o.InputRef)
|
||||
resolver.resolveReference(&o.OutputRef)
|
||||
|
||||
// Resolve references for errors also
|
||||
for i := range o.ErrorRefs {
|
||||
resolver.resolveReference(&o.ErrorRefs[i])
|
||||
o.ErrorRefs[i].Shape.IsError = true
|
||||
o.ErrorRefs[i].Shape.ErrorInfo.Type = o.ErrorRefs[i].Shape.ShapeName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A referenceResolver provides a way to resolve shape references to
|
||||
// shape definitions.
|
||||
type referenceResolver struct {
|
||||
*API
|
||||
visited map[*ShapeRef]bool
|
||||
}
|
||||
|
||||
var jsonvalueShape = &Shape{
|
||||
ShapeName: "JSONValue",
|
||||
Type: "jsonvalue",
|
||||
ValueRef: ShapeRef{
|
||||
JSONValue: true,
|
||||
},
|
||||
}
|
||||
|
||||
// resolveReference updates a shape reference to reference the API and
|
||||
// its shape definition. All other nested references are also resolved.
|
||||
func (r *referenceResolver) resolveReference(ref *ShapeRef) {
|
||||
if ref.ShapeName == "" {
|
||||
return
|
||||
}
|
||||
|
||||
shape, ok := r.API.Shapes[ref.ShapeName]
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("unable resolve reference, %s", ref.ShapeName))
|
||||
return
|
||||
}
|
||||
|
||||
if ref.JSONValue {
|
||||
ref.ShapeName = "JSONValue"
|
||||
r.API.Shapes[ref.ShapeName] = jsonvalueShape
|
||||
}
|
||||
|
||||
ref.API = r.API // resolve reference back to API
|
||||
ref.Shape = shape // resolve shape reference
|
||||
|
||||
if r.visited[ref] {
|
||||
return
|
||||
}
|
||||
r.visited[ref] = true
|
||||
|
||||
shape.refs = append(shape.refs, ref) // register the ref
|
||||
|
||||
// resolve shape's references, if it has any
|
||||
r.resolveShape(shape)
|
||||
}
|
||||
|
||||
// resolveShape resolves a shape's Member Key Value, and nested member
|
||||
// shape references.
|
||||
func (r *referenceResolver) resolveShape(shape *Shape) {
|
||||
r.resolveReference(&shape.MemberRef)
|
||||
r.resolveReference(&shape.KeyRef)
|
||||
r.resolveReference(&shape.ValueRef)
|
||||
for _, m := range shape.MemberRefs {
|
||||
r.resolveReference(m)
|
||||
}
|
||||
}
|
||||
|
||||
// renameToplevelShapes renames all top level shapes of an API to their
|
||||
// exportable variant. The shapes are also updated to include notations
|
||||
// if they are Input or Outputs.
|
||||
func (a *API) renameToplevelShapes() {
|
||||
for _, v := range a.OperationList() {
|
||||
if v.HasInput() {
|
||||
name := v.ExportedName + "Input"
|
||||
switch {
|
||||
case a.Shapes[name] == nil:
|
||||
if service, ok := shamelist[a.name]; ok {
|
||||
if check, ok := service[v.Name]; ok && check.input {
|
||||
break
|
||||
}
|
||||
}
|
||||
v.InputRef.Shape.Rename(name)
|
||||
}
|
||||
}
|
||||
if v.HasOutput() {
|
||||
name := v.ExportedName + "Output"
|
||||
switch {
|
||||
case a.Shapes[name] == nil:
|
||||
if service, ok := shamelist[a.name]; ok {
|
||||
if check, ok := service[v.Name]; ok && check.output {
|
||||
break
|
||||
}
|
||||
}
|
||||
v.OutputRef.Shape.Rename(name)
|
||||
}
|
||||
}
|
||||
v.InputRef.Payload = a.ExportableName(v.InputRef.Payload)
|
||||
v.OutputRef.Payload = a.ExportableName(v.OutputRef.Payload)
|
||||
}
|
||||
}
|
||||
|
||||
// fixStutterNames fixes all name struttering based on Go naming conventions.
|
||||
// "Stuttering" is when the prefix of a structure or function matches the
|
||||
// package name (case insensitive).
|
||||
func (a *API) fixStutterNames() {
|
||||
str, end := a.StructName(), ""
|
||||
if len(str) > 1 {
|
||||
l := len(str) - 1
|
||||
str, end = str[0:l], str[l:]
|
||||
}
|
||||
re := regexp.MustCompile(fmt.Sprintf(`\A(?i:%s)%s`, str, end))
|
||||
|
||||
for name, op := range a.Operations {
|
||||
newName := re.ReplaceAllString(name, "")
|
||||
if newName != name && len(newName) > 0 {
|
||||
delete(a.Operations, name)
|
||||
a.Operations[newName] = op
|
||||
}
|
||||
op.ExportedName = newName
|
||||
}
|
||||
|
||||
for k, s := range a.Shapes {
|
||||
newName := re.ReplaceAllString(k, "")
|
||||
if newName != s.ShapeName && len(newName) > 0 {
|
||||
s.Rename(newName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// renameExportable renames all operation names to be exportable names.
|
||||
// All nested Shape names are also updated to the exportable variant.
|
||||
func (a *API) renameExportable() {
|
||||
for name, op := range a.Operations {
|
||||
newName := a.ExportableName(name)
|
||||
if newName != name {
|
||||
delete(a.Operations, name)
|
||||
a.Operations[newName] = op
|
||||
}
|
||||
op.ExportedName = newName
|
||||
}
|
||||
|
||||
for k, s := range a.Shapes {
|
||||
// FIXME SNS has lower and uppercased shape names with the same name,
|
||||
// except the lowercased variant is used exclusively for string and
|
||||
// other primitive types. Renaming both would cause a collision.
|
||||
// We work around this by only renaming the structure shapes.
|
||||
if s.Type == "string" {
|
||||
continue
|
||||
}
|
||||
|
||||
for mName, member := range s.MemberRefs {
|
||||
newName := a.ExportableName(mName)
|
||||
if newName != mName {
|
||||
delete(s.MemberRefs, mName)
|
||||
s.MemberRefs[newName] = member
|
||||
|
||||
// also apply locationName trait so we keep the old one
|
||||
// but only if there's no locationName trait on ref or shape
|
||||
if member.LocationName == "" && member.Shape.LocationName == "" {
|
||||
member.LocationName = mName
|
||||
}
|
||||
}
|
||||
|
||||
if newName == "_" {
|
||||
panic("Shape " + s.ShapeName + " uses reserved member name '_'")
|
||||
}
|
||||
}
|
||||
|
||||
newName := a.ExportableName(k)
|
||||
if newName != s.ShapeName {
|
||||
s.Rename(newName)
|
||||
}
|
||||
|
||||
s.Payload = a.ExportableName(s.Payload)
|
||||
|
||||
// fix required trait names
|
||||
for i, n := range s.Required {
|
||||
s.Required[i] = a.ExportableName(n)
|
||||
}
|
||||
}
|
||||
|
||||
for _, s := range a.Shapes {
|
||||
// fix enum names
|
||||
if s.IsEnum() {
|
||||
s.EnumConsts = make([]string, len(s.Enum))
|
||||
for i := range s.Enum {
|
||||
shape := s.ShapeName
|
||||
shape = strings.ToUpper(shape[0:1]) + shape[1:]
|
||||
s.EnumConsts[i] = shape + s.EnumName(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// renameCollidingFields will rename any fields that uses an SDK or Golang
|
||||
// specific name.
|
||||
func (a *API) renameCollidingFields() {
|
||||
for _, v := range a.Shapes {
|
||||
namesWithSet := map[string]struct{}{}
|
||||
for k, field := range v.MemberRefs {
|
||||
if strings.HasPrefix(k, "Set") {
|
||||
namesWithSet[k] = struct{}{}
|
||||
}
|
||||
|
||||
if collides(k) {
|
||||
renameCollidingField(k, v, field)
|
||||
}
|
||||
}
|
||||
|
||||
// checks if any field names collide with setters.
|
||||
for name := range namesWithSet {
|
||||
if field, ok := v.MemberRefs["Set"+name]; ok {
|
||||
renameCollidingField(name, v, field)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func renameCollidingField(name string, v *Shape, field *ShapeRef) {
|
||||
newName := name + "_"
|
||||
fmt.Printf("Shape %s's field %q renamed to %q\n", v.ShapeName, name, newName)
|
||||
delete(v.MemberRefs, name)
|
||||
v.MemberRefs[newName] = field
|
||||
}
|
||||
|
||||
// collides will return true if it is a name used by the SDK or Golang.
|
||||
func collides(name string) bool {
|
||||
switch name {
|
||||
case "String",
|
||||
"GoString",
|
||||
"Validate":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// createInputOutputShapes creates toplevel input/output shapes if they
|
||||
// have not been defined in the API. This normalizes all APIs to always
|
||||
// have an input and output structure in the signature.
|
||||
func (a *API) createInputOutputShapes() {
|
||||
for _, op := range a.Operations {
|
||||
if !op.HasInput() {
|
||||
setAsPlacholderShape(&op.InputRef, op.ExportedName+"Input", a)
|
||||
}
|
||||
if !op.HasOutput() {
|
||||
setAsPlacholderShape(&op.OutputRef, op.ExportedName+"Output", a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setAsPlacholderShape(tgtShapeRef *ShapeRef, name string, a *API) {
|
||||
shape := a.makeIOShape(name)
|
||||
shape.Placeholder = true
|
||||
*tgtShapeRef = ShapeRef{API: a, ShapeName: shape.ShapeName, Shape: shape}
|
||||
shape.refs = append(shape.refs, tgtShapeRef)
|
||||
}
|
||||
|
||||
// makeIOShape returns a pointer to a new Shape initialized by the name provided.
|
||||
func (a *API) makeIOShape(name string) *Shape {
|
||||
shape := &Shape{
|
||||
API: a, ShapeName: name, Type: "structure",
|
||||
MemberRefs: map[string]*ShapeRef{},
|
||||
}
|
||||
a.Shapes[name] = shape
|
||||
return shape
|
||||
}
|
||||
|
||||
// removeUnusedShapes removes shapes from the API which are not referenced by any
|
||||
// other shape in the API.
|
||||
func (a *API) removeUnusedShapes() {
|
||||
for _, s := range a.Shapes {
|
||||
if len(s.refs) == 0 {
|
||||
a.removeShape(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Represents the service package name to EndpointsID mapping
|
||||
var custEndpointsKey = map[string]string{
|
||||
"applicationautoscaling": "application-autoscaling",
|
||||
}
|
||||
|
||||
// Sents the EndpointsID field of Metadata with the value of the
|
||||
// EndpointPrefix if EndpointsID is not set. Also adds
|
||||
// customizations for services if EndpointPrefix is not a valid key.
|
||||
func (a *API) setMetadataEndpointsKey() {
|
||||
if len(a.Metadata.EndpointsID) != 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if v, ok := custEndpointsKey[a.PackageName()]; ok {
|
||||
a.Metadata.EndpointsID = v
|
||||
} else {
|
||||
a.Metadata.EndpointsID = a.Metadata.EndpointPrefix
|
||||
}
|
||||
}
|
211
vendor/github.com/aws/aws-sdk-go/private/model/api/passes_test.go
generated
vendored
211
vendor/github.com/aws/aws-sdk-go/private/model/api/passes_test.go
generated
vendored
|
@ -1,211 +0,0 @@
|
|||
// +build 1.6,codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUniqueInputAndOutputs(t *testing.T) {
|
||||
shamelist["FooService"] = map[string]struct {
|
||||
input bool
|
||||
output bool
|
||||
}{}
|
||||
v := shamelist["FooService"]["OpOutputNoRename"]
|
||||
v.output = true
|
||||
shamelist["FooService"]["OpOutputNoRename"] = v
|
||||
v = shamelist["FooService"]["InputNoRename"]
|
||||
v.input = true
|
||||
shamelist["FooService"]["OpInputNoRename"] = v
|
||||
v = shamelist["FooService"]["BothNoRename"]
|
||||
v.input = true
|
||||
v.output = true
|
||||
shamelist["FooService"]["OpBothNoRename"] = v
|
||||
|
||||
cases := [][]struct {
|
||||
expectedInput string
|
||||
expectedOutput string
|
||||
operation string
|
||||
input string
|
||||
inputRef string
|
||||
output string
|
||||
outputRef string
|
||||
}{
|
||||
{
|
||||
{
|
||||
expectedInput: "FooOperationInput",
|
||||
expectedOutput: "FooOperationOutput",
|
||||
operation: "FooOperation",
|
||||
input: "FooInputShape",
|
||||
inputRef: "FooInputShapeRef",
|
||||
output: "FooOutputShape",
|
||||
outputRef: "FooOutputShapeRef",
|
||||
},
|
||||
{
|
||||
expectedInput: "BarOperationInput",
|
||||
expectedOutput: "BarOperationOutput",
|
||||
operation: "BarOperation",
|
||||
input: "FooInputShape",
|
||||
inputRef: "FooInputShapeRef",
|
||||
output: "FooOutputShape",
|
||||
outputRef: "FooOutputShapeRef",
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
expectedInput: "FooOperationInput",
|
||||
expectedOutput: "FooOperationOutput",
|
||||
operation: "FooOperation",
|
||||
input: "FooInputShape",
|
||||
inputRef: "FooInputShapeRef",
|
||||
output: "FooOutputShape",
|
||||
outputRef: "FooOutputShapeRef",
|
||||
},
|
||||
{
|
||||
expectedInput: "OpOutputNoRenameInput",
|
||||
expectedOutput: "OpOutputNoRenameOutputShape",
|
||||
operation: "OpOutputNoRename",
|
||||
input: "OpOutputNoRenameInputShape",
|
||||
inputRef: "OpOutputNoRenameInputRef",
|
||||
output: "OpOutputNoRenameOutputShape",
|
||||
outputRef: "OpOutputNoRenameOutputRef",
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
expectedInput: "FooOperationInput",
|
||||
expectedOutput: "FooOperationOutput",
|
||||
operation: "FooOperation",
|
||||
input: "FooInputShape",
|
||||
inputRef: "FooInputShapeRef",
|
||||
output: "FooOutputShape",
|
||||
outputRef: "FooOutputShapeRef",
|
||||
},
|
||||
{
|
||||
expectedInput: "OpInputNoRenameInputShape",
|
||||
expectedOutput: "OpInputNoRenameOutput",
|
||||
operation: "OpInputNoRename",
|
||||
input: "OpInputNoRenameInputShape",
|
||||
inputRef: "OpInputNoRenameInputRef",
|
||||
output: "OpInputNoRenameOutputShape",
|
||||
outputRef: "OpInputNoRenameOutputRef",
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
expectedInput: "FooOperationInput",
|
||||
expectedOutput: "FooOperationOutput",
|
||||
operation: "FooOperation",
|
||||
input: "FooInputShape",
|
||||
inputRef: "FooInputShapeRef",
|
||||
output: "FooOutputShape",
|
||||
outputRef: "FooOutputShapeRef",
|
||||
},
|
||||
{
|
||||
expectedInput: "OpInputNoRenameInputShape",
|
||||
expectedOutput: "OpInputNoRenameOutputShape",
|
||||
operation: "OpBothNoRename",
|
||||
input: "OpInputNoRenameInputShape",
|
||||
inputRef: "OpInputNoRenameInputRef",
|
||||
output: "OpInputNoRenameOutputShape",
|
||||
outputRef: "OpInputNoRenameOutputRef",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
a := &API{
|
||||
name: "FooService",
|
||||
Operations: map[string]*Operation{},
|
||||
}
|
||||
|
||||
expected := map[string][]string{}
|
||||
a.Shapes = map[string]*Shape{}
|
||||
for _, op := range c {
|
||||
a.Operations[op.operation] = &Operation{
|
||||
ExportedName: op.operation,
|
||||
}
|
||||
a.Operations[op.operation].Name = op.operation
|
||||
a.Operations[op.operation].InputRef = ShapeRef{
|
||||
API: a,
|
||||
ShapeName: op.inputRef,
|
||||
Shape: &Shape{
|
||||
API: a,
|
||||
ShapeName: op.input,
|
||||
},
|
||||
}
|
||||
a.Operations[op.operation].OutputRef = ShapeRef{
|
||||
API: a,
|
||||
ShapeName: op.outputRef,
|
||||
Shape: &Shape{
|
||||
API: a,
|
||||
ShapeName: op.output,
|
||||
},
|
||||
}
|
||||
|
||||
a.Shapes[op.input] = &Shape{
|
||||
ShapeName: op.input,
|
||||
}
|
||||
a.Shapes[op.output] = &Shape{
|
||||
ShapeName: op.output,
|
||||
}
|
||||
|
||||
expected[op.operation] = append(expected[op.operation], op.expectedInput)
|
||||
expected[op.operation] = append(expected[op.operation], op.expectedOutput)
|
||||
}
|
||||
|
||||
a.fixStutterNames()
|
||||
a.renameToplevelShapes()
|
||||
for k, v := range expected {
|
||||
if a.Operations[k].InputRef.Shape.ShapeName != v[0] {
|
||||
t.Errorf("Error %d case: Expected %q, but received %q", k, v[0], a.Operations[k].InputRef.Shape.ShapeName)
|
||||
}
|
||||
if a.Operations[k].OutputRef.Shape.ShapeName != v[1] {
|
||||
t.Errorf("Error %d case: Expected %q, but received %q", k, v[1], a.Operations[k].OutputRef.Shape.ShapeName)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestCollidingFields(t *testing.T) {
|
||||
cases := []struct {
|
||||
api *API
|
||||
expected []*Shapes
|
||||
}{
|
||||
{
|
||||
&API{
|
||||
name: "FooService",
|
||||
Shapes: []*Shapes{
|
||||
{
|
||||
MemberRefs: map[string]*ShapeRef{
|
||||
"String": &ShapeRef{},
|
||||
"GoString": &ShapeRef{},
|
||||
"Validate": &ShapeRef{},
|
||||
"Foo": &ShapeRef{},
|
||||
"SetFoo": &ShapeRef{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
[]*Shapes{
|
||||
{
|
||||
MemberRefs: map[string]*ShapeRef{
|
||||
"String_": &ShapeRef{},
|
||||
"GoString_": &ShapeRef{},
|
||||
"Validate_": &ShapeRef{},
|
||||
"Foo": &ShapeRef{},
|
||||
"SetFoo_": &ShapeRef{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range testCases {
|
||||
c.api.renameCollidingFields()
|
||||
if !reflect.DeepEqual(c.api.Shapes, c.expected) {
|
||||
t.Errorf("expected %v, but received %v", c.expected, c.api.Shapes)
|
||||
}
|
||||
}
|
||||
}
|
159
vendor/github.com/aws/aws-sdk-go/private/model/api/service_name.go
generated
vendored
159
vendor/github.com/aws/aws-sdk-go/private/model/api/service_name.go
generated
vendored
|
@ -1,159 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
// ServiceName returns the SDK's naming of the service. Has
|
||||
// backwards compatability built in for services that were
|
||||
// incorrectly named with the service's endpoint prefix.
|
||||
func ServiceName(a *API) string {
|
||||
if oldName, ok := oldServiceNames[a.PackageName()]; ok {
|
||||
return oldName
|
||||
}
|
||||
|
||||
return ServiceID(a)
|
||||
}
|
||||
|
||||
var oldServiceNames = map[string]string{
|
||||
"migrationhub": "mgh",
|
||||
"acmpca": "acm-pca",
|
||||
"acm": "acm",
|
||||
"alexaforbusiness": "a4b",
|
||||
"apigateway": "apigateway",
|
||||
"applicationautoscaling": "autoscaling",
|
||||
"appstream": "appstream2",
|
||||
"appsync": "appsync",
|
||||
"athena": "athena",
|
||||
"autoscalingplans": "autoscaling",
|
||||
"autoscaling": "autoscaling",
|
||||
"batch": "batch",
|
||||
"budgets": "budgets",
|
||||
"costexplorer": "ce",
|
||||
"cloud9": "cloud9",
|
||||
"clouddirectory": "clouddirectory",
|
||||
"cloudformation": "cloudformation",
|
||||
"cloudfront": "cloudfront",
|
||||
"cloudhsm": "cloudhsm",
|
||||
"cloudhsmv2": "cloudhsmv2",
|
||||
"cloudsearch": "cloudsearch",
|
||||
"cloudsearchdomain": "cloudsearchdomain",
|
||||
"cloudtrail": "cloudtrail",
|
||||
"codebuild": "codebuild",
|
||||
"codecommit": "codecommit",
|
||||
"codedeploy": "codedeploy",
|
||||
"codepipeline": "codepipeline",
|
||||
"codestar": "codestar",
|
||||
"cognitoidentity": "cognito-identity",
|
||||
"cognitoidentityprovider": "cognito-idp",
|
||||
"cognitosync": "cognito-sync",
|
||||
"comprehend": "comprehend",
|
||||
"configservice": "config",
|
||||
"connect": "connect",
|
||||
"costandusagereportservice": "cur",
|
||||
"datapipeline": "datapipeline",
|
||||
"dax": "dax",
|
||||
"devicefarm": "devicefarm",
|
||||
"directconnect": "directconnect",
|
||||
"applicationdiscoveryservice": "discovery",
|
||||
"databasemigrationservice": "dms",
|
||||
"directoryservice": "ds",
|
||||
"dynamodb": "dynamodb",
|
||||
"ec2": "ec2",
|
||||
"ecr": "ecr",
|
||||
"ecs": "ecs",
|
||||
"eks": "eks",
|
||||
"elasticache": "elasticache",
|
||||
"elasticbeanstalk": "elasticbeanstalk",
|
||||
"efs": "elasticfilesystem",
|
||||
"elb": "elasticloadbalancing",
|
||||
"elbv2": "elasticloadbalancing",
|
||||
"emr": "elasticmapreduce",
|
||||
"elastictranscoder": "elastictranscoder",
|
||||
"ses": "email",
|
||||
"marketplaceentitlementservice": "entitlement.marketplace",
|
||||
"elasticsearchservice": "es",
|
||||
"cloudwatchevents": "events",
|
||||
"firehose": "firehose",
|
||||
"fms": "fms",
|
||||
"gamelift": "gamelift",
|
||||
"glacier": "glacier",
|
||||
"glue": "glue",
|
||||
"greengrass": "greengrass",
|
||||
"guardduty": "guardduty",
|
||||
"health": "health",
|
||||
"iam": "iam",
|
||||
"inspector": "inspector",
|
||||
"iotdataplane": "data.iot",
|
||||
"iotjobsdataplane": "data.jobs.iot",
|
||||
"iot": "iot",
|
||||
"iot1clickdevicesservice": "devices.iot1click",
|
||||
"iot1clickprojects": "projects.iot1click",
|
||||
"iotanalytics": "iotanalytics",
|
||||
"kinesisvideoarchivedmedia": "kinesisvideo",
|
||||
"kinesisvideomedia": "kinesisvideo",
|
||||
"kinesis": "kinesis",
|
||||
"kinesisanalytics": "kinesisanalytics",
|
||||
"kinesisvideo": "kinesisvideo",
|
||||
"kms": "kms",
|
||||
"lambda": "lambda",
|
||||
"lexmodelbuildingservice": "models.lex",
|
||||
"lightsail": "lightsail",
|
||||
"cloudwatchlogs": "logs",
|
||||
"machinelearning": "machinelearning",
|
||||
"marketplacecommerceanalytics": "marketplacecommerceanalytics",
|
||||
"mediaconvert": "mediaconvert",
|
||||
"medialive": "medialive",
|
||||
"mediapackage": "mediapackage",
|
||||
"mediastoredata": "data.mediastore",
|
||||
"mediastore": "mediastore",
|
||||
"mediatailor": "api.mediatailor",
|
||||
"marketplacemetering": "metering.marketplace",
|
||||
"mobile": "mobile",
|
||||
"mobileanalytics": "mobileanalytics",
|
||||
"cloudwatch": "monitoring",
|
||||
"mq": "mq",
|
||||
"mturk": "mturk-requester",
|
||||
"neptune": "rds",
|
||||
"opsworks": "opsworks",
|
||||
"opsworkscm": "opsworks-cm",
|
||||
"organizations": "organizations",
|
||||
"pi": "pi",
|
||||
"pinpoint": "pinpoint",
|
||||
"polly": "polly",
|
||||
"pricing": "api.pricing",
|
||||
"rds": "rds",
|
||||
"redshift": "redshift",
|
||||
"rekognition": "rekognition",
|
||||
"resourcegroups": "resource-groups",
|
||||
"resourcegroupstaggingapi": "tagging",
|
||||
"route53": "route53",
|
||||
"route53domains": "route53domains",
|
||||
"lexruntimeservice": "runtime.lex",
|
||||
"sagemakerruntime": "runtime.sagemaker",
|
||||
"s3": "s3",
|
||||
"sagemaker": "sagemaker",
|
||||
"simpledb": "sdb",
|
||||
"secretsmanager": "secretsmanager",
|
||||
"serverlessapplicationrepository": "serverlessrepo",
|
||||
"servicecatalog": "servicecatalog",
|
||||
"servicediscovery": "servicediscovery",
|
||||
"shield": "shield",
|
||||
"sms": "sms",
|
||||
"snowball": "snowball",
|
||||
"sns": "sns",
|
||||
"sqs": "sqs",
|
||||
"ssm": "ssm",
|
||||
"sfn": "states",
|
||||
"storagegateway": "storagegateway",
|
||||
"dynamodbstreams": "streams.dynamodb",
|
||||
"sts": "sts",
|
||||
"support": "support",
|
||||
"swf": "swf",
|
||||
"transcribeservice": "transcribe",
|
||||
"translate": "translate",
|
||||
"wafregional": "waf-regional",
|
||||
"waf": "waf",
|
||||
"workdocs": "workdocs",
|
||||
"workmail": "workmail",
|
||||
"workspaces": "workspaces",
|
||||
"xray": "xray",
|
||||
}
|
744
vendor/github.com/aws/aws-sdk-go/private/model/api/shape.go
generated
vendored
744
vendor/github.com/aws/aws-sdk-go/private/model/api/shape.go
generated
vendored
|
@ -1,744 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"path"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
// ErrorInfo represents the error block of a shape's structure
|
||||
type ErrorInfo struct {
|
||||
Type string
|
||||
Code string
|
||||
HTTPStatusCode int
|
||||
}
|
||||
|
||||
// A XMLInfo defines URL and prefix for Shapes when rendered as XML
|
||||
type XMLInfo struct {
|
||||
Prefix string
|
||||
URI string
|
||||
}
|
||||
|
||||
// A ShapeRef defines the usage of a shape within the API.
|
||||
type ShapeRef struct {
|
||||
API *API `json:"-"`
|
||||
Shape *Shape `json:"-"`
|
||||
Documentation string
|
||||
ShapeName string `json:"shape"`
|
||||
Location string
|
||||
LocationName string
|
||||
QueryName string
|
||||
Flattened bool
|
||||
Streaming bool
|
||||
XMLAttribute bool
|
||||
// Ignore, if set, will not be sent over the wire
|
||||
Ignore bool
|
||||
XMLNamespace XMLInfo
|
||||
Payload string
|
||||
IdempotencyToken bool `json:"idempotencyToken"`
|
||||
JSONValue bool `json:"jsonvalue"`
|
||||
Deprecated bool `json:"deprecated"`
|
||||
|
||||
OrigShapeName string `json:"-"`
|
||||
|
||||
GenerateGetter bool
|
||||
|
||||
IsEventPayload bool `json:"eventpayload"`
|
||||
IsEventHeader bool `json:"eventheader"`
|
||||
}
|
||||
|
||||
// A Shape defines the definition of a shape type
|
||||
type Shape struct {
|
||||
API *API `json:"-"`
|
||||
ShapeName string
|
||||
Documentation string
|
||||
MemberRefs map[string]*ShapeRef `json:"members"`
|
||||
MemberRef ShapeRef `json:"member"` // List ref
|
||||
KeyRef ShapeRef `json:"key"` // map key ref
|
||||
ValueRef ShapeRef `json:"value"` // map value ref
|
||||
Required []string
|
||||
Payload string
|
||||
Type string
|
||||
Exception bool
|
||||
Enum []string
|
||||
EnumConsts []string
|
||||
Flattened bool
|
||||
Streaming bool
|
||||
Location string
|
||||
LocationName string
|
||||
IdempotencyToken bool `json:"idempotencyToken"`
|
||||
XMLNamespace XMLInfo
|
||||
Min float64 // optional Minimum length (string, list) or value (number)
|
||||
Max float64 // optional Maximum length (string, list) or value (number)
|
||||
|
||||
EventStreamsMemberName string `json:"-"`
|
||||
EventStreamAPI *EventStreamAPI `json:"-"`
|
||||
EventFor []*EventStream `json:"-"`
|
||||
|
||||
IsEventStream bool `json:"eventstream"`
|
||||
IsEvent bool `json:"event"`
|
||||
|
||||
refs []*ShapeRef // References to this shape
|
||||
resolvePkg string // use this package in the goType() if present
|
||||
|
||||
OrigShapeName string `json:"-"`
|
||||
|
||||
// Defines if the shape is a placeholder and should not be used directly
|
||||
Placeholder bool
|
||||
|
||||
Deprecated bool `json:"deprecated"`
|
||||
|
||||
Validations ShapeValidations
|
||||
|
||||
// Error information that is set if the shape is an error shape.
|
||||
IsError bool
|
||||
ErrorInfo ErrorInfo `json:"error"`
|
||||
}
|
||||
|
||||
// ErrorCodeName will return the error shape's name formated for
|
||||
// error code const.
|
||||
func (s *Shape) ErrorCodeName() string {
|
||||
return "ErrCode" + s.ShapeName
|
||||
}
|
||||
|
||||
// ErrorName will return the shape's name or error code if available based
|
||||
// on the API's protocol. This is the error code string returned by the service.
|
||||
func (s *Shape) ErrorName() string {
|
||||
name := s.ErrorInfo.Type
|
||||
switch s.API.Metadata.Protocol {
|
||||
case "query", "ec2query", "rest-xml":
|
||||
if len(s.ErrorInfo.Code) > 0 {
|
||||
name = s.ErrorInfo.Code
|
||||
}
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
// PayloadRefName returns the payload member of the shape if there is one
|
||||
// modeled. If no payload is modeled, empty string will be returned.
|
||||
func (s *Shape) PayloadRefName() string {
|
||||
if name := s.Payload; len(name) != 0 {
|
||||
// Root shape
|
||||
return name
|
||||
}
|
||||
|
||||
for name, ref := range s.MemberRefs {
|
||||
if ref.IsEventPayload {
|
||||
return name
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// GoTags returns the struct tags for a shape.
|
||||
func (s *Shape) GoTags(root, required bool) string {
|
||||
ref := &ShapeRef{ShapeName: s.ShapeName, API: s.API, Shape: s}
|
||||
return ref.GoTags(root, required)
|
||||
}
|
||||
|
||||
// Rename changes the name of the Shape to newName. Also updates
|
||||
// the associated API's reference to use newName.
|
||||
func (s *Shape) Rename(newName string) {
|
||||
for _, r := range s.refs {
|
||||
r.OrigShapeName = r.ShapeName
|
||||
r.ShapeName = newName
|
||||
}
|
||||
|
||||
delete(s.API.Shapes, s.ShapeName)
|
||||
s.OrigShapeName = s.ShapeName
|
||||
s.API.Shapes[newName] = s
|
||||
s.ShapeName = newName
|
||||
}
|
||||
|
||||
// MemberNames returns a slice of struct member names.
|
||||
func (s *Shape) MemberNames() []string {
|
||||
i, names := 0, make([]string, len(s.MemberRefs))
|
||||
for n := range s.MemberRefs {
|
||||
names[i] = n
|
||||
i++
|
||||
}
|
||||
sort.Strings(names)
|
||||
return names
|
||||
}
|
||||
|
||||
// GoTypeWithPkgName returns a shape's type as a string with the package name in
|
||||
// <packageName>.<type> format. Package naming only applies to structures.
|
||||
func (s *Shape) GoTypeWithPkgName() string {
|
||||
return goType(s, true)
|
||||
}
|
||||
|
||||
// GoTypeWithPkgNameElem returns the shapes type as a string with the "*"
|
||||
// removed if there was one preset.
|
||||
func (s *Shape) GoTypeWithPkgNameElem() string {
|
||||
t := goType(s, true)
|
||||
if strings.HasPrefix(t, "*") {
|
||||
return t[1:]
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// UseIndirection returns if the shape's reference should use indirection or not.
|
||||
func (s *ShapeRef) UseIndirection() bool {
|
||||
switch s.Shape.Type {
|
||||
case "map", "list", "blob", "structure", "jsonvalue":
|
||||
return false
|
||||
}
|
||||
|
||||
if s.Streaming || s.Shape.Streaming {
|
||||
return false
|
||||
}
|
||||
|
||||
if s.JSONValue {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// GoStructValueType returns the Shape's Go type value instead of a pointer
|
||||
// for the type.
|
||||
func (s *Shape) GoStructValueType(name string, ref *ShapeRef) string {
|
||||
v := s.GoStructType(name, ref)
|
||||
|
||||
if ref.UseIndirection() && v[0] == '*' {
|
||||
return v[1:]
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
// GoStructType returns the type of a struct field based on the API
|
||||
// model definition.
|
||||
func (s *Shape) GoStructType(name string, ref *ShapeRef) string {
|
||||
if (ref.Streaming || ref.Shape.Streaming) && s.Payload == name {
|
||||
rtype := "io.ReadSeeker"
|
||||
if strings.HasSuffix(s.ShapeName, "Output") {
|
||||
rtype = "io.ReadCloser"
|
||||
}
|
||||
|
||||
s.API.imports["io"] = true
|
||||
return rtype
|
||||
}
|
||||
|
||||
if ref.JSONValue {
|
||||
s.API.imports["github.com/aws/aws-sdk-go/aws"] = true
|
||||
return "aws.JSONValue"
|
||||
}
|
||||
|
||||
for _, v := range s.Validations {
|
||||
// TODO move this to shape validation resolution
|
||||
if (v.Ref.Shape.Type == "map" || v.Ref.Shape.Type == "list") && v.Type == ShapeValidationNested {
|
||||
s.API.imports["fmt"] = true
|
||||
}
|
||||
}
|
||||
|
||||
return ref.GoType()
|
||||
}
|
||||
|
||||
// GoType returns a shape's Go type
|
||||
func (s *Shape) GoType() string {
|
||||
return goType(s, false)
|
||||
}
|
||||
|
||||
// GoType returns a shape ref's Go type.
|
||||
func (ref *ShapeRef) GoType() string {
|
||||
if ref.Shape == nil {
|
||||
panic(fmt.Errorf("missing shape definition on reference for %#v", ref))
|
||||
}
|
||||
|
||||
return ref.Shape.GoType()
|
||||
}
|
||||
|
||||
// GoTypeWithPkgName returns a shape's type as a string with the package name in
|
||||
// <packageName>.<type> format. Package naming only applies to structures.
|
||||
func (ref *ShapeRef) GoTypeWithPkgName() string {
|
||||
if ref.Shape == nil {
|
||||
panic(fmt.Errorf("missing shape definition on reference for %#v", ref))
|
||||
}
|
||||
|
||||
return ref.Shape.GoTypeWithPkgName()
|
||||
}
|
||||
|
||||
// Returns a string version of the Shape's type.
|
||||
// If withPkgName is true, the package name will be added as a prefix
|
||||
func goType(s *Shape, withPkgName bool) string {
|
||||
switch s.Type {
|
||||
case "structure":
|
||||
if withPkgName || s.resolvePkg != "" {
|
||||
pkg := s.resolvePkg
|
||||
if pkg != "" {
|
||||
s.API.imports[pkg] = true
|
||||
pkg = path.Base(pkg)
|
||||
} else {
|
||||
pkg = s.API.PackageName()
|
||||
}
|
||||
return fmt.Sprintf("*%s.%s", pkg, s.ShapeName)
|
||||
}
|
||||
return "*" + s.ShapeName
|
||||
case "map":
|
||||
return "map[string]" + goType(s.ValueRef.Shape, withPkgName)
|
||||
case "jsonvalue":
|
||||
return "aws.JSONValue"
|
||||
case "list":
|
||||
return "[]" + goType(s.MemberRef.Shape, withPkgName)
|
||||
case "boolean":
|
||||
return "*bool"
|
||||
case "string", "character":
|
||||
return "*string"
|
||||
case "blob":
|
||||
return "[]byte"
|
||||
case "integer", "long":
|
||||
return "*int64"
|
||||
case "float", "double":
|
||||
return "*float64"
|
||||
case "timestamp":
|
||||
s.API.imports["time"] = true
|
||||
return "*time.Time"
|
||||
default:
|
||||
panic("Unsupported shape type: " + s.Type)
|
||||
}
|
||||
}
|
||||
|
||||
// GoTypeElem returns the Go type for the Shape. If the shape type is a pointer just
|
||||
// the type will be returned minus the pointer *.
|
||||
func (s *Shape) GoTypeElem() string {
|
||||
t := s.GoType()
|
||||
if strings.HasPrefix(t, "*") {
|
||||
return t[1:]
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// GoTypeElem returns the Go type for the Shape. If the shape type is a pointer just
|
||||
// the type will be returned minus the pointer *.
|
||||
func (ref *ShapeRef) GoTypeElem() string {
|
||||
if ref.Shape == nil {
|
||||
panic(fmt.Errorf("missing shape definition on reference for %#v", ref))
|
||||
}
|
||||
|
||||
return ref.Shape.GoTypeElem()
|
||||
}
|
||||
|
||||
// ShapeTag is a struct tag that will be applied to a shape's generated code
|
||||
type ShapeTag struct {
|
||||
Key, Val string
|
||||
}
|
||||
|
||||
// String returns the string representation of the shape tag
|
||||
func (s ShapeTag) String() string {
|
||||
return fmt.Sprintf(`%s:"%s"`, s.Key, s.Val)
|
||||
}
|
||||
|
||||
// ShapeTags is a collection of shape tags and provides serialization of the
|
||||
// tags in an ordered list.
|
||||
type ShapeTags []ShapeTag
|
||||
|
||||
// Join returns an ordered serialization of the shape tags with the provided
|
||||
// separator.
|
||||
func (s ShapeTags) Join(sep string) string {
|
||||
o := &bytes.Buffer{}
|
||||
for i, t := range s {
|
||||
o.WriteString(t.String())
|
||||
if i < len(s)-1 {
|
||||
o.WriteString(sep)
|
||||
}
|
||||
}
|
||||
|
||||
return o.String()
|
||||
}
|
||||
|
||||
// String is an alias for Join with the empty space separator.
|
||||
func (s ShapeTags) String() string {
|
||||
return s.Join(" ")
|
||||
}
|
||||
|
||||
// GoTags returns the rendered tags string for the ShapeRef
|
||||
func (ref *ShapeRef) GoTags(toplevel bool, isRequired bool) string {
|
||||
tags := ShapeTags{}
|
||||
|
||||
if ref.Location != "" {
|
||||
tags = append(tags, ShapeTag{"location", ref.Location})
|
||||
} else if ref.Shape.Location != "" {
|
||||
tags = append(tags, ShapeTag{"location", ref.Shape.Location})
|
||||
}
|
||||
|
||||
if ref.LocationName != "" {
|
||||
tags = append(tags, ShapeTag{"locationName", ref.LocationName})
|
||||
} else if ref.Shape.LocationName != "" {
|
||||
tags = append(tags, ShapeTag{"locationName", ref.Shape.LocationName})
|
||||
}
|
||||
|
||||
if ref.QueryName != "" {
|
||||
tags = append(tags, ShapeTag{"queryName", ref.QueryName})
|
||||
}
|
||||
if ref.Shape.MemberRef.LocationName != "" {
|
||||
tags = append(tags, ShapeTag{"locationNameList", ref.Shape.MemberRef.LocationName})
|
||||
}
|
||||
if ref.Shape.KeyRef.LocationName != "" {
|
||||
tags = append(tags, ShapeTag{"locationNameKey", ref.Shape.KeyRef.LocationName})
|
||||
}
|
||||
if ref.Shape.ValueRef.LocationName != "" {
|
||||
tags = append(tags, ShapeTag{"locationNameValue", ref.Shape.ValueRef.LocationName})
|
||||
}
|
||||
if ref.Shape.Min > 0 {
|
||||
tags = append(tags, ShapeTag{"min", fmt.Sprintf("%v", ref.Shape.Min)})
|
||||
}
|
||||
|
||||
if ref.Deprecated || ref.Shape.Deprecated {
|
||||
tags = append(tags, ShapeTag{"deprecated", "true"})
|
||||
}
|
||||
|
||||
// All shapes have a type
|
||||
tags = append(tags, ShapeTag{"type", ref.Shape.Type})
|
||||
|
||||
// embed the timestamp type for easier lookups
|
||||
if ref.Shape.Type == "timestamp" {
|
||||
t := ShapeTag{Key: "timestampFormat"}
|
||||
if ref.Location == "header" {
|
||||
t.Val = "rfc822"
|
||||
} else {
|
||||
switch ref.API.Metadata.Protocol {
|
||||
case "json", "rest-json":
|
||||
t.Val = "unix"
|
||||
case "rest-xml", "ec2", "query":
|
||||
t.Val = "iso8601"
|
||||
}
|
||||
}
|
||||
tags = append(tags, t)
|
||||
}
|
||||
|
||||
if ref.Shape.Flattened || ref.Flattened {
|
||||
tags = append(tags, ShapeTag{"flattened", "true"})
|
||||
}
|
||||
if ref.XMLAttribute {
|
||||
tags = append(tags, ShapeTag{"xmlAttribute", "true"})
|
||||
}
|
||||
if isRequired {
|
||||
tags = append(tags, ShapeTag{"required", "true"})
|
||||
}
|
||||
if ref.Shape.IsEnum() {
|
||||
tags = append(tags, ShapeTag{"enum", ref.ShapeName})
|
||||
}
|
||||
|
||||
if toplevel {
|
||||
if name := ref.Shape.PayloadRefName(); len(name) > 0 {
|
||||
tags = append(tags, ShapeTag{"payload", name})
|
||||
}
|
||||
}
|
||||
|
||||
if ref.XMLNamespace.Prefix != "" {
|
||||
tags = append(tags, ShapeTag{"xmlPrefix", ref.XMLNamespace.Prefix})
|
||||
} else if ref.Shape.XMLNamespace.Prefix != "" {
|
||||
tags = append(tags, ShapeTag{"xmlPrefix", ref.Shape.XMLNamespace.Prefix})
|
||||
}
|
||||
|
||||
if ref.XMLNamespace.URI != "" {
|
||||
tags = append(tags, ShapeTag{"xmlURI", ref.XMLNamespace.URI})
|
||||
} else if ref.Shape.XMLNamespace.URI != "" {
|
||||
tags = append(tags, ShapeTag{"xmlURI", ref.Shape.XMLNamespace.URI})
|
||||
}
|
||||
|
||||
if ref.IdempotencyToken || ref.Shape.IdempotencyToken {
|
||||
tags = append(tags, ShapeTag{"idempotencyToken", "true"})
|
||||
}
|
||||
|
||||
if ref.Ignore {
|
||||
tags = append(tags, ShapeTag{"ignore", "true"})
|
||||
}
|
||||
|
||||
return fmt.Sprintf("`%s`", tags)
|
||||
}
|
||||
|
||||
// Docstring returns the godocs formated documentation
|
||||
func (ref *ShapeRef) Docstring() string {
|
||||
if ref.Documentation != "" {
|
||||
return strings.Trim(ref.Documentation, "\n ")
|
||||
}
|
||||
return ref.Shape.Docstring()
|
||||
}
|
||||
|
||||
// Docstring returns the godocs formated documentation
|
||||
func (s *Shape) Docstring() string {
|
||||
return strings.Trim(s.Documentation, "\n ")
|
||||
}
|
||||
|
||||
// IndentedDocstring is the indented form of the doc string.
|
||||
func (ref *ShapeRef) IndentedDocstring() string {
|
||||
doc := ref.Docstring()
|
||||
return strings.Replace(doc, "// ", "// ", -1)
|
||||
}
|
||||
|
||||
var goCodeStringerTmpl = template.Must(template.New("goCodeStringerTmpl").Parse(`
|
||||
// String returns the string representation
|
||||
func (s {{ .ShapeName }}) String() string {
|
||||
return awsutil.Prettify(s)
|
||||
}
|
||||
// GoString returns the string representation
|
||||
func (s {{ .ShapeName }}) GoString() string {
|
||||
return s.String()
|
||||
}
|
||||
`))
|
||||
|
||||
// GoCodeStringers renders the Stringers for API input/output shapes
|
||||
func (s *Shape) GoCodeStringers() string {
|
||||
w := bytes.Buffer{}
|
||||
if err := goCodeStringerTmpl.Execute(&w, s); err != nil {
|
||||
panic(fmt.Sprintln("Unexpected error executing GoCodeStringers template", err))
|
||||
}
|
||||
|
||||
return w.String()
|
||||
}
|
||||
|
||||
var enumStrip = regexp.MustCompile(`[^a-zA-Z0-9_:\./-]`)
|
||||
var enumDelims = regexp.MustCompile(`[-_:\./]+`)
|
||||
var enumCamelCase = regexp.MustCompile(`([a-z])([A-Z])`)
|
||||
|
||||
// EnumName returns the Nth enum in the shapes Enum list
|
||||
func (s *Shape) EnumName(n int) string {
|
||||
enum := s.Enum[n]
|
||||
enum = enumStrip.ReplaceAllLiteralString(enum, "")
|
||||
enum = enumCamelCase.ReplaceAllString(enum, "$1-$2")
|
||||
parts := enumDelims.Split(enum, -1)
|
||||
for i, v := range parts {
|
||||
v = strings.ToLower(v)
|
||||
parts[i] = ""
|
||||
if len(v) > 0 {
|
||||
parts[i] = strings.ToUpper(v[0:1])
|
||||
}
|
||||
if len(v) > 1 {
|
||||
parts[i] += v[1:]
|
||||
}
|
||||
}
|
||||
enum = strings.Join(parts, "")
|
||||
enum = strings.ToUpper(enum[0:1]) + enum[1:]
|
||||
return enum
|
||||
}
|
||||
|
||||
// NestedShape returns the shape pointer value for the shape which is nested
|
||||
// under the current shape. If the shape is not nested nil will be returned.
|
||||
//
|
||||
// strucutures, the current shape is returned
|
||||
// map: the value shape of the map is returned
|
||||
// list: the element shape of the list is returned
|
||||
func (s *Shape) NestedShape() *Shape {
|
||||
var nestedShape *Shape
|
||||
switch s.Type {
|
||||
case "structure":
|
||||
nestedShape = s
|
||||
case "map":
|
||||
nestedShape = s.ValueRef.Shape
|
||||
case "list":
|
||||
nestedShape = s.MemberRef.Shape
|
||||
}
|
||||
|
||||
return nestedShape
|
||||
}
|
||||
|
||||
var structShapeTmpl = func() *template.Template {
|
||||
shapeTmpl := template.Must(
|
||||
template.New("structShapeTmpl").
|
||||
Funcs(template.FuncMap{
|
||||
"GetCrosslinkURL": GetCrosslinkURL,
|
||||
}).
|
||||
Parse(structShapeTmplDef),
|
||||
)
|
||||
|
||||
template.Must(
|
||||
shapeTmpl.AddParseTree(
|
||||
"eventStreamAPILoopMethodTmpl", eventStreamAPILoopMethodTmpl.Tree),
|
||||
)
|
||||
|
||||
template.Must(
|
||||
shapeTmpl.AddParseTree(
|
||||
"eventStreamEventShapeTmpl", eventStreamEventShapeTmpl.Tree),
|
||||
)
|
||||
|
||||
return shapeTmpl
|
||||
}()
|
||||
|
||||
const structShapeTmplDef = `
|
||||
{{ .Docstring }}
|
||||
{{ $context := . -}}
|
||||
type {{ .ShapeName }} struct {
|
||||
_ struct{} {{ .GoTags true false }}
|
||||
|
||||
{{ range $_, $name := $context.MemberNames -}}
|
||||
{{ $elem := index $context.MemberRefs $name -}}
|
||||
{{ $isBlob := $context.WillRefBeBase64Encoded $name -}}
|
||||
{{ $isRequired := $context.IsRequired $name -}}
|
||||
{{ $doc := $elem.Docstring -}}
|
||||
|
||||
{{ if $doc -}}
|
||||
{{ $doc }}
|
||||
{{ end -}}
|
||||
{{ if $isBlob -}}
|
||||
{{ if $doc -}}
|
||||
//
|
||||
{{ end -}}
|
||||
// {{ $name }} is automatically base64 encoded/decoded by the SDK.
|
||||
{{ end -}}
|
||||
{{ if $isRequired -}}
|
||||
{{ if or $doc $isBlob -}}
|
||||
//
|
||||
{{ end -}}
|
||||
// {{ $name }} is a required field
|
||||
{{ end -}}
|
||||
{{ $name }} {{ $context.GoStructType $name $elem }} {{ $elem.GoTags false $isRequired }}
|
||||
|
||||
{{ end }}
|
||||
}
|
||||
{{ if not .API.NoStringerMethods }}
|
||||
{{ .GoCodeStringers }}
|
||||
{{ end }}
|
||||
{{ if not .API.NoValidataShapeMethods }}
|
||||
{{ if .Validations -}}
|
||||
{{ .Validations.GoCode . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if not .API.NoGenStructFieldAccessors }}
|
||||
{{ $builderShapeName := print .ShapeName -}}
|
||||
{{ range $_, $name := $context.MemberNames -}}
|
||||
{{ $elem := index $context.MemberRefs $name -}}
|
||||
|
||||
// Set{{ $name }} sets the {{ $name }} field's value.
|
||||
func (s *{{ $builderShapeName }}) Set{{ $name }}(v {{ $context.GoStructValueType $name $elem }}) *{{ $builderShapeName }} {
|
||||
{{ if $elem.UseIndirection -}}
|
||||
s.{{ $name }} = &v
|
||||
{{ else -}}
|
||||
s.{{ $name }} = v
|
||||
{{ end -}}
|
||||
return s
|
||||
}
|
||||
|
||||
{{ if $elem.GenerateGetter -}}
|
||||
func (s *{{ $builderShapeName }}) get{{ $name }}() (v {{ $context.GoStructValueType $name $elem }}) {
|
||||
{{ if $elem.UseIndirection -}}
|
||||
if s.{{ $name }} == nil {
|
||||
return v
|
||||
}
|
||||
return *s.{{ $name }}
|
||||
{{ else -}}
|
||||
return s.{{ $name }}
|
||||
{{ end -}}
|
||||
}
|
||||
{{- end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ if $.EventStreamsMemberName }}
|
||||
{{ template "eventStreamAPILoopMethodTmpl" $ }}
|
||||
{{ end }}
|
||||
|
||||
{{ if $.IsEvent }}
|
||||
{{ template "eventStreamEventShapeTmpl" $ }}
|
||||
{{ end }}
|
||||
`
|
||||
|
||||
var enumShapeTmpl = template.Must(template.New("EnumShape").Parse(`
|
||||
{{ .Docstring }}
|
||||
const (
|
||||
{{ $context := . -}}
|
||||
{{ range $index, $elem := .Enum -}}
|
||||
{{ $name := index $context.EnumConsts $index -}}
|
||||
// {{ $name }} is a {{ $context.ShapeName }} enum value
|
||||
{{ $name }} = "{{ $elem }}"
|
||||
|
||||
{{ end }}
|
||||
)
|
||||
`))
|
||||
|
||||
// GoCode returns the rendered Go code for the Shape.
|
||||
func (s *Shape) GoCode() string {
|
||||
w := &bytes.Buffer{}
|
||||
|
||||
switch {
|
||||
case s.EventStreamAPI != nil:
|
||||
if err := renderEventStreamAPIShape(w, s); err != nil {
|
||||
panic(
|
||||
fmt.Sprintf(
|
||||
"failed to generate eventstream API shape, %s, %v",
|
||||
s.ShapeName, err),
|
||||
)
|
||||
}
|
||||
case s.Type == "structure":
|
||||
if err := structShapeTmpl.Execute(w, s); err != nil {
|
||||
panic(
|
||||
fmt.Sprintf(
|
||||
"Failed to generate struct shape %s, %v",
|
||||
s.ShapeName, err),
|
||||
)
|
||||
}
|
||||
case s.IsEnum():
|
||||
if err := enumShapeTmpl.Execute(w, s); err != nil {
|
||||
panic(
|
||||
fmt.Sprintf(
|
||||
"Failed to generate enum shape %s, %v",
|
||||
s.ShapeName, err),
|
||||
)
|
||||
}
|
||||
default:
|
||||
panic(fmt.Sprintln("Cannot generate toplevel shape for", s.Type))
|
||||
}
|
||||
|
||||
return w.String()
|
||||
}
|
||||
|
||||
// IsEnum returns whether this shape is an enum list
|
||||
func (s *Shape) IsEnum() bool {
|
||||
return s.Type == "string" && len(s.Enum) > 0
|
||||
}
|
||||
|
||||
// IsRequired returns if member is a required field.
|
||||
func (s *Shape) IsRequired(member string) bool {
|
||||
for _, n := range s.Required {
|
||||
if n == member {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// IsInternal returns whether the shape was defined in this package
|
||||
func (s *Shape) IsInternal() bool {
|
||||
return s.resolvePkg == ""
|
||||
}
|
||||
|
||||
// removeRef removes a shape reference from the list of references this
|
||||
// shape is used in.
|
||||
func (s *Shape) removeRef(ref *ShapeRef) {
|
||||
r := s.refs
|
||||
for i := 0; i < len(r); i++ {
|
||||
if r[i] == ref {
|
||||
j := i + 1
|
||||
copy(r[i:], r[j:])
|
||||
for k, n := len(r)-j+i, len(r); k < n; k++ {
|
||||
r[k] = nil // free up the end of the list
|
||||
} // for k
|
||||
s.refs = r[:len(r)-j+i]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Shape) WillRefBeBase64Encoded(refName string) bool {
|
||||
payloadRefName := s.Payload
|
||||
if payloadRefName == refName {
|
||||
return false
|
||||
}
|
||||
|
||||
ref, ok := s.MemberRefs[refName]
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("shape %s does not contain %q refName", s.ShapeName, refName))
|
||||
}
|
||||
|
||||
return ref.Shape.Type == "blob"
|
||||
}
|
155
vendor/github.com/aws/aws-sdk-go/private/model/api/shape_validation.go
generated
vendored
155
vendor/github.com/aws/aws-sdk-go/private/model/api/shape_validation.go
generated
vendored
|
@ -1,155 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
// A ShapeValidationType is the type of validation that a shape needs
|
||||
type ShapeValidationType int
|
||||
|
||||
const (
|
||||
// ShapeValidationRequired states the shape must be set
|
||||
ShapeValidationRequired = iota
|
||||
|
||||
// ShapeValidationMinVal states the shape must have at least a number of
|
||||
// elements, or for numbers a minimum value
|
||||
ShapeValidationMinVal
|
||||
|
||||
// ShapeValidationNested states the shape has nested values that need
|
||||
// to be validated
|
||||
ShapeValidationNested
|
||||
)
|
||||
|
||||
// A ShapeValidation contains information about a shape and the type of validation
|
||||
// that is needed
|
||||
type ShapeValidation struct {
|
||||
// Name of the shape to be validated
|
||||
Name string
|
||||
// Reference to the shape within the context the shape is referenced
|
||||
Ref *ShapeRef
|
||||
// Type of validation needed
|
||||
Type ShapeValidationType
|
||||
}
|
||||
|
||||
var validationGoCodeTmpls = template.Must(template.New("validationGoCodeTmpls").Parse(`
|
||||
{{ define "requiredValue" -}}
|
||||
if s.{{ .Name }} == nil {
|
||||
invalidParams.Add(request.NewErrParamRequired("{{ .Name }}"))
|
||||
}
|
||||
{{- end }}
|
||||
{{ define "minLen" -}}
|
||||
if s.{{ .Name }} != nil && len(s.{{ .Name }}) < {{ .Ref.Shape.Min }} {
|
||||
invalidParams.Add(request.NewErrParamMinLen("{{ .Name }}", {{ .Ref.Shape.Min }}))
|
||||
}
|
||||
{{- end }}
|
||||
{{ define "minLenString" -}}
|
||||
if s.{{ .Name }} != nil && len(*s.{{ .Name }}) < {{ .Ref.Shape.Min }} {
|
||||
invalidParams.Add(request.NewErrParamMinLen("{{ .Name }}", {{ .Ref.Shape.Min }}))
|
||||
}
|
||||
{{- end }}
|
||||
{{ define "minVal" -}}
|
||||
if s.{{ .Name }} != nil && *s.{{ .Name }} < {{ .Ref.Shape.Min }} {
|
||||
invalidParams.Add(request.NewErrParamMinValue("{{ .Name }}", {{ .Ref.Shape.Min }}))
|
||||
}
|
||||
{{- end }}
|
||||
{{ define "nestedMapList" -}}
|
||||
if s.{{ .Name }} != nil {
|
||||
for i, v := range s.{{ .Name }} {
|
||||
if v == nil { continue }
|
||||
if err := v.Validate(); err != nil {
|
||||
invalidParams.AddNested(fmt.Sprintf("%s[%v]", "{{ .Name }}", i), err.(request.ErrInvalidParams))
|
||||
}
|
||||
}
|
||||
}
|
||||
{{- end }}
|
||||
{{ define "nestedStruct" -}}
|
||||
if s.{{ .Name }} != nil {
|
||||
if err := s.{{ .Name }}.Validate(); err != nil {
|
||||
invalidParams.AddNested("{{ .Name }}", err.(request.ErrInvalidParams))
|
||||
}
|
||||
}
|
||||
{{- end }}
|
||||
`))
|
||||
|
||||
// GoCode returns the generated Go code for the Shape with its validation type.
|
||||
func (sv ShapeValidation) GoCode() string {
|
||||
var err error
|
||||
|
||||
w := &bytes.Buffer{}
|
||||
switch sv.Type {
|
||||
case ShapeValidationRequired:
|
||||
err = validationGoCodeTmpls.ExecuteTemplate(w, "requiredValue", sv)
|
||||
case ShapeValidationMinVal:
|
||||
switch sv.Ref.Shape.Type {
|
||||
case "list", "map", "blob":
|
||||
err = validationGoCodeTmpls.ExecuteTemplate(w, "minLen", sv)
|
||||
case "string":
|
||||
err = validationGoCodeTmpls.ExecuteTemplate(w, "minLenString", sv)
|
||||
case "integer", "long", "float", "double":
|
||||
err = validationGoCodeTmpls.ExecuteTemplate(w, "minVal", sv)
|
||||
default:
|
||||
panic(fmt.Sprintf("ShapeValidation.GoCode, %s's type %s, no min value handling",
|
||||
sv.Name, sv.Ref.Shape.Type))
|
||||
}
|
||||
case ShapeValidationNested:
|
||||
switch sv.Ref.Shape.Type {
|
||||
case "map", "list":
|
||||
err = validationGoCodeTmpls.ExecuteTemplate(w, "nestedMapList", sv)
|
||||
default:
|
||||
err = validationGoCodeTmpls.ExecuteTemplate(w, "nestedStruct", sv)
|
||||
}
|
||||
default:
|
||||
panic(fmt.Sprintf("ShapeValidation.GoCode, %s's type %d, unknown validation type",
|
||||
sv.Name, sv.Type))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("ShapeValidation.GoCode failed, err: %v", err))
|
||||
}
|
||||
|
||||
return w.String()
|
||||
}
|
||||
|
||||
// A ShapeValidations is a collection of shape validations needed nested within
|
||||
// a parent shape
|
||||
type ShapeValidations []ShapeValidation
|
||||
|
||||
var validateShapeTmpl = template.Must(template.New("ValidateShape").Parse(`
|
||||
// Validate inspects the fields of the type to determine if they are valid.
|
||||
func (s *{{ .Shape.ShapeName }}) Validate() error {
|
||||
invalidParams := request.ErrInvalidParams{Context: "{{ .Shape.ShapeName }}"}
|
||||
{{ range $_, $v := .Validations -}}
|
||||
{{ $v.GoCode }}
|
||||
{{ end }}
|
||||
if invalidParams.Len() > 0 {
|
||||
return invalidParams
|
||||
}
|
||||
return nil
|
||||
}
|
||||
`))
|
||||
|
||||
// GoCode generates the Go code needed to perform validations for the
|
||||
// shape and its nested fields.
|
||||
func (vs ShapeValidations) GoCode(shape *Shape) string {
|
||||
buf := &bytes.Buffer{}
|
||||
validateShapeTmpl.Execute(buf, map[string]interface{}{
|
||||
"Shape": shape,
|
||||
"Validations": vs,
|
||||
})
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// Has returns true or false if the ShapeValidations already contains the
|
||||
// the reference and validation type.
|
||||
func (vs ShapeValidations) Has(ref *ShapeRef, typ ShapeValidationType) bool {
|
||||
for _, v := range vs {
|
||||
if v.Ref == ref && v.Type == typ {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
28
vendor/github.com/aws/aws-sdk-go/private/model/api/shapetag_test.go
generated
vendored
28
vendor/github.com/aws/aws-sdk-go/private/model/api/shapetag_test.go
generated
vendored
|
@ -1,28 +0,0 @@
|
|||
// +build 1.6,codegen
|
||||
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/private/model/api"
|
||||
)
|
||||
|
||||
func TestShapeTagJoin(t *testing.T) {
|
||||
s := api.ShapeTags{
|
||||
{Key: "location", Val: "query"},
|
||||
{Key: "locationName", Val: "abc"},
|
||||
{Key: "type", Val: "string"},
|
||||
}
|
||||
|
||||
expected := `location:"query" locationName:"abc" type:"string"`
|
||||
|
||||
o := s.Join(" ")
|
||||
o2 := s.String()
|
||||
if expected != o {
|
||||
t.Errorf("Expected %s, but received %s", expected, o)
|
||||
}
|
||||
if expected != o2 {
|
||||
t.Errorf("Expected %s, but received %s", expected, o2)
|
||||
}
|
||||
}
|
189
vendor/github.com/aws/aws-sdk-go/private/model/api/waiters.go
generated
vendored
189
vendor/github.com/aws/aws-sdk-go/private/model/api/waiters.go
generated
vendored
|
@ -1,189 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
// WaiterAcceptor is the acceptors defined in the model the SDK will use
|
||||
// to wait on resource states with.
|
||||
type WaiterAcceptor struct {
|
||||
State string
|
||||
Matcher string
|
||||
Argument string
|
||||
Expected interface{}
|
||||
}
|
||||
|
||||
// ExpectedString returns the string that was expected by the WaiterAcceptor
|
||||
func (a *WaiterAcceptor) ExpectedString() string {
|
||||
switch a.Expected.(type) {
|
||||
case string:
|
||||
return fmt.Sprintf("%q", a.Expected)
|
||||
default:
|
||||
return fmt.Sprintf("%v", a.Expected)
|
||||
}
|
||||
}
|
||||
|
||||
// A Waiter is an individual waiter definition.
|
||||
type Waiter struct {
|
||||
Name string
|
||||
Delay int
|
||||
MaxAttempts int
|
||||
OperationName string `json:"operation"`
|
||||
Operation *Operation
|
||||
Acceptors []WaiterAcceptor
|
||||
}
|
||||
|
||||
// WaitersGoCode generates and returns Go code for each of the waiters of
|
||||
// this API.
|
||||
func (a *API) WaitersGoCode() string {
|
||||
var buf bytes.Buffer
|
||||
fmt.Fprintf(&buf, "import (\n%q\n\n%q\n%q\n)",
|
||||
"time",
|
||||
"github.com/aws/aws-sdk-go/aws",
|
||||
"github.com/aws/aws-sdk-go/aws/request",
|
||||
)
|
||||
|
||||
for _, w := range a.Waiters {
|
||||
buf.WriteString(w.GoCode())
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// used for unmarshaling from the waiter JSON file
|
||||
type waiterDefinitions struct {
|
||||
*API
|
||||
Waiters map[string]Waiter
|
||||
}
|
||||
|
||||
// AttachWaiters reads a file of waiter definitions, and adds those to the API.
|
||||
// Will panic if an error occurs.
|
||||
func (a *API) AttachWaiters(filename string) {
|
||||
p := waiterDefinitions{API: a}
|
||||
|
||||
f, err := os.Open(filename)
|
||||
defer f.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = json.NewDecoder(f).Decode(&p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
p.setup()
|
||||
}
|
||||
|
||||
func (p *waiterDefinitions) setup() {
|
||||
p.API.Waiters = []Waiter{}
|
||||
i, keys := 0, make([]string, len(p.Waiters))
|
||||
for k := range p.Waiters {
|
||||
keys[i] = k
|
||||
i++
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
for _, n := range keys {
|
||||
e := p.Waiters[n]
|
||||
n = p.ExportableName(n)
|
||||
e.Name = n
|
||||
e.OperationName = p.ExportableName(e.OperationName)
|
||||
e.Operation = p.API.Operations[e.OperationName]
|
||||
if e.Operation == nil {
|
||||
panic("unknown operation " + e.OperationName + " for waiter " + n)
|
||||
}
|
||||
p.API.Waiters = append(p.API.Waiters, e)
|
||||
}
|
||||
}
|
||||
|
||||
var waiterTmpls = template.Must(template.New("waiterTmpls").Funcs(
|
||||
template.FuncMap{
|
||||
"titleCase": func(v string) string {
|
||||
return strings.Title(v)
|
||||
},
|
||||
},
|
||||
).Parse(`
|
||||
{{ define "waiter"}}
|
||||
// WaitUntil{{ .Name }} uses the {{ .Operation.API.NiceName }} API operation
|
||||
// {{ .OperationName }} to wait for a condition to be met before returning.
|
||||
// If the condition is not met within the max attempt window, an error will
|
||||
// be returned.
|
||||
func (c *{{ .Operation.API.StructName }}) WaitUntil{{ .Name }}(input {{ .Operation.InputRef.GoType }}) error {
|
||||
return c.WaitUntil{{ .Name }}WithContext(aws.BackgroundContext(), input)
|
||||
}
|
||||
|
||||
// WaitUntil{{ .Name }}WithContext is an extended version of WaitUntil{{ .Name }}.
|
||||
// With the support for passing in a context and options to configure the
|
||||
// Waiter and the underlying request options.
|
||||
//
|
||||
// The context must be non-nil and will be used for request cancellation. If
|
||||
// the context is nil a panic will occur. In the future the SDK may create
|
||||
// sub-contexts for http.Requests. See https://golang.org/pkg/context/
|
||||
// for more information on using Contexts.
|
||||
func (c *{{ .Operation.API.StructName }}) WaitUntil{{ .Name }}WithContext(` +
|
||||
`ctx aws.Context, input {{ .Operation.InputRef.GoType }}, opts ...request.WaiterOption) error {
|
||||
w := request.Waiter{
|
||||
Name: "WaitUntil{{ .Name }}",
|
||||
MaxAttempts: {{ .MaxAttempts }},
|
||||
Delay: request.ConstantWaiterDelay({{ .Delay }} * time.Second),
|
||||
Acceptors: []request.WaiterAcceptor{
|
||||
{{ range $_, $a := .Acceptors }}{
|
||||
State: request.{{ titleCase .State }}WaiterState,
|
||||
Matcher: request.{{ titleCase .Matcher }}WaiterMatch,
|
||||
{{- if .Argument }}Argument: "{{ .Argument }}",{{ end }}
|
||||
Expected: {{ .ExpectedString }},
|
||||
},
|
||||
{{ end }}
|
||||
},
|
||||
Logger: c.Config.Logger,
|
||||
NewRequest: func(opts []request.Option) (*request.Request, error) {
|
||||
var inCpy {{ .Operation.InputRef.GoType }}
|
||||
if input != nil {
|
||||
tmp := *input
|
||||
inCpy = &tmp
|
||||
}
|
||||
req, _ := c.{{ .OperationName }}Request(inCpy)
|
||||
req.SetContext(ctx)
|
||||
req.ApplyOptions(opts...)
|
||||
return req, nil
|
||||
},
|
||||
}
|
||||
w.ApplyOptions(opts...)
|
||||
|
||||
return w.WaitWithContext(ctx)
|
||||
}
|
||||
{{- end }}
|
||||
|
||||
{{ define "waiter interface" }}
|
||||
WaitUntil{{ .Name }}({{ .Operation.InputRef.GoTypeWithPkgName }}) error
|
||||
WaitUntil{{ .Name }}WithContext(aws.Context, {{ .Operation.InputRef.GoTypeWithPkgName }}, ...request.WaiterOption) error
|
||||
{{- end }}
|
||||
`))
|
||||
|
||||
// InterfaceSignature returns a string representing the Waiter's interface
|
||||
// function signature.
|
||||
func (w *Waiter) InterfaceSignature() string {
|
||||
var buf bytes.Buffer
|
||||
if err := waiterTmpls.ExecuteTemplate(&buf, "waiter interface", w); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return strings.TrimSpace(buf.String())
|
||||
}
|
||||
|
||||
// GoCode returns the generated Go code for an individual waiter.
|
||||
func (w *Waiter) GoCode() string {
|
||||
var buf bytes.Buffer
|
||||
if err := waiterTmpls.ExecuteTemplate(&buf, "waiter", w); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
29
vendor/github.com/aws/aws-sdk-go/private/model/cli/api-info/api-info.go
generated
vendored
29
vendor/github.com/aws/aws-sdk-go/private/model/cli/api-info/api-info.go
generated
vendored
|
@ -1,29 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
||||
"github.com/aws/aws-sdk-go/private/model/api"
|
||||
)
|
||||
|
||||
func main() {
|
||||
dir, _ := os.Open(filepath.Join("models", "apis"))
|
||||
names, _ := dir.Readdirnames(0)
|
||||
for _, name := range names {
|
||||
m, _ := filepath.Glob(filepath.Join("models", "apis", name, "*", "api-2.json"))
|
||||
if len(m) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
sort.Strings(m)
|
||||
f := m[len(m)-1]
|
||||
a := api.API{}
|
||||
a.Attach(f)
|
||||
fmt.Printf("%s\t%s\n", a.Metadata.ServiceFullName, a.Metadata.APIVersion)
|
||||
}
|
||||
}
|
315
vendor/github.com/aws/aws-sdk-go/private/model/cli/gen-api/main.go
generated
vendored
315
vendor/github.com/aws/aws-sdk-go/private/model/cli/gen-api/main.go
generated
vendored
|
@ -1,315 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
// Command aws-gen-gocli parses a JSON description of an AWS API and generates a
|
||||
// Go file containing a client for the API.
|
||||
//
|
||||
// aws-gen-gocli apis/s3/2006-03-03/api-2.json
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/debug"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/aws/aws-sdk-go/private/model/api"
|
||||
"github.com/aws/aws-sdk-go/private/util"
|
||||
)
|
||||
|
||||
type generateInfo struct {
|
||||
*api.API
|
||||
PackageDir string
|
||||
}
|
||||
|
||||
var excludeServices = map[string]struct{}{
|
||||
"importexport": {},
|
||||
}
|
||||
|
||||
// newGenerateInfo initializes the service API's folder structure for a specific service.
|
||||
// If the SERVICES environment variable is set, and this service is not apart of the list
|
||||
// this service will be skipped.
|
||||
func newGenerateInfo(modelFile, svcPath, svcImportPath string) *generateInfo {
|
||||
g := &generateInfo{API: &api.API{SvcClientImportPath: svcImportPath, BaseCrosslinkURL: "https://docs.aws.amazon.com"}}
|
||||
g.API.Attach(modelFile)
|
||||
|
||||
if _, ok := excludeServices[g.API.PackageName()]; ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
paginatorsFile := strings.Replace(modelFile, "api-2.json", "paginators-1.json", -1)
|
||||
if _, err := os.Stat(paginatorsFile); err == nil {
|
||||
g.API.AttachPaginators(paginatorsFile)
|
||||
} else if !os.IsNotExist(err) {
|
||||
fmt.Println("api-2.json error:", err)
|
||||
}
|
||||
|
||||
docsFile := strings.Replace(modelFile, "api-2.json", "docs-2.json", -1)
|
||||
if _, err := os.Stat(docsFile); err == nil {
|
||||
g.API.AttachDocs(docsFile)
|
||||
} else {
|
||||
fmt.Println("docs-2.json error:", err)
|
||||
}
|
||||
|
||||
waitersFile := strings.Replace(modelFile, "api-2.json", "waiters-2.json", -1)
|
||||
if _, err := os.Stat(waitersFile); err == nil {
|
||||
g.API.AttachWaiters(waitersFile)
|
||||
} else if !os.IsNotExist(err) {
|
||||
fmt.Println("waiters-2.json error:", err)
|
||||
}
|
||||
|
||||
examplesFile := strings.Replace(modelFile, "api-2.json", "examples-1.json", -1)
|
||||
if _, err := os.Stat(examplesFile); err == nil {
|
||||
g.API.AttachExamples(examplesFile)
|
||||
} else if !os.IsNotExist(err) {
|
||||
fmt.Println("examples-1.json error:", err)
|
||||
}
|
||||
|
||||
// pkgDocAddonsFile := strings.Replace(modelFile, "api-2.json", "go-pkg-doc.gotmpl", -1)
|
||||
// if _, err := os.Stat(pkgDocAddonsFile); err == nil {
|
||||
// g.API.AttachPackageDocAddons(pkgDocAddonsFile)
|
||||
// } else if !os.IsNotExist(err) {
|
||||
// fmt.Println("go-pkg-doc.gotmpl error:", err)
|
||||
// }
|
||||
|
||||
g.API.Setup()
|
||||
|
||||
if svc := os.Getenv("SERVICES"); svc != "" {
|
||||
svcs := strings.Split(svc, ",")
|
||||
|
||||
included := false
|
||||
for _, s := range svcs {
|
||||
if s == g.API.PackageName() {
|
||||
included = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !included {
|
||||
// skip this non-included service
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ensure the directory exists
|
||||
pkgDir := filepath.Join(svcPath, g.API.PackageName())
|
||||
os.MkdirAll(pkgDir, 0775)
|
||||
os.MkdirAll(filepath.Join(pkgDir, g.API.InterfacePackageName()), 0775)
|
||||
|
||||
g.PackageDir = pkgDir
|
||||
|
||||
return g
|
||||
}
|
||||
|
||||
// Generates service api, examples, and interface from api json definition files.
|
||||
//
|
||||
// Flags:
|
||||
// -path alternative service path to write generated files to for each service.
|
||||
//
|
||||
// Env:
|
||||
// SERVICES comma separated list of services to generate.
|
||||
func main() {
|
||||
var svcPath, sessionPath, svcImportPath string
|
||||
flag.StringVar(&svcPath, "path", "service", "directory to generate service clients in")
|
||||
flag.StringVar(&sessionPath, "sessionPath", filepath.Join("aws", "session"), "generate session service client factories")
|
||||
flag.StringVar(&svcImportPath, "svc-import-path", "github.com/aws/aws-sdk-go/service", "namespace to generate service client Go code import path under")
|
||||
flag.Parse()
|
||||
api.Bootstrap()
|
||||
|
||||
files := []string{}
|
||||
for i := 0; i < flag.NArg(); i++ {
|
||||
file := flag.Arg(i)
|
||||
if strings.Contains(file, "*") {
|
||||
paths, _ := filepath.Glob(file)
|
||||
files = append(files, paths...)
|
||||
} else {
|
||||
files = append(files, file)
|
||||
}
|
||||
}
|
||||
|
||||
for svcName := range excludeServices {
|
||||
if strings.Contains(os.Getenv("SERVICES"), svcName) {
|
||||
fmt.Fprintf(os.Stderr, "Service %s is not supported\n", svcName)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Strings(files)
|
||||
|
||||
// Remove old API versions from list
|
||||
m := map[string]bool{}
|
||||
// caches paths to ensure we are not overriding previously generated
|
||||
// code.
|
||||
servicePaths := map[string]struct{}{}
|
||||
|
||||
for i := range files {
|
||||
idx := len(files) - 1 - i
|
||||
parts := strings.Split(files[idx], string(filepath.Separator))
|
||||
svc := parts[len(parts)-3] // service name is 2nd-to-last component
|
||||
|
||||
if m[svc] {
|
||||
files[idx] = "" // wipe this one out if we already saw the service
|
||||
}
|
||||
m[svc] = true
|
||||
}
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
for i := range files {
|
||||
filename := files[i]
|
||||
if filename == "" { // empty file
|
||||
continue
|
||||
}
|
||||
|
||||
genInfo := newGenerateInfo(filename, svcPath, svcImportPath)
|
||||
if genInfo == nil {
|
||||
continue
|
||||
}
|
||||
if _, ok := excludeServices[genInfo.API.PackageName()]; ok {
|
||||
// Skip services not yet supported.
|
||||
continue
|
||||
}
|
||||
|
||||
if _, ok := servicePaths[genInfo.PackageDir]; ok {
|
||||
fmt.Fprintf(os.Stderr, "Path %q has already been generated", genInfo.PackageDir)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
servicePaths[genInfo.PackageDir] = struct{}{}
|
||||
|
||||
wg.Add(1)
|
||||
go func(g *generateInfo, filename string) {
|
||||
defer wg.Done()
|
||||
writeServiceFiles(g, filename)
|
||||
}(genInfo, filename)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func writeServiceFiles(g *generateInfo, filename string) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error generating %s\n%s\n%s\n",
|
||||
filename, r, debug.Stack())
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
|
||||
fmt.Printf("Generating %s (%s)...\n",
|
||||
g.API.PackageName(), g.API.Metadata.APIVersion)
|
||||
|
||||
// write files for service client and API
|
||||
Must(writeServiceDocFile(g))
|
||||
Must(writeAPIFile(g))
|
||||
Must(writeServiceFile(g))
|
||||
Must(writeInterfaceFile(g))
|
||||
Must(writeWaitersFile(g))
|
||||
Must(writeAPIErrorsFile(g))
|
||||
Must(writeExamplesFile(g))
|
||||
}
|
||||
|
||||
// Must will panic if the error passed in is not nil.
|
||||
func Must(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
const codeLayout = `// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
|
||||
|
||||
%s
|
||||
package %s
|
||||
|
||||
%s
|
||||
`
|
||||
|
||||
func writeGoFile(file string, layout string, args ...interface{}) error {
|
||||
return ioutil.WriteFile(file, []byte(util.GoFmt(fmt.Sprintf(layout, args...))), 0664)
|
||||
}
|
||||
|
||||
// writeServiceDocFile generates the documentation for service package.
|
||||
func writeServiceDocFile(g *generateInfo) error {
|
||||
return writeGoFile(filepath.Join(g.PackageDir, "doc.go"),
|
||||
codeLayout,
|
||||
strings.TrimSpace(g.API.ServicePackageDoc()),
|
||||
g.API.PackageName(),
|
||||
"",
|
||||
)
|
||||
}
|
||||
|
||||
// writeExamplesFile writes out the service example file.
|
||||
func writeExamplesFile(g *generateInfo) error {
|
||||
code := g.API.ExamplesGoCode()
|
||||
if len(code) > 0 {
|
||||
return writeGoFile(filepath.Join(g.PackageDir, "examples_test.go"),
|
||||
codeLayout,
|
||||
"",
|
||||
g.API.PackageName()+"_test",
|
||||
code,
|
||||
)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// writeServiceFile writes out the service initialization file.
|
||||
func writeServiceFile(g *generateInfo) error {
|
||||
return writeGoFile(filepath.Join(g.PackageDir, "service.go"),
|
||||
codeLayout,
|
||||
"",
|
||||
g.API.PackageName(),
|
||||
g.API.ServiceGoCode(),
|
||||
)
|
||||
}
|
||||
|
||||
// writeInterfaceFile writes out the service interface file.
|
||||
func writeInterfaceFile(g *generateInfo) error {
|
||||
const pkgDoc = `
|
||||
// Package %s provides an interface to enable mocking the %s service client
|
||||
// for testing your code.
|
||||
//
|
||||
// It is important to note that this interface will have breaking changes
|
||||
// when the service model is updated and adds new API operations, paginators,
|
||||
// and waiters.`
|
||||
return writeGoFile(filepath.Join(g.PackageDir, g.API.InterfacePackageName(), "interface.go"),
|
||||
codeLayout,
|
||||
fmt.Sprintf(pkgDoc, g.API.InterfacePackageName(), g.API.Metadata.ServiceFullName),
|
||||
g.API.InterfacePackageName(),
|
||||
g.API.InterfaceGoCode(),
|
||||
)
|
||||
}
|
||||
|
||||
func writeWaitersFile(g *generateInfo) error {
|
||||
if len(g.API.Waiters) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return writeGoFile(filepath.Join(g.PackageDir, "waiters.go"),
|
||||
codeLayout,
|
||||
"",
|
||||
g.API.PackageName(),
|
||||
g.API.WaitersGoCode(),
|
||||
)
|
||||
}
|
||||
|
||||
// writeAPIFile writes out the service API file.
|
||||
func writeAPIFile(g *generateInfo) error {
|
||||
return writeGoFile(filepath.Join(g.PackageDir, "api.go"),
|
||||
codeLayout,
|
||||
"",
|
||||
g.API.PackageName(),
|
||||
g.API.APIGoCode(),
|
||||
)
|
||||
}
|
||||
|
||||
// writeAPIErrorsFile writes out the service API errors file.
|
||||
func writeAPIErrorsFile(g *generateInfo) error {
|
||||
return writeGoFile(filepath.Join(g.PackageDir, "errors.go"),
|
||||
codeLayout,
|
||||
"",
|
||||
g.API.PackageName(),
|
||||
g.API.APIErrorsGoCode(),
|
||||
)
|
||||
}
|
56
vendor/github.com/aws/aws-sdk-go/private/model/cli/gen-endpoints/main.go
generated
vendored
56
vendor/github.com/aws/aws-sdk-go/private/model/cli/gen-endpoints/main.go
generated
vendored
|
@ -1,56 +0,0 @@
|
|||
// +build codegen
|
||||
|
||||
// Command gen-endpoints parses a JSON description of the AWS endpoint
|
||||
// discovery logic and generates a Go file which returns an endpoint.
|
||||
//
|
||||
// aws-gen-goendpoints apis/_endpoints.json aws/endpoints_map.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/endpoints"
|
||||
)
|
||||
|
||||
// Generates the endpoints from json description
|
||||
//
|
||||
// Args:
|
||||
// -model The definition file to use
|
||||
// -out The output file to generate
|
||||
func main() {
|
||||
var modelName, outName string
|
||||
flag.StringVar(&modelName, "model", "", "Endpoints definition model")
|
||||
flag.StringVar(&outName, "out", "", "File to write generated endpoints to.")
|
||||
flag.Parse()
|
||||
|
||||
if len(modelName) == 0 || len(outName) == 0 {
|
||||
exitErrorf("model and out both required.")
|
||||
}
|
||||
|
||||
modelFile, err := os.Open(modelName)
|
||||
if err != nil {
|
||||
exitErrorf("failed to open model definition, %v.", err)
|
||||
}
|
||||
defer modelFile.Close()
|
||||
|
||||
outFile, err := os.Create(outName)
|
||||
if err != nil {
|
||||
exitErrorf("failed to open out file, %v.", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := outFile.Close(); err != nil {
|
||||
exitErrorf("failed to successfully write %q file, %v", outName, err)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := endpoints.CodeGenModel(modelFile, outFile); err != nil {
|
||||
exitErrorf("failed to codegen model, %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func exitErrorf(msg string, args ...interface{}) {
|
||||
fmt.Fprintf(os.Stderr, msg+"\n", args...)
|
||||
os.Exit(1)
|
||||
}
|
35
vendor/github.com/aws/aws-sdk-go/private/protocol/ec2query/build.go
generated
vendored
35
vendor/github.com/aws/aws-sdk-go/private/protocol/ec2query/build.go
generated
vendored
|
@ -1,35 +0,0 @@
|
|||
// Package ec2query provides serialization of AWS EC2 requests and responses.
|
||||
package ec2query
|
||||
|
||||
//go:generate go run -tags codegen ../../../models/protocol_tests/generate.go ../../../models/protocol_tests/input/ec2.json build_test.go
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/query/queryutil"
|
||||
)
|
||||
|
||||
// BuildHandler is a named request handler for building ec2query protocol requests
|
||||
var BuildHandler = request.NamedHandler{Name: "awssdk.ec2query.Build", Fn: Build}
|
||||
|
||||
// Build builds a request for the EC2 protocol.
|
||||
func Build(r *request.Request) {
|
||||
body := url.Values{
|
||||
"Action": {r.Operation.Name},
|
||||
"Version": {r.ClientInfo.APIVersion},
|
||||
}
|
||||
if err := queryutil.Parse(body, r.Params, true); err != nil {
|
||||
r.Error = awserr.New("SerializationError", "failed encoding EC2 Query request", err)
|
||||
}
|
||||
|
||||
if !r.IsPresigned() {
|
||||
r.HTTPRequest.Method = "POST"
|
||||
r.HTTPRequest.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
|
||||
r.SetBufferBody([]byte(body.Encode()))
|
||||
} else { // This is a pre-signed request
|
||||
r.HTTPRequest.Method = "GET"
|
||||
r.HTTPRequest.URL.RawQuery = body.Encode()
|
||||
}
|
||||
}
|
85
vendor/github.com/aws/aws-sdk-go/private/protocol/ec2query/build_bench_test.go
generated
vendored
85
vendor/github.com/aws/aws-sdk-go/private/protocol/ec2query/build_bench_test.go
generated
vendored
|
@ -1,85 +0,0 @@
|
|||
// +build bench
|
||||
|
||||
package ec2query_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/awstesting"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/ec2query"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
)
|
||||
|
||||
func BenchmarkEC2QueryBuild_Complex_ec2AuthorizeSecurityGroupEgress(b *testing.B) {
|
||||
params := &ec2.AuthorizeSecurityGroupEgressInput{
|
||||
GroupId: aws.String("String"), // Required
|
||||
CidrIp: aws.String("String"),
|
||||
DryRun: aws.Bool(true),
|
||||
FromPort: aws.Int64(1),
|
||||
IpPermissions: []*ec2.IpPermission{
|
||||
{ // Required
|
||||
FromPort: aws.Int64(1),
|
||||
IpProtocol: aws.String("String"),
|
||||
IpRanges: []*ec2.IpRange{
|
||||
{ // Required
|
||||
CidrIp: aws.String("String"),
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
PrefixListIds: []*ec2.PrefixListId{
|
||||
{ // Required
|
||||
PrefixListId: aws.String("String"),
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
ToPort: aws.Int64(1),
|
||||
UserIdGroupPairs: []*ec2.UserIdGroupPair{
|
||||
{ // Required
|
||||
GroupId: aws.String("String"),
|
||||
GroupName: aws.String("String"),
|
||||
UserId: aws.String("String"),
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
IpProtocol: aws.String("String"),
|
||||
SourceSecurityGroupName: aws.String("String"),
|
||||
SourceSecurityGroupOwnerId: aws.String("String"),
|
||||
ToPort: aws.Int64(1),
|
||||
}
|
||||
|
||||
benchEC2QueryBuild(b, "AuthorizeSecurityGroupEgress", params)
|
||||
}
|
||||
|
||||
func BenchmarkEC2QueryBuild_Simple_ec2AttachNetworkInterface(b *testing.B) {
|
||||
params := &ec2.AttachNetworkInterfaceInput{
|
||||
DeviceIndex: aws.Int64(1), // Required
|
||||
InstanceId: aws.String("String"), // Required
|
||||
NetworkInterfaceId: aws.String("String"), // Required
|
||||
DryRun: aws.Bool(true),
|
||||
}
|
||||
|
||||
benchEC2QueryBuild(b, "AttachNetworkInterface", params)
|
||||
}
|
||||
|
||||
func benchEC2QueryBuild(b *testing.B, opName string, params interface{}) {
|
||||
svc := awstesting.NewClient()
|
||||
svc.ServiceName = "ec2"
|
||||
svc.APIVersion = "2015-04-15"
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
r := svc.NewRequest(&request.Operation{
|
||||
Name: opName,
|
||||
HTTPMethod: "POST",
|
||||
HTTPPath: "/",
|
||||
}, params, nil)
|
||||
ec2query.Build(r)
|
||||
if r.Error != nil {
|
||||
b.Fatal("Unexpected error", r.Error)
|
||||
}
|
||||
}
|
||||
}
|
2102
vendor/github.com/aws/aws-sdk-go/private/protocol/ec2query/build_test.go
generated
vendored
2102
vendor/github.com/aws/aws-sdk-go/private/protocol/ec2query/build_test.go
generated
vendored
File diff suppressed because it is too large
Load diff
63
vendor/github.com/aws/aws-sdk-go/private/protocol/ec2query/unmarshal.go
generated
vendored
63
vendor/github.com/aws/aws-sdk-go/private/protocol/ec2query/unmarshal.go
generated
vendored
|
@ -1,63 +0,0 @@
|
|||
package ec2query
|
||||
|
||||
//go:generate go run -tags codegen ../../../models/protocol_tests/generate.go ../../../models/protocol_tests/output/ec2.json unmarshal_test.go
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"io"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil"
|
||||
)
|
||||
|
||||
// UnmarshalHandler is a named request handler for unmarshaling ec2query protocol requests
|
||||
var UnmarshalHandler = request.NamedHandler{Name: "awssdk.ec2query.Unmarshal", Fn: Unmarshal}
|
||||
|
||||
// UnmarshalMetaHandler is a named request handler for unmarshaling ec2query protocol request metadata
|
||||
var UnmarshalMetaHandler = request.NamedHandler{Name: "awssdk.ec2query.UnmarshalMeta", Fn: UnmarshalMeta}
|
||||
|
||||
// UnmarshalErrorHandler is a named request handler for unmarshaling ec2query protocol request errors
|
||||
var UnmarshalErrorHandler = request.NamedHandler{Name: "awssdk.ec2query.UnmarshalError", Fn: UnmarshalError}
|
||||
|
||||
// Unmarshal unmarshals a response body for the EC2 protocol.
|
||||
func Unmarshal(r *request.Request) {
|
||||
defer r.HTTPResponse.Body.Close()
|
||||
if r.DataFilled() {
|
||||
decoder := xml.NewDecoder(r.HTTPResponse.Body)
|
||||
err := xmlutil.UnmarshalXML(r.Data, decoder, "")
|
||||
if err != nil {
|
||||
r.Error = awserr.New("SerializationError", "failed decoding EC2 Query response", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalMeta unmarshals response headers for the EC2 protocol.
|
||||
func UnmarshalMeta(r *request.Request) {
|
||||
// TODO implement unmarshaling of request IDs
|
||||
}
|
||||
|
||||
type xmlErrorResponse struct {
|
||||
XMLName xml.Name `xml:"Response"`
|
||||
Code string `xml:"Errors>Error>Code"`
|
||||
Message string `xml:"Errors>Error>Message"`
|
||||
RequestID string `xml:"RequestID"`
|
||||
}
|
||||
|
||||
// UnmarshalError unmarshals a response error for the EC2 protocol.
|
||||
func UnmarshalError(r *request.Request) {
|
||||
defer r.HTTPResponse.Body.Close()
|
||||
|
||||
resp := &xmlErrorResponse{}
|
||||
err := xml.NewDecoder(r.HTTPResponse.Body).Decode(resp)
|
||||
if err != nil && err != io.EOF {
|
||||
r.Error = awserr.New("SerializationError", "failed decoding EC2 Query error response", err)
|
||||
} else {
|
||||
r.Error = awserr.NewRequestFailure(
|
||||
awserr.New(resp.Code, resp.Message, nil),
|
||||
r.HTTPResponse.StatusCode,
|
||||
resp.RequestID,
|
||||
)
|
||||
}
|
||||
}
|
1879
vendor/github.com/aws/aws-sdk-go/private/protocol/ec2query/unmarshal_test.go
generated
vendored
1879
vendor/github.com/aws/aws-sdk-go/private/protocol/ec2query/unmarshal_test.go
generated
vendored
File diff suppressed because it is too large
Load diff
144
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/debug.go
generated
vendored
144
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/debug.go
generated
vendored
|
@ -1,144 +0,0 @@
|
|||
package eventstream
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type decodedMessage struct {
|
||||
rawMessage
|
||||
Headers decodedHeaders `json:"headers"`
|
||||
}
|
||||
type jsonMessage struct {
|
||||
Length json.Number `json:"total_length"`
|
||||
HeadersLen json.Number `json:"headers_length"`
|
||||
PreludeCRC json.Number `json:"prelude_crc"`
|
||||
Headers decodedHeaders `json:"headers"`
|
||||
Payload []byte `json:"payload"`
|
||||
CRC json.Number `json:"message_crc"`
|
||||
}
|
||||
|
||||
func (d *decodedMessage) UnmarshalJSON(b []byte) (err error) {
|
||||
var jsonMsg jsonMessage
|
||||
if err = json.Unmarshal(b, &jsonMsg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.Length, err = numAsUint32(jsonMsg.Length)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.HeadersLen, err = numAsUint32(jsonMsg.HeadersLen)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.PreludeCRC, err = numAsUint32(jsonMsg.PreludeCRC)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.Headers = jsonMsg.Headers
|
||||
d.Payload = jsonMsg.Payload
|
||||
d.CRC, err = numAsUint32(jsonMsg.CRC)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *decodedMessage) MarshalJSON() ([]byte, error) {
|
||||
jsonMsg := jsonMessage{
|
||||
Length: json.Number(strconv.Itoa(int(d.Length))),
|
||||
HeadersLen: json.Number(strconv.Itoa(int(d.HeadersLen))),
|
||||
PreludeCRC: json.Number(strconv.Itoa(int(d.PreludeCRC))),
|
||||
Headers: d.Headers,
|
||||
Payload: d.Payload,
|
||||
CRC: json.Number(strconv.Itoa(int(d.CRC))),
|
||||
}
|
||||
|
||||
return json.Marshal(jsonMsg)
|
||||
}
|
||||
|
||||
func numAsUint32(n json.Number) (uint32, error) {
|
||||
v, err := n.Int64()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to get int64 json number, %v", err)
|
||||
}
|
||||
|
||||
return uint32(v), nil
|
||||
}
|
||||
|
||||
func (d decodedMessage) Message() Message {
|
||||
return Message{
|
||||
Headers: Headers(d.Headers),
|
||||
Payload: d.Payload,
|
||||
}
|
||||
}
|
||||
|
||||
type decodedHeaders Headers
|
||||
|
||||
func (hs *decodedHeaders) UnmarshalJSON(b []byte) error {
|
||||
var jsonHeaders []struct {
|
||||
Name string `json:"name"`
|
||||
Type valueType `json:"type"`
|
||||
Value interface{} `json:"value"`
|
||||
}
|
||||
|
||||
decoder := json.NewDecoder(bytes.NewReader(b))
|
||||
decoder.UseNumber()
|
||||
if err := decoder.Decode(&jsonHeaders); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var headers Headers
|
||||
for _, h := range jsonHeaders {
|
||||
value, err := valueFromType(h.Type, h.Value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
headers.Set(h.Name, value)
|
||||
}
|
||||
(*hs) = decodedHeaders(headers)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func valueFromType(typ valueType, val interface{}) (Value, error) {
|
||||
switch typ {
|
||||
case trueValueType:
|
||||
return BoolValue(true), nil
|
||||
case falseValueType:
|
||||
return BoolValue(false), nil
|
||||
case int8ValueType:
|
||||
v, err := val.(json.Number).Int64()
|
||||
return Int8Value(int8(v)), err
|
||||
case int16ValueType:
|
||||
v, err := val.(json.Number).Int64()
|
||||
return Int16Value(int16(v)), err
|
||||
case int32ValueType:
|
||||
v, err := val.(json.Number).Int64()
|
||||
return Int32Value(int32(v)), err
|
||||
case int64ValueType:
|
||||
v, err := val.(json.Number).Int64()
|
||||
return Int64Value(v), err
|
||||
case bytesValueType:
|
||||
v, err := base64.StdEncoding.DecodeString(val.(string))
|
||||
return BytesValue(v), err
|
||||
case stringValueType:
|
||||
v, err := base64.StdEncoding.DecodeString(val.(string))
|
||||
return StringValue(string(v)), err
|
||||
case timestampValueType:
|
||||
v, err := val.(json.Number).Int64()
|
||||
return TimestampValue(timeFromEpochMilli(v)), err
|
||||
case uuidValueType:
|
||||
v, err := base64.StdEncoding.DecodeString(val.(string))
|
||||
var tv UUIDValue
|
||||
copy(tv[:], v)
|
||||
return tv, err
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown type, %s, %T", typ.String(), val))
|
||||
}
|
||||
}
|
199
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/decode.go
generated
vendored
199
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/decode.go
generated
vendored
|
@ -1,199 +0,0 @@
|
|||
package eventstream
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"hash"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
)
|
||||
|
||||
// Decoder provides decoding of an Event Stream messages.
|
||||
type Decoder struct {
|
||||
r io.Reader
|
||||
logger aws.Logger
|
||||
}
|
||||
|
||||
// NewDecoder initializes and returns a Decoder for decoding event
|
||||
// stream messages from the reader provided.
|
||||
func NewDecoder(r io.Reader) *Decoder {
|
||||
return &Decoder{
|
||||
r: r,
|
||||
}
|
||||
}
|
||||
|
||||
// Decode attempts to decode a single message from the event stream reader.
|
||||
// Will return the event stream message, or error if Decode fails to read
|
||||
// the message from the stream.
|
||||
func (d *Decoder) Decode(payloadBuf []byte) (m Message, err error) {
|
||||
reader := d.r
|
||||
if d.logger != nil {
|
||||
debugMsgBuf := bytes.NewBuffer(nil)
|
||||
reader = io.TeeReader(reader, debugMsgBuf)
|
||||
defer func() {
|
||||
logMessageDecode(d.logger, debugMsgBuf, m, err)
|
||||
}()
|
||||
}
|
||||
|
||||
crc := crc32.New(crc32IEEETable)
|
||||
hashReader := io.TeeReader(reader, crc)
|
||||
|
||||
prelude, err := decodePrelude(hashReader, crc)
|
||||
if err != nil {
|
||||
return Message{}, err
|
||||
}
|
||||
|
||||
if prelude.HeadersLen > 0 {
|
||||
lr := io.LimitReader(hashReader, int64(prelude.HeadersLen))
|
||||
m.Headers, err = decodeHeaders(lr)
|
||||
if err != nil {
|
||||
return Message{}, err
|
||||
}
|
||||
}
|
||||
|
||||
if payloadLen := prelude.PayloadLen(); payloadLen > 0 {
|
||||
buf, err := decodePayload(payloadBuf, io.LimitReader(hashReader, int64(payloadLen)))
|
||||
if err != nil {
|
||||
return Message{}, err
|
||||
}
|
||||
m.Payload = buf
|
||||
}
|
||||
|
||||
msgCRC := crc.Sum32()
|
||||
if err := validateCRC(reader, msgCRC); err != nil {
|
||||
return Message{}, err
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// UseLogger specifies the Logger that that the decoder should use to log the
|
||||
// message decode to.
|
||||
func (d *Decoder) UseLogger(logger aws.Logger) {
|
||||
d.logger = logger
|
||||
}
|
||||
|
||||
func logMessageDecode(logger aws.Logger, msgBuf *bytes.Buffer, msg Message, decodeErr error) {
|
||||
w := bytes.NewBuffer(nil)
|
||||
defer func() { logger.Log(w.String()) }()
|
||||
|
||||
fmt.Fprintf(w, "Raw message:\n%s\n",
|
||||
hex.Dump(msgBuf.Bytes()))
|
||||
|
||||
if decodeErr != nil {
|
||||
fmt.Fprintf(w, "Decode error: %v\n", decodeErr)
|
||||
return
|
||||
}
|
||||
|
||||
rawMsg, err := msg.rawMessage()
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "failed to create raw message, %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
decodedMsg := decodedMessage{
|
||||
rawMessage: rawMsg,
|
||||
Headers: decodedHeaders(msg.Headers),
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "Decoded message:\n")
|
||||
encoder := json.NewEncoder(w)
|
||||
if err := encoder.Encode(decodedMsg); err != nil {
|
||||
fmt.Fprintf(w, "failed to generate decoded message, %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
func decodePrelude(r io.Reader, crc hash.Hash32) (messagePrelude, error) {
|
||||
var p messagePrelude
|
||||
|
||||
var err error
|
||||
p.Length, err = decodeUint32(r)
|
||||
if err != nil {
|
||||
return messagePrelude{}, err
|
||||
}
|
||||
|
||||
p.HeadersLen, err = decodeUint32(r)
|
||||
if err != nil {
|
||||
return messagePrelude{}, err
|
||||
}
|
||||
|
||||
if err := p.ValidateLens(); err != nil {
|
||||
return messagePrelude{}, err
|
||||
}
|
||||
|
||||
preludeCRC := crc.Sum32()
|
||||
if err := validateCRC(r, preludeCRC); err != nil {
|
||||
return messagePrelude{}, err
|
||||
}
|
||||
|
||||
p.PreludeCRC = preludeCRC
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func decodePayload(buf []byte, r io.Reader) ([]byte, error) {
|
||||
w := bytes.NewBuffer(buf[0:0])
|
||||
|
||||
_, err := io.Copy(w, r)
|
||||
return w.Bytes(), err
|
||||
}
|
||||
|
||||
func decodeUint8(r io.Reader) (uint8, error) {
|
||||
type byteReader interface {
|
||||
ReadByte() (byte, error)
|
||||
}
|
||||
|
||||
if br, ok := r.(byteReader); ok {
|
||||
v, err := br.ReadByte()
|
||||
return uint8(v), err
|
||||
}
|
||||
|
||||
var b [1]byte
|
||||
_, err := io.ReadFull(r, b[:])
|
||||
return uint8(b[0]), err
|
||||
}
|
||||
func decodeUint16(r io.Reader) (uint16, error) {
|
||||
var b [2]byte
|
||||
bs := b[:]
|
||||
_, err := io.ReadFull(r, bs)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return binary.BigEndian.Uint16(bs), nil
|
||||
}
|
||||
func decodeUint32(r io.Reader) (uint32, error) {
|
||||
var b [4]byte
|
||||
bs := b[:]
|
||||
_, err := io.ReadFull(r, bs)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return binary.BigEndian.Uint32(bs), nil
|
||||
}
|
||||
func decodeUint64(r io.Reader) (uint64, error) {
|
||||
var b [8]byte
|
||||
bs := b[:]
|
||||
_, err := io.ReadFull(r, bs)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return binary.BigEndian.Uint64(bs), nil
|
||||
}
|
||||
|
||||
func validateCRC(r io.Reader, expect uint32) error {
|
||||
msgCRC, err := decodeUint32(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if msgCRC != expect {
|
||||
return ChecksumError{}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
168
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/decode_test.go
generated
vendored
168
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/decode_test.go
generated
vendored
|
@ -1,168 +0,0 @@
|
|||
package eventstream
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWriteEncodedFromDecoded(t *testing.T) {
|
||||
cases, err := readPositiveTests("testdata")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to load positive tests, %v", err)
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
f, err := os.Create(filepath.Join("testdata", "encoded", "positive", c.Name))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open %q, %v", c.Name, err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
encoder := NewEncoder(f)
|
||||
|
||||
msg := c.Decoded.Message()
|
||||
if err := encoder.Encode(msg); err != nil {
|
||||
t.Errorf("failed to encode %q, %v", c.Name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecoder_Decode(t *testing.T) {
|
||||
cases, err := readPositiveTests("testdata")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to load positive tests, %v", err)
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
decoder := NewDecoder(bytes.NewBuffer(c.Encoded))
|
||||
|
||||
msg, err := decoder.Decode(nil)
|
||||
if err != nil {
|
||||
t.Fatalf("%s, expect no decode error, got %v", c.Name, err)
|
||||
}
|
||||
|
||||
raw, err := msg.rawMessage() // rawMessage will fail if payload read CRC fails
|
||||
if err != nil {
|
||||
t.Fatalf("%s, failed to get raw decoded message %v", c.Name, err)
|
||||
}
|
||||
|
||||
if e, a := c.Decoded.Length, raw.Length; e != a {
|
||||
t.Errorf("%s, expect %v length, got %v", c.Name, e, a)
|
||||
}
|
||||
if e, a := c.Decoded.HeadersLen, raw.HeadersLen; e != a {
|
||||
t.Errorf("%s, expect %v HeadersLen, got %v", c.Name, e, a)
|
||||
}
|
||||
if e, a := c.Decoded.PreludeCRC, raw.PreludeCRC; e != a {
|
||||
t.Errorf("%s, expect %v PreludeCRC, got %v", c.Name, e, a)
|
||||
}
|
||||
if e, a := Headers(c.Decoded.Headers), msg.Headers; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("%s, expect %v headers, got %v", c.Name, e, a)
|
||||
}
|
||||
if e, a := c.Decoded.Payload, raw.Payload; !bytes.Equal(e, a) {
|
||||
t.Errorf("%s, expect %v payload, got %v", c.Name, e, a)
|
||||
}
|
||||
if e, a := c.Decoded.CRC, raw.CRC; e != a {
|
||||
t.Errorf("%s, expect %v CRC, got %v", c.Name, e, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecoder_Decode_Negative(t *testing.T) {
|
||||
cases, err := readNegativeTests("testdata")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to load negative tests, %v", err)
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
decoder := NewDecoder(bytes.NewBuffer(c.Encoded))
|
||||
|
||||
msg, err := decoder.Decode(nil)
|
||||
if err == nil {
|
||||
rawMsg, rawMsgErr := msg.rawMessage()
|
||||
t.Fatalf("%s, expect error, got none, %s,\n%s\n%#v, %v\n", c.Name,
|
||||
c.Err, hex.Dump(c.Encoded), rawMsg, rawMsgErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var testEncodedMsg = []byte{0, 0, 0, 61, 0, 0, 0, 32, 7, 253, 131, 150, 12, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101, 7, 0, 16, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 106, 115, 111, 110, 123, 39, 102, 111, 111, 39, 58, 39, 98, 97, 114, 39, 125, 141, 156, 8, 177}
|
||||
|
||||
func TestDecoder_DecodeMultipleMessages(t *testing.T) {
|
||||
const (
|
||||
expectMsgCount = 10
|
||||
expectPayloadLen = 13
|
||||
)
|
||||
|
||||
r := bytes.NewBuffer(nil)
|
||||
for i := 0; i < expectMsgCount; i++ {
|
||||
r.Write(testEncodedMsg)
|
||||
}
|
||||
|
||||
decoder := NewDecoder(r)
|
||||
|
||||
var err error
|
||||
var msg Message
|
||||
var count int
|
||||
for {
|
||||
msg, err = decoder.Decode(nil)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
count++
|
||||
|
||||
if e, a := expectPayloadLen, len(msg.Payload); e != a {
|
||||
t.Errorf("expect %v payload len, got %v", e, a)
|
||||
}
|
||||
|
||||
if e, a := []byte(`{'foo':'bar'}`), msg.Payload; !bytes.Equal(e, a) {
|
||||
t.Errorf("expect %v payload, got %v", e, a)
|
||||
}
|
||||
}
|
||||
|
||||
type causer interface {
|
||||
Cause() error
|
||||
}
|
||||
if err != nil && count != expectMsgCount {
|
||||
t.Fatalf("expect, no error, got %v", err)
|
||||
}
|
||||
|
||||
if e, a := expectMsgCount, count; e != a {
|
||||
t.Errorf("expect %v messages read, got %v", e, a)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDecode(b *testing.B) {
|
||||
r := bytes.NewReader(testEncodedMsg)
|
||||
decoder := NewDecoder(r)
|
||||
payloadBuf := make([]byte, 0, 5*1024)
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
msg, err := decoder.Decode(payloadBuf)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
// Release the payload buffer
|
||||
payloadBuf = msg.Payload[0:0]
|
||||
r.Seek(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDecode_NoPayloadBuf(b *testing.B) {
|
||||
r := bytes.NewReader(testEncodedMsg)
|
||||
decoder := NewDecoder(r)
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := decoder.Decode(nil)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
r.Seek(0, 0)
|
||||
}
|
||||
}
|
114
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/encode.go
generated
vendored
114
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/encode.go
generated
vendored
|
@ -1,114 +0,0 @@
|
|||
package eventstream
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"hash"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Encoder provides EventStream message encoding.
|
||||
type Encoder struct {
|
||||
w io.Writer
|
||||
|
||||
headersBuf *bytes.Buffer
|
||||
}
|
||||
|
||||
// NewEncoder initializes and returns an Encoder to encode Event Stream
|
||||
// messages to an io.Writer.
|
||||
func NewEncoder(w io.Writer) *Encoder {
|
||||
return &Encoder{
|
||||
w: w,
|
||||
headersBuf: bytes.NewBuffer(nil),
|
||||
}
|
||||
}
|
||||
|
||||
// Encode encodes a single EventStream message to the io.Writer the Encoder
|
||||
// was created with. An error is returned if writing the message fails.
|
||||
func (e *Encoder) Encode(msg Message) error {
|
||||
e.headersBuf.Reset()
|
||||
|
||||
err := encodeHeaders(e.headersBuf, msg.Headers)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
crc := crc32.New(crc32IEEETable)
|
||||
hashWriter := io.MultiWriter(e.w, crc)
|
||||
|
||||
headersLen := uint32(e.headersBuf.Len())
|
||||
payloadLen := uint32(len(msg.Payload))
|
||||
|
||||
if err := encodePrelude(hashWriter, crc, headersLen, payloadLen); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if headersLen > 0 {
|
||||
if _, err := io.Copy(hashWriter, e.headersBuf); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if payloadLen > 0 {
|
||||
if _, err := hashWriter.Write(msg.Payload); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
msgCRC := crc.Sum32()
|
||||
return binary.Write(e.w, binary.BigEndian, msgCRC)
|
||||
}
|
||||
|
||||
func encodePrelude(w io.Writer, crc hash.Hash32, headersLen, payloadLen uint32) error {
|
||||
p := messagePrelude{
|
||||
Length: minMsgLen + headersLen + payloadLen,
|
||||
HeadersLen: headersLen,
|
||||
}
|
||||
if err := p.ValidateLens(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := binaryWriteFields(w, binary.BigEndian,
|
||||
p.Length,
|
||||
p.HeadersLen,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.PreludeCRC = crc.Sum32()
|
||||
err = binary.Write(w, binary.BigEndian, p.PreludeCRC)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func encodeHeaders(w io.Writer, headers Headers) error {
|
||||
for _, h := range headers {
|
||||
hn := headerName{
|
||||
Len: uint8(len(h.Name)),
|
||||
}
|
||||
copy(hn.Name[:hn.Len], h.Name)
|
||||
if err := hn.encode(w); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := h.Value.encode(w); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func binaryWriteFields(w io.Writer, order binary.ByteOrder, vs ...interface{}) error {
|
||||
for _, v := range vs {
|
||||
if err := binary.Write(w, order, v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
50
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/encode_test.go
generated
vendored
50
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/encode_test.go
generated
vendored
|
@ -1,50 +0,0 @@
|
|||
package eventstream
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEncoder_Encode(t *testing.T) {
|
||||
cases, err := readPositiveTests("testdata")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to load positive tests, %v", err)
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
var w bytes.Buffer
|
||||
encoder := NewEncoder(&w)
|
||||
|
||||
err = encoder.Encode(c.Decoded.Message())
|
||||
if err != nil {
|
||||
t.Fatalf("%s, failed to encode message, %v", c.Name, err)
|
||||
}
|
||||
|
||||
if e, a := c.Encoded, w.Bytes(); !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("%s, expect:\n%v\nactual:\n%v\n", c.Name,
|
||||
hex.Dump(e), hex.Dump(a))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEncode(b *testing.B) {
|
||||
var w bytes.Buffer
|
||||
encoder := NewEncoder(&w)
|
||||
msg := Message{
|
||||
Headers: Headers{
|
||||
{Name: "event-id", Value: Int16Value(123)},
|
||||
},
|
||||
Payload: []byte(`{"abc":123}`),
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
err := encoder.Encode(msg)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
23
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/error.go
generated
vendored
23
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/error.go
generated
vendored
|
@ -1,23 +0,0 @@
|
|||
package eventstream
|
||||
|
||||
import "fmt"
|
||||
|
||||
// LengthError provides the error for items being larger than a maximum length.
|
||||
type LengthError struct {
|
||||
Part string
|
||||
Want int
|
||||
Have int
|
||||
Value interface{}
|
||||
}
|
||||
|
||||
func (e LengthError) Error() string {
|
||||
return fmt.Sprintf("%s length invalid, %d/%d, %v",
|
||||
e.Part, e.Want, e.Have, e.Value)
|
||||
}
|
||||
|
||||
// ChecksumError provides the error for message checksum invalidation errors.
|
||||
type ChecksumError struct{}
|
||||
|
||||
func (e ChecksumError) Error() string {
|
||||
return "message checksum mismatch"
|
||||
}
|
160
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/eventstreamapi/api.go
generated
vendored
160
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/eventstreamapi/api.go
generated
vendored
|
@ -1,160 +0,0 @@
|
|||
package eventstreamapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/private/protocol"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/eventstream"
|
||||
)
|
||||
|
||||
// Unmarshaler provides the interface for unmarshaling a EventStream
|
||||
// message into a SDK type.
|
||||
type Unmarshaler interface {
|
||||
UnmarshalEvent(protocol.PayloadUnmarshaler, eventstream.Message) error
|
||||
}
|
||||
|
||||
// EventStream headers with specific meaning to async API functionality.
|
||||
const (
|
||||
MessageTypeHeader = `:message-type` // Identifies type of message.
|
||||
EventMessageType = `event`
|
||||
ErrorMessageType = `error`
|
||||
ExceptionMessageType = `exception`
|
||||
|
||||
// Message Events
|
||||
EventTypeHeader = `:event-type` // Identifies message event type e.g. "Stats".
|
||||
|
||||
// Message Error
|
||||
ErrorCodeHeader = `:error-code`
|
||||
ErrorMessageHeader = `:error-message`
|
||||
|
||||
// Message Exception
|
||||
ExceptionTypeHeader = `:exception-type`
|
||||
)
|
||||
|
||||
// EventReader provides reading from the EventStream of an reader.
|
||||
type EventReader struct {
|
||||
reader io.ReadCloser
|
||||
decoder *eventstream.Decoder
|
||||
|
||||
unmarshalerForEventType func(string) (Unmarshaler, error)
|
||||
payloadUnmarshaler protocol.PayloadUnmarshaler
|
||||
|
||||
payloadBuf []byte
|
||||
}
|
||||
|
||||
// NewEventReader returns a EventReader built from the reader and unmarshaler
|
||||
// provided. Use ReadStream method to start reading from the EventStream.
|
||||
func NewEventReader(
|
||||
reader io.ReadCloser,
|
||||
payloadUnmarshaler protocol.PayloadUnmarshaler,
|
||||
unmarshalerForEventType func(string) (Unmarshaler, error),
|
||||
) *EventReader {
|
||||
return &EventReader{
|
||||
reader: reader,
|
||||
decoder: eventstream.NewDecoder(reader),
|
||||
payloadUnmarshaler: payloadUnmarshaler,
|
||||
unmarshalerForEventType: unmarshalerForEventType,
|
||||
payloadBuf: make([]byte, 10*1024),
|
||||
}
|
||||
}
|
||||
|
||||
// UseLogger instructs the EventReader to use the logger and log level
|
||||
// specified.
|
||||
func (r *EventReader) UseLogger(logger aws.Logger, logLevel aws.LogLevelType) {
|
||||
if logger != nil && logLevel.Matches(aws.LogDebugWithEventStreamBody) {
|
||||
r.decoder.UseLogger(logger)
|
||||
}
|
||||
}
|
||||
|
||||
// ReadEvent attempts to read a message from the EventStream and return the
|
||||
// unmarshaled event value that the message is for.
|
||||
//
|
||||
// For EventStream API errors check if the returned error satisfies the
|
||||
// awserr.Error interface to get the error's Code and Message components.
|
||||
//
|
||||
// EventUnmarshalers called with EventStream messages must take copies of the
|
||||
// message's Payload. The payload will is reused between events read.
|
||||
func (r *EventReader) ReadEvent() (event interface{}, err error) {
|
||||
msg, err := r.decoder.Decode(r.payloadBuf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
// Reclaim payload buffer for next message read.
|
||||
r.payloadBuf = msg.Payload[0:0]
|
||||
}()
|
||||
|
||||
typ, err := GetHeaderString(msg, MessageTypeHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch typ {
|
||||
case EventMessageType:
|
||||
return r.unmarshalEventMessage(msg)
|
||||
case ErrorMessageType:
|
||||
return nil, r.unmarshalErrorMessage(msg)
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown eventstream message type, %v", typ)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *EventReader) unmarshalEventMessage(
|
||||
msg eventstream.Message,
|
||||
) (event interface{}, err error) {
|
||||
eventType, err := GetHeaderString(msg, EventTypeHeader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ev, err := r.unmarshalerForEventType(eventType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = ev.UnmarshalEvent(r.payloadUnmarshaler, msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ev, nil
|
||||
}
|
||||
|
||||
func (r *EventReader) unmarshalErrorMessage(msg eventstream.Message) (err error) {
|
||||
var msgErr messageError
|
||||
|
||||
msgErr.code, err = GetHeaderString(msg, ErrorCodeHeader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msgErr.msg, err = GetHeaderString(msg, ErrorMessageHeader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return msgErr
|
||||
}
|
||||
|
||||
// Close closes the EventReader's EventStream reader.
|
||||
func (r *EventReader) Close() error {
|
||||
return r.reader.Close()
|
||||
}
|
||||
|
||||
// GetHeaderString returns the value of the header as a string. If the header
|
||||
// is not set or the value is not a string an error will be returned.
|
||||
func GetHeaderString(msg eventstream.Message, headerName string) (string, error) {
|
||||
headerVal := msg.Headers.Get(headerName)
|
||||
if headerVal == nil {
|
||||
return "", fmt.Errorf("error header %s not present", headerName)
|
||||
}
|
||||
|
||||
v, ok := headerVal.Get().(string)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("error header value is not a string, %T", headerVal)
|
||||
}
|
||||
|
||||
return v, nil
|
||||
}
|
197
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/eventstreamapi/api_test.go
generated
vendored
197
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/eventstreamapi/api_test.go
generated
vendored
|
@ -1,197 +0,0 @@
|
|||
package eventstreamapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/private/protocol"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/eventstream"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/restjson"
|
||||
)
|
||||
|
||||
var eventMessageTypeHeader = eventstream.Header{
|
||||
Name: MessageTypeHeader,
|
||||
Value: eventstream.StringValue(EventMessageType),
|
||||
}
|
||||
|
||||
func TestEventReader(t *testing.T) {
|
||||
stream := createStream(
|
||||
eventstream.Message{
|
||||
Headers: eventstream.Headers{
|
||||
eventMessageTypeHeader,
|
||||
eventstream.Header{
|
||||
Name: EventTypeHeader,
|
||||
Value: eventstream.StringValue("eventABC"),
|
||||
},
|
||||
},
|
||||
},
|
||||
eventstream.Message{
|
||||
Headers: eventstream.Headers{
|
||||
eventMessageTypeHeader,
|
||||
eventstream.Header{
|
||||
Name: EventTypeHeader,
|
||||
Value: eventstream.StringValue("eventEFG"),
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
var unmarshalers request.HandlerList
|
||||
unmarshalers.PushBackNamed(restjson.UnmarshalHandler)
|
||||
|
||||
eventReader := NewEventReader(stream,
|
||||
protocol.HandlerPayloadUnmarshal{
|
||||
Unmarshalers: unmarshalers,
|
||||
},
|
||||
unmarshalerForEventType,
|
||||
)
|
||||
|
||||
event, err := eventReader.ReadEvent()
|
||||
if err != nil {
|
||||
t.Fatalf("expect no error, got %v", err)
|
||||
}
|
||||
|
||||
if event == nil {
|
||||
t.Fatalf("expect event got none")
|
||||
}
|
||||
|
||||
event, err = eventReader.ReadEvent()
|
||||
if err == nil {
|
||||
t.Fatalf("expect error for unknown event, got none")
|
||||
}
|
||||
|
||||
if event != nil {
|
||||
t.Fatalf("expect no event, got %T, %v", event, event)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEventReader_Error(t *testing.T) {
|
||||
stream := createStream(
|
||||
eventstream.Message{
|
||||
Headers: eventstream.Headers{
|
||||
eventstream.Header{
|
||||
Name: MessageTypeHeader,
|
||||
Value: eventstream.StringValue(ErrorMessageType),
|
||||
},
|
||||
eventstream.Header{
|
||||
Name: ErrorCodeHeader,
|
||||
Value: eventstream.StringValue("errorCode"),
|
||||
},
|
||||
eventstream.Header{
|
||||
Name: ErrorMessageHeader,
|
||||
Value: eventstream.StringValue("error message occur"),
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
var unmarshalers request.HandlerList
|
||||
unmarshalers.PushBackNamed(restjson.UnmarshalHandler)
|
||||
|
||||
eventReader := NewEventReader(stream,
|
||||
protocol.HandlerPayloadUnmarshal{
|
||||
Unmarshalers: unmarshalers,
|
||||
},
|
||||
unmarshalerForEventType,
|
||||
)
|
||||
|
||||
event, err := eventReader.ReadEvent()
|
||||
if err == nil {
|
||||
t.Fatalf("expect error got none")
|
||||
}
|
||||
|
||||
if event != nil {
|
||||
t.Fatalf("expect no event, got %v", event)
|
||||
}
|
||||
|
||||
aerr := err.(awserr.Error)
|
||||
if e, a := "errorCode", aerr.Code(); e != a {
|
||||
t.Errorf("expect %v code, got %v", e, a)
|
||||
}
|
||||
if e, a := "error message occur", aerr.Message(); e != a {
|
||||
t.Errorf("expect %v message, got %v", e, a)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEventReader(b *testing.B) {
|
||||
var buf bytes.Buffer
|
||||
encoder := eventstream.NewEncoder(&buf)
|
||||
msg := eventstream.Message{
|
||||
Headers: eventstream.Headers{
|
||||
eventMessageTypeHeader,
|
||||
eventstream.Header{
|
||||
Name: EventTypeHeader,
|
||||
Value: eventstream.StringValue("eventABC"),
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := encoder.Encode(msg); err != nil {
|
||||
b.Fatalf("failed to encode message, %v", err)
|
||||
}
|
||||
stream := bytes.NewReader(buf.Bytes())
|
||||
|
||||
var unmarshalers request.HandlerList
|
||||
unmarshalers.PushBackNamed(restjson.UnmarshalHandler)
|
||||
|
||||
eventReader := NewEventReader(ioutil.NopCloser(stream),
|
||||
protocol.HandlerPayloadUnmarshal{
|
||||
Unmarshalers: unmarshalers,
|
||||
},
|
||||
unmarshalerForEventType,
|
||||
)
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
stream.Seek(0, 0)
|
||||
|
||||
event, err := eventReader.ReadEvent()
|
||||
if err != nil {
|
||||
b.Fatalf("expect no error, got %v", err)
|
||||
}
|
||||
if event == nil {
|
||||
b.Fatalf("expect event got none")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func unmarshalerForEventType(eventType string) (Unmarshaler, error) {
|
||||
switch eventType {
|
||||
case "eventABC":
|
||||
return &eventABC{}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown event type, %v", eventType)
|
||||
}
|
||||
}
|
||||
|
||||
type eventABC struct {
|
||||
_ struct{}
|
||||
|
||||
HeaderField string
|
||||
Payload []byte
|
||||
}
|
||||
|
||||
func (e *eventABC) UnmarshalEvent(
|
||||
unmarshaler protocol.PayloadUnmarshaler,
|
||||
msg eventstream.Message,
|
||||
) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func createStream(msgs ...eventstream.Message) io.ReadCloser {
|
||||
w := bytes.NewBuffer(nil)
|
||||
|
||||
encoder := eventstream.NewEncoder(w)
|
||||
|
||||
for _, msg := range msgs {
|
||||
if err := encoder.Encode(msg); err != nil {
|
||||
panic("createStream failed, " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
return ioutil.NopCloser(w)
|
||||
}
|
24
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/eventstreamapi/error.go
generated
vendored
24
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/eventstreamapi/error.go
generated
vendored
|
@ -1,24 +0,0 @@
|
|||
package eventstreamapi
|
||||
|
||||
import "fmt"
|
||||
|
||||
type messageError struct {
|
||||
code string
|
||||
msg string
|
||||
}
|
||||
|
||||
func (e messageError) Code() string {
|
||||
return e.code
|
||||
}
|
||||
|
||||
func (e messageError) Message() string {
|
||||
return e.msg
|
||||
}
|
||||
|
||||
func (e messageError) Error() string {
|
||||
return fmt.Sprintf("%s: %s", e.code, e.msg)
|
||||
}
|
||||
|
||||
func (e messageError) OrigErr() error {
|
||||
return nil
|
||||
}
|
116
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/eventstreamtest/testing.go
generated
vendored
116
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/eventstreamtest/testing.go
generated
vendored
|
@ -1,116 +0,0 @@
|
|||
package eventstreamtest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/awstesting/unit"
|
||||
"github.com/aws/aws-sdk-go/private/protocol"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/eventstream"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/eventstream/eventstreamapi"
|
||||
"golang.org/x/net/http2"
|
||||
)
|
||||
|
||||
// ServeEventStream provides serving EventStream messages from a HTTP server to
|
||||
// the client. The events are sent sequentially to the client without delay.
|
||||
type ServeEventStream struct {
|
||||
T *testing.T
|
||||
Events []eventstream.Message
|
||||
}
|
||||
|
||||
func (s ServeEventStream) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
encoder := eventstream.NewEncoder(flushWriter{w})
|
||||
|
||||
for _, event := range s.Events {
|
||||
encoder.Encode(event)
|
||||
}
|
||||
}
|
||||
|
||||
// SetupEventStreamSession creates a HTTP server SDK session for communicating
|
||||
// with that server to be used for EventStream APIs. If HTTP/2 is enabled the
|
||||
// server/client will only attempt to use HTTP/2.
|
||||
func SetupEventStreamSession(
|
||||
t *testing.T, handler http.Handler, h2 bool,
|
||||
) (sess *session.Session, cleanupFn func(), err error) {
|
||||
server := httptest.NewUnstartedServer(handler)
|
||||
server.Config.TLSConfig = &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
|
||||
clientTrans := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
}
|
||||
|
||||
if h2 {
|
||||
http2.ConfigureServer(server.Config, nil)
|
||||
http2.ConfigureTransport(clientTrans)
|
||||
server.Config.TLSConfig.NextProtos = []string{http2.NextProtoTLS}
|
||||
clientTrans.TLSClientConfig.NextProtos = []string{http2.NextProtoTLS}
|
||||
}
|
||||
server.TLS = server.Config.TLSConfig
|
||||
|
||||
server.StartTLS()
|
||||
cleanupFn = func() {
|
||||
server.Close()
|
||||
}
|
||||
|
||||
client := &http.Client{
|
||||
Transport: clientTrans,
|
||||
}
|
||||
|
||||
sess, err = session.NewSession(unit.Session.Config, &aws.Config{
|
||||
Endpoint: &server.URL,
|
||||
DisableParamValidation: aws.Bool(true),
|
||||
HTTPClient: client,
|
||||
// LogLevel: aws.LogLevel(aws.LogDebugWithEventStreamBody),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return sess, cleanupFn, nil
|
||||
}
|
||||
|
||||
type flushWriter struct {
|
||||
w io.Writer
|
||||
}
|
||||
|
||||
func (fw flushWriter) Write(p []byte) (n int, err error) {
|
||||
n, err = fw.w.Write(p)
|
||||
if f, ok := fw.w.(http.Flusher); ok {
|
||||
f.Flush()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// MarshalEventPayload marshals a SDK API shape into its associated wire
|
||||
// protocol payload.
|
||||
func MarshalEventPayload(
|
||||
payloadMarshaler protocol.PayloadMarshaler,
|
||||
v interface{},
|
||||
) []byte {
|
||||
var w bytes.Buffer
|
||||
err := payloadMarshaler.MarshalPayload(&w, v)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to marshal event %T, %v", v, v))
|
||||
}
|
||||
|
||||
return w.Bytes()
|
||||
}
|
||||
|
||||
// EventMessageTypeHeader is a event message type header for marking an
|
||||
// message as being the event type.
|
||||
var EventMessageTypeHeader = eventstream.Header{
|
||||
Name: eventstreamapi.MessageTypeHeader,
|
||||
Value: eventstream.StringValue(eventstreamapi.EventMessageType),
|
||||
}
|
166
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/header.go
generated
vendored
166
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/header.go
generated
vendored
|
@ -1,166 +0,0 @@
|
|||
package eventstream
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Headers are a collection of EventStream header values.
|
||||
type Headers []Header
|
||||
|
||||
// Header is a single EventStream Key Value header pair.
|
||||
type Header struct {
|
||||
Name string
|
||||
Value Value
|
||||
}
|
||||
|
||||
// Set associates the name with a value. If the header name already exists in
|
||||
// the Headers the value will be replaced with the new one.
|
||||
func (hs *Headers) Set(name string, value Value) {
|
||||
var i int
|
||||
for ; i < len(*hs); i++ {
|
||||
if (*hs)[i].Name == name {
|
||||
(*hs)[i].Value = value
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
*hs = append(*hs, Header{
|
||||
Name: name, Value: value,
|
||||
})
|
||||
}
|
||||
|
||||
// Get returns the Value associated with the header. Nil is returned if the
|
||||
// value does not exist.
|
||||
func (hs Headers) Get(name string) Value {
|
||||
for i := 0; i < len(hs); i++ {
|
||||
if h := hs[i]; h.Name == name {
|
||||
return h.Value
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Del deletes the value in the Headers if it exists.
|
||||
func (hs *Headers) Del(name string) {
|
||||
for i := 0; i < len(*hs); i++ {
|
||||
if (*hs)[i].Name == name {
|
||||
copy((*hs)[i:], (*hs)[i+1:])
|
||||
(*hs) = (*hs)[:len(*hs)-1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func decodeHeaders(r io.Reader) (Headers, error) {
|
||||
hs := Headers{}
|
||||
|
||||
for {
|
||||
name, err := decodeHeaderName(r)
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
// EOF while getting header name means no more headers
|
||||
break
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
value, err := decodeHeaderValue(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
hs.Set(name, value)
|
||||
}
|
||||
|
||||
return hs, nil
|
||||
}
|
||||
|
||||
func decodeHeaderName(r io.Reader) (string, error) {
|
||||
var n headerName
|
||||
|
||||
var err error
|
||||
n.Len, err = decodeUint8(r)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
name := n.Name[:n.Len]
|
||||
if _, err := io.ReadFull(r, name); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(name), nil
|
||||
}
|
||||
|
||||
func decodeHeaderValue(r io.Reader) (Value, error) {
|
||||
var raw rawValue
|
||||
|
||||
typ, err := decodeUint8(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
raw.Type = valueType(typ)
|
||||
|
||||
var v Value
|
||||
|
||||
switch raw.Type {
|
||||
case trueValueType:
|
||||
v = BoolValue(true)
|
||||
case falseValueType:
|
||||
v = BoolValue(false)
|
||||
case int8ValueType:
|
||||
var tv Int8Value
|
||||
err = tv.decode(r)
|
||||
v = tv
|
||||
case int16ValueType:
|
||||
var tv Int16Value
|
||||
err = tv.decode(r)
|
||||
v = tv
|
||||
case int32ValueType:
|
||||
var tv Int32Value
|
||||
err = tv.decode(r)
|
||||
v = tv
|
||||
case int64ValueType:
|
||||
var tv Int64Value
|
||||
err = tv.decode(r)
|
||||
v = tv
|
||||
case bytesValueType:
|
||||
var tv BytesValue
|
||||
err = tv.decode(r)
|
||||
v = tv
|
||||
case stringValueType:
|
||||
var tv StringValue
|
||||
err = tv.decode(r)
|
||||
v = tv
|
||||
case timestampValueType:
|
||||
var tv TimestampValue
|
||||
err = tv.decode(r)
|
||||
v = tv
|
||||
case uuidValueType:
|
||||
var tv UUIDValue
|
||||
err = tv.decode(r)
|
||||
v = tv
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown value type %d", raw.Type))
|
||||
}
|
||||
|
||||
// Error could be EOF, let caller deal with it
|
||||
return v, err
|
||||
}
|
||||
|
||||
const maxHeaderNameLen = 255
|
||||
|
||||
type headerName struct {
|
||||
Len uint8
|
||||
Name [maxHeaderNameLen]byte
|
||||
}
|
||||
|
||||
func (v headerName) encode(w io.Writer) error {
|
||||
if err := binary.Write(w, binary.BigEndian, v.Len); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := w.Write(v.Name[:v.Len])
|
||||
return err
|
||||
}
|
66
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/header_test.go
generated
vendored
66
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/header_test.go
generated
vendored
|
@ -1,66 +0,0 @@
|
|||
package eventstream
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestHeaders_Set(t *testing.T) {
|
||||
expect := Headers{
|
||||
{Name: "ABC", Value: StringValue("123")},
|
||||
{Name: "EFG", Value: TimestampValue(time.Time{})},
|
||||
}
|
||||
|
||||
var actual Headers
|
||||
actual.Set("ABC", Int32Value(123))
|
||||
actual.Set("ABC", StringValue("123")) // replase case
|
||||
actual.Set("EFG", TimestampValue(time.Time{}))
|
||||
|
||||
if e, a := expect, actual; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("expect %v headers, got %v", e, a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeaders_Get(t *testing.T) {
|
||||
headers := Headers{
|
||||
{Name: "ABC", Value: StringValue("123")},
|
||||
{Name: "EFG", Value: TimestampValue(time.Time{})},
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
Name string
|
||||
Value Value
|
||||
}{
|
||||
{Name: "ABC", Value: StringValue("123")},
|
||||
{Name: "EFG", Value: TimestampValue(time.Time{})},
|
||||
{Name: "NotFound"},
|
||||
}
|
||||
|
||||
for i, c := range cases {
|
||||
actual := headers.Get(c.Name)
|
||||
if e, a := c.Value, actual; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("%d, expect %v value, got %v", i, e, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeaders_Del(t *testing.T) {
|
||||
headers := Headers{
|
||||
{Name: "ABC", Value: StringValue("123")},
|
||||
{Name: "EFG", Value: TimestampValue(time.Time{})},
|
||||
{Name: "HIJ", Value: StringValue("123")},
|
||||
{Name: "KML", Value: TimestampValue(time.Time{})},
|
||||
}
|
||||
expectAfterDel := Headers{
|
||||
{Name: "EFG", Value: TimestampValue(time.Time{})},
|
||||
}
|
||||
|
||||
headers.Del("HIJ")
|
||||
headers.Del("ABC")
|
||||
headers.Del("KML")
|
||||
|
||||
if e, a := expectAfterDel, headers; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("expect %v headers, got %v", e, a)
|
||||
}
|
||||
}
|
501
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/header_value.go
generated
vendored
501
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/header_value.go
generated
vendored
|
@ -1,501 +0,0 @@
|
|||
package eventstream
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const maxHeaderValueLen = 1<<15 - 1 // 2^15-1 or 32KB - 1
|
||||
|
||||
// valueType is the EventStream header value type.
|
||||
type valueType uint8
|
||||
|
||||
// Header value types
|
||||
const (
|
||||
trueValueType valueType = iota
|
||||
falseValueType
|
||||
int8ValueType // Byte
|
||||
int16ValueType // Short
|
||||
int32ValueType // Integer
|
||||
int64ValueType // Long
|
||||
bytesValueType
|
||||
stringValueType
|
||||
timestampValueType
|
||||
uuidValueType
|
||||
)
|
||||
|
||||
func (t valueType) String() string {
|
||||
switch t {
|
||||
case trueValueType:
|
||||
return "bool"
|
||||
case falseValueType:
|
||||
return "bool"
|
||||
case int8ValueType:
|
||||
return "int8"
|
||||
case int16ValueType:
|
||||
return "int16"
|
||||
case int32ValueType:
|
||||
return "int32"
|
||||
case int64ValueType:
|
||||
return "int64"
|
||||
case bytesValueType:
|
||||
return "byte_array"
|
||||
case stringValueType:
|
||||
return "string"
|
||||
case timestampValueType:
|
||||
return "timestamp"
|
||||
case uuidValueType:
|
||||
return "uuid"
|
||||
default:
|
||||
return fmt.Sprintf("unknown value type %d", uint8(t))
|
||||
}
|
||||
}
|
||||
|
||||
type rawValue struct {
|
||||
Type valueType
|
||||
Len uint16 // Only set for variable length slices
|
||||
Value []byte // byte representation of value, BigEndian encoding.
|
||||
}
|
||||
|
||||
func (r rawValue) encodeScalar(w io.Writer, v interface{}) error {
|
||||
return binaryWriteFields(w, binary.BigEndian,
|
||||
r.Type,
|
||||
v,
|
||||
)
|
||||
}
|
||||
|
||||
func (r rawValue) encodeFixedSlice(w io.Writer, v []byte) error {
|
||||
binary.Write(w, binary.BigEndian, r.Type)
|
||||
|
||||
_, err := w.Write(v)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r rawValue) encodeBytes(w io.Writer, v []byte) error {
|
||||
if len(v) > maxHeaderValueLen {
|
||||
return LengthError{
|
||||
Part: "header value",
|
||||
Want: maxHeaderValueLen, Have: len(v),
|
||||
Value: v,
|
||||
}
|
||||
}
|
||||
r.Len = uint16(len(v))
|
||||
|
||||
err := binaryWriteFields(w, binary.BigEndian,
|
||||
r.Type,
|
||||
r.Len,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = w.Write(v)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r rawValue) encodeString(w io.Writer, v string) error {
|
||||
if len(v) > maxHeaderValueLen {
|
||||
return LengthError{
|
||||
Part: "header value",
|
||||
Want: maxHeaderValueLen, Have: len(v),
|
||||
Value: v,
|
||||
}
|
||||
}
|
||||
r.Len = uint16(len(v))
|
||||
|
||||
type stringWriter interface {
|
||||
WriteString(string) (int, error)
|
||||
}
|
||||
|
||||
err := binaryWriteFields(w, binary.BigEndian,
|
||||
r.Type,
|
||||
r.Len,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if sw, ok := w.(stringWriter); ok {
|
||||
_, err = sw.WriteString(v)
|
||||
} else {
|
||||
_, err = w.Write([]byte(v))
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func decodeFixedBytesValue(r io.Reader, buf []byte) error {
|
||||
_, err := io.ReadFull(r, buf)
|
||||
return err
|
||||
}
|
||||
|
||||
func decodeBytesValue(r io.Reader) ([]byte, error) {
|
||||
var raw rawValue
|
||||
var err error
|
||||
raw.Len, err = decodeUint16(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
buf := make([]byte, raw.Len)
|
||||
_, err = io.ReadFull(r, buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
func decodeStringValue(r io.Reader) (string, error) {
|
||||
v, err := decodeBytesValue(r)
|
||||
return string(v), err
|
||||
}
|
||||
|
||||
// Value represents the abstract header value.
|
||||
type Value interface {
|
||||
Get() interface{}
|
||||
String() string
|
||||
valueType() valueType
|
||||
encode(io.Writer) error
|
||||
}
|
||||
|
||||
// An BoolValue provides eventstream encoding, and representation
|
||||
// of a Go bool value.
|
||||
type BoolValue bool
|
||||
|
||||
// Get returns the underlying type
|
||||
func (v BoolValue) Get() interface{} {
|
||||
return bool(v)
|
||||
}
|
||||
|
||||
// valueType returns the EventStream header value type value.
|
||||
func (v BoolValue) valueType() valueType {
|
||||
if v {
|
||||
return trueValueType
|
||||
}
|
||||
return falseValueType
|
||||
}
|
||||
|
||||
func (v BoolValue) String() string {
|
||||
return strconv.FormatBool(bool(v))
|
||||
}
|
||||
|
||||
// encode encodes the BoolValue into an eventstream binary value
|
||||
// representation.
|
||||
func (v BoolValue) encode(w io.Writer) error {
|
||||
return binary.Write(w, binary.BigEndian, v.valueType())
|
||||
}
|
||||
|
||||
// An Int8Value provides eventstream encoding, and representation of a Go
|
||||
// int8 value.
|
||||
type Int8Value int8
|
||||
|
||||
// Get returns the underlying value.
|
||||
func (v Int8Value) Get() interface{} {
|
||||
return int8(v)
|
||||
}
|
||||
|
||||
// valueType returns the EventStream header value type value.
|
||||
func (Int8Value) valueType() valueType {
|
||||
return int8ValueType
|
||||
}
|
||||
|
||||
func (v Int8Value) String() string {
|
||||
return fmt.Sprintf("0x%02x", int8(v))
|
||||
}
|
||||
|
||||
// encode encodes the Int8Value into an eventstream binary value
|
||||
// representation.
|
||||
func (v Int8Value) encode(w io.Writer) error {
|
||||
raw := rawValue{
|
||||
Type: v.valueType(),
|
||||
}
|
||||
|
||||
return raw.encodeScalar(w, v)
|
||||
}
|
||||
|
||||
func (v *Int8Value) decode(r io.Reader) error {
|
||||
n, err := decodeUint8(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*v = Int8Value(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
// An Int16Value provides eventstream encoding, and representation of a Go
|
||||
// int16 value.
|
||||
type Int16Value int16
|
||||
|
||||
// Get returns the underlying value.
|
||||
func (v Int16Value) Get() interface{} {
|
||||
return int16(v)
|
||||
}
|
||||
|
||||
// valueType returns the EventStream header value type value.
|
||||
func (Int16Value) valueType() valueType {
|
||||
return int16ValueType
|
||||
}
|
||||
|
||||
func (v Int16Value) String() string {
|
||||
return fmt.Sprintf("0x%04x", int16(v))
|
||||
}
|
||||
|
||||
// encode encodes the Int16Value into an eventstream binary value
|
||||
// representation.
|
||||
func (v Int16Value) encode(w io.Writer) error {
|
||||
raw := rawValue{
|
||||
Type: v.valueType(),
|
||||
}
|
||||
return raw.encodeScalar(w, v)
|
||||
}
|
||||
|
||||
func (v *Int16Value) decode(r io.Reader) error {
|
||||
n, err := decodeUint16(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*v = Int16Value(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
// An Int32Value provides eventstream encoding, and representation of a Go
|
||||
// int32 value.
|
||||
type Int32Value int32
|
||||
|
||||
// Get returns the underlying value.
|
||||
func (v Int32Value) Get() interface{} {
|
||||
return int32(v)
|
||||
}
|
||||
|
||||
// valueType returns the EventStream header value type value.
|
||||
func (Int32Value) valueType() valueType {
|
||||
return int32ValueType
|
||||
}
|
||||
|
||||
func (v Int32Value) String() string {
|
||||
return fmt.Sprintf("0x%08x", int32(v))
|
||||
}
|
||||
|
||||
// encode encodes the Int32Value into an eventstream binary value
|
||||
// representation.
|
||||
func (v Int32Value) encode(w io.Writer) error {
|
||||
raw := rawValue{
|
||||
Type: v.valueType(),
|
||||
}
|
||||
return raw.encodeScalar(w, v)
|
||||
}
|
||||
|
||||
func (v *Int32Value) decode(r io.Reader) error {
|
||||
n, err := decodeUint32(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*v = Int32Value(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
// An Int64Value provides eventstream encoding, and representation of a Go
|
||||
// int64 value.
|
||||
type Int64Value int64
|
||||
|
||||
// Get returns the underlying value.
|
||||
func (v Int64Value) Get() interface{} {
|
||||
return int64(v)
|
||||
}
|
||||
|
||||
// valueType returns the EventStream header value type value.
|
||||
func (Int64Value) valueType() valueType {
|
||||
return int64ValueType
|
||||
}
|
||||
|
||||
func (v Int64Value) String() string {
|
||||
return fmt.Sprintf("0x%016x", int64(v))
|
||||
}
|
||||
|
||||
// encode encodes the Int64Value into an eventstream binary value
|
||||
// representation.
|
||||
func (v Int64Value) encode(w io.Writer) error {
|
||||
raw := rawValue{
|
||||
Type: v.valueType(),
|
||||
}
|
||||
return raw.encodeScalar(w, v)
|
||||
}
|
||||
|
||||
func (v *Int64Value) decode(r io.Reader) error {
|
||||
n, err := decodeUint64(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*v = Int64Value(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
// An BytesValue provides eventstream encoding, and representation of a Go
|
||||
// byte slice.
|
||||
type BytesValue []byte
|
||||
|
||||
// Get returns the underlying value.
|
||||
func (v BytesValue) Get() interface{} {
|
||||
return []byte(v)
|
||||
}
|
||||
|
||||
// valueType returns the EventStream header value type value.
|
||||
func (BytesValue) valueType() valueType {
|
||||
return bytesValueType
|
||||
}
|
||||
|
||||
func (v BytesValue) String() string {
|
||||
return base64.StdEncoding.EncodeToString([]byte(v))
|
||||
}
|
||||
|
||||
// encode encodes the BytesValue into an eventstream binary value
|
||||
// representation.
|
||||
func (v BytesValue) encode(w io.Writer) error {
|
||||
raw := rawValue{
|
||||
Type: v.valueType(),
|
||||
}
|
||||
|
||||
return raw.encodeBytes(w, []byte(v))
|
||||
}
|
||||
|
||||
func (v *BytesValue) decode(r io.Reader) error {
|
||||
buf, err := decodeBytesValue(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*v = BytesValue(buf)
|
||||
return nil
|
||||
}
|
||||
|
||||
// An StringValue provides eventstream encoding, and representation of a Go
|
||||
// string.
|
||||
type StringValue string
|
||||
|
||||
// Get returns the underlying value.
|
||||
func (v StringValue) Get() interface{} {
|
||||
return string(v)
|
||||
}
|
||||
|
||||
// valueType returns the EventStream header value type value.
|
||||
func (StringValue) valueType() valueType {
|
||||
return stringValueType
|
||||
}
|
||||
|
||||
func (v StringValue) String() string {
|
||||
return string(v)
|
||||
}
|
||||
|
||||
// encode encodes the StringValue into an eventstream binary value
|
||||
// representation.
|
||||
func (v StringValue) encode(w io.Writer) error {
|
||||
raw := rawValue{
|
||||
Type: v.valueType(),
|
||||
}
|
||||
|
||||
return raw.encodeString(w, string(v))
|
||||
}
|
||||
|
||||
func (v *StringValue) decode(r io.Reader) error {
|
||||
s, err := decodeStringValue(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*v = StringValue(s)
|
||||
return nil
|
||||
}
|
||||
|
||||
// An TimestampValue provides eventstream encoding, and representation of a Go
|
||||
// timestamp.
|
||||
type TimestampValue time.Time
|
||||
|
||||
// Get returns the underlying value.
|
||||
func (v TimestampValue) Get() interface{} {
|
||||
return time.Time(v)
|
||||
}
|
||||
|
||||
// valueType returns the EventStream header value type value.
|
||||
func (TimestampValue) valueType() valueType {
|
||||
return timestampValueType
|
||||
}
|
||||
|
||||
func (v TimestampValue) epochMilli() int64 {
|
||||
nano := time.Time(v).UnixNano()
|
||||
msec := nano / int64(time.Millisecond)
|
||||
return msec
|
||||
}
|
||||
|
||||
func (v TimestampValue) String() string {
|
||||
msec := v.epochMilli()
|
||||
return strconv.FormatInt(msec, 10)
|
||||
}
|
||||
|
||||
// encode encodes the TimestampValue into an eventstream binary value
|
||||
// representation.
|
||||
func (v TimestampValue) encode(w io.Writer) error {
|
||||
raw := rawValue{
|
||||
Type: v.valueType(),
|
||||
}
|
||||
|
||||
msec := v.epochMilli()
|
||||
return raw.encodeScalar(w, msec)
|
||||
}
|
||||
|
||||
func (v *TimestampValue) decode(r io.Reader) error {
|
||||
n, err := decodeUint64(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*v = TimestampValue(timeFromEpochMilli(int64(n)))
|
||||
return nil
|
||||
}
|
||||
|
||||
func timeFromEpochMilli(t int64) time.Time {
|
||||
secs := t / 1e3
|
||||
msec := t % 1e3
|
||||
return time.Unix(secs, msec*int64(time.Millisecond))
|
||||
}
|
||||
|
||||
// An UUIDValue provides eventstream encoding, and representation of a UUID
|
||||
// value.
|
||||
type UUIDValue [16]byte
|
||||
|
||||
// Get returns the underlying value.
|
||||
func (v UUIDValue) Get() interface{} {
|
||||
return v[:]
|
||||
}
|
||||
|
||||
// valueType returns the EventStream header value type value.
|
||||
func (UUIDValue) valueType() valueType {
|
||||
return uuidValueType
|
||||
}
|
||||
|
||||
func (v UUIDValue) String() string {
|
||||
return fmt.Sprintf(`%X-%X-%X-%X-%X`, v[0:4], v[4:6], v[6:8], v[8:10], v[10:])
|
||||
}
|
||||
|
||||
// encode encodes the UUIDValue into an eventstream binary value
|
||||
// representation.
|
||||
func (v UUIDValue) encode(w io.Writer) error {
|
||||
raw := rawValue{
|
||||
Type: v.valueType(),
|
||||
}
|
||||
|
||||
return raw.encodeFixedSlice(w, v[:])
|
||||
}
|
||||
|
||||
func (v *UUIDValue) decode(r io.Reader) error {
|
||||
tv := (*v)[:]
|
||||
return decodeFixedBytesValue(r, tv)
|
||||
}
|
203
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/header_value_test.go
generated
vendored
203
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/header_value_test.go
generated
vendored
|
@ -1,203 +0,0 @@
|
|||
package eventstream
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"io"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func binWrite(v interface{}) []byte {
|
||||
var w bytes.Buffer
|
||||
binary.Write(&w, binary.BigEndian, v)
|
||||
return w.Bytes()
|
||||
}
|
||||
|
||||
var testValueEncodingCases = []struct {
|
||||
Val Value
|
||||
Expect []byte
|
||||
Decode func(io.Reader) (Value, error)
|
||||
}{
|
||||
{
|
||||
BoolValue(true),
|
||||
[]byte{byte(trueValueType)},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
BoolValue(false),
|
||||
[]byte{byte(falseValueType)},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
Int8Value(0x0f),
|
||||
[]byte{byte(int8ValueType), 0x0f},
|
||||
func(r io.Reader) (Value, error) {
|
||||
var v Int8Value
|
||||
err := v.decode(r)
|
||||
return v, err
|
||||
},
|
||||
},
|
||||
{
|
||||
Int16Value(0x0f),
|
||||
append([]byte{byte(int16ValueType)}, binWrite(int16(0x0f))...),
|
||||
func(r io.Reader) (Value, error) {
|
||||
var v Int16Value
|
||||
err := v.decode(r)
|
||||
return v, err
|
||||
},
|
||||
},
|
||||
{
|
||||
Int32Value(0x0f),
|
||||
append([]byte{byte(int32ValueType)}, binWrite(int32(0x0f))...),
|
||||
func(r io.Reader) (Value, error) {
|
||||
var v Int32Value
|
||||
err := v.decode(r)
|
||||
return v, err
|
||||
},
|
||||
},
|
||||
{
|
||||
Int64Value(0x0f),
|
||||
append([]byte{byte(int64ValueType)}, binWrite(int64(0x0f))...),
|
||||
func(r io.Reader) (Value, error) {
|
||||
var v Int64Value
|
||||
err := v.decode(r)
|
||||
return v, err
|
||||
},
|
||||
},
|
||||
{
|
||||
BytesValue([]byte{0, 1, 2, 3}),
|
||||
[]byte{byte(bytesValueType), 0x00, 0x04, 0, 1, 2, 3},
|
||||
func(r io.Reader) (Value, error) {
|
||||
var v BytesValue
|
||||
err := v.decode(r)
|
||||
return v, err
|
||||
},
|
||||
},
|
||||
{
|
||||
StringValue("abc123"),
|
||||
append([]byte{byte(stringValueType), 0, 6}, []byte("abc123")...),
|
||||
func(r io.Reader) (Value, error) {
|
||||
var v StringValue
|
||||
err := v.decode(r)
|
||||
return v, err
|
||||
},
|
||||
},
|
||||
{
|
||||
TimestampValue(
|
||||
time.Date(2014, 04, 04, 0, 1, 0, 0, time.FixedZone("PDT", -7)),
|
||||
),
|
||||
append([]byte{byte(timestampValueType)}, binWrite(int64(1396569667000))...),
|
||||
func(r io.Reader) (Value, error) {
|
||||
var v TimestampValue
|
||||
err := v.decode(r)
|
||||
return v, err
|
||||
},
|
||||
},
|
||||
{
|
||||
UUIDValue(
|
||||
[16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf},
|
||||
),
|
||||
[]byte{byte(uuidValueType), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf},
|
||||
func(r io.Reader) (Value, error) {
|
||||
var v UUIDValue
|
||||
err := v.decode(r)
|
||||
return v, err
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestValue_MarshalValue(t *testing.T) {
|
||||
for i, c := range testValueEncodingCases {
|
||||
var w bytes.Buffer
|
||||
|
||||
if err := c.Val.encode(&w); err != nil {
|
||||
t.Fatalf("%d, expect no error, got %v", i, err)
|
||||
}
|
||||
|
||||
if e, a := c.Expect, w.Bytes(); !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("%d, expect %v, got %v", i, e, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHeader_DecodeValues(t *testing.T) {
|
||||
for i, c := range testValueEncodingCases {
|
||||
r := bytes.NewBuffer(c.Expect)
|
||||
v, err := decodeHeaderValue(r)
|
||||
if err != nil {
|
||||
t.Fatalf("%d, expect no error, got %v", i, err)
|
||||
}
|
||||
|
||||
switch tv := v.(type) {
|
||||
case TimestampValue:
|
||||
exp := time.Time(c.Val.(TimestampValue))
|
||||
if e, a := exp, time.Time(tv); !e.Equal(a) {
|
||||
t.Errorf("%d, expect %v, got %v", i, e, a)
|
||||
}
|
||||
default:
|
||||
if e, a := c.Val, v; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("%d, expect %v, got %v", i, e, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValue_Decode(t *testing.T) {
|
||||
for i, c := range testValueEncodingCases {
|
||||
if c.Decode == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
r := bytes.NewBuffer(c.Expect)
|
||||
r.ReadByte() // strip off Type field
|
||||
|
||||
v, err := c.Decode(r)
|
||||
if err != nil {
|
||||
t.Fatalf("%d, expect no error, got %v", i, err)
|
||||
}
|
||||
|
||||
switch tv := v.(type) {
|
||||
case TimestampValue:
|
||||
exp := time.Time(c.Val.(TimestampValue))
|
||||
if e, a := exp, time.Time(tv); !e.Equal(a) {
|
||||
t.Errorf("%d, expect %v, got %v", i, e, a)
|
||||
}
|
||||
default:
|
||||
if e, a := c.Val, v; !reflect.DeepEqual(e, a) {
|
||||
t.Errorf("%d, expect %v, got %v", i, e, a)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValue_String(t *testing.T) {
|
||||
cases := []struct {
|
||||
Val Value
|
||||
Expect string
|
||||
}{
|
||||
{BoolValue(true), "true"},
|
||||
{BoolValue(false), "false"},
|
||||
{Int8Value(0x0f), "0x0f"},
|
||||
{Int16Value(0x0f), "0x000f"},
|
||||
{Int32Value(0x0f), "0x0000000f"},
|
||||
{Int64Value(0x0f), "0x000000000000000f"},
|
||||
{BytesValue([]byte{0, 1, 2, 3}), "AAECAw=="},
|
||||
{StringValue("abc123"), "abc123"},
|
||||
{TimestampValue(
|
||||
time.Date(2014, 04, 04, 0, 1, 0, 0, time.FixedZone("PDT", -7)),
|
||||
),
|
||||
"1396569667000",
|
||||
},
|
||||
{UUIDValue([16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf}),
|
||||
"00010203-0405-0607-0809-0A0B0C0D0E0F",
|
||||
},
|
||||
}
|
||||
|
||||
for i, c := range cases {
|
||||
if e, a := c.Expect, c.Val.String(); e != a {
|
||||
t.Errorf("%d, expect %v, got %v", i, e, a)
|
||||
}
|
||||
}
|
||||
}
|
103
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/message.go
generated
vendored
103
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/message.go
generated
vendored
|
@ -1,103 +0,0 @@
|
|||
package eventstream
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"hash/crc32"
|
||||
)
|
||||
|
||||
const preludeLen = 8
|
||||
const preludeCRCLen = 4
|
||||
const msgCRCLen = 4
|
||||
const minMsgLen = preludeLen + preludeCRCLen + msgCRCLen
|
||||
const maxPayloadLen = 1024 * 1024 * 16 // 16MB
|
||||
const maxHeadersLen = 1024 * 128 // 128KB
|
||||
const maxMsgLen = minMsgLen + maxHeadersLen + maxPayloadLen
|
||||
|
||||
var crc32IEEETable = crc32.MakeTable(crc32.IEEE)
|
||||
|
||||
// A Message provides the eventstream message representation.
|
||||
type Message struct {
|
||||
Headers Headers
|
||||
Payload []byte
|
||||
}
|
||||
|
||||
func (m *Message) rawMessage() (rawMessage, error) {
|
||||
var raw rawMessage
|
||||
|
||||
if len(m.Headers) > 0 {
|
||||
var headers bytes.Buffer
|
||||
if err := encodeHeaders(&headers, m.Headers); err != nil {
|
||||
return rawMessage{}, err
|
||||
}
|
||||
raw.Headers = headers.Bytes()
|
||||
raw.HeadersLen = uint32(len(raw.Headers))
|
||||
}
|
||||
|
||||
raw.Length = raw.HeadersLen + uint32(len(m.Payload)) + minMsgLen
|
||||
|
||||
hash := crc32.New(crc32IEEETable)
|
||||
binaryWriteFields(hash, binary.BigEndian, raw.Length, raw.HeadersLen)
|
||||
raw.PreludeCRC = hash.Sum32()
|
||||
|
||||
binaryWriteFields(hash, binary.BigEndian, raw.PreludeCRC)
|
||||
|
||||
if raw.HeadersLen > 0 {
|
||||
hash.Write(raw.Headers)
|
||||
}
|
||||
|
||||
// Read payload bytes and update hash for it as well.
|
||||
if len(m.Payload) > 0 {
|
||||
raw.Payload = m.Payload
|
||||
hash.Write(raw.Payload)
|
||||
}
|
||||
|
||||
raw.CRC = hash.Sum32()
|
||||
|
||||
return raw, nil
|
||||
}
|
||||
|
||||
type messagePrelude struct {
|
||||
Length uint32
|
||||
HeadersLen uint32
|
||||
PreludeCRC uint32
|
||||
}
|
||||
|
||||
func (p messagePrelude) PayloadLen() uint32 {
|
||||
return p.Length - p.HeadersLen - minMsgLen
|
||||
}
|
||||
|
||||
func (p messagePrelude) ValidateLens() error {
|
||||
if p.Length == 0 || p.Length > maxMsgLen {
|
||||
return LengthError{
|
||||
Part: "message prelude",
|
||||
Want: maxMsgLen,
|
||||
Have: int(p.Length),
|
||||
}
|
||||
}
|
||||
if p.HeadersLen > maxHeadersLen {
|
||||
return LengthError{
|
||||
Part: "message headers",
|
||||
Want: maxHeadersLen,
|
||||
Have: int(p.HeadersLen),
|
||||
}
|
||||
}
|
||||
if payloadLen := p.PayloadLen(); payloadLen > maxPayloadLen {
|
||||
return LengthError{
|
||||
Part: "message payload",
|
||||
Want: maxPayloadLen,
|
||||
Have: int(payloadLen),
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type rawMessage struct {
|
||||
messagePrelude
|
||||
|
||||
Headers []byte
|
||||
Payload []byte
|
||||
|
||||
CRC uint32
|
||||
}
|
152
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/shared_test.go
generated
vendored
152
vendor/github.com/aws/aws-sdk-go/private/protocol/eventstream/shared_test.go
generated
vendored
|
@ -1,152 +0,0 @@
|
|||
package eventstream
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type testCase struct {
|
||||
Name string
|
||||
Encoded []byte
|
||||
Decoded decodedMessage
|
||||
}
|
||||
|
||||
type testErrorCase struct {
|
||||
Name string
|
||||
Encoded []byte
|
||||
Err string
|
||||
}
|
||||
|
||||
type rawTestCase struct {
|
||||
Name string
|
||||
Encoded, Decoded []byte
|
||||
}
|
||||
|
||||
func readRawTestCases(root, class string) (map[string]rawTestCase, error) {
|
||||
encoded, err := readTests(filepath.Join(root, "encoded", class))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
decoded, err := readTests(filepath.Join(root, "decoded", class))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(encoded) == 0 {
|
||||
return nil, fmt.Errorf("expect encoded cases, found none")
|
||||
}
|
||||
|
||||
if len(encoded) != len(decoded) {
|
||||
return nil, fmt.Errorf("encoded and decoded sets different")
|
||||
}
|
||||
|
||||
rawCases := map[string]rawTestCase{}
|
||||
for name, encData := range encoded {
|
||||
decData, ok := decoded[name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("encoded %q case not found in decoded set", name)
|
||||
}
|
||||
|
||||
rawCases[name] = rawTestCase{
|
||||
Name: name,
|
||||
Encoded: encData,
|
||||
Decoded: decData,
|
||||
}
|
||||
}
|
||||
|
||||
return rawCases, nil
|
||||
}
|
||||
|
||||
func readNegativeTests(root string) ([]testErrorCase, error) {
|
||||
rawCases, err := readRawTestCases(root, "negative")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cases := make([]testErrorCase, 0, len(rawCases))
|
||||
for name, rawCase := range rawCases {
|
||||
cases = append(cases, testErrorCase{
|
||||
Name: name,
|
||||
Encoded: rawCase.Encoded,
|
||||
Err: string(rawCase.Decoded),
|
||||
})
|
||||
}
|
||||
|
||||
return cases, nil
|
||||
}
|
||||
|
||||
func readPositiveTests(root string) ([]testCase, error) {
|
||||
rawCases, err := readRawTestCases(root, "positive")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cases := make([]testCase, 0, len(rawCases))
|
||||
for name, rawCase := range rawCases {
|
||||
|
||||
var dec decodedMessage
|
||||
if err := json.Unmarshal(rawCase.Decoded, &dec); err != nil {
|
||||
return nil, fmt.Errorf("failed to decode %q, %v", name, err)
|
||||
}
|
||||
|
||||
cases = append(cases, testCase{
|
||||
Name: name,
|
||||
Encoded: rawCase.Encoded,
|
||||
Decoded: dec,
|
||||
})
|
||||
}
|
||||
|
||||
return cases, nil
|
||||
}
|
||||
|
||||
func readTests(root string) (map[string][]byte, error) {
|
||||
items, err := ioutil.ReadDir(root)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read test suite %q dirs, %v", root, err)
|
||||
}
|
||||
|
||||
cases := map[string][]byte{}
|
||||
for _, item := range items {
|
||||
if item.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
filename := filepath.Join(root, item.Name())
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read test_data file %q, %v", filename, err)
|
||||
}
|
||||
|
||||
cases[item.Name()] = data
|
||||
}
|
||||
|
||||
return cases, nil
|
||||
}
|
||||
|
||||
func compareLines(t *testing.T, a, b []byte) bool {
|
||||
as := bufio.NewScanner(bytes.NewBuffer(a))
|
||||
bs := bufio.NewScanner(bytes.NewBuffer(b))
|
||||
|
||||
var failed bool
|
||||
for {
|
||||
if ab, bb := as.Scan(), bs.Scan(); ab != bb {
|
||||
t.Errorf("expect a & b to have same number of lines")
|
||||
return false
|
||||
} else if !ab {
|
||||
break
|
||||
}
|
||||
|
||||
if v1, v2 := as.Text(), bs.Text(); v1 != v2 {
|
||||
t.Errorf("expect %q to be %q", v1, v2)
|
||||
failed = true
|
||||
}
|
||||
}
|
||||
|
||||
return !failed
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
Prelude checksum mismatch
|
|
@ -1 +0,0 @@
|
|||
Message checksum mismatch
|
|
@ -1 +0,0 @@
|
|||
Prelude checksum mismatch
|
|
@ -1 +0,0 @@
|
|||
Message checksum mismatch
|
|
@ -1,58 +0,0 @@
|
|||
{
|
||||
"total_length": 204,
|
||||
"headers_length": 175,
|
||||
"prelude_crc": 263087306,
|
||||
"headers": [ {
|
||||
"name": "event-type",
|
||||
"type": 4,
|
||||
"value": 40972
|
||||
},
|
||||
{
|
||||
"name": "content-type",
|
||||
"type": 7,
|
||||
"value": "YXBwbGljYXRpb24vanNvbg=="
|
||||
},
|
||||
{
|
||||
"name": "bool false",
|
||||
"type": 1,
|
||||
"value": false
|
||||
},
|
||||
{
|
||||
"name": "bool true",
|
||||
"type": 0,
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"name": "byte",
|
||||
"type": 2,
|
||||
"value": -49
|
||||
},
|
||||
{
|
||||
"name": "byte buf",
|
||||
"type": 6,
|
||||
"value": "SSdtIGEgbGl0dGxlIHRlYXBvdCE="
|
||||
},
|
||||
{
|
||||
"name": "timestamp",
|
||||
"type": 8,
|
||||
"value": 8675309
|
||||
},
|
||||
{
|
||||
"name": "int16",
|
||||
"type": 3,
|
||||
"value": 42
|
||||
},
|
||||
{
|
||||
"name": "int64",
|
||||
"type": 5,
|
||||
"value": 42424242
|
||||
},
|
||||
{
|
||||
"name": "uuid",
|
||||
"type": 9,
|
||||
"value": "AQIDBAUGBwgJCgsMDQ4PEA=="
|
||||
}
|
||||
],
|
||||
"payload": "eydmb28nOidiYXInfQ==",
|
||||
"message_crc": -1415188212
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"total_length": 16,
|
||||
"headers_length": 0,
|
||||
"prelude_crc": 96618731,
|
||||
"headers": [ ],
|
||||
"payload": "",
|
||||
"message_crc": 2107164927
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"total_length": 45,
|
||||
"headers_length": 16,
|
||||
"prelude_crc": 1103373496,
|
||||
"headers": [ {
|
||||
"name": "event-type",
|
||||
"type": 4,
|
||||
"value": 40972
|
||||
}
|
||||
],
|
||||
"payload": "eydmb28nOidiYXInfQ==",
|
||||
"message_crc": 921993376
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"total_length": 29,
|
||||
"headers_length": 0,
|
||||
"prelude_crc": -44921766,
|
||||
"headers": [ ],
|
||||
"payload": "eydmb28nOidiYXInfQ==",
|
||||
"message_crc": -1016776394
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"total_length": 61,
|
||||
"headers_length": 32,
|
||||
"prelude_crc": 134054806,
|
||||
"headers": [ {
|
||||
"name": "content-type",
|
||||
"type": 7,
|
||||
"value": "YXBwbGljYXRpb24vanNvbg=="
|
||||
}
|
||||
],
|
||||
"payload": "eydmb28nOidiYXInfQ==",
|
||||
"message_crc": -1919153999
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
286
vendor/github.com/aws/aws-sdk-go/private/protocol/json/jsonutil/build.go
generated
vendored
286
vendor/github.com/aws/aws-sdk-go/private/protocol/json/jsonutil/build.go
generated
vendored
|
@ -1,286 +0,0 @@
|
|||
// Package jsonutil provides JSON serialization of AWS requests and responses.
|
||||
package jsonutil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/private/protocol"
|
||||
)
|
||||
|
||||
var timeType = reflect.ValueOf(time.Time{}).Type()
|
||||
var byteSliceType = reflect.ValueOf([]byte{}).Type()
|
||||
|
||||
// BuildJSON builds a JSON string for a given object v.
|
||||
func BuildJSON(v interface{}) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
err := buildAny(reflect.ValueOf(v), &buf, "")
|
||||
return buf.Bytes(), err
|
||||
}
|
||||
|
||||
func buildAny(value reflect.Value, buf *bytes.Buffer, tag reflect.StructTag) error {
|
||||
origVal := value
|
||||
value = reflect.Indirect(value)
|
||||
if !value.IsValid() {
|
||||
return nil
|
||||
}
|
||||
|
||||
vtype := value.Type()
|
||||
|
||||
t := tag.Get("type")
|
||||
if t == "" {
|
||||
switch vtype.Kind() {
|
||||
case reflect.Struct:
|
||||
// also it can't be a time object
|
||||
if value.Type() != timeType {
|
||||
t = "structure"
|
||||
}
|
||||
case reflect.Slice:
|
||||
// also it can't be a byte slice
|
||||
if _, ok := value.Interface().([]byte); !ok {
|
||||
t = "list"
|
||||
}
|
||||
case reflect.Map:
|
||||
// cannot be a JSONValue map
|
||||
if _, ok := value.Interface().(aws.JSONValue); !ok {
|
||||
t = "map"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch t {
|
||||
case "structure":
|
||||
if field, ok := vtype.FieldByName("_"); ok {
|
||||
tag = field.Tag
|
||||
}
|
||||
return buildStruct(value, buf, tag)
|
||||
case "list":
|
||||
return buildList(value, buf, tag)
|
||||
case "map":
|
||||
return buildMap(value, buf, tag)
|
||||
default:
|
||||
return buildScalar(origVal, buf, tag)
|
||||
}
|
||||
}
|
||||
|
||||
func buildStruct(value reflect.Value, buf *bytes.Buffer, tag reflect.StructTag) error {
|
||||
if !value.IsValid() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// unwrap payloads
|
||||
if payload := tag.Get("payload"); payload != "" {
|
||||
field, _ := value.Type().FieldByName(payload)
|
||||
tag = field.Tag
|
||||
value = elemOf(value.FieldByName(payload))
|
||||
|
||||
if !value.IsValid() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
buf.WriteByte('{')
|
||||
|
||||
t := value.Type()
|
||||
first := true
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
member := value.Field(i)
|
||||
|
||||
// This allocates the most memory.
|
||||
// Additionally, we cannot skip nil fields due to
|
||||
// idempotency auto filling.
|
||||
field := t.Field(i)
|
||||
|
||||
if field.PkgPath != "" {
|
||||
continue // ignore unexported fields
|
||||
}
|
||||
if field.Tag.Get("json") == "-" {
|
||||
continue
|
||||
}
|
||||
if field.Tag.Get("location") != "" {
|
||||
continue // ignore non-body elements
|
||||
}
|
||||
if field.Tag.Get("ignore") != "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if protocol.CanSetIdempotencyToken(member, field) {
|
||||
token := protocol.GetIdempotencyToken()
|
||||
member = reflect.ValueOf(&token)
|
||||
}
|
||||
|
||||
if (member.Kind() == reflect.Ptr || member.Kind() == reflect.Slice || member.Kind() == reflect.Map) && member.IsNil() {
|
||||
continue // ignore unset fields
|
||||
}
|
||||
|
||||
if first {
|
||||
first = false
|
||||
} else {
|
||||
buf.WriteByte(',')
|
||||
}
|
||||
|
||||
// figure out what this field is called
|
||||
name := field.Name
|
||||
if locName := field.Tag.Get("locationName"); locName != "" {
|
||||
name = locName
|
||||
}
|
||||
|
||||
writeString(name, buf)
|
||||
buf.WriteString(`:`)
|
||||
|
||||
err := buildAny(member, buf, field.Tag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
buf.WriteString("}")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildList(value reflect.Value, buf *bytes.Buffer, tag reflect.StructTag) error {
|
||||
buf.WriteString("[")
|
||||
|
||||
for i := 0; i < value.Len(); i++ {
|
||||
buildAny(value.Index(i), buf, "")
|
||||
|
||||
if i < value.Len()-1 {
|
||||
buf.WriteString(",")
|
||||
}
|
||||
}
|
||||
|
||||
buf.WriteString("]")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type sortedValues []reflect.Value
|
||||
|
||||
func (sv sortedValues) Len() int { return len(sv) }
|
||||
func (sv sortedValues) Swap(i, j int) { sv[i], sv[j] = sv[j], sv[i] }
|
||||
func (sv sortedValues) Less(i, j int) bool { return sv[i].String() < sv[j].String() }
|
||||
|
||||
func buildMap(value reflect.Value, buf *bytes.Buffer, tag reflect.StructTag) error {
|
||||
buf.WriteString("{")
|
||||
|
||||
sv := sortedValues(value.MapKeys())
|
||||
sort.Sort(sv)
|
||||
|
||||
for i, k := range sv {
|
||||
if i > 0 {
|
||||
buf.WriteByte(',')
|
||||
}
|
||||
|
||||
writeString(k.String(), buf)
|
||||
buf.WriteString(`:`)
|
||||
|
||||
buildAny(value.MapIndex(k), buf, "")
|
||||
}
|
||||
|
||||
buf.WriteString("}")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildScalar(v reflect.Value, buf *bytes.Buffer, tag reflect.StructTag) error {
|
||||
// prevents allocation on the heap.
|
||||
scratch := [64]byte{}
|
||||
switch value := reflect.Indirect(v); value.Kind() {
|
||||
case reflect.String:
|
||||
writeString(value.String(), buf)
|
||||
case reflect.Bool:
|
||||
if value.Bool() {
|
||||
buf.WriteString("true")
|
||||
} else {
|
||||
buf.WriteString("false")
|
||||
}
|
||||
case reflect.Int64:
|
||||
buf.Write(strconv.AppendInt(scratch[:0], value.Int(), 10))
|
||||
case reflect.Float64:
|
||||
f := value.Float()
|
||||
if math.IsInf(f, 0) || math.IsNaN(f) {
|
||||
return &json.UnsupportedValueError{Value: v, Str: strconv.FormatFloat(f, 'f', -1, 64)}
|
||||
}
|
||||
buf.Write(strconv.AppendFloat(scratch[:0], f, 'f', -1, 64))
|
||||
default:
|
||||
switch converted := value.Interface().(type) {
|
||||
case time.Time:
|
||||
buf.Write(strconv.AppendInt(scratch[:0], converted.UTC().Unix(), 10))
|
||||
case []byte:
|
||||
if !value.IsNil() {
|
||||
buf.WriteByte('"')
|
||||
if len(converted) < 1024 {
|
||||
// for small buffers, using Encode directly is much faster.
|
||||
dst := make([]byte, base64.StdEncoding.EncodedLen(len(converted)))
|
||||
base64.StdEncoding.Encode(dst, converted)
|
||||
buf.Write(dst)
|
||||
} else {
|
||||
// for large buffers, avoid unnecessary extra temporary
|
||||
// buffer space.
|
||||
enc := base64.NewEncoder(base64.StdEncoding, buf)
|
||||
enc.Write(converted)
|
||||
enc.Close()
|
||||
}
|
||||
buf.WriteByte('"')
|
||||
}
|
||||
case aws.JSONValue:
|
||||
str, err := protocol.EncodeJSONValue(converted, protocol.QuotedEscape)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to encode JSONValue, %v", err)
|
||||
}
|
||||
buf.WriteString(str)
|
||||
default:
|
||||
return fmt.Errorf("unsupported JSON value %v (%s)", value.Interface(), value.Type())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var hex = "0123456789abcdef"
|
||||
|
||||
func writeString(s string, buf *bytes.Buffer) {
|
||||
buf.WriteByte('"')
|
||||
for i := 0; i < len(s); i++ {
|
||||
if s[i] == '"' {
|
||||
buf.WriteString(`\"`)
|
||||
} else if s[i] == '\\' {
|
||||
buf.WriteString(`\\`)
|
||||
} else if s[i] == '\b' {
|
||||
buf.WriteString(`\b`)
|
||||
} else if s[i] == '\f' {
|
||||
buf.WriteString(`\f`)
|
||||
} else if s[i] == '\r' {
|
||||
buf.WriteString(`\r`)
|
||||
} else if s[i] == '\t' {
|
||||
buf.WriteString(`\t`)
|
||||
} else if s[i] == '\n' {
|
||||
buf.WriteString(`\n`)
|
||||
} else if s[i] < 32 {
|
||||
buf.WriteString("\\u00")
|
||||
buf.WriteByte(hex[s[i]>>4])
|
||||
buf.WriteByte(hex[s[i]&0xF])
|
||||
} else {
|
||||
buf.WriteByte(s[i])
|
||||
}
|
||||
}
|
||||
buf.WriteByte('"')
|
||||
}
|
||||
|
||||
// Returns the reflection element of a value, if it is a pointer.
|
||||
func elemOf(value reflect.Value) reflect.Value {
|
||||
for value.Kind() == reflect.Ptr {
|
||||
value = value.Elem()
|
||||
}
|
||||
return value
|
||||
}
|
109
vendor/github.com/aws/aws-sdk-go/private/protocol/json/jsonutil/build_test.go
generated
vendored
109
vendor/github.com/aws/aws-sdk-go/private/protocol/json/jsonutil/build_test.go
generated
vendored
|
@ -1,109 +0,0 @@
|
|||
package jsonutil_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/private/protocol/json/jsonutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func S(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
func D(s int64) *int64 {
|
||||
return &s
|
||||
}
|
||||
|
||||
func F(s float64) *float64 {
|
||||
return &s
|
||||
}
|
||||
|
||||
func T(s time.Time) *time.Time {
|
||||
return &s
|
||||
}
|
||||
|
||||
type J struct {
|
||||
S *string
|
||||
SS []string
|
||||
D *int64
|
||||
F *float64
|
||||
T *time.Time
|
||||
}
|
||||
|
||||
var zero = 0.0
|
||||
|
||||
var jsonTests = []struct {
|
||||
in interface{}
|
||||
out string
|
||||
err string
|
||||
}{
|
||||
{
|
||||
J{},
|
||||
`{}`,
|
||||
``,
|
||||
},
|
||||
{
|
||||
J{
|
||||
S: S("str"),
|
||||
SS: []string{"A", "B", "C"},
|
||||
D: D(123),
|
||||
F: F(4.56),
|
||||
T: T(time.Unix(987, 0)),
|
||||
},
|
||||
`{"S":"str","SS":["A","B","C"],"D":123,"F":4.56,"T":987}`,
|
||||
``,
|
||||
},
|
||||
{
|
||||
J{
|
||||
S: S(`"''"`),
|
||||
},
|
||||
`{"S":"\"''\""}`,
|
||||
``,
|
||||
},
|
||||
{
|
||||
J{
|
||||
S: S("\x00føø\u00FF\n\\\"\r\t\b\f"),
|
||||
},
|
||||
`{"S":"\u0000føøÿ\n\\\"\r\t\b\f"}`,
|
||||
``,
|
||||
},
|
||||
{
|
||||
J{
|
||||
F: F(4.56 / zero),
|
||||
},
|
||||
"",
|
||||
`json: unsupported value: +Inf`,
|
||||
},
|
||||
}
|
||||
|
||||
func TestBuildJSON(t *testing.T) {
|
||||
for _, test := range jsonTests {
|
||||
out, err := jsonutil.BuildJSON(test.in)
|
||||
if test.err != "" {
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), test.err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, string(out), test.out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBuildJSON(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
for _, test := range jsonTests {
|
||||
jsonutil.BuildJSON(test.in)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkStdlibJSON(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
for _, test := range jsonTests {
|
||||
json.Marshal(test.in)
|
||||
}
|
||||
}
|
||||
}
|
226
vendor/github.com/aws/aws-sdk-go/private/protocol/json/jsonutil/unmarshal.go
generated
vendored
226
vendor/github.com/aws/aws-sdk-go/private/protocol/json/jsonutil/unmarshal.go
generated
vendored
|
@ -1,226 +0,0 @@
|
|||
package jsonutil
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/private/protocol"
|
||||
)
|
||||
|
||||
// UnmarshalJSON reads a stream and unmarshals the results in object v.
|
||||
func UnmarshalJSON(v interface{}, stream io.Reader) error {
|
||||
var out interface{}
|
||||
|
||||
b, err := ioutil.ReadAll(stream)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(b) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(b, &out); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return unmarshalAny(reflect.ValueOf(v), out, "")
|
||||
}
|
||||
|
||||
func unmarshalAny(value reflect.Value, data interface{}, tag reflect.StructTag) error {
|
||||
vtype := value.Type()
|
||||
if vtype.Kind() == reflect.Ptr {
|
||||
vtype = vtype.Elem() // check kind of actual element type
|
||||
}
|
||||
|
||||
t := tag.Get("type")
|
||||
if t == "" {
|
||||
switch vtype.Kind() {
|
||||
case reflect.Struct:
|
||||
// also it can't be a time object
|
||||
if _, ok := value.Interface().(*time.Time); !ok {
|
||||
t = "structure"
|
||||
}
|
||||
case reflect.Slice:
|
||||
// also it can't be a byte slice
|
||||
if _, ok := value.Interface().([]byte); !ok {
|
||||
t = "list"
|
||||
}
|
||||
case reflect.Map:
|
||||
// cannot be a JSONValue map
|
||||
if _, ok := value.Interface().(aws.JSONValue); !ok {
|
||||
t = "map"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch t {
|
||||
case "structure":
|
||||
if field, ok := vtype.FieldByName("_"); ok {
|
||||
tag = field.Tag
|
||||
}
|
||||
return unmarshalStruct(value, data, tag)
|
||||
case "list":
|
||||
return unmarshalList(value, data, tag)
|
||||
case "map":
|
||||
return unmarshalMap(value, data, tag)
|
||||
default:
|
||||
return unmarshalScalar(value, data, tag)
|
||||
}
|
||||
}
|
||||
|
||||
func unmarshalStruct(value reflect.Value, data interface{}, tag reflect.StructTag) error {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
mapData, ok := data.(map[string]interface{})
|
||||
if !ok {
|
||||
return fmt.Errorf("JSON value is not a structure (%#v)", data)
|
||||
}
|
||||
|
||||
t := value.Type()
|
||||
if value.Kind() == reflect.Ptr {
|
||||
if value.IsNil() { // create the structure if it's nil
|
||||
s := reflect.New(value.Type().Elem())
|
||||
value.Set(s)
|
||||
value = s
|
||||
}
|
||||
|
||||
value = value.Elem()
|
||||
t = t.Elem()
|
||||
}
|
||||
|
||||
// unwrap any payloads
|
||||
if payload := tag.Get("payload"); payload != "" {
|
||||
field, _ := t.FieldByName(payload)
|
||||
return unmarshalAny(value.FieldByName(payload), data, field.Tag)
|
||||
}
|
||||
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
field := t.Field(i)
|
||||
if field.PkgPath != "" {
|
||||
continue // ignore unexported fields
|
||||
}
|
||||
|
||||
// figure out what this field is called
|
||||
name := field.Name
|
||||
if locName := field.Tag.Get("locationName"); locName != "" {
|
||||
name = locName
|
||||
}
|
||||
|
||||
member := value.FieldByIndex(field.Index)
|
||||
err := unmarshalAny(member, mapData[name], field.Tag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalList(value reflect.Value, data interface{}, tag reflect.StructTag) error {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
listData, ok := data.([]interface{})
|
||||
if !ok {
|
||||
return fmt.Errorf("JSON value is not a list (%#v)", data)
|
||||
}
|
||||
|
||||
if value.IsNil() {
|
||||
l := len(listData)
|
||||
value.Set(reflect.MakeSlice(value.Type(), l, l))
|
||||
}
|
||||
|
||||
for i, c := range listData {
|
||||
err := unmarshalAny(value.Index(i), c, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalMap(value reflect.Value, data interface{}, tag reflect.StructTag) error {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
mapData, ok := data.(map[string]interface{})
|
||||
if !ok {
|
||||
return fmt.Errorf("JSON value is not a map (%#v)", data)
|
||||
}
|
||||
|
||||
if value.IsNil() {
|
||||
value.Set(reflect.MakeMap(value.Type()))
|
||||
}
|
||||
|
||||
for k, v := range mapData {
|
||||
kvalue := reflect.ValueOf(k)
|
||||
vvalue := reflect.New(value.Type().Elem()).Elem()
|
||||
|
||||
unmarshalAny(vvalue, v, "")
|
||||
value.SetMapIndex(kvalue, vvalue)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalScalar(value reflect.Value, data interface{}, tag reflect.StructTag) error {
|
||||
errf := func() error {
|
||||
return fmt.Errorf("unsupported value: %v (%s)", value.Interface(), value.Type())
|
||||
}
|
||||
|
||||
switch d := data.(type) {
|
||||
case nil:
|
||||
return nil // nothing to do here
|
||||
case string:
|
||||
switch value.Interface().(type) {
|
||||
case *string:
|
||||
value.Set(reflect.ValueOf(&d))
|
||||
case []byte:
|
||||
b, err := base64.StdEncoding.DecodeString(d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
value.Set(reflect.ValueOf(b))
|
||||
case aws.JSONValue:
|
||||
// No need to use escaping as the value is a non-quoted string.
|
||||
v, err := protocol.DecodeJSONValue(d, protocol.NoEscape)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
value.Set(reflect.ValueOf(v))
|
||||
default:
|
||||
return errf()
|
||||
}
|
||||
case float64:
|
||||
switch value.Interface().(type) {
|
||||
case *int64:
|
||||
di := int64(d)
|
||||
value.Set(reflect.ValueOf(&di))
|
||||
case *float64:
|
||||
value.Set(reflect.ValueOf(&d))
|
||||
case *time.Time:
|
||||
t := time.Unix(int64(d), 0).UTC()
|
||||
value.Set(reflect.ValueOf(&t))
|
||||
default:
|
||||
return errf()
|
||||
}
|
||||
case bool:
|
||||
switch value.Interface().(type) {
|
||||
case *bool:
|
||||
value.Set(reflect.ValueOf(&d))
|
||||
default:
|
||||
return errf()
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unsupported JSON value (%v)", data)
|
||||
}
|
||||
return nil
|
||||
}
|
71
vendor/github.com/aws/aws-sdk-go/private/protocol/jsonrpc/build_bench_test.go
generated
vendored
71
vendor/github.com/aws/aws-sdk-go/private/protocol/jsonrpc/build_bench_test.go
generated
vendored
|
@ -1,71 +0,0 @@
|
|||
// +build bench
|
||||
|
||||
package jsonrpc_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/awstesting"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/json/jsonutil"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/jsonrpc"
|
||||
"github.com/aws/aws-sdk-go/service/dynamodb"
|
||||
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
|
||||
)
|
||||
|
||||
func BenchmarkJSONRPCBuild_Simple_dynamodbPutItem(b *testing.B) {
|
||||
svc := awstesting.NewClient()
|
||||
|
||||
params := getDynamodbPutItemParams(b)
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
r := svc.NewRequest(&request.Operation{Name: "Operation"}, params, nil)
|
||||
jsonrpc.Build(r)
|
||||
if r.Error != nil {
|
||||
b.Fatal("Unexpected error", r.Error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkJSONUtilBuild_Simple_dynamodbPutItem(b *testing.B) {
|
||||
svc := awstesting.NewClient()
|
||||
|
||||
params := getDynamodbPutItemParams(b)
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
r := svc.NewRequest(&request.Operation{Name: "Operation"}, params, nil)
|
||||
_, err := jsonutil.BuildJSON(r.Params)
|
||||
if err != nil {
|
||||
b.Fatal("Unexpected error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkEncodingJSONMarshal_Simple_dynamodbPutItem(b *testing.B) {
|
||||
params := getDynamodbPutItemParams(b)
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
buf := &bytes.Buffer{}
|
||||
encoder := json.NewEncoder(buf)
|
||||
if err := encoder.Encode(params); err != nil {
|
||||
b.Fatal("Unexpected error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getDynamodbPutItemParams(b *testing.B) *dynamodb.PutItemInput {
|
||||
av, err := dynamodbattribute.ConvertToMap(struct {
|
||||
Key string
|
||||
Data string
|
||||
}{Key: "MyKey", Data: "MyData"})
|
||||
if err != nil {
|
||||
b.Fatal("benchPutItem, expect no ConvertToMap errors", err)
|
||||
}
|
||||
return &dynamodb.PutItemInput{
|
||||
Item: av,
|
||||
TableName: aws.String("tablename"),
|
||||
}
|
||||
}
|
2452
vendor/github.com/aws/aws-sdk-go/private/protocol/jsonrpc/build_test.go
generated
vendored
2452
vendor/github.com/aws/aws-sdk-go/private/protocol/jsonrpc/build_test.go
generated
vendored
File diff suppressed because it is too large
Load diff
111
vendor/github.com/aws/aws-sdk-go/private/protocol/jsonrpc/jsonrpc.go
generated
vendored
111
vendor/github.com/aws/aws-sdk-go/private/protocol/jsonrpc/jsonrpc.go
generated
vendored
|
@ -1,111 +0,0 @@
|
|||
// Package jsonrpc provides JSON RPC utilities for serialization of AWS
|
||||
// requests and responses.
|
||||
package jsonrpc
|
||||
|
||||
//go:generate go run -tags codegen ../../../models/protocol_tests/generate.go ../../../models/protocol_tests/input/json.json build_test.go
|
||||
//go:generate go run -tags codegen ../../../models/protocol_tests/generate.go ../../../models/protocol_tests/output/json.json unmarshal_test.go
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/json/jsonutil"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/rest"
|
||||
)
|
||||
|
||||
var emptyJSON = []byte("{}")
|
||||
|
||||
// BuildHandler is a named request handler for building jsonrpc protocol requests
|
||||
var BuildHandler = request.NamedHandler{Name: "awssdk.jsonrpc.Build", Fn: Build}
|
||||
|
||||
// UnmarshalHandler is a named request handler for unmarshaling jsonrpc protocol requests
|
||||
var UnmarshalHandler = request.NamedHandler{Name: "awssdk.jsonrpc.Unmarshal", Fn: Unmarshal}
|
||||
|
||||
// UnmarshalMetaHandler is a named request handler for unmarshaling jsonrpc protocol request metadata
|
||||
var UnmarshalMetaHandler = request.NamedHandler{Name: "awssdk.jsonrpc.UnmarshalMeta", Fn: UnmarshalMeta}
|
||||
|
||||
// UnmarshalErrorHandler is a named request handler for unmarshaling jsonrpc protocol request errors
|
||||
var UnmarshalErrorHandler = request.NamedHandler{Name: "awssdk.jsonrpc.UnmarshalError", Fn: UnmarshalError}
|
||||
|
||||
// Build builds a JSON payload for a JSON RPC request.
|
||||
func Build(req *request.Request) {
|
||||
var buf []byte
|
||||
var err error
|
||||
if req.ParamsFilled() {
|
||||
buf, err = jsonutil.BuildJSON(req.Params)
|
||||
if err != nil {
|
||||
req.Error = awserr.New("SerializationError", "failed encoding JSON RPC request", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
buf = emptyJSON
|
||||
}
|
||||
|
||||
if req.ClientInfo.TargetPrefix != "" || string(buf) != "{}" {
|
||||
req.SetBufferBody(buf)
|
||||
}
|
||||
|
||||
if req.ClientInfo.TargetPrefix != "" {
|
||||
target := req.ClientInfo.TargetPrefix + "." + req.Operation.Name
|
||||
req.HTTPRequest.Header.Add("X-Amz-Target", target)
|
||||
}
|
||||
if req.ClientInfo.JSONVersion != "" {
|
||||
jsonVersion := req.ClientInfo.JSONVersion
|
||||
req.HTTPRequest.Header.Add("Content-Type", "application/x-amz-json-"+jsonVersion)
|
||||
}
|
||||
}
|
||||
|
||||
// Unmarshal unmarshals a response for a JSON RPC service.
|
||||
func Unmarshal(req *request.Request) {
|
||||
defer req.HTTPResponse.Body.Close()
|
||||
if req.DataFilled() {
|
||||
err := jsonutil.UnmarshalJSON(req.Data, req.HTTPResponse.Body)
|
||||
if err != nil {
|
||||
req.Error = awserr.New("SerializationError", "failed decoding JSON RPC response", err)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// UnmarshalMeta unmarshals headers from a response for a JSON RPC service.
|
||||
func UnmarshalMeta(req *request.Request) {
|
||||
rest.UnmarshalMeta(req)
|
||||
}
|
||||
|
||||
// UnmarshalError unmarshals an error response for a JSON RPC service.
|
||||
func UnmarshalError(req *request.Request) {
|
||||
defer req.HTTPResponse.Body.Close()
|
||||
bodyBytes, err := ioutil.ReadAll(req.HTTPResponse.Body)
|
||||
if err != nil {
|
||||
req.Error = awserr.New("SerializationError", "failed reading JSON RPC error response", err)
|
||||
return
|
||||
}
|
||||
if len(bodyBytes) == 0 {
|
||||
req.Error = awserr.NewRequestFailure(
|
||||
awserr.New("SerializationError", req.HTTPResponse.Status, nil),
|
||||
req.HTTPResponse.StatusCode,
|
||||
"",
|
||||
)
|
||||
return
|
||||
}
|
||||
var jsonErr jsonErrorResponse
|
||||
if err := json.Unmarshal(bodyBytes, &jsonErr); err != nil {
|
||||
req.Error = awserr.New("SerializationError", "failed decoding JSON RPC error response", err)
|
||||
return
|
||||
}
|
||||
|
||||
codes := strings.SplitN(jsonErr.Code, "#", 2)
|
||||
req.Error = awserr.NewRequestFailure(
|
||||
awserr.New(codes[len(codes)-1], jsonErr.Message, nil),
|
||||
req.HTTPResponse.StatusCode,
|
||||
req.RequestID,
|
||||
)
|
||||
}
|
||||
|
||||
type jsonErrorResponse struct {
|
||||
Code string `json:"__type"`
|
||||
Message string `json:"message"`
|
||||
}
|
1528
vendor/github.com/aws/aws-sdk-go/private/protocol/jsonrpc/unmarshal_test.go
generated
vendored
1528
vendor/github.com/aws/aws-sdk-go/private/protocol/jsonrpc/unmarshal_test.go
generated
vendored
File diff suppressed because it is too large
Load diff
350
vendor/github.com/aws/aws-sdk-go/private/protocol/restjson/build_bench_test.go
generated
vendored
350
vendor/github.com/aws/aws-sdk-go/private/protocol/restjson/build_bench_test.go
generated
vendored
|
@ -1,350 +0,0 @@
|
|||
// +build bench
|
||||
|
||||
package restjson_test
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/endpoints"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/restjson"
|
||||
"github.com/aws/aws-sdk-go/service/elastictranscoder"
|
||||
)
|
||||
|
||||
var (
|
||||
elastictranscoderSvc *elastictranscoder.ElasticTranscoder
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
|
||||
sess := session.Must(session.NewSession(&aws.Config{
|
||||
Credentials: credentials.NewStaticCredentials("Key", "Secret", "Token"),
|
||||
Endpoint: aws.String(server.URL),
|
||||
S3ForcePathStyle: aws.Bool(true),
|
||||
DisableSSL: aws.Bool(true),
|
||||
Region: aws.String(endpoints.UsWest2RegionID),
|
||||
}))
|
||||
elastictranscoderSvc = elastictranscoder.New(sess)
|
||||
|
||||
c := m.Run()
|
||||
server.Close()
|
||||
os.Exit(c)
|
||||
}
|
||||
|
||||
func BenchmarkRESTJSONBuild_Complex_ETCCreateJob(b *testing.B) {
|
||||
params := elastictranscoderCreateJobInput()
|
||||
|
||||
benchRESTJSONBuild(b, func() *request.Request {
|
||||
req, _ := elastictranscoderSvc.CreateJobRequest(params)
|
||||
return req
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkRESTJSONBuild_Simple_ETCListJobsByPipeline(b *testing.B) {
|
||||
params := elastictranscoderListJobsByPipeline()
|
||||
|
||||
benchRESTJSONBuild(b, func() *request.Request {
|
||||
req, _ := elastictranscoderSvc.ListJobsByPipelineRequest(params)
|
||||
return req
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkRESTJSONRequest_Complex_CFCreateJob(b *testing.B) {
|
||||
benchRESTJSONRequest(b, func() *request.Request {
|
||||
req, _ := elastictranscoderSvc.CreateJobRequest(elastictranscoderCreateJobInput())
|
||||
return req
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkRESTJSONRequest_Simple_ETCListJobsByPipeline(b *testing.B) {
|
||||
benchRESTJSONRequest(b, func() *request.Request {
|
||||
req, _ := elastictranscoderSvc.ListJobsByPipelineRequest(elastictranscoderListJobsByPipeline())
|
||||
return req
|
||||
})
|
||||
}
|
||||
|
||||
func benchRESTJSONBuild(b *testing.B, reqFn func() *request.Request) {
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
req := reqFn()
|
||||
restjson.Build(req)
|
||||
if req.Error != nil {
|
||||
b.Fatal("Unexpected error", req.Error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func benchRESTJSONRequest(b *testing.B, reqFn func() *request.Request) {
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
err := reqFn().Send()
|
||||
if err != nil {
|
||||
b.Fatal("Unexpected error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func elastictranscoderListJobsByPipeline() *elastictranscoder.ListJobsByPipelineInput {
|
||||
return &elastictranscoder.ListJobsByPipelineInput{
|
||||
PipelineId: aws.String("Id"), // Required
|
||||
Ascending: aws.String("Ascending"),
|
||||
PageToken: aws.String("Id"),
|
||||
}
|
||||
}
|
||||
|
||||
func elastictranscoderCreateJobInput() *elastictranscoder.CreateJobInput {
|
||||
return &elastictranscoder.CreateJobInput{
|
||||
Input: &elastictranscoder.JobInput{ // Required
|
||||
AspectRatio: aws.String("AspectRatio"),
|
||||
Container: aws.String("JobContainer"),
|
||||
DetectedProperties: &elastictranscoder.DetectedProperties{
|
||||
DurationMillis: aws.Int64(1),
|
||||
FileSize: aws.Int64(1),
|
||||
FrameRate: aws.String("FloatString"),
|
||||
Height: aws.Int64(1),
|
||||
Width: aws.Int64(1),
|
||||
},
|
||||
Encryption: &elastictranscoder.Encryption{
|
||||
InitializationVector: aws.String("ZeroTo255String"),
|
||||
Key: aws.String("Base64EncodedString"),
|
||||
KeyMd5: aws.String("Base64EncodedString"),
|
||||
Mode: aws.String("EncryptionMode"),
|
||||
},
|
||||
FrameRate: aws.String("FrameRate"),
|
||||
Interlaced: aws.String("Interlaced"),
|
||||
Key: aws.String("Key"),
|
||||
Resolution: aws.String("Resolution"),
|
||||
},
|
||||
PipelineId: aws.String("Id"), // Required
|
||||
Output: &elastictranscoder.CreateJobOutput{
|
||||
AlbumArt: &elastictranscoder.JobAlbumArt{
|
||||
Artwork: []*elastictranscoder.Artwork{
|
||||
{ // Required
|
||||
AlbumArtFormat: aws.String("JpgOrPng"),
|
||||
Encryption: &elastictranscoder.Encryption{
|
||||
InitializationVector: aws.String("ZeroTo255String"),
|
||||
Key: aws.String("Base64EncodedString"),
|
||||
KeyMd5: aws.String("Base64EncodedString"),
|
||||
Mode: aws.String("EncryptionMode"),
|
||||
},
|
||||
InputKey: aws.String("WatermarkKey"),
|
||||
MaxHeight: aws.String("DigitsOrAuto"),
|
||||
MaxWidth: aws.String("DigitsOrAuto"),
|
||||
PaddingPolicy: aws.String("PaddingPolicy"),
|
||||
SizingPolicy: aws.String("SizingPolicy"),
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
MergePolicy: aws.String("MergePolicy"),
|
||||
},
|
||||
Captions: &elastictranscoder.Captions{
|
||||
CaptionFormats: []*elastictranscoder.CaptionFormat{
|
||||
{ // Required
|
||||
Encryption: &elastictranscoder.Encryption{
|
||||
InitializationVector: aws.String("ZeroTo255String"),
|
||||
Key: aws.String("Base64EncodedString"),
|
||||
KeyMd5: aws.String("Base64EncodedString"),
|
||||
Mode: aws.String("EncryptionMode"),
|
||||
},
|
||||
Format: aws.String("CaptionFormatFormat"),
|
||||
Pattern: aws.String("CaptionFormatPattern"),
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
CaptionSources: []*elastictranscoder.CaptionSource{
|
||||
{ // Required
|
||||
Encryption: &elastictranscoder.Encryption{
|
||||
InitializationVector: aws.String("ZeroTo255String"),
|
||||
Key: aws.String("Base64EncodedString"),
|
||||
KeyMd5: aws.String("Base64EncodedString"),
|
||||
Mode: aws.String("EncryptionMode"),
|
||||
},
|
||||
Key: aws.String("Key"),
|
||||
Label: aws.String("Name"),
|
||||
Language: aws.String("Key"),
|
||||
TimeOffset: aws.String("TimeOffset"),
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
MergePolicy: aws.String("CaptionMergePolicy"),
|
||||
},
|
||||
Composition: []*elastictranscoder.Clip{
|
||||
{ // Required
|
||||
TimeSpan: &elastictranscoder.TimeSpan{
|
||||
Duration: aws.String("Time"),
|
||||
StartTime: aws.String("Time"),
|
||||
},
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
Encryption: &elastictranscoder.Encryption{
|
||||
InitializationVector: aws.String("ZeroTo255String"),
|
||||
Key: aws.String("Base64EncodedString"),
|
||||
KeyMd5: aws.String("Base64EncodedString"),
|
||||
Mode: aws.String("EncryptionMode"),
|
||||
},
|
||||
Key: aws.String("Key"),
|
||||
PresetId: aws.String("Id"),
|
||||
Rotate: aws.String("Rotate"),
|
||||
SegmentDuration: aws.String("FloatString"),
|
||||
ThumbnailEncryption: &elastictranscoder.Encryption{
|
||||
InitializationVector: aws.String("ZeroTo255String"),
|
||||
Key: aws.String("Base64EncodedString"),
|
||||
KeyMd5: aws.String("Base64EncodedString"),
|
||||
Mode: aws.String("EncryptionMode"),
|
||||
},
|
||||
ThumbnailPattern: aws.String("ThumbnailPattern"),
|
||||
Watermarks: []*elastictranscoder.JobWatermark{
|
||||
{ // Required
|
||||
Encryption: &elastictranscoder.Encryption{
|
||||
InitializationVector: aws.String("ZeroTo255String"),
|
||||
Key: aws.String("Base64EncodedString"),
|
||||
KeyMd5: aws.String("Base64EncodedString"),
|
||||
Mode: aws.String("EncryptionMode"),
|
||||
},
|
||||
InputKey: aws.String("WatermarkKey"),
|
||||
PresetWatermarkId: aws.String("PresetWatermarkId"),
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
},
|
||||
OutputKeyPrefix: aws.String("Key"),
|
||||
Outputs: []*elastictranscoder.CreateJobOutput{
|
||||
{ // Required
|
||||
AlbumArt: &elastictranscoder.JobAlbumArt{
|
||||
Artwork: []*elastictranscoder.Artwork{
|
||||
{ // Required
|
||||
AlbumArtFormat: aws.String("JpgOrPng"),
|
||||
Encryption: &elastictranscoder.Encryption{
|
||||
InitializationVector: aws.String("ZeroTo255String"),
|
||||
Key: aws.String("Base64EncodedString"),
|
||||
KeyMd5: aws.String("Base64EncodedString"),
|
||||
Mode: aws.String("EncryptionMode"),
|
||||
},
|
||||
InputKey: aws.String("WatermarkKey"),
|
||||
MaxHeight: aws.String("DigitsOrAuto"),
|
||||
MaxWidth: aws.String("DigitsOrAuto"),
|
||||
PaddingPolicy: aws.String("PaddingPolicy"),
|
||||
SizingPolicy: aws.String("SizingPolicy"),
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
MergePolicy: aws.String("MergePolicy"),
|
||||
},
|
||||
Captions: &elastictranscoder.Captions{
|
||||
CaptionFormats: []*elastictranscoder.CaptionFormat{
|
||||
{ // Required
|
||||
Encryption: &elastictranscoder.Encryption{
|
||||
InitializationVector: aws.String("ZeroTo255String"),
|
||||
Key: aws.String("Base64EncodedString"),
|
||||
KeyMd5: aws.String("Base64EncodedString"),
|
||||
Mode: aws.String("EncryptionMode"),
|
||||
},
|
||||
Format: aws.String("CaptionFormatFormat"),
|
||||
Pattern: aws.String("CaptionFormatPattern"),
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
CaptionSources: []*elastictranscoder.CaptionSource{
|
||||
{ // Required
|
||||
Encryption: &elastictranscoder.Encryption{
|
||||
InitializationVector: aws.String("ZeroTo255String"),
|
||||
Key: aws.String("Base64EncodedString"),
|
||||
KeyMd5: aws.String("Base64EncodedString"),
|
||||
Mode: aws.String("EncryptionMode"),
|
||||
},
|
||||
Key: aws.String("Key"),
|
||||
Label: aws.String("Name"),
|
||||
Language: aws.String("Key"),
|
||||
TimeOffset: aws.String("TimeOffset"),
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
MergePolicy: aws.String("CaptionMergePolicy"),
|
||||
},
|
||||
Composition: []*elastictranscoder.Clip{
|
||||
{ // Required
|
||||
TimeSpan: &elastictranscoder.TimeSpan{
|
||||
Duration: aws.String("Time"),
|
||||
StartTime: aws.String("Time"),
|
||||
},
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
Encryption: &elastictranscoder.Encryption{
|
||||
InitializationVector: aws.String("ZeroTo255String"),
|
||||
Key: aws.String("Base64EncodedString"),
|
||||
KeyMd5: aws.String("Base64EncodedString"),
|
||||
Mode: aws.String("EncryptionMode"),
|
||||
},
|
||||
Key: aws.String("Key"),
|
||||
PresetId: aws.String("Id"),
|
||||
Rotate: aws.String("Rotate"),
|
||||
SegmentDuration: aws.String("FloatString"),
|
||||
ThumbnailEncryption: &elastictranscoder.Encryption{
|
||||
InitializationVector: aws.String("ZeroTo255String"),
|
||||
Key: aws.String("Base64EncodedString"),
|
||||
KeyMd5: aws.String("Base64EncodedString"),
|
||||
Mode: aws.String("EncryptionMode"),
|
||||
},
|
||||
ThumbnailPattern: aws.String("ThumbnailPattern"),
|
||||
Watermarks: []*elastictranscoder.JobWatermark{
|
||||
{ // Required
|
||||
Encryption: &elastictranscoder.Encryption{
|
||||
InitializationVector: aws.String("ZeroTo255String"),
|
||||
Key: aws.String("Base64EncodedString"),
|
||||
KeyMd5: aws.String("Base64EncodedString"),
|
||||
Mode: aws.String("EncryptionMode"),
|
||||
},
|
||||
InputKey: aws.String("WatermarkKey"),
|
||||
PresetWatermarkId: aws.String("PresetWatermarkId"),
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
Playlists: []*elastictranscoder.CreateJobPlaylist{
|
||||
{ // Required
|
||||
Format: aws.String("PlaylistFormat"),
|
||||
HlsContentProtection: &elastictranscoder.HlsContentProtection{
|
||||
InitializationVector: aws.String("ZeroTo255String"),
|
||||
Key: aws.String("Base64EncodedString"),
|
||||
KeyMd5: aws.String("Base64EncodedString"),
|
||||
KeyStoragePolicy: aws.String("KeyStoragePolicy"),
|
||||
LicenseAcquisitionUrl: aws.String("ZeroTo512String"),
|
||||
Method: aws.String("HlsContentProtectionMethod"),
|
||||
},
|
||||
Name: aws.String("Filename"),
|
||||
OutputKeys: []*string{
|
||||
aws.String("Key"), // Required
|
||||
// More values...
|
||||
},
|
||||
PlayReadyDrm: &elastictranscoder.PlayReadyDrm{
|
||||
Format: aws.String("PlayReadyDrmFormatString"),
|
||||
InitializationVector: aws.String("ZeroTo255String"),
|
||||
Key: aws.String("NonEmptyBase64EncodedString"),
|
||||
KeyId: aws.String("KeyIdGuid"),
|
||||
KeyMd5: aws.String("NonEmptyBase64EncodedString"),
|
||||
LicenseAcquisitionUrl: aws.String("OneTo512String"),
|
||||
},
|
||||
},
|
||||
// More values...
|
||||
},
|
||||
UserMetadata: map[string]*string{
|
||||
"Key": aws.String("String"), // Required
|
||||
// More values...
|
||||
},
|
||||
}
|
||||
}
|
5658
vendor/github.com/aws/aws-sdk-go/private/protocol/restjson/build_test.go
generated
vendored
5658
vendor/github.com/aws/aws-sdk-go/private/protocol/restjson/build_test.go
generated
vendored
File diff suppressed because it is too large
Load diff
92
vendor/github.com/aws/aws-sdk-go/private/protocol/restjson/restjson.go
generated
vendored
92
vendor/github.com/aws/aws-sdk-go/private/protocol/restjson/restjson.go
generated
vendored
|
@ -1,92 +0,0 @@
|
|||
// Package restjson provides RESTful JSON serialization of AWS
|
||||
// requests and responses.
|
||||
package restjson
|
||||
|
||||
//go:generate go run -tags codegen ../../../models/protocol_tests/generate.go ../../../models/protocol_tests/input/rest-json.json build_test.go
|
||||
//go:generate go run -tags codegen ../../../models/protocol_tests/generate.go ../../../models/protocol_tests/output/rest-json.json unmarshal_test.go
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/jsonrpc"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/rest"
|
||||
)
|
||||
|
||||
// BuildHandler is a named request handler for building restjson protocol requests
|
||||
var BuildHandler = request.NamedHandler{Name: "awssdk.restjson.Build", Fn: Build}
|
||||
|
||||
// UnmarshalHandler is a named request handler for unmarshaling restjson protocol requests
|
||||
var UnmarshalHandler = request.NamedHandler{Name: "awssdk.restjson.Unmarshal", Fn: Unmarshal}
|
||||
|
||||
// UnmarshalMetaHandler is a named request handler for unmarshaling restjson protocol request metadata
|
||||
var UnmarshalMetaHandler = request.NamedHandler{Name: "awssdk.restjson.UnmarshalMeta", Fn: UnmarshalMeta}
|
||||
|
||||
// UnmarshalErrorHandler is a named request handler for unmarshaling restjson protocol request errors
|
||||
var UnmarshalErrorHandler = request.NamedHandler{Name: "awssdk.restjson.UnmarshalError", Fn: UnmarshalError}
|
||||
|
||||
// Build builds a request for the REST JSON protocol.
|
||||
func Build(r *request.Request) {
|
||||
rest.Build(r)
|
||||
|
||||
if t := rest.PayloadType(r.Params); t == "structure" || t == "" {
|
||||
jsonrpc.Build(r)
|
||||
}
|
||||
}
|
||||
|
||||
// Unmarshal unmarshals a response body for the REST JSON protocol.
|
||||
func Unmarshal(r *request.Request) {
|
||||
if t := rest.PayloadType(r.Data); t == "structure" || t == "" {
|
||||
jsonrpc.Unmarshal(r)
|
||||
} else {
|
||||
rest.Unmarshal(r)
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalMeta unmarshals response headers for the REST JSON protocol.
|
||||
func UnmarshalMeta(r *request.Request) {
|
||||
rest.UnmarshalMeta(r)
|
||||
}
|
||||
|
||||
// UnmarshalError unmarshals a response error for the REST JSON protocol.
|
||||
func UnmarshalError(r *request.Request) {
|
||||
defer r.HTTPResponse.Body.Close()
|
||||
code := r.HTTPResponse.Header.Get("X-Amzn-Errortype")
|
||||
bodyBytes, err := ioutil.ReadAll(r.HTTPResponse.Body)
|
||||
if err != nil {
|
||||
r.Error = awserr.New("SerializationError", "failed reading REST JSON error response", err)
|
||||
return
|
||||
}
|
||||
if len(bodyBytes) == 0 {
|
||||
r.Error = awserr.NewRequestFailure(
|
||||
awserr.New("SerializationError", r.HTTPResponse.Status, nil),
|
||||
r.HTTPResponse.StatusCode,
|
||||
"",
|
||||
)
|
||||
return
|
||||
}
|
||||
var jsonErr jsonErrorResponse
|
||||
if err := json.Unmarshal(bodyBytes, &jsonErr); err != nil {
|
||||
r.Error = awserr.New("SerializationError", "failed decoding REST JSON error response", err)
|
||||
return
|
||||
}
|
||||
|
||||
if code == "" {
|
||||
code = jsonErr.Code
|
||||
}
|
||||
|
||||
code = strings.SplitN(code, ":", 2)[0]
|
||||
r.Error = awserr.NewRequestFailure(
|
||||
awserr.New(code, jsonErr.Message, nil),
|
||||
r.HTTPResponse.StatusCode,
|
||||
r.RequestID,
|
||||
)
|
||||
}
|
||||
|
||||
type jsonErrorResponse struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
}
|
2839
vendor/github.com/aws/aws-sdk-go/private/protocol/restjson/unmarshal_test.go
generated
vendored
2839
vendor/github.com/aws/aws-sdk-go/private/protocol/restjson/unmarshal_test.go
generated
vendored
File diff suppressed because it is too large
Load diff
180
vendor/github.com/aws/aws-sdk-go/private/signer/v2/v2.go
generated
vendored
180
vendor/github.com/aws/aws-sdk-go/private/signer/v2/v2.go
generated
vendored
|
@ -1,180 +0,0 @@
|
|||
package v2
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
)
|
||||
|
||||
var (
|
||||
errInvalidMethod = errors.New("v2 signer only handles HTTP POST")
|
||||
)
|
||||
|
||||
const (
|
||||
signatureVersion = "2"
|
||||
signatureMethod = "HmacSHA256"
|
||||
timeFormat = "2006-01-02T15:04:05Z"
|
||||
)
|
||||
|
||||
type signer struct {
|
||||
// Values that must be populated from the request
|
||||
Request *http.Request
|
||||
Time time.Time
|
||||
Credentials *credentials.Credentials
|
||||
Debug aws.LogLevelType
|
||||
Logger aws.Logger
|
||||
|
||||
Query url.Values
|
||||
stringToSign string
|
||||
signature string
|
||||
}
|
||||
|
||||
// SignRequestHandler is a named request handler the SDK will use to sign
|
||||
// service client request with using the V4 signature.
|
||||
var SignRequestHandler = request.NamedHandler{
|
||||
Name: "v2.SignRequestHandler", Fn: SignSDKRequest,
|
||||
}
|
||||
|
||||
// SignSDKRequest requests with signature version 2.
|
||||
//
|
||||
// Will sign the requests with the service config's Credentials object
|
||||
// Signing is skipped if the credentials is the credentials.AnonymousCredentials
|
||||
// object.
|
||||
func SignSDKRequest(req *request.Request) {
|
||||
// If the request does not need to be signed ignore the signing of the
|
||||
// request if the AnonymousCredentials object is used.
|
||||
if req.Config.Credentials == credentials.AnonymousCredentials {
|
||||
return
|
||||
}
|
||||
|
||||
if req.HTTPRequest.Method != "POST" && req.HTTPRequest.Method != "GET" {
|
||||
// The V2 signer only supports GET and POST
|
||||
req.Error = errInvalidMethod
|
||||
return
|
||||
}
|
||||
|
||||
v2 := signer{
|
||||
Request: req.HTTPRequest,
|
||||
Time: req.Time,
|
||||
Credentials: req.Config.Credentials,
|
||||
Debug: req.Config.LogLevel.Value(),
|
||||
Logger: req.Config.Logger,
|
||||
}
|
||||
|
||||
req.Error = v2.Sign()
|
||||
|
||||
if req.Error != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if req.HTTPRequest.Method == "POST" {
|
||||
// Set the body of the request based on the modified query parameters
|
||||
req.SetStringBody(v2.Query.Encode())
|
||||
|
||||
// Now that the body has changed, remove any Content-Length header,
|
||||
// because it will be incorrect
|
||||
req.HTTPRequest.ContentLength = 0
|
||||
req.HTTPRequest.Header.Del("Content-Length")
|
||||
} else {
|
||||
req.HTTPRequest.URL.RawQuery = v2.Query.Encode()
|
||||
}
|
||||
}
|
||||
|
||||
func (v2 *signer) Sign() error {
|
||||
credValue, err := v2.Credentials.Get()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if v2.Request.Method == "POST" {
|
||||
// Parse the HTTP request to obtain the query parameters that will
|
||||
// be used to build the string to sign. Note that because the HTTP
|
||||
// request will need to be modified, the PostForm and Form properties
|
||||
// are reset to nil after parsing.
|
||||
v2.Request.ParseForm()
|
||||
v2.Query = v2.Request.PostForm
|
||||
v2.Request.PostForm = nil
|
||||
v2.Request.Form = nil
|
||||
} else {
|
||||
v2.Query = v2.Request.URL.Query()
|
||||
}
|
||||
|
||||
// Set new query parameters
|
||||
v2.Query.Set("AWSAccessKeyId", credValue.AccessKeyID)
|
||||
v2.Query.Set("SignatureVersion", signatureVersion)
|
||||
v2.Query.Set("SignatureMethod", signatureMethod)
|
||||
v2.Query.Set("Timestamp", v2.Time.UTC().Format(timeFormat))
|
||||
if credValue.SessionToken != "" {
|
||||
v2.Query.Set("SecurityToken", credValue.SessionToken)
|
||||
}
|
||||
|
||||
// in case this is a retry, ensure no signature present
|
||||
v2.Query.Del("Signature")
|
||||
|
||||
method := v2.Request.Method
|
||||
host := v2.Request.URL.Host
|
||||
path := v2.Request.URL.Path
|
||||
if path == "" {
|
||||
path = "/"
|
||||
}
|
||||
|
||||
// obtain all of the query keys and sort them
|
||||
queryKeys := make([]string, 0, len(v2.Query))
|
||||
for key := range v2.Query {
|
||||
queryKeys = append(queryKeys, key)
|
||||
}
|
||||
sort.Strings(queryKeys)
|
||||
|
||||
// build URL-encoded query keys and values
|
||||
queryKeysAndValues := make([]string, len(queryKeys))
|
||||
for i, key := range queryKeys {
|
||||
k := strings.Replace(url.QueryEscape(key), "+", "%20", -1)
|
||||
v := strings.Replace(url.QueryEscape(v2.Query.Get(key)), "+", "%20", -1)
|
||||
queryKeysAndValues[i] = k + "=" + v
|
||||
}
|
||||
|
||||
// join into one query string
|
||||
query := strings.Join(queryKeysAndValues, "&")
|
||||
|
||||
// build the canonical string for the V2 signature
|
||||
v2.stringToSign = strings.Join([]string{
|
||||
method,
|
||||
host,
|
||||
path,
|
||||
query,
|
||||
}, "\n")
|
||||
|
||||
hash := hmac.New(sha256.New, []byte(credValue.SecretAccessKey))
|
||||
hash.Write([]byte(v2.stringToSign))
|
||||
v2.signature = base64.StdEncoding.EncodeToString(hash.Sum(nil))
|
||||
v2.Query.Set("Signature", v2.signature)
|
||||
|
||||
if v2.Debug.Matches(aws.LogDebugWithSigning) {
|
||||
v2.logSigningInfo()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
const logSignInfoMsg = `DEBUG: Request Signature:
|
||||
---[ STRING TO SIGN ]--------------------------------
|
||||
%s
|
||||
---[ SIGNATURE ]-------------------------------------
|
||||
%s
|
||||
-----------------------------------------------------`
|
||||
|
||||
func (v2 *signer) logSigningInfo() {
|
||||
msg := fmt.Sprintf(logSignInfoMsg, v2.stringToSign, v2.Query.Get("Signature"))
|
||||
v2.Logger.Log(msg)
|
||||
}
|
237
vendor/github.com/aws/aws-sdk-go/private/signer/v2/v2_test.go
generated
vendored
237
vendor/github.com/aws/aws-sdk-go/private/signer/v2/v2_test.go
generated
vendored
|
@ -1,237 +0,0 @@
|
|||
package v2
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/credentials"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/awstesting"
|
||||
)
|
||||
|
||||
type signerBuilder struct {
|
||||
ServiceName string
|
||||
Region string
|
||||
SignTime time.Time
|
||||
Query url.Values
|
||||
Method string
|
||||
SessionToken string
|
||||
}
|
||||
|
||||
func (sb signerBuilder) BuildSigner() signer {
|
||||
endpoint := "https://" + sb.ServiceName + "." + sb.Region + ".amazonaws.com"
|
||||
var req *http.Request
|
||||
if sb.Method == "POST" {
|
||||
body := []byte(sb.Query.Encode())
|
||||
reader := bytes.NewReader(body)
|
||||
req, _ = http.NewRequest(sb.Method, endpoint, reader)
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
req.Header.Add("Content-Length", string(len(body)))
|
||||
} else {
|
||||
req, _ = http.NewRequest(sb.Method, endpoint, nil)
|
||||
req.URL.RawQuery = sb.Query.Encode()
|
||||
}
|
||||
|
||||
sig := signer{
|
||||
Request: req,
|
||||
Time: sb.SignTime,
|
||||
Credentials: credentials.NewStaticCredentials(
|
||||
"AKID",
|
||||
"SECRET",
|
||||
sb.SessionToken),
|
||||
}
|
||||
|
||||
if os.Getenv("DEBUG") != "" {
|
||||
sig.Debug = aws.LogDebug
|
||||
sig.Logger = aws.NewDefaultLogger()
|
||||
}
|
||||
|
||||
return sig
|
||||
}
|
||||
|
||||
func TestSignRequestWithAndWithoutSession(t *testing.T) {
|
||||
// have to create more than once, so use a function
|
||||
newQuery := func() url.Values {
|
||||
query := make(url.Values)
|
||||
query.Add("Action", "CreateDomain")
|
||||
query.Add("DomainName", "TestDomain-1437033376")
|
||||
query.Add("Version", "2009-04-15")
|
||||
return query
|
||||
}
|
||||
|
||||
// create request without a SecurityToken (session) in the credentials
|
||||
|
||||
query := newQuery()
|
||||
timestamp := time.Date(2015, 7, 16, 7, 56, 16, 0, time.UTC)
|
||||
builder := signerBuilder{
|
||||
Method: "POST",
|
||||
ServiceName: "sdb",
|
||||
Region: "ap-southeast-2",
|
||||
SignTime: timestamp,
|
||||
Query: query,
|
||||
}
|
||||
|
||||
signer := builder.BuildSigner()
|
||||
|
||||
err := signer.Sign()
|
||||
if err != nil {
|
||||
t.Fatalf("expect no error, got %v", err)
|
||||
}
|
||||
if e, a := "tm4dX8Ks7pzFSVHz7qHdoJVXKRLuC4gWz9eti60d8ks=", signer.signature; e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
if e, a := 8, len(signer.Query); e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
if e, a := "AKID", signer.Query.Get("AWSAccessKeyId"); e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
if e, a := "2015-07-16T07:56:16Z", signer.Query.Get("Timestamp"); e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
if e, a := "HmacSHA256", signer.Query.Get("SignatureMethod"); e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
if e, a := "2", signer.Query.Get("SignatureVersion"); e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
if e, a := "tm4dX8Ks7pzFSVHz7qHdoJVXKRLuC4gWz9eti60d8ks=", signer.Query.Get("Signature"); e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
if e, a := "CreateDomain", signer.Query.Get("Action"); e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
if e, a := "TestDomain-1437033376", signer.Query.Get("DomainName"); e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
if e, a := "2009-04-15", signer.Query.Get("Version"); e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
|
||||
// should not have a SecurityToken parameter
|
||||
_, ok := signer.Query["SecurityToken"]
|
||||
if ok {
|
||||
t.Errorf("expect SecurityToken found, was not")
|
||||
}
|
||||
|
||||
// now sign again, this time with a security token (session)
|
||||
|
||||
query = newQuery()
|
||||
builder.SessionToken = "SESSION"
|
||||
signer = builder.BuildSigner()
|
||||
|
||||
err = signer.Sign()
|
||||
if err != nil {
|
||||
t.Fatalf("expect no error, got %v", err)
|
||||
}
|
||||
if e, a := "Ch6qv3rzXB1SLqY2vFhsgA1WQ9rnQIE2WJCigOvAJwI=", signer.signature; e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
if e, a := 9, len(signer.Query); e != a { // expect one more parameter
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
if e, a := "Ch6qv3rzXB1SLqY2vFhsgA1WQ9rnQIE2WJCigOvAJwI=", signer.Query.Get("Signature"); e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
if e, a := "SESSION", signer.Query.Get("SecurityToken"); e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMoreComplexSignRequest(t *testing.T) {
|
||||
query := make(url.Values)
|
||||
query.Add("Action", "PutAttributes")
|
||||
query.Add("DomainName", "TestDomain-1437041569")
|
||||
query.Add("Version", "2009-04-15")
|
||||
query.Add("Attribute.2.Name", "Attr2")
|
||||
query.Add("Attribute.2.Value", "Value2")
|
||||
query.Add("Attribute.2.Replace", "true")
|
||||
query.Add("Attribute.1.Name", "Attr1-%\\+ %")
|
||||
query.Add("Attribute.1.Value", " \tValue1 +!@#$%^&*(){}[]\"';:?/.>,<\x12\x00")
|
||||
query.Add("Attribute.1.Replace", "true")
|
||||
query.Add("ItemName", "Item 1")
|
||||
|
||||
timestamp := time.Date(2015, 7, 16, 10, 12, 51, 0, time.UTC)
|
||||
builder := signerBuilder{
|
||||
Method: "POST",
|
||||
ServiceName: "sdb",
|
||||
Region: "ap-southeast-2",
|
||||
SignTime: timestamp,
|
||||
Query: query,
|
||||
SessionToken: "SESSION",
|
||||
}
|
||||
|
||||
signer := builder.BuildSigner()
|
||||
|
||||
err := signer.Sign()
|
||||
if err != nil {
|
||||
t.Fatalf("expect no error, got %v", err)
|
||||
}
|
||||
if e, a := "WNdE62UJKLKoA6XncVY/9RDbrKmcVMdQPQOTAs8SgwQ=", signer.signature; e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
svc := awstesting.NewClient(&aws.Config{
|
||||
Credentials: credentials.NewStaticCredentials("AKID", "SECRET", "SESSION"),
|
||||
Region: aws.String("ap-southeast-2"),
|
||||
})
|
||||
r := svc.NewRequest(
|
||||
&request.Operation{
|
||||
Name: "OpName",
|
||||
HTTPMethod: "GET",
|
||||
HTTPPath: "/",
|
||||
},
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
|
||||
r.Build()
|
||||
if e, a := "GET", r.HTTPRequest.Method; e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
if e, a := "", r.HTTPRequest.URL.Query().Get("Signature"); e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
|
||||
SignSDKRequest(r)
|
||||
if r.Error != nil {
|
||||
t.Fatalf("expect no error, got %v", r.Error)
|
||||
}
|
||||
t.Logf("Signature: %s", r.HTTPRequest.URL.Query().Get("Signature"))
|
||||
if len(r.HTTPRequest.URL.Query().Get("Signature")) == 0 {
|
||||
t.Errorf("expect signature to be set, was not")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnonymousCredentials(t *testing.T) {
|
||||
svc := awstesting.NewClient(&aws.Config{
|
||||
Credentials: credentials.AnonymousCredentials,
|
||||
Region: aws.String("ap-southeast-2"),
|
||||
})
|
||||
r := svc.NewRequest(
|
||||
&request.Operation{
|
||||
Name: "PutAttributes",
|
||||
HTTPMethod: "POST",
|
||||
HTTPPath: "/",
|
||||
},
|
||||
nil,
|
||||
nil,
|
||||
)
|
||||
r.Build()
|
||||
|
||||
SignSDKRequest(r)
|
||||
|
||||
req := r.HTTPRequest
|
||||
req.ParseForm()
|
||||
|
||||
if a := req.PostForm.Get("Signature"); len(a) != 0 {
|
||||
t.Errorf("expect no signature, got %v", a)
|
||||
}
|
||||
}
|
14
vendor/github.com/aws/aws-sdk-go/private/util/sort_keys.go
generated
vendored
14
vendor/github.com/aws/aws-sdk-go/private/util/sort_keys.go
generated
vendored
|
@ -1,14 +0,0 @@
|
|||
package util
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortedKeys returns a sorted slice of keys of a map.
|
||||
func SortedKeys(m map[string]interface{}) []string {
|
||||
i, sorted := 0, make([]string, len(m))
|
||||
for k := range m {
|
||||
sorted[i] = k
|
||||
i++
|
||||
}
|
||||
sort.Strings(sorted)
|
||||
return sorted
|
||||
}
|
109
vendor/github.com/aws/aws-sdk-go/private/util/util.go
generated
vendored
109
vendor/github.com/aws/aws-sdk-go/private/util/util.go
generated
vendored
|
@ -1,109 +0,0 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"go/format"
|
||||
"io"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil"
|
||||
)
|
||||
|
||||
// GoFmt returns the Go formated string of the input.
|
||||
//
|
||||
// Panics if the format fails.
|
||||
func GoFmt(buf string) string {
|
||||
formatted, err := format.Source([]byte(buf))
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("%s\nOriginal code:\n%s", err.Error(), buf))
|
||||
}
|
||||
return string(formatted)
|
||||
}
|
||||
|
||||
var reTrim = regexp.MustCompile(`\s{2,}`)
|
||||
|
||||
// Trim removes all leading and trailing white space.
|
||||
//
|
||||
// All consecutive spaces will be reduced to a single space.
|
||||
func Trim(s string) string {
|
||||
return strings.TrimSpace(reTrim.ReplaceAllString(s, " "))
|
||||
}
|
||||
|
||||
// Capitalize capitalizes the first character of the string.
|
||||
func Capitalize(s string) string {
|
||||
if len(s) == 1 {
|
||||
return strings.ToUpper(s)
|
||||
}
|
||||
return strings.ToUpper(s[0:1]) + s[1:]
|
||||
}
|
||||
|
||||
// SortXML sorts the reader's XML elements
|
||||
func SortXML(r io.Reader) string {
|
||||
var buf bytes.Buffer
|
||||
d := xml.NewDecoder(r)
|
||||
root, _ := xmlutil.XMLToStruct(d, nil)
|
||||
e := xml.NewEncoder(&buf)
|
||||
xmlutil.StructToXML(e, root, true)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// PrettyPrint generates a human readable representation of the value v.
|
||||
// All values of v are recursively found and pretty printed also.
|
||||
func PrettyPrint(v interface{}) string {
|
||||
value := reflect.ValueOf(v)
|
||||
switch value.Kind() {
|
||||
case reflect.Struct:
|
||||
str := fullName(value.Type()) + "{\n"
|
||||
for i := 0; i < value.NumField(); i++ {
|
||||
l := string(value.Type().Field(i).Name[0])
|
||||
if strings.ToUpper(l) == l {
|
||||
str += value.Type().Field(i).Name + ": "
|
||||
str += PrettyPrint(value.Field(i).Interface())
|
||||
str += ",\n"
|
||||
}
|
||||
}
|
||||
str += "}"
|
||||
return str
|
||||
case reflect.Map:
|
||||
str := "map[" + fullName(value.Type().Key()) + "]" + fullName(value.Type().Elem()) + "{\n"
|
||||
for _, k := range value.MapKeys() {
|
||||
str += "\"" + k.String() + "\": "
|
||||
str += PrettyPrint(value.MapIndex(k).Interface())
|
||||
str += ",\n"
|
||||
}
|
||||
str += "}"
|
||||
return str
|
||||
case reflect.Ptr:
|
||||
if e := value.Elem(); e.IsValid() {
|
||||
return "&" + PrettyPrint(e.Interface())
|
||||
}
|
||||
return "nil"
|
||||
case reflect.Slice:
|
||||
str := "[]" + fullName(value.Type().Elem()) + "{\n"
|
||||
for i := 0; i < value.Len(); i++ {
|
||||
str += PrettyPrint(value.Index(i).Interface())
|
||||
str += ",\n"
|
||||
}
|
||||
str += "}"
|
||||
return str
|
||||
default:
|
||||
return fmt.Sprintf("%#v", v)
|
||||
}
|
||||
}
|
||||
|
||||
func pkgName(t reflect.Type) string {
|
||||
pkg := t.PkgPath()
|
||||
c := strings.Split(pkg, "/")
|
||||
return c[len(c)-1]
|
||||
}
|
||||
|
||||
func fullName(t reflect.Type) string {
|
||||
if pkg := pkgName(t); pkg != "" {
|
||||
return pkg + "." + t.Name()
|
||||
}
|
||||
return t.Name()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue