...

Source file src/github.com/sigstore/timestamp-authority/pkg/generated/restapi/operations/timestamp_server_api.go

Documentation: github.com/sigstore/timestamp-authority/pkg/generated/restapi/operations

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

View as plain text