maps-service/pkg/api/oas_handlers_gen.go

2231 lines
60 KiB
Go
Raw Normal View History

2024-11-26 01:22:45 +00:00
// Code generated by ogen, DO NOT EDIT.
package api
import (
"context"
"net/http"
"time"
"github.com/go-faster/errors"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/metric"
2024-11-26 20:39:10 +00:00
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
2024-11-26 01:22:45 +00:00
"go.opentelemetry.io/otel/trace"
ht "github.com/ogen-go/ogen/http"
"github.com/ogen-go/ogen/middleware"
"github.com/ogen-go/ogen/ogenerrors"
"github.com/ogen-go/ogen/otelogen"
)
// handleActionSubmissionPublishRequest handles actionSubmissionPublish operation.
//
// Role Validator changes status from Publishing -> Published.
//
// PATCH /submissions/{SubmissionID}/status/publish
func (s *Server) handleActionSubmissionPublishRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("actionSubmissionPublish"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/publish"),
}
// Start a span for this request.
2024-11-29 22:33:48 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), ActionSubmissionPublishOperation,
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Add Labeler to context.
labeler := &Labeler{attrs: otelAttrs}
ctx = contextWithLabeler(ctx, labeler)
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
attrOpt := metric.WithAttributeSet(labeler.AttributeSet())
// Increment request counter.
s.requests.Add(ctx, 1, attrOpt)
// Use floating point division here for higher precision (instead of Millisecond method).
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt)
}()
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet()))
}
err error
opErrContext = ogenerrors.OperationContext{
2024-11-29 22:33:48 +00:00
Name: ActionSubmissionPublishOperation,
ID: "actionSubmissionPublish",
}
)
2024-11-29 22:33:48 +00:00
{
type bitset = [1]uint8
var satisfied bitset
{
sctx, ok, err := s.securityCookieAuth(ctx, ActionSubmissionPublishOperation, r)
if err != nil {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Security: "CookieAuth",
Err: err,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security:CookieAuth", err)
}
return
}
if ok {
satisfied[0] |= 1 << 0
ctx = sctx
}
}
if ok := func() bool {
nextRequirement:
for _, requirement := range []bitset{
{0b00000001},
} {
for i, mask := range requirement {
if satisfied[i]&mask != mask {
continue nextRequirement
}
}
return true
}
return false
}(); !ok {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security", err)
}
return
}
}
params, err := decodeActionSubmissionPublishParams(args, argsEscaped, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
defer recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response *ActionSubmissionPublishOK
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-11-29 22:33:48 +00:00
OperationName: ActionSubmissionPublishOperation,
OperationSummary: "Role Validator changes status from Publishing -> Published",
OperationID: "actionSubmissionPublish",
Body: nil,
Params: middleware.Parameters{
{
Name: "SubmissionID",
In: "path",
}: params.SubmissionID,
},
Raw: r,
}
type (
Request = struct{}
Params = ActionSubmissionPublishParams
Response = *ActionSubmissionPublishOK
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackActionSubmissionPublishParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
err = s.h.ActionSubmissionPublish(ctx, params)
return response, err
},
)
} else {
err = s.h.ActionSubmissionPublish(ctx, params)
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
if err := encodeErrorResponse(errRes, w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if errors.Is(err, ht.ErrNotImplemented) {
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if err := encodeActionSubmissionPublishResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
return
}
}
// handleActionSubmissionRejectRequest handles actionSubmissionReject operation.
//
// Role Reviewer changes status from Submitted -> Rejected.
//
// PATCH /submissions/{SubmissionID}/status/reject
func (s *Server) handleActionSubmissionRejectRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("actionSubmissionReject"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/reject"),
}
// Start a span for this request.
2024-11-29 22:33:48 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), ActionSubmissionRejectOperation,
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Add Labeler to context.
labeler := &Labeler{attrs: otelAttrs}
ctx = contextWithLabeler(ctx, labeler)
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
attrOpt := metric.WithAttributeSet(labeler.AttributeSet())
// Increment request counter.
s.requests.Add(ctx, 1, attrOpt)
// Use floating point division here for higher precision (instead of Millisecond method).
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt)
}()
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet()))
}
err error
opErrContext = ogenerrors.OperationContext{
2024-11-29 22:33:48 +00:00
Name: ActionSubmissionRejectOperation,
ID: "actionSubmissionReject",
}
)
2024-11-29 22:33:48 +00:00
{
type bitset = [1]uint8
var satisfied bitset
{
sctx, ok, err := s.securityCookieAuth(ctx, ActionSubmissionRejectOperation, r)
if err != nil {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Security: "CookieAuth",
Err: err,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security:CookieAuth", err)
}
return
}
if ok {
satisfied[0] |= 1 << 0
ctx = sctx
}
}
if ok := func() bool {
nextRequirement:
for _, requirement := range []bitset{
{0b00000001},
} {
for i, mask := range requirement {
if satisfied[i]&mask != mask {
continue nextRequirement
}
}
return true
}
return false
}(); !ok {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security", err)
}
return
}
}
params, err := decodeActionSubmissionRejectParams(args, argsEscaped, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
defer recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response *ActionSubmissionRejectOK
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-11-29 22:33:48 +00:00
OperationName: ActionSubmissionRejectOperation,
OperationSummary: "Role Reviewer changes status from Submitted -> Rejected",
OperationID: "actionSubmissionReject",
Body: nil,
Params: middleware.Parameters{
{
Name: "SubmissionID",
In: "path",
}: params.SubmissionID,
},
Raw: r,
}
type (
Request = struct{}
Params = ActionSubmissionRejectParams
Response = *ActionSubmissionRejectOK
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackActionSubmissionRejectParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
err = s.h.ActionSubmissionReject(ctx, params)
return response, err
},
)
} else {
err = s.h.ActionSubmissionReject(ctx, params)
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
if err := encodeErrorResponse(errRes, w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if errors.Is(err, ht.ErrNotImplemented) {
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if err := encodeActionSubmissionRejectResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
return
}
}
// handleActionSubmissionRequestChangesRequest handles actionSubmissionRequestChanges operation.
//
// Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested.
//
// PATCH /submissions/{SubmissionID}/status/request-changes
func (s *Server) handleActionSubmissionRequestChangesRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("actionSubmissionRequestChanges"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/request-changes"),
}
// Start a span for this request.
2024-11-29 22:33:48 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), ActionSubmissionRequestChangesOperation,
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Add Labeler to context.
labeler := &Labeler{attrs: otelAttrs}
ctx = contextWithLabeler(ctx, labeler)
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
attrOpt := metric.WithAttributeSet(labeler.AttributeSet())
// Increment request counter.
s.requests.Add(ctx, 1, attrOpt)
// Use floating point division here for higher precision (instead of Millisecond method).
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt)
}()
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet()))
}
err error
opErrContext = ogenerrors.OperationContext{
2024-11-29 22:33:48 +00:00
Name: ActionSubmissionRequestChangesOperation,
ID: "actionSubmissionRequestChanges",
}
)
2024-11-29 22:33:48 +00:00
{
type bitset = [1]uint8
var satisfied bitset
{
sctx, ok, err := s.securityCookieAuth(ctx, ActionSubmissionRequestChangesOperation, r)
if err != nil {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Security: "CookieAuth",
Err: err,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security:CookieAuth", err)
}
return
}
if ok {
satisfied[0] |= 1 << 0
ctx = sctx
}
}
if ok := func() bool {
nextRequirement:
for _, requirement := range []bitset{
{0b00000001},
} {
for i, mask := range requirement {
if satisfied[i]&mask != mask {
continue nextRequirement
}
}
return true
}
return false
}(); !ok {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security", err)
}
return
}
}
params, err := decodeActionSubmissionRequestChangesParams(args, argsEscaped, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
defer recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response *ActionSubmissionRequestChangesOK
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-11-29 22:33:48 +00:00
OperationName: ActionSubmissionRequestChangesOperation,
OperationSummary: "Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested",
OperationID: "actionSubmissionRequestChanges",
Body: nil,
Params: middleware.Parameters{
{
Name: "SubmissionID",
In: "path",
}: params.SubmissionID,
},
Raw: r,
}
type (
Request = struct{}
Params = ActionSubmissionRequestChangesParams
Response = *ActionSubmissionRequestChangesOK
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackActionSubmissionRequestChangesParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
err = s.h.ActionSubmissionRequestChanges(ctx, params)
return response, err
},
)
} else {
err = s.h.ActionSubmissionRequestChanges(ctx, params)
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
if err := encodeErrorResponse(errRes, w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if errors.Is(err, ht.ErrNotImplemented) {
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if err := encodeActionSubmissionRequestChangesResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
return
}
}
// handleActionSubmissionRevokeRequest handles actionSubmissionRevoke operation.
//
// Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction.
//
// PATCH /submissions/{SubmissionID}/status/revoke
func (s *Server) handleActionSubmissionRevokeRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("actionSubmissionRevoke"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/revoke"),
}
// Start a span for this request.
2024-11-29 22:33:48 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), ActionSubmissionRevokeOperation,
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Add Labeler to context.
labeler := &Labeler{attrs: otelAttrs}
ctx = contextWithLabeler(ctx, labeler)
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
attrOpt := metric.WithAttributeSet(labeler.AttributeSet())
// Increment request counter.
s.requests.Add(ctx, 1, attrOpt)
// Use floating point division here for higher precision (instead of Millisecond method).
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt)
}()
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet()))
}
err error
opErrContext = ogenerrors.OperationContext{
2024-11-29 22:33:48 +00:00
Name: ActionSubmissionRevokeOperation,
ID: "actionSubmissionRevoke",
}
)
2024-11-29 22:33:48 +00:00
{
type bitset = [1]uint8
var satisfied bitset
{
sctx, ok, err := s.securityCookieAuth(ctx, ActionSubmissionRevokeOperation, r)
if err != nil {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Security: "CookieAuth",
Err: err,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security:CookieAuth", err)
}
return
}
if ok {
satisfied[0] |= 1 << 0
ctx = sctx
}
}
if ok := func() bool {
nextRequirement:
for _, requirement := range []bitset{
{0b00000001},
} {
for i, mask := range requirement {
if satisfied[i]&mask != mask {
continue nextRequirement
}
}
return true
}
return false
}(); !ok {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security", err)
}
return
}
}
params, err := decodeActionSubmissionRevokeParams(args, argsEscaped, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
defer recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response *ActionSubmissionRevokeOK
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-11-29 22:33:48 +00:00
OperationName: ActionSubmissionRevokeOperation,
OperationSummary: "Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction",
OperationID: "actionSubmissionRevoke",
Body: nil,
Params: middleware.Parameters{
{
Name: "SubmissionID",
In: "path",
}: params.SubmissionID,
},
Raw: r,
}
type (
Request = struct{}
Params = ActionSubmissionRevokeParams
Response = *ActionSubmissionRevokeOK
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackActionSubmissionRevokeParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
err = s.h.ActionSubmissionRevoke(ctx, params)
return response, err
},
)
} else {
err = s.h.ActionSubmissionRevoke(ctx, params)
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
if err := encodeErrorResponse(errRes, w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if errors.Is(err, ht.ErrNotImplemented) {
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if err := encodeActionSubmissionRevokeResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
return
}
}
// handleActionSubmissionSubmitRequest handles actionSubmissionSubmit operation.
//
// Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted.
//
// PATCH /submissions/{SubmissionID}/status/submit
func (s *Server) handleActionSubmissionSubmitRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("actionSubmissionSubmit"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/submit"),
}
// Start a span for this request.
2024-11-29 22:33:48 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), ActionSubmissionSubmitOperation,
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Add Labeler to context.
labeler := &Labeler{attrs: otelAttrs}
ctx = contextWithLabeler(ctx, labeler)
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
attrOpt := metric.WithAttributeSet(labeler.AttributeSet())
// Increment request counter.
s.requests.Add(ctx, 1, attrOpt)
// Use floating point division here for higher precision (instead of Millisecond method).
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt)
}()
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet()))
}
err error
opErrContext = ogenerrors.OperationContext{
2024-11-29 22:33:48 +00:00
Name: ActionSubmissionSubmitOperation,
ID: "actionSubmissionSubmit",
}
)
2024-11-29 22:33:48 +00:00
{
type bitset = [1]uint8
var satisfied bitset
{
sctx, ok, err := s.securityCookieAuth(ctx, ActionSubmissionSubmitOperation, r)
if err != nil {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Security: "CookieAuth",
Err: err,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security:CookieAuth", err)
}
return
}
if ok {
satisfied[0] |= 1 << 0
ctx = sctx
}
}
if ok := func() bool {
nextRequirement:
for _, requirement := range []bitset{
{0b00000001},
} {
for i, mask := range requirement {
if satisfied[i]&mask != mask {
continue nextRequirement
}
}
return true
}
return false
}(); !ok {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security", err)
}
return
}
}
params, err := decodeActionSubmissionSubmitParams(args, argsEscaped, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
defer recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response *ActionSubmissionSubmitOK
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-11-29 22:33:48 +00:00
OperationName: ActionSubmissionSubmitOperation,
OperationSummary: "Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted",
OperationID: "actionSubmissionSubmit",
Body: nil,
Params: middleware.Parameters{
{
Name: "SubmissionID",
In: "path",
}: params.SubmissionID,
},
Raw: r,
}
type (
Request = struct{}
Params = ActionSubmissionSubmitParams
Response = *ActionSubmissionSubmitOK
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackActionSubmissionSubmitParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
err = s.h.ActionSubmissionSubmit(ctx, params)
return response, err
},
)
} else {
err = s.h.ActionSubmissionSubmit(ctx, params)
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
if err := encodeErrorResponse(errRes, w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if errors.Is(err, ht.ErrNotImplemented) {
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if err := encodeActionSubmissionSubmitResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
return
}
}
// handleActionSubmissionTriggerPublishRequest handles actionSubmissionTriggerPublish operation.
//
// Role Admin changes status from Validated -> Publishing.
//
// PATCH /submissions/{SubmissionID}/status/trigger-publish
func (s *Server) handleActionSubmissionTriggerPublishRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("actionSubmissionTriggerPublish"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/trigger-publish"),
}
// Start a span for this request.
2024-11-29 22:33:48 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), ActionSubmissionTriggerPublishOperation,
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Add Labeler to context.
labeler := &Labeler{attrs: otelAttrs}
ctx = contextWithLabeler(ctx, labeler)
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
attrOpt := metric.WithAttributeSet(labeler.AttributeSet())
// Increment request counter.
s.requests.Add(ctx, 1, attrOpt)
// Use floating point division here for higher precision (instead of Millisecond method).
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt)
}()
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet()))
}
err error
opErrContext = ogenerrors.OperationContext{
2024-11-29 22:33:48 +00:00
Name: ActionSubmissionTriggerPublishOperation,
ID: "actionSubmissionTriggerPublish",
}
)
2024-11-29 22:33:48 +00:00
{
type bitset = [1]uint8
var satisfied bitset
{
sctx, ok, err := s.securityCookieAuth(ctx, ActionSubmissionTriggerPublishOperation, r)
if err != nil {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Security: "CookieAuth",
Err: err,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security:CookieAuth", err)
}
return
}
if ok {
satisfied[0] |= 1 << 0
ctx = sctx
}
}
if ok := func() bool {
nextRequirement:
for _, requirement := range []bitset{
{0b00000001},
} {
for i, mask := range requirement {
if satisfied[i]&mask != mask {
continue nextRequirement
}
}
return true
}
return false
}(); !ok {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security", err)
}
return
}
}
params, err := decodeActionSubmissionTriggerPublishParams(args, argsEscaped, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
defer recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response *ActionSubmissionTriggerPublishOK
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-11-29 22:33:48 +00:00
OperationName: ActionSubmissionTriggerPublishOperation,
OperationSummary: "Role Admin changes status from Validated -> Publishing",
OperationID: "actionSubmissionTriggerPublish",
Body: nil,
Params: middleware.Parameters{
{
Name: "SubmissionID",
In: "path",
}: params.SubmissionID,
},
Raw: r,
}
type (
Request = struct{}
Params = ActionSubmissionTriggerPublishParams
Response = *ActionSubmissionTriggerPublishOK
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackActionSubmissionTriggerPublishParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
err = s.h.ActionSubmissionTriggerPublish(ctx, params)
return response, err
},
)
} else {
err = s.h.ActionSubmissionTriggerPublish(ctx, params)
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
if err := encodeErrorResponse(errRes, w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if errors.Is(err, ht.ErrNotImplemented) {
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if err := encodeActionSubmissionTriggerPublishResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
return
}
}
// handleActionSubmissionTriggerValidateRequest handles actionSubmissionTriggerValidate operation.
//
// Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating.
//
// PATCH /submissions/{SubmissionID}/status/trigger-validate
func (s *Server) handleActionSubmissionTriggerValidateRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("actionSubmissionTriggerValidate"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/trigger-validate"),
}
// Start a span for this request.
2024-11-29 22:33:48 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), ActionSubmissionTriggerValidateOperation,
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Add Labeler to context.
labeler := &Labeler{attrs: otelAttrs}
ctx = contextWithLabeler(ctx, labeler)
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
attrOpt := metric.WithAttributeSet(labeler.AttributeSet())
// Increment request counter.
s.requests.Add(ctx, 1, attrOpt)
// Use floating point division here for higher precision (instead of Millisecond method).
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt)
}()
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet()))
}
err error
opErrContext = ogenerrors.OperationContext{
2024-11-29 22:33:48 +00:00
Name: ActionSubmissionTriggerValidateOperation,
ID: "actionSubmissionTriggerValidate",
}
)
2024-11-29 22:33:48 +00:00
{
type bitset = [1]uint8
var satisfied bitset
{
sctx, ok, err := s.securityCookieAuth(ctx, ActionSubmissionTriggerValidateOperation, r)
if err != nil {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Security: "CookieAuth",
Err: err,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security:CookieAuth", err)
}
return
}
if ok {
satisfied[0] |= 1 << 0
ctx = sctx
}
}
if ok := func() bool {
nextRequirement:
for _, requirement := range []bitset{
{0b00000001},
} {
for i, mask := range requirement {
if satisfied[i]&mask != mask {
continue nextRequirement
}
}
return true
}
return false
}(); !ok {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security", err)
}
return
}
}
params, err := decodeActionSubmissionTriggerValidateParams(args, argsEscaped, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
defer recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response *ActionSubmissionTriggerValidateOK
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-11-29 22:33:48 +00:00
OperationName: ActionSubmissionTriggerValidateOperation,
OperationSummary: "Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating",
OperationID: "actionSubmissionTriggerValidate",
Body: nil,
Params: middleware.Parameters{
{
Name: "SubmissionID",
In: "path",
}: params.SubmissionID,
},
Raw: r,
}
type (
Request = struct{}
Params = ActionSubmissionTriggerValidateParams
Response = *ActionSubmissionTriggerValidateOK
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackActionSubmissionTriggerValidateParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
err = s.h.ActionSubmissionTriggerValidate(ctx, params)
return response, err
},
)
} else {
err = s.h.ActionSubmissionTriggerValidate(ctx, params)
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
if err := encodeErrorResponse(errRes, w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if errors.Is(err, ht.ErrNotImplemented) {
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if err := encodeActionSubmissionTriggerValidateResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
return
}
}
// handleActionSubmissionValidateRequest handles actionSubmissionValidate operation.
//
// Role Validator changes status from Validating -> Validated.
//
// PATCH /submissions/{SubmissionID}/status/validate
func (s *Server) handleActionSubmissionValidateRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("actionSubmissionValidate"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/validate"),
}
// Start a span for this request.
2024-11-29 22:33:48 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), ActionSubmissionValidateOperation,
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Add Labeler to context.
labeler := &Labeler{attrs: otelAttrs}
ctx = contextWithLabeler(ctx, labeler)
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
attrOpt := metric.WithAttributeSet(labeler.AttributeSet())
// Increment request counter.
s.requests.Add(ctx, 1, attrOpt)
// Use floating point division here for higher precision (instead of Millisecond method).
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt)
}()
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet()))
}
err error
opErrContext = ogenerrors.OperationContext{
2024-11-29 22:33:48 +00:00
Name: ActionSubmissionValidateOperation,
ID: "actionSubmissionValidate",
}
)
2024-11-29 22:33:48 +00:00
{
type bitset = [1]uint8
var satisfied bitset
{
sctx, ok, err := s.securityCookieAuth(ctx, ActionSubmissionValidateOperation, r)
if err != nil {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Security: "CookieAuth",
Err: err,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security:CookieAuth", err)
}
return
}
if ok {
satisfied[0] |= 1 << 0
ctx = sctx
}
}
if ok := func() bool {
nextRequirement:
for _, requirement := range []bitset{
{0b00000001},
} {
for i, mask := range requirement {
if satisfied[i]&mask != mask {
continue nextRequirement
}
}
return true
}
return false
}(); !ok {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security", err)
}
return
}
}
params, err := decodeActionSubmissionValidateParams(args, argsEscaped, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
defer recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response *ActionSubmissionValidateOK
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-11-29 22:33:48 +00:00
OperationName: ActionSubmissionValidateOperation,
OperationSummary: "Role Validator changes status from Validating -> Validated",
OperationID: "actionSubmissionValidate",
Body: nil,
Params: middleware.Parameters{
{
Name: "SubmissionID",
In: "path",
}: params.SubmissionID,
},
Raw: r,
}
type (
Request = struct{}
Params = ActionSubmissionValidateParams
Response = *ActionSubmissionValidateOK
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackActionSubmissionValidateParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
err = s.h.ActionSubmissionValidate(ctx, params)
return response, err
},
)
} else {
err = s.h.ActionSubmissionValidate(ctx, params)
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
if err := encodeErrorResponse(errRes, w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if errors.Is(err, ht.ErrNotImplemented) {
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if err := encodeActionSubmissionValidateResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
return
}
}
2024-11-26 20:39:10 +00:00
// handleCreateSubmissionRequest handles createSubmission operation.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// Create new submission.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// POST /submissions
func (s *Server) handleCreateSubmissionRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
2024-11-26 01:22:45 +00:00
otelAttrs := []attribute.KeyValue{
2024-11-26 20:39:10 +00:00
otelogen.OperationID("createSubmission"),
semconv.HTTPRequestMethodKey.String("POST"),
semconv.HTTPRouteKey.String("/submissions"),
2024-11-26 01:22:45 +00:00
}
// Start a span for this request.
2024-11-29 22:33:48 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), CreateSubmissionOperation,
2024-11-26 20:39:10 +00:00
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Add Labeler to context.
labeler := &Labeler{attrs: otelAttrs}
ctx = contextWithLabeler(ctx, labeler)
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
attrOpt := metric.WithAttributeSet(labeler.AttributeSet())
// Increment request counter.
s.requests.Add(ctx, 1, attrOpt)
// Use floating point division here for higher precision (instead of Millisecond method).
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt)
}()
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet()))
}
2024-11-27 23:38:17 +00:00
err error
opErrContext = ogenerrors.OperationContext{
2024-11-29 22:33:48 +00:00
Name: CreateSubmissionOperation,
2024-11-27 23:38:17 +00:00
ID: "createSubmission",
}
2024-11-26 20:39:10 +00:00
)
2024-11-29 22:33:48 +00:00
{
type bitset = [1]uint8
var satisfied bitset
{
sctx, ok, err := s.securityCookieAuth(ctx, CreateSubmissionOperation, r)
if err != nil {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Security: "CookieAuth",
Err: err,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security:CookieAuth", err)
}
return
}
if ok {
satisfied[0] |= 1 << 0
ctx = sctx
}
}
if ok := func() bool {
nextRequirement:
for _, requirement := range []bitset{
{0b00000001},
} {
for i, mask := range requirement {
if satisfied[i]&mask != mask {
continue nextRequirement
}
}
return true
}
return false
}(); !ok {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security", err)
}
return
}
}
2024-11-27 23:38:17 +00:00
request, close, err := s.decodeCreateSubmissionRequest(r)
if err != nil {
err = &ogenerrors.DecodeRequestError{
OperationContext: opErrContext,
Err: err,
}
defer recordError("DecodeRequest", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
defer func() {
if err := close(); err != nil {
recordError("CloseRequest", err)
}
}()
2024-11-26 20:39:10 +00:00
2024-11-28 00:13:43 +00:00
var response *ID
2024-11-26 20:39:10 +00:00
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-11-29 22:33:48 +00:00
OperationName: CreateSubmissionOperation,
2024-11-26 20:39:10 +00:00
OperationSummary: "Create new submission",
OperationID: "createSubmission",
2024-11-27 23:38:17 +00:00
Body: request,
2024-11-26 20:39:10 +00:00
Params: middleware.Parameters{},
Raw: r,
}
type (
2024-11-27 23:38:17 +00:00
Request = OptSubmissionCreate
2024-11-26 20:39:10 +00:00
Params = struct{}
2024-11-28 00:13:43 +00:00
Response = *ID
2024-11-26 20:39:10 +00:00
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
nil,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
2024-11-27 23:38:17 +00:00
response, err = s.h.CreateSubmission(ctx, request)
2024-11-26 20:39:10 +00:00
return response, err
},
)
} else {
2024-11-27 23:38:17 +00:00
response, err = s.h.CreateSubmission(ctx, request)
2024-11-26 20:39:10 +00:00
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
if err := encodeErrorResponse(errRes, w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if errors.Is(err, ht.ErrNotImplemented) {
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if err := encodeCreateSubmissionResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
return
}
}
// handleGetSubmissionRequest handles getSubmission operation.
//
// Retrieve map with ID.
//
// GET /submissions/{SubmissionID}
func (s *Server) handleGetSubmissionRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("getSubmission"),
semconv.HTTPRequestMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}"),
}
// Start a span for this request.
2024-11-29 22:33:48 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), GetSubmissionOperation,
2024-11-26 01:22:45 +00:00
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Add Labeler to context.
labeler := &Labeler{attrs: otelAttrs}
ctx = contextWithLabeler(ctx, labeler)
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
attrOpt := metric.WithAttributeSet(labeler.AttributeSet())
// Increment request counter.
s.requests.Add(ctx, 1, attrOpt)
// Use floating point division here for higher precision (instead of Millisecond method).
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt)
}()
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet()))
}
err error
opErrContext = ogenerrors.OperationContext{
2024-11-29 22:33:48 +00:00
Name: GetSubmissionOperation,
2024-11-26 20:39:10 +00:00
ID: "getSubmission",
2024-11-26 01:22:45 +00:00
}
)
2024-11-29 22:33:48 +00:00
{
type bitset = [1]uint8
var satisfied bitset
{
sctx, ok, err := s.securityCookieAuth(ctx, GetSubmissionOperation, r)
if err != nil {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Security: "CookieAuth",
Err: err,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security:CookieAuth", err)
}
return
}
if ok {
satisfied[0] |= 1 << 0
ctx = sctx
}
}
if ok := func() bool {
nextRequirement:
for _, requirement := range []bitset{
{0b00000001},
} {
for i, mask := range requirement {
if satisfied[i]&mask != mask {
continue nextRequirement
}
}
return true
}
return false
}(); !ok {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security", err)
}
return
}
}
2024-11-26 20:39:10 +00:00
params, err := decodeGetSubmissionParams(args, argsEscaped, r)
2024-11-26 01:22:45 +00:00
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
defer recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
2024-11-26 20:39:10 +00:00
var response *Submission
2024-11-26 01:22:45 +00:00
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-11-29 22:33:48 +00:00
OperationName: GetSubmissionOperation,
2024-11-26 20:39:10 +00:00
OperationSummary: "Retrieve map with ID",
OperationID: "getSubmission",
2024-11-26 01:22:45 +00:00
Body: nil,
Params: middleware.Parameters{
{
2024-11-26 20:39:10 +00:00
Name: "SubmissionID",
2024-11-26 01:22:45 +00:00
In: "path",
2024-11-26 20:39:10 +00:00
}: params.SubmissionID,
2024-11-26 01:22:45 +00:00
},
Raw: r,
}
type (
Request = struct{}
2024-11-26 20:39:10 +00:00
Params = GetSubmissionParams
Response = *Submission
2024-11-26 01:22:45 +00:00
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
2024-11-26 20:39:10 +00:00
unpackGetSubmissionParams,
2024-11-26 01:22:45 +00:00
func(ctx context.Context, request Request, params Params) (response Response, err error) {
2024-11-26 20:39:10 +00:00
response, err = s.h.GetSubmission(ctx, params)
2024-11-26 01:22:45 +00:00
return response, err
},
)
} else {
2024-11-26 20:39:10 +00:00
response, err = s.h.GetSubmission(ctx, params)
2024-11-26 01:22:45 +00:00
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
if err := encodeErrorResponse(errRes, w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if errors.Is(err, ht.ErrNotImplemented) {
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
defer recordError("Internal", err)
}
return
}
2024-11-26 20:39:10 +00:00
if err := encodeGetSubmissionResponse(response, w, span); err != nil {
2024-11-26 01:22:45 +00:00
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
return
}
}
2024-11-26 20:39:10 +00:00
// handleListSubmissionsRequest handles listSubmissions operation.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// Get list of submissions.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// GET /submissions
func (s *Server) handleListSubmissionsRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
2024-11-26 01:22:45 +00:00
otelAttrs := []attribute.KeyValue{
2024-11-26 20:39:10 +00:00
otelogen.OperationID("listSubmissions"),
semconv.HTTPRequestMethodKey.String("GET"),
semconv.HTTPRouteKey.String("/submissions"),
2024-11-26 01:22:45 +00:00
}
// Start a span for this request.
2024-11-29 22:33:48 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), ListSubmissionsOperation,
2024-11-26 01:22:45 +00:00
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Add Labeler to context.
labeler := &Labeler{attrs: otelAttrs}
ctx = contextWithLabeler(ctx, labeler)
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
attrOpt := metric.WithAttributeSet(labeler.AttributeSet())
// Increment request counter.
s.requests.Add(ctx, 1, attrOpt)
// Use floating point division here for higher precision (instead of Millisecond method).
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt)
}()
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet()))
}
err error
opErrContext = ogenerrors.OperationContext{
2024-11-29 22:33:48 +00:00
Name: ListSubmissionsOperation,
2024-11-26 20:39:10 +00:00
ID: "listSubmissions",
2024-11-26 01:22:45 +00:00
}
)
2024-11-29 22:33:48 +00:00
{
type bitset = [1]uint8
var satisfied bitset
{
sctx, ok, err := s.securityCookieAuth(ctx, ListSubmissionsOperation, r)
if err != nil {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Security: "CookieAuth",
Err: err,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security:CookieAuth", err)
}
return
}
if ok {
satisfied[0] |= 1 << 0
ctx = sctx
}
}
if ok := func() bool {
nextRequirement:
for _, requirement := range []bitset{
{0b00000001},
} {
for i, mask := range requirement {
if satisfied[i]&mask != mask {
continue nextRequirement
}
}
return true
}
return false
}(); !ok {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security", err)
}
return
}
}
2024-11-26 20:39:10 +00:00
params, err := decodeListSubmissionsParams(args, argsEscaped, r)
2024-11-26 01:22:45 +00:00
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
defer recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
2024-11-26 20:39:10 +00:00
var response []Submission
2024-11-26 01:22:45 +00:00
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-11-29 22:33:48 +00:00
OperationName: ListSubmissionsOperation,
2024-11-26 20:39:10 +00:00
OperationSummary: "Get list of submissions",
OperationID: "listSubmissions",
2024-11-26 01:22:45 +00:00
Body: nil,
Params: middleware.Parameters{
{
2024-11-26 20:39:10 +00:00
Name: "page",
2024-11-26 01:22:45 +00:00
In: "query",
2024-11-26 20:39:10 +00:00
}: params.Page,
2024-11-26 01:22:45 +00:00
{
2024-11-26 20:39:10 +00:00
Name: "filter",
2024-11-26 01:22:45 +00:00
In: "query",
2024-11-26 20:39:10 +00:00
}: params.Filter,
},
Raw: r,
}
type (
Request = struct{}
Params = ListSubmissionsParams
Response = []Submission
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
unpackListSubmissionsParams,
func(ctx context.Context, request Request, params Params) (response Response, err error) {
response, err = s.h.ListSubmissions(ctx, params)
return response, err
},
)
} else {
response, err = s.h.ListSubmissions(ctx, params)
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
if err := encodeErrorResponse(errRes, w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if errors.Is(err, ht.ErrNotImplemented) {
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if err := encodeListSubmissionsResponse(response, w, span); err != nil {
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
return
}
}
// handlePatchSubmissionCompletedRequest handles patchSubmissionCompleted operation.
//
// Retrieve map with ID.
//
// PATCH /submissions/{SubmissionID}/completed
func (s *Server) handlePatchSubmissionCompletedRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
otelAttrs := []attribute.KeyValue{
otelogen.OperationID("patchSubmissionCompleted"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/completed"),
}
// Start a span for this request.
2024-11-29 22:33:48 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), PatchSubmissionCompletedOperation,
2024-11-26 20:39:10 +00:00
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Add Labeler to context.
labeler := &Labeler{attrs: otelAttrs}
ctx = contextWithLabeler(ctx, labeler)
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
attrOpt := metric.WithAttributeSet(labeler.AttributeSet())
// Increment request counter.
s.requests.Add(ctx, 1, attrOpt)
// Use floating point division here for higher precision (instead of Millisecond method).
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt)
}()
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet()))
}
err error
opErrContext = ogenerrors.OperationContext{
2024-11-29 22:33:48 +00:00
Name: PatchSubmissionCompletedOperation,
2024-11-26 20:39:10 +00:00
ID: "patchSubmissionCompleted",
}
)
2024-11-29 22:33:48 +00:00
{
type bitset = [1]uint8
var satisfied bitset
{
sctx, ok, err := s.securityCookieAuth(ctx, PatchSubmissionCompletedOperation, r)
if err != nil {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Security: "CookieAuth",
Err: err,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security:CookieAuth", err)
}
return
}
if ok {
satisfied[0] |= 1 << 0
ctx = sctx
}
}
if ok := func() bool {
nextRequirement:
for _, requirement := range []bitset{
{0b00000001},
} {
for i, mask := range requirement {
if satisfied[i]&mask != mask {
continue nextRequirement
}
}
return true
}
return false
}(); !ok {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security", err)
}
return
}
}
2024-11-26 20:39:10 +00:00
params, err := decodePatchSubmissionCompletedParams(args, argsEscaped, r)
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
defer recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
var response *PatchSubmissionCompletedOK
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-11-29 22:33:48 +00:00
OperationName: PatchSubmissionCompletedOperation,
2024-11-26 20:39:10 +00:00
OperationSummary: "Retrieve map with ID",
OperationID: "patchSubmissionCompleted",
Body: nil,
Params: middleware.Parameters{
{
Name: "SubmissionID",
In: "path",
}: params.SubmissionID,
2024-11-26 01:22:45 +00:00
},
Raw: r,
}
type (
Request = struct{}
2024-11-26 20:39:10 +00:00
Params = PatchSubmissionCompletedParams
Response = *PatchSubmissionCompletedOK
2024-11-26 01:22:45 +00:00
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
2024-11-26 20:39:10 +00:00
unpackPatchSubmissionCompletedParams,
2024-11-26 01:22:45 +00:00
func(ctx context.Context, request Request, params Params) (response Response, err error) {
2024-11-26 20:39:10 +00:00
err = s.h.PatchSubmissionCompleted(ctx, params)
2024-11-26 01:22:45 +00:00
return response, err
},
)
} else {
2024-11-26 20:39:10 +00:00
err = s.h.PatchSubmissionCompleted(ctx, params)
2024-11-26 01:22:45 +00:00
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
if err := encodeErrorResponse(errRes, w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if errors.Is(err, ht.ErrNotImplemented) {
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
defer recordError("Internal", err)
}
return
}
2024-11-26 20:39:10 +00:00
if err := encodePatchSubmissionCompletedResponse(response, w, span); err != nil {
2024-11-26 01:22:45 +00:00
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
return
}
}
2024-11-26 20:39:10 +00:00
// handlePatchSubmissionModelRequest handles patchSubmissionModel operation.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// Update model following role restrictions.
2024-11-26 01:22:45 +00:00
//
2024-11-26 20:39:10 +00:00
// PATCH /submissions/{SubmissionID}/model
func (s *Server) handlePatchSubmissionModelRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
2024-11-26 01:22:45 +00:00
otelAttrs := []attribute.KeyValue{
2024-11-26 20:39:10 +00:00
otelogen.OperationID("patchSubmissionModel"),
semconv.HTTPRequestMethodKey.String("PATCH"),
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/model"),
2024-11-26 01:22:45 +00:00
}
// Start a span for this request.
2024-11-29 22:33:48 +00:00
ctx, span := s.cfg.Tracer.Start(r.Context(), PatchSubmissionModelOperation,
2024-11-26 01:22:45 +00:00
trace.WithAttributes(otelAttrs...),
serverSpanKind,
)
defer span.End()
// Add Labeler to context.
labeler := &Labeler{attrs: otelAttrs}
ctx = contextWithLabeler(ctx, labeler)
// Run stopwatch.
startTime := time.Now()
defer func() {
elapsedDuration := time.Since(startTime)
attrOpt := metric.WithAttributeSet(labeler.AttributeSet())
// Increment request counter.
s.requests.Add(ctx, 1, attrOpt)
// Use floating point division here for higher precision (instead of Millisecond method).
s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt)
}()
var (
recordError = func(stage string, err error) {
span.RecordError(err)
span.SetStatus(codes.Error, stage)
s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet()))
}
err error
opErrContext = ogenerrors.OperationContext{
2024-11-29 22:33:48 +00:00
Name: PatchSubmissionModelOperation,
2024-11-26 20:39:10 +00:00
ID: "patchSubmissionModel",
2024-11-26 01:22:45 +00:00
}
)
2024-11-29 22:33:48 +00:00
{
type bitset = [1]uint8
var satisfied bitset
{
sctx, ok, err := s.securityCookieAuth(ctx, PatchSubmissionModelOperation, r)
if err != nil {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Security: "CookieAuth",
Err: err,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security:CookieAuth", err)
}
return
}
if ok {
satisfied[0] |= 1 << 0
ctx = sctx
}
}
if ok := func() bool {
nextRequirement:
for _, requirement := range []bitset{
{0b00000001},
} {
for i, mask := range requirement {
if satisfied[i]&mask != mask {
continue nextRequirement
}
}
return true
}
return false
}(); !ok {
err = &ogenerrors.SecurityError{
OperationContext: opErrContext,
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
}
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
defer recordError("Security", err)
}
return
}
}
2024-11-26 20:39:10 +00:00
params, err := decodePatchSubmissionModelParams(args, argsEscaped, r)
2024-11-26 01:22:45 +00:00
if err != nil {
err = &ogenerrors.DecodeParamsError{
OperationContext: opErrContext,
Err: err,
}
defer recordError("DecodeParams", err)
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
2024-11-26 20:39:10 +00:00
var response *PatchSubmissionModelOK
2024-11-26 01:22:45 +00:00
if m := s.cfg.Middleware; m != nil {
mreq := middleware.Request{
Context: ctx,
2024-11-29 22:33:48 +00:00
OperationName: PatchSubmissionModelOperation,
2024-11-26 20:39:10 +00:00
OperationSummary: "Update model following role restrictions",
OperationID: "patchSubmissionModel",
2024-11-26 01:22:45 +00:00
Body: nil,
Params: middleware.Parameters{
{
2024-11-26 20:39:10 +00:00
Name: "SubmissionID",
In: "path",
}: params.SubmissionID,
{
Name: "ModelID",
2024-11-26 01:22:45 +00:00
In: "query",
2024-11-26 20:39:10 +00:00
}: params.ModelID,
2024-11-26 01:22:45 +00:00
{
2024-11-26 20:39:10 +00:00
Name: "VersionID",
2024-11-26 01:22:45 +00:00
In: "query",
2024-11-26 20:39:10 +00:00
}: params.VersionID,
2024-11-26 01:22:45 +00:00
},
Raw: r,
}
type (
Request = struct{}
2024-11-26 20:39:10 +00:00
Params = PatchSubmissionModelParams
Response = *PatchSubmissionModelOK
2024-11-26 01:22:45 +00:00
)
response, err = middleware.HookMiddleware[
Request,
Params,
Response,
](
m,
mreq,
2024-11-26 20:39:10 +00:00
unpackPatchSubmissionModelParams,
2024-11-26 01:22:45 +00:00
func(ctx context.Context, request Request, params Params) (response Response, err error) {
2024-11-26 20:39:10 +00:00
err = s.h.PatchSubmissionModel(ctx, params)
2024-11-26 01:22:45 +00:00
return response, err
},
)
} else {
2024-11-26 20:39:10 +00:00
err = s.h.PatchSubmissionModel(ctx, params)
2024-11-26 01:22:45 +00:00
}
if err != nil {
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
if err := encodeErrorResponse(errRes, w, span); err != nil {
defer recordError("Internal", err)
}
return
}
if errors.Is(err, ht.ErrNotImplemented) {
s.cfg.ErrorHandler(ctx, w, r, err)
return
}
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
defer recordError("Internal", err)
}
return
}
2024-11-26 20:39:10 +00:00
if err := encodePatchSubmissionModelResponse(response, w, span); err != nil {
2024-11-26 01:22:45 +00:00
defer recordError("EncodeResponse", err)
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
s.cfg.ErrorHandler(ctx, w, r, err)
}
return
}
}