Skip to content
Snippets Groups Projects
Unverified Commit 6a860261 authored by Bob Callaway's avatar Bob Callaway Committed by GitHub
Browse files

add XML & YAML support to API (#66)

* add xml & yaml format support

* add attributes to denote files that are generated so GH skips them on diffs
parent 0d60aaae
No related branches found
No related tags found
No related merge requests found
/pkg/generated/** linguist-generated
/pkg/generated/restapi/configure_rekor_server.go -linguist-generated
......@@ -35,6 +35,12 @@ var serveCmd = &cobra.Command{
doc, _ := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON)
server := restapi.NewServer(operations.NewRekorServerAPI(doc))
defer func() {
if err := server.Shutdown(); err != nil {
log.Logger.Error(err)
}
}()
server.Host = viper.GetString("rekor_server.address")
server.Port = int(viper.GetUint("rekor_server.port"))
server.ConfigureAPI()
......
......@@ -6,8 +6,12 @@ info:
consumes:
- application/json
- application/xml
- application/yaml
produces:
- application/json
- application/xml
- application/yaml
paths:
/api/v1/log:
......
......@@ -54,8 +54,8 @@ func (a *Client) CreateLogEntry(params *CreateLogEntryParams) (*CreateLogEntryCr
ID: "createLogEntry",
Method: "POST",
PathPattern: "/api/v1/log/entries",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
ProducesMediaTypes: []string{"application/json", "application/xml", "application/yaml"},
ConsumesMediaTypes: []string{"application/json", "application/xml", "application/yaml"},
Schemes: []string{"http"},
Params: params,
Reader: &CreateLogEntryReader{formats: a.formats},
......@@ -87,8 +87,8 @@ func (a *Client) GetLogEntryByIndex(params *GetLogEntryByIndexParams) (*GetLogEn
ID: "getLogEntryByIndex",
Method: "GET",
PathPattern: "/api/v1/log/entries",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
ProducesMediaTypes: []string{"application/json", "application/xml", "application/yaml"},
ConsumesMediaTypes: []string{"application/json", "application/xml", "application/yaml"},
Schemes: []string{"http"},
Params: params,
Reader: &GetLogEntryByIndexReader{formats: a.formats},
......@@ -120,8 +120,8 @@ func (a *Client) GetLogEntryByUUID(params *GetLogEntryByUUIDParams) (*GetLogEntr
ID: "getLogEntryByUUID",
Method: "GET",
PathPattern: "/api/v1/log/entries/{entryUUID}",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
ProducesMediaTypes: []string{"application/json", "application/xml", "application/yaml"},
ConsumesMediaTypes: []string{"application/json", "application/xml", "application/yaml"},
Schemes: []string{"http"},
Params: params,
Reader: &GetLogEntryByUUIDReader{formats: a.formats},
......@@ -155,8 +155,8 @@ func (a *Client) GetLogEntryProof(params *GetLogEntryProofParams) (*GetLogEntryP
ID: "getLogEntryProof",
Method: "GET",
PathPattern: "/api/v1/log/entries/{entryUUID}/proof",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
ProducesMediaTypes: []string{"application/json", "application/xml", "application/yaml"},
ConsumesMediaTypes: []string{"application/json", "application/xml", "application/yaml"},
Schemes: []string{"http"},
Params: params,
Reader: &GetLogEntryProofReader{formats: a.formats},
......@@ -188,8 +188,8 @@ func (a *Client) SearchLogQuery(params *SearchLogQueryParams) (*SearchLogQueryOK
ID: "searchLogQuery",
Method: "POST",
PathPattern: "/api/v1/log/entries/retrieve",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
ProducesMediaTypes: []string{"application/json", "application/xml", "application/yaml"},
ConsumesMediaTypes: []string{"application/json", "application/xml", "application/yaml"},
Schemes: []string{"http"},
Params: params,
Reader: &SearchLogQueryReader{formats: a.formats},
......
......@@ -47,8 +47,8 @@ func (a *Client) GetLogInfo(params *GetLogInfoParams) (*GetLogInfoOK, error) {
ID: "getLogInfo",
Method: "GET",
PathPattern: "/api/v1/log",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
ProducesMediaTypes: []string{"application/json", "application/xml", "application/yaml"},
ConsumesMediaTypes: []string{"application/json", "application/xml", "application/yaml"},
Schemes: []string{"http"},
Params: params,
Reader: &GetLogInfoReader{formats: a.formats},
......@@ -82,8 +82,8 @@ func (a *Client) GetLogProof(params *GetLogProofParams) (*GetLogProofOK, error)
ID: "getLogProof",
Method: "GET",
PathPattern: "/api/v1/log/proof",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
ProducesMediaTypes: []string{"application/json", "application/xml", "application/yaml"},
ConsumesMediaTypes: []string{"application/json", "application/xml", "application/yaml"},
Schemes: []string{"http"},
Params: params,
Reader: &GetLogProofReader{formats: a.formats},
......
......@@ -38,6 +38,9 @@ func configureAPI(api *operations.RekorServerAPI) http.Handler {
// To continue using redoc as your UI, uncomment the following line
// api.UseRedoc()
// this is needed to adhere to the order of producers specified in openapi.yaml
api.SetDefaultProduces("")
api.JSONConsumer = runtime.JSONConsumer()
api.JSONProducer = runtime.JSONProducer()
......
......@@ -11,9 +11,13 @@
//
// Consumes:
// - application/json
// - application/xml
// - application/yaml
//
// Produces:
// - application/json
// - application/xml
// - application/yaml
//
// swagger:meta
package restapi
......@@ -19,10 +19,14 @@ var (
func init() {
SwaggerJSON = json.RawMessage([]byte(`{
"consumes": [
"application/json"
"application/json",
"application/xml",
"application/yaml"
],
"produces": [
"application/json"
"application/json",
"application/xml",
"application/yaml"
],
"swagger": "2.0",
"info": {
......@@ -529,10 +533,14 @@ func init() {
}`))
FlatSwaggerJSON = json.RawMessage([]byte(`{
"consumes": [
"application/json"
"application/json",
"application/xml",
"application/yaml"
],
"produces": [
"application/json"
"application/json",
"application/xml",
"application/yaml"
],
"swagger": "2.0",
"info": {
......
......@@ -15,6 +15,7 @@ import (
"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/runtime/security"
"github.com/go-openapi/runtime/yamlpc"
"github.com/go-openapi/spec"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
......@@ -42,8 +43,12 @@ func NewRekorServerAPI(spec *loads.Document) *RekorServerAPI {
BearerAuthenticator: security.BearerAuth,
JSONConsumer: runtime.JSONConsumer(),
XMLConsumer: runtime.XMLConsumer(),
YamlConsumer: yamlpc.YAMLConsumer(),
JSONProducer: runtime.JSONProducer(),
XMLProducer: runtime.XMLProducer(),
YamlProducer: yamlpc.YAMLProducer(),
EntriesCreateLogEntryHandler: entries.CreateLogEntryHandlerFunc(func(params entries.CreateLogEntryParams) middleware.Responder {
return middleware.NotImplemented("operation entries.CreateLogEntry has not yet been implemented")
......@@ -95,10 +100,22 @@ type RekorServerAPI struct {
// JSONConsumer registers a consumer for the following mime types:
// - application/json
JSONConsumer runtime.Consumer
// XMLConsumer registers a consumer for the following mime types:
// - application/xml
XMLConsumer runtime.Consumer
// YamlConsumer registers a consumer for the following mime types:
// - application/yaml
YamlConsumer runtime.Consumer
// JSONProducer registers a producer for the following mime types:
// - application/json
JSONProducer runtime.Producer
// XMLProducer registers a producer for the following mime types:
// - application/xml
XMLProducer runtime.Producer
// YamlProducer registers a producer for the following mime types:
// - application/yaml
YamlProducer runtime.Producer
// EntriesCreateLogEntryHandler sets the operation handler for the create log entry operation
EntriesCreateLogEntryHandler entries.CreateLogEntryHandler
......@@ -185,10 +202,22 @@ func (o *RekorServerAPI) Validate() error {
if o.JSONConsumer == nil {
unregistered = append(unregistered, "JSONConsumer")
}
if o.XMLConsumer == nil {
unregistered = append(unregistered, "XMLConsumer")
}
if o.YamlConsumer == nil {
unregistered = append(unregistered, "YamlConsumer")
}
if o.JSONProducer == nil {
unregistered = append(unregistered, "JSONProducer")
}
if o.XMLProducer == nil {
unregistered = append(unregistered, "XMLProducer")
}
if o.YamlProducer == nil {
unregistered = append(unregistered, "YamlProducer")
}
if o.EntriesCreateLogEntryHandler == nil {
unregistered = append(unregistered, "entries.CreateLogEntryHandler")
......@@ -242,6 +271,10 @@ func (o *RekorServerAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Co
switch mt {
case "application/json":
result["application/json"] = o.JSONConsumer
case "application/xml":
result["application/xml"] = o.XMLConsumer
case "application/yaml":
result["application/yaml"] = o.YamlConsumer
}
if c, ok := o.customConsumers[mt]; ok {
......@@ -259,6 +292,10 @@ func (o *RekorServerAPI) ProducersFor(mediaTypes []string) map[string]runtime.Pr
switch mt {
case "application/json":
result["application/json"] = o.JSONProducer
case "application/xml":
result["application/xml"] = o.XMLProducer
case "application/yaml":
result["application/yaml"] = o.YamlProducer
}
if p, ok := o.customProducers[mt]; ok {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment