...

Source file src/github.com/sigstore/rekor/pkg/generated/restapi/operations/rekor_server_api.go

Documentation: github.com/sigstore/rekor/pkg/generated/restapi/operations

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  //
     4  // Copyright 2021 The Sigstore Authors.
     5  //
     6  // Licensed under the Apache License, Version 2.0 (the "License");
     7  // you may not use this file except in compliance with the License.
     8  // You may obtain a copy of the License at
     9  //
    10  //     http://www.apache.org/licenses/LICENSE-2.0
    11  //
    12  // Unless required by applicable law or agreed to in writing, software
    13  // distributed under the License is distributed on an "AS IS" BASIS,
    14  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  // See the License for the specific language governing permissions and
    16  // limitations under the License.
    17  //
    18  
    19  package operations
    20  
    21  // This file was generated by the swagger tool.
    22  // Editing this file might prove futile when you re-run the swagger generate command
    23  
    24  import (
    25  	"fmt"
    26  	"io"
    27  	"net/http"
    28  	"strings"
    29  
    30  	"github.com/go-openapi/errors"
    31  	"github.com/go-openapi/loads"
    32  	"github.com/go-openapi/runtime"
    33  	"github.com/go-openapi/runtime/middleware"
    34  	"github.com/go-openapi/runtime/security"
    35  	"github.com/go-openapi/spec"
    36  	"github.com/go-openapi/strfmt"
    37  	"github.com/go-openapi/swag"
    38  
    39  	"github.com/sigstore/rekor/pkg/generated/restapi/operations/entries"
    40  	"github.com/sigstore/rekor/pkg/generated/restapi/operations/index"
    41  	"github.com/sigstore/rekor/pkg/generated/restapi/operations/pubkey"
    42  	"github.com/sigstore/rekor/pkg/generated/restapi/operations/tlog"
    43  )
    44  
    45  // NewRekorServerAPI creates a new RekorServer instance
    46  func NewRekorServerAPI(spec *loads.Document) *RekorServerAPI {
    47  	return &RekorServerAPI{
    48  		handlers:            make(map[string]map[string]http.Handler),
    49  		formats:             strfmt.Default,
    50  		defaultConsumes:     "application/json",
    51  		defaultProduces:     "application/json",
    52  		customConsumers:     make(map[string]runtime.Consumer),
    53  		customProducers:     make(map[string]runtime.Producer),
    54  		PreServerShutdown:   func() {},
    55  		ServerShutdown:      func() {},
    56  		spec:                spec,
    57  		useSwaggerUI:        false,
    58  		ServeError:          errors.ServeError,
    59  		BasicAuthenticator:  security.BasicAuth,
    60  		APIKeyAuthenticator: security.APIKeyAuth,
    61  		BearerAuthenticator: security.BearerAuth,
    62  
    63  		JSONConsumer: runtime.JSONConsumer(),
    64  
    65  		ApplicationXPemFileProducer: runtime.ProducerFunc(func(w io.Writer, data interface{}) error {
    66  			return errors.NotImplemented("applicationXPemFile producer has not yet been implemented")
    67  		}),
    68  		JSONProducer: runtime.JSONProducer(),
    69  
    70  		EntriesCreateLogEntryHandler: entries.CreateLogEntryHandlerFunc(func(params entries.CreateLogEntryParams) middleware.Responder {
    71  			return middleware.NotImplemented("operation entries.CreateLogEntry has not yet been implemented")
    72  		}),
    73  		EntriesGetLogEntryByIndexHandler: entries.GetLogEntryByIndexHandlerFunc(func(params entries.GetLogEntryByIndexParams) middleware.Responder {
    74  			return middleware.NotImplemented("operation entries.GetLogEntryByIndex has not yet been implemented")
    75  		}),
    76  		EntriesGetLogEntryByUUIDHandler: entries.GetLogEntryByUUIDHandlerFunc(func(params entries.GetLogEntryByUUIDParams) middleware.Responder {
    77  			return middleware.NotImplemented("operation entries.GetLogEntryByUUID has not yet been implemented")
    78  		}),
    79  		TlogGetLogInfoHandler: tlog.GetLogInfoHandlerFunc(func(params tlog.GetLogInfoParams) middleware.Responder {
    80  			return middleware.NotImplemented("operation tlog.GetLogInfo has not yet been implemented")
    81  		}),
    82  		TlogGetLogProofHandler: tlog.GetLogProofHandlerFunc(func(params tlog.GetLogProofParams) middleware.Responder {
    83  			return middleware.NotImplemented("operation tlog.GetLogProof has not yet been implemented")
    84  		}),
    85  		PubkeyGetPublicKeyHandler: pubkey.GetPublicKeyHandlerFunc(func(params pubkey.GetPublicKeyParams) middleware.Responder {
    86  			return middleware.NotImplemented("operation pubkey.GetPublicKey has not yet been implemented")
    87  		}),
    88  		IndexSearchIndexHandler: index.SearchIndexHandlerFunc(func(params index.SearchIndexParams) middleware.Responder {
    89  			return middleware.NotImplemented("operation index.SearchIndex has not yet been implemented")
    90  		}),
    91  		EntriesSearchLogQueryHandler: entries.SearchLogQueryHandlerFunc(func(params entries.SearchLogQueryParams) middleware.Responder {
    92  			return middleware.NotImplemented("operation entries.SearchLogQuery has not yet been implemented")
    93  		}),
    94  	}
    95  }
    96  
    97  /*RekorServerAPI Rekor is a cryptographically secure, immutable transparency log for signed software releases. */
    98  type RekorServerAPI struct {
    99  	spec            *loads.Document
   100  	context         *middleware.Context
   101  	handlers        map[string]map[string]http.Handler
   102  	formats         strfmt.Registry
   103  	customConsumers map[string]runtime.Consumer
   104  	customProducers map[string]runtime.Producer
   105  	defaultConsumes string
   106  	defaultProduces string
   107  	Middleware      func(middleware.Builder) http.Handler
   108  	useSwaggerUI    bool
   109  
   110  	// BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function.
   111  	// It has a default implementation in the security package, however you can replace it for your particular usage.
   112  	BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator
   113  
   114  	// APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function.
   115  	// It has a default implementation in the security package, however you can replace it for your particular usage.
   116  	APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator
   117  
   118  	// BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function.
   119  	// It has a default implementation in the security package, however you can replace it for your particular usage.
   120  	BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
   121  
   122  	// JSONConsumer registers a consumer for the following mime types:
   123  	//   - application/json
   124  	JSONConsumer runtime.Consumer
   125  
   126  	// ApplicationXPemFileProducer registers a producer for the following mime types:
   127  	//   - application/x-pem-file
   128  	ApplicationXPemFileProducer runtime.Producer
   129  	// JSONProducer registers a producer for the following mime types:
   130  	//   - application/json
   131  	JSONProducer runtime.Producer
   132  
   133  	// EntriesCreateLogEntryHandler sets the operation handler for the create log entry operation
   134  	EntriesCreateLogEntryHandler entries.CreateLogEntryHandler
   135  	// EntriesGetLogEntryByIndexHandler sets the operation handler for the get log entry by index operation
   136  	EntriesGetLogEntryByIndexHandler entries.GetLogEntryByIndexHandler
   137  	// EntriesGetLogEntryByUUIDHandler sets the operation handler for the get log entry by UUID operation
   138  	EntriesGetLogEntryByUUIDHandler entries.GetLogEntryByUUIDHandler
   139  	// TlogGetLogInfoHandler sets the operation handler for the get log info operation
   140  	TlogGetLogInfoHandler tlog.GetLogInfoHandler
   141  	// TlogGetLogProofHandler sets the operation handler for the get log proof operation
   142  	TlogGetLogProofHandler tlog.GetLogProofHandler
   143  	// PubkeyGetPublicKeyHandler sets the operation handler for the get public key operation
   144  	PubkeyGetPublicKeyHandler pubkey.GetPublicKeyHandler
   145  	// IndexSearchIndexHandler sets the operation handler for the search index operation
   146  	IndexSearchIndexHandler index.SearchIndexHandler
   147  	// EntriesSearchLogQueryHandler sets the operation handler for the search log query operation
   148  	EntriesSearchLogQueryHandler entries.SearchLogQueryHandler
   149  
   150  	// ServeError is called when an error is received, there is a default handler
   151  	// but you can set your own with this
   152  	ServeError func(http.ResponseWriter, *http.Request, error)
   153  
   154  	// PreServerShutdown is called before the HTTP(S) server is shutdown
   155  	// This allows for custom functions to get executed before the HTTP(S) server stops accepting traffic
   156  	PreServerShutdown func()
   157  
   158  	// ServerShutdown is called when the HTTP(S) server is shut down and done
   159  	// handling all active connections and does not accept connections any more
   160  	ServerShutdown func()
   161  
   162  	// Custom command line argument groups with their descriptions
   163  	CommandLineOptionsGroups []swag.CommandLineOptionsGroup
   164  
   165  	// User defined logger function.
   166  	Logger func(string, ...interface{})
   167  }
   168  
   169  // UseRedoc for documentation at /docs
   170  func (o *RekorServerAPI) UseRedoc() {
   171  	o.useSwaggerUI = false
   172  }
   173  
   174  // UseSwaggerUI for documentation at /docs
   175  func (o *RekorServerAPI) UseSwaggerUI() {
   176  	o.useSwaggerUI = true
   177  }
   178  
   179  // SetDefaultProduces sets the default produces media type
   180  func (o *RekorServerAPI) SetDefaultProduces(mediaType string) {
   181  	o.defaultProduces = mediaType
   182  }
   183  
   184  // SetDefaultConsumes returns the default consumes media type
   185  func (o *RekorServerAPI) SetDefaultConsumes(mediaType string) {
   186  	o.defaultConsumes = mediaType
   187  }
   188  
   189  // SetSpec sets a spec that will be served for the clients.
   190  func (o *RekorServerAPI) SetSpec(spec *loads.Document) {
   191  	o.spec = spec
   192  }
   193  
   194  // DefaultProduces returns the default produces media type
   195  func (o *RekorServerAPI) DefaultProduces() string {
   196  	return o.defaultProduces
   197  }
   198  
   199  // DefaultConsumes returns the default consumes media type
   200  func (o *RekorServerAPI) DefaultConsumes() string {
   201  	return o.defaultConsumes
   202  }
   203  
   204  // Formats returns the registered string formats
   205  func (o *RekorServerAPI) Formats() strfmt.Registry {
   206  	return o.formats
   207  }
   208  
   209  // RegisterFormat registers a custom format validator
   210  func (o *RekorServerAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
   211  	o.formats.Add(name, format, validator)
   212  }
   213  
   214  // Validate validates the registrations in the RekorServerAPI
   215  func (o *RekorServerAPI) Validate() error {
   216  	var unregistered []string
   217  
   218  	if o.JSONConsumer == nil {
   219  		unregistered = append(unregistered, "JSONConsumer")
   220  	}
   221  
   222  	if o.ApplicationXPemFileProducer == nil {
   223  		unregistered = append(unregistered, "ApplicationXPemFileProducer")
   224  	}
   225  	if o.JSONProducer == nil {
   226  		unregistered = append(unregistered, "JSONProducer")
   227  	}
   228  
   229  	if o.EntriesCreateLogEntryHandler == nil {
   230  		unregistered = append(unregistered, "entries.CreateLogEntryHandler")
   231  	}
   232  	if o.EntriesGetLogEntryByIndexHandler == nil {
   233  		unregistered = append(unregistered, "entries.GetLogEntryByIndexHandler")
   234  	}
   235  	if o.EntriesGetLogEntryByUUIDHandler == nil {
   236  		unregistered = append(unregistered, "entries.GetLogEntryByUUIDHandler")
   237  	}
   238  	if o.TlogGetLogInfoHandler == nil {
   239  		unregistered = append(unregistered, "tlog.GetLogInfoHandler")
   240  	}
   241  	if o.TlogGetLogProofHandler == nil {
   242  		unregistered = append(unregistered, "tlog.GetLogProofHandler")
   243  	}
   244  	if o.PubkeyGetPublicKeyHandler == nil {
   245  		unregistered = append(unregistered, "pubkey.GetPublicKeyHandler")
   246  	}
   247  	if o.IndexSearchIndexHandler == nil {
   248  		unregistered = append(unregistered, "index.SearchIndexHandler")
   249  	}
   250  	if o.EntriesSearchLogQueryHandler == nil {
   251  		unregistered = append(unregistered, "entries.SearchLogQueryHandler")
   252  	}
   253  
   254  	if len(unregistered) > 0 {
   255  		return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
   256  	}
   257  
   258  	return nil
   259  }
   260  
   261  // ServeErrorFor gets a error handler for a given operation id
   262  func (o *RekorServerAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
   263  	return o.ServeError
   264  }
   265  
   266  // AuthenticatorsFor gets the authenticators for the specified security schemes
   267  func (o *RekorServerAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
   268  	return nil
   269  }
   270  
   271  // Authorizer returns the registered authorizer
   272  func (o *RekorServerAPI) Authorizer() runtime.Authorizer {
   273  	return nil
   274  }
   275  
   276  // ConsumersFor gets the consumers for the specified media types.
   277  // MIME type parameters are ignored here.
   278  func (o *RekorServerAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer {
   279  	result := make(map[string]runtime.Consumer, len(mediaTypes))
   280  	for _, mt := range mediaTypes {
   281  		switch mt {
   282  		case "application/json":
   283  			result["application/json"] = o.JSONConsumer
   284  		}
   285  
   286  		if c, ok := o.customConsumers[mt]; ok {
   287  			result[mt] = c
   288  		}
   289  	}
   290  	return result
   291  }
   292  
   293  // ProducersFor gets the producers for the specified media types.
   294  // MIME type parameters are ignored here.
   295  func (o *RekorServerAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer {
   296  	result := make(map[string]runtime.Producer, len(mediaTypes))
   297  	for _, mt := range mediaTypes {
   298  		switch mt {
   299  		case "application/x-pem-file":
   300  			result["application/x-pem-file"] = o.ApplicationXPemFileProducer
   301  		case "application/json":
   302  			result["application/json"] = o.JSONProducer
   303  		}
   304  
   305  		if p, ok := o.customProducers[mt]; ok {
   306  			result[mt] = p
   307  		}
   308  	}
   309  	return result
   310  }
   311  
   312  // HandlerFor gets a http.Handler for the provided operation method and path
   313  func (o *RekorServerAPI) HandlerFor(method, path string) (http.Handler, bool) {
   314  	if o.handlers == nil {
   315  		return nil, false
   316  	}
   317  	um := strings.ToUpper(method)
   318  	if _, ok := o.handlers[um]; !ok {
   319  		return nil, false
   320  	}
   321  	if path == "/" {
   322  		path = ""
   323  	}
   324  	h, ok := o.handlers[um][path]
   325  	return h, ok
   326  }
   327  
   328  // Context returns the middleware context for the rekor server API
   329  func (o *RekorServerAPI) Context() *middleware.Context {
   330  	if o.context == nil {
   331  		o.context = middleware.NewRoutableContext(o.spec, o, nil)
   332  	}
   333  
   334  	return o.context
   335  }
   336  
   337  func (o *RekorServerAPI) initHandlerCache() {
   338  	o.Context() // don't care about the result, just that the initialization happened
   339  	if o.handlers == nil {
   340  		o.handlers = make(map[string]map[string]http.Handler)
   341  	}
   342  
   343  	if o.handlers["POST"] == nil {
   344  		o.handlers["POST"] = make(map[string]http.Handler)
   345  	}
   346  	o.handlers["POST"]["/api/v1/log/entries"] = entries.NewCreateLogEntry(o.context, o.EntriesCreateLogEntryHandler)
   347  	if o.handlers["GET"] == nil {
   348  		o.handlers["GET"] = make(map[string]http.Handler)
   349  	}
   350  	o.handlers["GET"]["/api/v1/log/entries"] = entries.NewGetLogEntryByIndex(o.context, o.EntriesGetLogEntryByIndexHandler)
   351  	if o.handlers["GET"] == nil {
   352  		o.handlers["GET"] = make(map[string]http.Handler)
   353  	}
   354  	o.handlers["GET"]["/api/v1/log/entries/{entryUUID}"] = entries.NewGetLogEntryByUUID(o.context, o.EntriesGetLogEntryByUUIDHandler)
   355  	if o.handlers["GET"] == nil {
   356  		o.handlers["GET"] = make(map[string]http.Handler)
   357  	}
   358  	o.handlers["GET"]["/api/v1/log"] = tlog.NewGetLogInfo(o.context, o.TlogGetLogInfoHandler)
   359  	if o.handlers["GET"] == nil {
   360  		o.handlers["GET"] = make(map[string]http.Handler)
   361  	}
   362  	o.handlers["GET"]["/api/v1/log/proof"] = tlog.NewGetLogProof(o.context, o.TlogGetLogProofHandler)
   363  	if o.handlers["GET"] == nil {
   364  		o.handlers["GET"] = make(map[string]http.Handler)
   365  	}
   366  	o.handlers["GET"]["/api/v1/log/publicKey"] = pubkey.NewGetPublicKey(o.context, o.PubkeyGetPublicKeyHandler)
   367  	if o.handlers["POST"] == nil {
   368  		o.handlers["POST"] = make(map[string]http.Handler)
   369  	}
   370  	o.handlers["POST"]["/api/v1/index/retrieve"] = index.NewSearchIndex(o.context, o.IndexSearchIndexHandler)
   371  	if o.handlers["POST"] == nil {
   372  		o.handlers["POST"] = make(map[string]http.Handler)
   373  	}
   374  	o.handlers["POST"]["/api/v1/log/entries/retrieve"] = entries.NewSearchLogQuery(o.context, o.EntriesSearchLogQueryHandler)
   375  }
   376  
   377  // Serve creates a http handler to serve the API over HTTP
   378  // can be used directly in http.ListenAndServe(":8000", api.Serve(nil))
   379  func (o *RekorServerAPI) Serve(builder middleware.Builder) http.Handler {
   380  	o.Init()
   381  
   382  	if o.Middleware != nil {
   383  		return o.Middleware(builder)
   384  	}
   385  	if o.useSwaggerUI {
   386  		return o.context.APIHandlerSwaggerUI(builder)
   387  	}
   388  	return o.context.APIHandler(builder)
   389  }
   390  
   391  // Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit
   392  func (o *RekorServerAPI) Init() {
   393  	if len(o.handlers) == 0 {
   394  		o.initHandlerCache()
   395  	}
   396  }
   397  
   398  // RegisterConsumer allows you to add (or override) a consumer for a media type.
   399  func (o *RekorServerAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
   400  	o.customConsumers[mediaType] = consumer
   401  }
   402  
   403  // RegisterProducer allows you to add (or override) a producer for a media type.
   404  func (o *RekorServerAPI) RegisterProducer(mediaType string, producer runtime.Producer) {
   405  	o.customProducers[mediaType] = producer
   406  }
   407  
   408  // AddMiddlewareFor adds a http middleware to existing handler
   409  func (o *RekorServerAPI) AddMiddlewareFor(method, path string, builder middleware.Builder) {
   410  	um := strings.ToUpper(method)
   411  	if path == "/" {
   412  		path = ""
   413  	}
   414  	o.Init()
   415  	if h, ok := o.handlers[um][path]; ok {
   416  		o.handlers[um][path] = builder(h)
   417  	}
   418  }
   419  

View as plain text