From d3fa7da0291c7c27ea77a8900b11bc4cdef5fa3d Mon Sep 17 00:00:00 2001 From: Hayden B Date: Wed, 27 Jul 2022 11:33:52 -0700 Subject: [PATCH] Drop application/yaml content type (#933) * Drop application/yaml content type This is a breaking change for any clients that are currently requesting application/yaml. This is the simplest fix to #593, as openapi randomly switches between json and yaml responses when no content type is provided. Fixes #593 Signed-off-by: Hayden Blauzvern * remove default-consumes from Makefile Signed-off-by: Hayden Blauzvern * Fix comment generation Signed-off-by: Hayden Blauzvern --- Makefile | 2 +- openapi.yaml | 4 +- pkg/client/rekor_client.go | 4 +- pkg/client/yaml.go | 46 ------------------- .../client/entries/entries_client.go | 16 +++---- pkg/generated/client/index/index_client.go | 4 +- pkg/generated/client/pubkey/pubkey_client.go | 2 +- pkg/generated/client/server/server_client.go | 4 +- pkg/generated/client/tlog/tlog_client.go | 8 ++-- .../restapi/configure_rekor_server.go | 4 -- pkg/generated/restapi/doc.go | 2 - pkg/generated/restapi/embedded_spec.go | 12 ++--- .../restapi/operations/rekor_server_api.go | 19 -------- pkg/sharding/ranges.go | 6 +-- 14 files changed, 28 insertions(+), 105 deletions(-) delete mode 100644 pkg/client/yaml.go diff --git a/Makefile b/Makefile index 56e869968..a0d1ae1a8 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ SERVER_LDFLAGS=$(REKOR_LDFLAGS) Makefile.swagger: $(SWAGGER) $(OPENAPIDEPS) $(SWAGGER) validate openapi.yaml - $(SWAGGER) generate client -f openapi.yaml -q -r COPYRIGHT.txt -t pkg/generated --default-consumes application/json\;q=1 --additional-initialism=TUF + $(SWAGGER) generate client -f openapi.yaml -q -r COPYRIGHT.txt -t pkg/generated --additional-initialism=TUF $(SWAGGER) generate server -f openapi.yaml -q -r COPYRIGHT.txt -t pkg/generated --exclude-main -A rekor_server --flag-strategy=pflag --default-produces application/json --additional-initialism=TUF @echo "# This file is generated after swagger runs as part of the build; do not edit!" > Makefile.swagger @echo "SWAGGER_GEN=`find pkg/generated/client pkg/generated/models/ pkg/generated/restapi/ -iname '*.go' | grep -v 'configure_rekor_server' | sort -d | tr '\n' ' ' | sed 's/ $$//'`" >> Makefile.swagger; diff --git a/openapi.yaml b/openapi.yaml index fa53c02ab..dcba72992 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -25,10 +25,8 @@ schemes: consumes: - application/json - - application/yaml produces: - - application/json;q=1 - - application/yaml + - application/json paths: /api/v1/version: diff --git a/pkg/client/rekor_client.go b/pkg/client/rekor_client.go index f676e7e96..9d2804916 100644 --- a/pkg/client/rekor_client.go +++ b/pkg/client/rekor_client.go @@ -33,10 +33,10 @@ func GetRekorClient(rekorServerURL string, opts ...Option) (*client.Rekor, error o := makeOptions(opts...) rt := httptransport.New(url.Host, client.DefaultBasePath, []string{url.Scheme}) - rt.Consumers["application/yaml"] = YamlConsumer() + rt.Consumers["application/json"] = runtime.JSONConsumer() rt.Consumers["application/x-pem-file"] = runtime.TextConsumer() rt.Consumers["application/pem-certificate-chain"] = runtime.TextConsumer() - rt.Producers["application/yaml"] = YamlProducer() + rt.Producers["application/json"] = runtime.JSONProducer() rt.Producers["application/timestamp-query"] = runtime.ByteStreamProducer() rt.Consumers["application/timestamp-reply"] = runtime.ByteStreamConsumer() diff --git a/pkg/client/yaml.go b/pkg/client/yaml.go deleted file mode 100644 index e738cf9f4..000000000 --- a/pkg/client/yaml.go +++ /dev/null @@ -1,46 +0,0 @@ -// -// Copyright 2021 The Sigstore Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package client - -import ( - "bytes" - "io" - "io/ioutil" - - "github.com/ghodss/yaml" - "github.com/go-openapi/runtime" -) - -func YamlConsumer() runtime.Consumer { - return runtime.ConsumerFunc(func(r io.Reader, v interface{}) error { - bytes, err := ioutil.ReadAll(r) - if err != nil { - return err - } - return yaml.Unmarshal(bytes, v) - }) -} - -func YamlProducer() runtime.Producer { - return runtime.ProducerFunc(func(w io.Writer, v interface{}) error { - b, err := yaml.Marshal(v) - if err != nil { - return err - } - _, err = io.Copy(w, bytes.NewReader(b)) - return err - }) -} diff --git a/pkg/generated/client/entries/entries_client.go b/pkg/generated/client/entries/entries_client.go index a6a9bf19f..05c6abb92 100644 --- a/pkg/generated/client/entries/entries_client.go +++ b/pkg/generated/client/entries/entries_client.go @@ -70,8 +70,8 @@ func (a *Client) CreateLogEntry(params *CreateLogEntryParams, opts ...ClientOpti ID: "createLogEntry", Method: "POST", PathPattern: "/api/v1/log/entries", - ProducesMediaTypes: []string{"application/json;q=1", "application/yaml"}, - ConsumesMediaTypes: []string{"application/json", "application/yaml"}, + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, Reader: &CreateLogEntryReader{formats: a.formats}, @@ -107,8 +107,8 @@ func (a *Client) GetLogEntryByIndex(params *GetLogEntryByIndexParams, opts ...Cl ID: "getLogEntryByIndex", Method: "GET", PathPattern: "/api/v1/log/entries", - ProducesMediaTypes: []string{"application/json;q=1", "application/yaml"}, - ConsumesMediaTypes: []string{"application/json", "application/yaml"}, + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, Reader: &GetLogEntryByIndexReader{formats: a.formats}, @@ -146,8 +146,8 @@ func (a *Client) GetLogEntryByUUID(params *GetLogEntryByUUIDParams, opts ...Clie ID: "getLogEntryByUUID", Method: "GET", PathPattern: "/api/v1/log/entries/{entryUUID}", - ProducesMediaTypes: []string{"application/json;q=1", "application/yaml"}, - ConsumesMediaTypes: []string{"application/json", "application/yaml"}, + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, Reader: &GetLogEntryByUUIDReader{formats: a.formats}, @@ -183,8 +183,8 @@ func (a *Client) SearchLogQuery(params *SearchLogQueryParams, opts ...ClientOpti ID: "searchLogQuery", Method: "POST", PathPattern: "/api/v1/log/entries/retrieve", - ProducesMediaTypes: []string{"application/json;q=1", "application/yaml"}, - ConsumesMediaTypes: []string{"application/json", "application/yaml"}, + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, Reader: &SearchLogQueryReader{formats: a.formats}, diff --git a/pkg/generated/client/index/index_client.go b/pkg/generated/client/index/index_client.go index bbe0f579c..f80b04afb 100644 --- a/pkg/generated/client/index/index_client.go +++ b/pkg/generated/client/index/index_client.go @@ -61,8 +61,8 @@ func (a *Client) SearchIndex(params *SearchIndexParams, opts ...ClientOption) (* ID: "searchIndex", Method: "POST", PathPattern: "/api/v1/index/retrieve", - ProducesMediaTypes: []string{"application/json;q=1", "application/yaml"}, - ConsumesMediaTypes: []string{"application/json", "application/yaml"}, + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, Reader: &SearchIndexReader{formats: a.formats}, diff --git a/pkg/generated/client/pubkey/pubkey_client.go b/pkg/generated/client/pubkey/pubkey_client.go index dd09cae30..0f780ad9b 100644 --- a/pkg/generated/client/pubkey/pubkey_client.go +++ b/pkg/generated/client/pubkey/pubkey_client.go @@ -64,7 +64,7 @@ func (a *Client) GetPublicKey(params *GetPublicKeyParams, opts ...ClientOption) Method: "GET", PathPattern: "/api/v1/log/publicKey", ProducesMediaTypes: []string{"application/x-pem-file"}, - ConsumesMediaTypes: []string{"application/json", "application/yaml"}, + ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, Reader: &GetPublicKeyReader{formats: a.formats}, diff --git a/pkg/generated/client/server/server_client.go b/pkg/generated/client/server/server_client.go index 2bd9b8864..f48e55062 100644 --- a/pkg/generated/client/server/server_client.go +++ b/pkg/generated/client/server/server_client.go @@ -61,8 +61,8 @@ func (a *Client) GetRekorVersion(params *GetRekorVersionParams, opts ...ClientOp ID: "getRekorVersion", Method: "GET", PathPattern: "/api/v1/version", - ProducesMediaTypes: []string{"application/json;q=1", "application/yaml"}, - ConsumesMediaTypes: []string{"application/json", "application/yaml"}, + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, Reader: &GetRekorVersionReader{formats: a.formats}, diff --git a/pkg/generated/client/tlog/tlog_client.go b/pkg/generated/client/tlog/tlog_client.go index 2fbb024d8..7fd8ffa19 100644 --- a/pkg/generated/client/tlog/tlog_client.go +++ b/pkg/generated/client/tlog/tlog_client.go @@ -65,8 +65,8 @@ func (a *Client) GetLogInfo(params *GetLogInfoParams, opts ...ClientOption) (*Ge ID: "getLogInfo", Method: "GET", PathPattern: "/api/v1/log", - ProducesMediaTypes: []string{"application/json;q=1", "application/yaml"}, - ConsumesMediaTypes: []string{"application/json", "application/yaml"}, + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, Reader: &GetLogInfoReader{formats: a.formats}, @@ -104,8 +104,8 @@ func (a *Client) GetLogProof(params *GetLogProofParams, opts ...ClientOption) (* ID: "getLogProof", Method: "GET", PathPattern: "/api/v1/log/proof", - ProducesMediaTypes: []string{"application/json;q=1", "application/yaml"}, - ConsumesMediaTypes: []string{"application/json", "application/yaml"}, + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, Schemes: []string{"http"}, Params: params, Reader: &GetLogProofReader{formats: a.formats}, diff --git a/pkg/generated/restapi/configure_rekor_server.go b/pkg/generated/restapi/configure_rekor_server.go index 212369d89..18ef50ec9 100644 --- a/pkg/generated/restapi/configure_rekor_server.go +++ b/pkg/generated/restapi/configure_rekor_server.go @@ -34,7 +34,6 @@ import ( "github.com/spf13/viper" pkgapi "github.com/sigstore/rekor/pkg/api" - "github.com/sigstore/rekor/pkg/client" "github.com/sigstore/rekor/pkg/generated/restapi/operations" "github.com/sigstore/rekor/pkg/generated/restapi/operations/entries" "github.com/sigstore/rekor/pkg/generated/restapi/operations/index" @@ -71,9 +70,6 @@ func configureAPI(api *operations.RekorServerAPI) http.Handler { api.JSONConsumer = runtime.JSONConsumer() api.JSONProducer = runtime.JSONProducer() - api.YamlConsumer = client.YamlConsumer() - api.YamlProducer = client.YamlProducer() - api.ApplicationXPemFileProducer = runtime.TextProducer() api.EntriesCreateLogEntryHandler = entries.CreateLogEntryHandlerFunc(pkgapi.CreateLogEntryHandler) diff --git a/pkg/generated/restapi/doc.go b/pkg/generated/restapi/doc.go index b2462c637..72dfdc654 100644 --- a/pkg/generated/restapi/doc.go +++ b/pkg/generated/restapi/doc.go @@ -26,12 +26,10 @@ // // Consumes: // - application/json -// - application/yaml // // Produces: // - application/x-pem-file // - application/json -// - application/yaml // // swagger:meta package restapi diff --git a/pkg/generated/restapi/embedded_spec.go b/pkg/generated/restapi/embedded_spec.go index 9aebb0b13..f1c14e252 100644 --- a/pkg/generated/restapi/embedded_spec.go +++ b/pkg/generated/restapi/embedded_spec.go @@ -35,12 +35,10 @@ var ( func init() { SwaggerJSON = json.RawMessage([]byte(`{ "consumes": [ - "application/json", - "application/yaml" + "application/json" ], "produces": [ - "application/json;q=1", - "application/yaml" + "application/json" ], "schemes": [ "http" @@ -943,12 +941,10 @@ func init() { }`)) FlatSwaggerJSON = json.RawMessage([]byte(`{ "consumes": [ - "application/json", - "application/yaml" + "application/json" ], "produces": [ - "application/json;q=1", - "application/yaml" + "application/json" ], "schemes": [ "http" diff --git a/pkg/generated/restapi/operations/rekor_server_api.go b/pkg/generated/restapi/operations/rekor_server_api.go index 9be6e2458..50c4f75ec 100644 --- a/pkg/generated/restapi/operations/rekor_server_api.go +++ b/pkg/generated/restapi/operations/rekor_server_api.go @@ -32,7 +32,6 @@ 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" @@ -63,13 +62,11 @@ func NewRekorServerAPI(spec *loads.Document) *RekorServerAPI { BearerAuthenticator: security.BearerAuth, JSONConsumer: runtime.JSONConsumer(), - YamlConsumer: yamlpc.YAMLConsumer(), ApplicationXPemFileProducer: runtime.ProducerFunc(func(w io.Writer, data interface{}) error { return errors.NotImplemented("applicationXPemFile producer has not yet been implemented") }), JSONProducer: runtime.JSONProducer(), - YamlProducer: yamlpc.YAMLProducer(), EntriesCreateLogEntryHandler: entries.CreateLogEntryHandlerFunc(func(params entries.CreateLogEntryParams) middleware.Responder { return middleware.NotImplemented("operation entries.CreateLogEntry has not yet been implemented") @@ -129,9 +126,6 @@ type RekorServerAPI struct { // JSONConsumer registers a consumer for the following mime types: // - application/json JSONConsumer runtime.Consumer - // YamlConsumer registers a consumer for the following mime types: - // - application/yaml - YamlConsumer runtime.Consumer // ApplicationXPemFileProducer registers a producer for the following mime types: // - application/x-pem-file @@ -139,9 +133,6 @@ type RekorServerAPI struct { // JSONProducer registers a producer for the following mime types: // - application/json JSONProducer 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 @@ -233,9 +224,6 @@ func (o *RekorServerAPI) Validate() error { if o.JSONConsumer == nil { unregistered = append(unregistered, "JSONConsumer") } - if o.YamlConsumer == nil { - unregistered = append(unregistered, "YamlConsumer") - } if o.ApplicationXPemFileProducer == nil { unregistered = append(unregistered, "ApplicationXPemFileProducer") @@ -243,9 +231,6 @@ func (o *RekorServerAPI) Validate() error { if o.JSONProducer == nil { unregistered = append(unregistered, "JSONProducer") } - if o.YamlProducer == nil { - unregistered = append(unregistered, "YamlProducer") - } if o.EntriesCreateLogEntryHandler == nil { unregistered = append(unregistered, "entries.CreateLogEntryHandler") @@ -305,8 +290,6 @@ func (o *RekorServerAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Co switch mt { case "application/json": result["application/json"] = o.JSONConsumer - case "application/yaml": - result["application/yaml"] = o.YamlConsumer } if c, ok := o.customConsumers[mt]; ok { @@ -326,8 +309,6 @@ func (o *RekorServerAPI) ProducersFor(mediaTypes []string) map[string]runtime.Pr result["application/x-pem-file"] = o.ApplicationXPemFileProducer case "application/json": result["application/json"] = o.JSONProducer - case "application/yaml": - result["application/yaml"] = o.YamlProducer } if p, ok := o.customProducers[mt]; ok { diff --git a/pkg/sharding/ranges.go b/pkg/sharding/ranges.go index 891806380..5b2772251 100644 --- a/pkg/sharding/ranges.go +++ b/pkg/sharding/ranges.go @@ -38,9 +38,9 @@ type LogRanges struct { type Ranges []LogRange type LogRange struct { - TreeID int64 `yaml:"treeID"` - TreeLength int64 `yaml:"treeLength"` - EncodedPublicKey string `yaml:"encodedPublicKey"` + TreeID int64 `json:"treeID"` + TreeLength int64 `json:"treeLength"` + EncodedPublicKey string `json:"encodedPublicKey"` decodedPublicKey string }