Add route53 plugin (#1390)

* Update vendor

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

* Add route53 plugin

This fix adds route53 plugin so that it is possible to
query route53 record through CoreDNS.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang
2018-01-15 09:59:29 -08:00
committed by GitHub
parent d699b89063
commit 584dd87c70
352 changed files with 81636 additions and 1798 deletions

View File

@@ -19,8 +19,30 @@ const (
// FormParameterKind = indicator of Request parameter type "form"
FormParameterKind
// CollectionFormatCSV comma separated values `foo,bar`
CollectionFormatCSV = CollectionFormat("csv")
// CollectionFormatSSV space separated values `foo bar`
CollectionFormatSSV = CollectionFormat("ssv")
// CollectionFormatTSV tab separated values `foo\tbar`
CollectionFormatTSV = CollectionFormat("tsv")
// CollectionFormatPipes pipe separated values `foo|bar`
CollectionFormatPipes = CollectionFormat("pipes")
// CollectionFormatMulti corresponds to multiple parameter instances instead of multiple values for a single
// instance `foo=bar&foo=baz`. This is valid only for QueryParameters and FormParameters
CollectionFormatMulti = CollectionFormat("multi")
)
type CollectionFormat string
func (cf CollectionFormat) String() string {
return string(cf)
}
// Parameter is for documententing the parameter used in a Http Request
// ParameterData kinds are Path,Query and Body
type Parameter struct {
@@ -36,6 +58,7 @@ type ParameterData struct {
AllowableValues map[string]string
AllowMultiple bool
DefaultValue string
CollectionFormat string
}
// Data returns the state of the Parameter
@@ -112,3 +135,9 @@ func (p *Parameter) Description(doc string) *Parameter {
p.data.Description = doc
return p
}
// CollectionFormat sets the collection format for an array type
func (p *Parameter) CollectionFormat(format CollectionFormat) *Parameter {
p.data.CollectionFormat = format.String()
return p
}

View File

@@ -43,6 +43,9 @@ type Route struct {
// Extra information used to store custom information about the route.
Metadata map[string]interface{}
// marks a route as deprecated
Deprecated bool
}
// Initialize for Route

View File

@@ -24,7 +24,7 @@ type RouteBuilder struct {
httpMethod string // required
function RouteFunction // required
filters []FilterFunction
conditions []RouteSelectionConditionFunction
conditions []RouteSelectionConditionFunction
typeNameHandleFunc TypeNameHandleFunction // required
@@ -36,6 +36,7 @@ type RouteBuilder struct {
parameters []*Parameter
errorMap map[int]ResponseError
metadata map[string]interface{}
deprecated bool
}
// Do evaluates each argument with the RouteBuilder itself.
@@ -98,15 +99,18 @@ func (b *RouteBuilder) Notes(notes string) *RouteBuilder {
// Reads tells what resource type will be read from the request payload. Optional.
// A parameter of type "body" is added ,required is set to true and the dataType is set to the qualified name of the sample's type.
func (b *RouteBuilder) Reads(sample interface{}) *RouteBuilder {
func (b *RouteBuilder) Reads(sample interface{}, optionalDescription ...string) *RouteBuilder {
fn := b.typeNameHandleFunc
if fn == nil {
fn = reflectTypeName
}
typeAsName := fn(sample)
description := ""
if len(optionalDescription) > 0 {
description = optionalDescription[0]
}
b.readSample = sample
bodyParameter := &Parameter{&ParameterData{Name: "body"}}
bodyParameter := &Parameter{&ParameterData{Name: "body", Description: description}}
bodyParameter.beBody()
bodyParameter.Required(true)
bodyParameter.DataType(typeAsName)
@@ -194,6 +198,12 @@ func (b *RouteBuilder) Metadata(key string, value interface{}) *RouteBuilder {
return b
}
// Deprecate sets the value of deprecated to true. Deprecated routes have a special UI treatment to warn against use
func (b *RouteBuilder) Deprecate() *RouteBuilder {
b.deprecated = true
return b
}
// ResponseError represents a response; not necessarily an error.
type ResponseError struct {
Code int
@@ -280,7 +290,8 @@ func (b *RouteBuilder) Build() Route {
ResponseErrors: b.errorMap,
ReadSample: b.readSample,
WriteSample: b.writeSample,
Metadata: b.metadata}
Metadata: b.metadata,
Deprecated: b.deprecated}
route.postBuild()
return route
}

View File

@@ -118,7 +118,7 @@ func (w *WebService) QueryParameter(name, description string) *Parameter {
// QueryParameter creates a new Parameter of kind Query for documentation purposes.
// It is initialized as not required with string as its DataType.
func QueryParameter(name, description string) *Parameter {
p := &Parameter{&ParameterData{Name: name, Description: description, Required: false, DataType: "string"}}
p := &Parameter{&ParameterData{Name: name, Description: description, Required: false, DataType: "string", CollectionFormat: CollectionFormatCSV.String()}}
p.beQuery()
return p
}

View File

@@ -246,7 +246,7 @@ type exampleBody struct{}
func TestParameterDataTypeDefaults(t *testing.T) {
tearDown()
ws := new(WebService)
route := ws.POST("/post").Reads(&exampleBody{})
route := ws.POST("/post").Reads(&exampleBody{}, "")
if route.parameters[0].data.DataType != "*restful.exampleBody" {
t.Errorf("body parameter incorrect name: %#v", route.parameters[0].data)
}
@@ -258,7 +258,7 @@ func TestParameterDataTypeCustomization(t *testing.T) {
ws.TypeNameHandler(func(sample interface{}) string {
return "my.custom.type.name"
})
route := ws.POST("/post").Reads(&exampleBody{})
route := ws.POST("/post").Reads(&exampleBody{}, "")
if route.parameters[0].data.DataType != "my.custom.type.name" {
t.Errorf("body parameter incorrect name: %#v", route.parameters[0].data)
}