1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package operations
20
21
22
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
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
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
111
112 BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator
113
114
115
116 APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator
117
118
119
120 BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
121
122
123
124 JSONConsumer runtime.Consumer
125
126
127
128 ApplicationXPemFileProducer runtime.Producer
129
130
131 JSONProducer runtime.Producer
132
133
134 EntriesCreateLogEntryHandler entries.CreateLogEntryHandler
135
136 EntriesGetLogEntryByIndexHandler entries.GetLogEntryByIndexHandler
137
138 EntriesGetLogEntryByUUIDHandler entries.GetLogEntryByUUIDHandler
139
140 TlogGetLogInfoHandler tlog.GetLogInfoHandler
141
142 TlogGetLogProofHandler tlog.GetLogProofHandler
143
144 PubkeyGetPublicKeyHandler pubkey.GetPublicKeyHandler
145
146 IndexSearchIndexHandler index.SearchIndexHandler
147
148 EntriesSearchLogQueryHandler entries.SearchLogQueryHandler
149
150
151
152 ServeError func(http.ResponseWriter, *http.Request, error)
153
154
155
156 PreServerShutdown func()
157
158
159
160 ServerShutdown func()
161
162
163 CommandLineOptionsGroups []swag.CommandLineOptionsGroup
164
165
166 Logger func(string, ...interface{})
167 }
168
169
170 func (o *RekorServerAPI) UseRedoc() {
171 o.useSwaggerUI = false
172 }
173
174
175 func (o *RekorServerAPI) UseSwaggerUI() {
176 o.useSwaggerUI = true
177 }
178
179
180 func (o *RekorServerAPI) SetDefaultProduces(mediaType string) {
181 o.defaultProduces = mediaType
182 }
183
184
185 func (o *RekorServerAPI) SetDefaultConsumes(mediaType string) {
186 o.defaultConsumes = mediaType
187 }
188
189
190 func (o *RekorServerAPI) SetSpec(spec *loads.Document) {
191 o.spec = spec
192 }
193
194
195 func (o *RekorServerAPI) DefaultProduces() string {
196 return o.defaultProduces
197 }
198
199
200 func (o *RekorServerAPI) DefaultConsumes() string {
201 return o.defaultConsumes
202 }
203
204
205 func (o *RekorServerAPI) Formats() strfmt.Registry {
206 return o.formats
207 }
208
209
210 func (o *RekorServerAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
211 o.formats.Add(name, format, validator)
212 }
213
214
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
262 func (o *RekorServerAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
263 return o.ServeError
264 }
265
266
267 func (o *RekorServerAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
268 return nil
269 }
270
271
272 func (o *RekorServerAPI) Authorizer() runtime.Authorizer {
273 return nil
274 }
275
276
277
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
294
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
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
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()
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
378
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
392 func (o *RekorServerAPI) Init() {
393 if len(o.handlers) == 0 {
394 o.initHandlerCache()
395 }
396 }
397
398
399 func (o *RekorServerAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
400 o.customConsumers[mediaType] = consumer
401 }
402
403
404 func (o *RekorServerAPI) RegisterProducer(mediaType string, producer runtime.Producer) {
405 o.customProducers[mediaType] = producer
406 }
407
408
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