1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package operations
19
20
21
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
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
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
94
95 BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator
96
97
98
99 APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator
100
101
102
103 BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
104
105
106
107 ApplicationTimestampQueryConsumer runtime.Consumer
108
109
110 JSONConsumer runtime.Consumer
111
112
113
114 ApplicationPemCertificateChainProducer runtime.Producer
115
116
117 ApplicationTimestampReplyProducer runtime.Producer
118
119
120 TimestampGetTimestampCertChainHandler timestamp.GetTimestampCertChainHandler
121
122 TimestampGetTimestampResponseHandler timestamp.GetTimestampResponseHandler
123
124
125
126 ServeError func(http.ResponseWriter, *http.Request, error)
127
128
129
130 PreServerShutdown func()
131
132
133
134 ServerShutdown func()
135
136
137 CommandLineOptionsGroups []swag.CommandLineOptionsGroup
138
139
140 Logger func(string, ...interface{})
141 }
142
143
144 func (o *TimestampServerAPI) UseRedoc() {
145 o.useSwaggerUI = false
146 }
147
148
149 func (o *TimestampServerAPI) UseSwaggerUI() {
150 o.useSwaggerUI = true
151 }
152
153
154 func (o *TimestampServerAPI) SetDefaultProduces(mediaType string) {
155 o.defaultProduces = mediaType
156 }
157
158
159 func (o *TimestampServerAPI) SetDefaultConsumes(mediaType string) {
160 o.defaultConsumes = mediaType
161 }
162
163
164 func (o *TimestampServerAPI) SetSpec(spec *loads.Document) {
165 o.spec = spec
166 }
167
168
169 func (o *TimestampServerAPI) DefaultProduces() string {
170 return o.defaultProduces
171 }
172
173
174 func (o *TimestampServerAPI) DefaultConsumes() string {
175 return o.defaultConsumes
176 }
177
178
179 func (o *TimestampServerAPI) Formats() strfmt.Registry {
180 return o.formats
181 }
182
183
184 func (o *TimestampServerAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
185 o.formats.Add(name, format, validator)
186 }
187
188
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
221 func (o *TimestampServerAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
222 return o.ServeError
223 }
224
225
226 func (o *TimestampServerAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
227 return nil
228 }
229
230
231 func (o *TimestampServerAPI) Authorizer() runtime.Authorizer {
232 return nil
233 }
234
235
236
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
255
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
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
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()
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
315
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
329 func (o *TimestampServerAPI) Init() {
330 if len(o.handlers) == 0 {
331 o.initHandlerCache()
332 }
333 }
334
335
336 func (o *TimestampServerAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
337 o.customConsumers[mediaType] = consumer
338 }
339
340
341 func (o *TimestampServerAPI) RegisterProducer(mediaType string, producer runtime.Producer) {
342 o.customProducers[mediaType] = producer
343 }
344
345
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