2024-12-14 19:55:56 +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"
|
|
|
|
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
|
|
|
type codeRecorder struct {
|
|
|
|
http.ResponseWriter
|
|
|
|
status int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *codeRecorder) WriteHeader(status int) {
|
|
|
|
c.status = status
|
|
|
|
c.ResponseWriter.WriteHeader(status)
|
|
|
|
}
|
|
|
|
|
|
|
|
// handleActionSubmissionReleasedRequest handles actionSubmissionReleased operation.
|
|
|
|
//
|
|
|
|
// (Internal endpoint) Role Releaser changes status from releasing -> released.
|
|
|
|
//
|
|
|
|
// POST /submissions/{SubmissionID}/status/releaser-released
|
|
|
|
func (s *Server) handleActionSubmissionReleasedRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
|
|
statusWriter := &codeRecorder{ResponseWriter: w}
|
|
|
|
w = statusWriter
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("actionSubmissionReleased"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/releaser-released"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a span for this request.
|
|
|
|
ctx, span := s.cfg.Tracer.Start(r.Context(), ActionSubmissionReleasedOperation,
|
|
|
|
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)
|
|
|
|
|
|
|
|
attrSet := labeler.AttributeSet()
|
|
|
|
attrs := attrSet.ToSlice()
|
|
|
|
code := statusWriter.status
|
|
|
|
if code != 0 {
|
|
|
|
codeAttr := semconv.HTTPResponseStatusCode(code)
|
|
|
|
attrs = append(attrs, codeAttr)
|
|
|
|
span.SetAttributes(codeAttr)
|
|
|
|
}
|
|
|
|
attrOpt := metric.WithAttributes(attrs...)
|
|
|
|
|
|
|
|
// 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(elapsedDuration)/float64(time.Millisecond), attrOpt)
|
|
|
|
}()
|
|
|
|
|
|
|
|
var (
|
|
|
|
recordError = func(stage string, err error) {
|
|
|
|
span.RecordError(err)
|
|
|
|
|
|
|
|
// https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status
|
|
|
|
// Span Status MUST be left unset if HTTP status code was in the 1xx, 2xx or 3xx ranges,
|
|
|
|
// unless there was another error (e.g., network error receiving the response body; or 3xx codes with
|
|
|
|
// max redirects exceeded), in which case status MUST be set to Error.
|
|
|
|
code := statusWriter.status
|
|
|
|
if code >= 100 && code < 500 {
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
}
|
|
|
|
|
|
|
|
attrSet := labeler.AttributeSet()
|
|
|
|
attrs := attrSet.ToSlice()
|
|
|
|
if code != 0 {
|
|
|
|
attrs = append(attrs, semconv.HTTPResponseStatusCode(code))
|
|
|
|
}
|
|
|
|
|
|
|
|
s.errors.Add(ctx, 1, metric.WithAttributes(attrs...))
|
|
|
|
}
|
|
|
|
err error
|
|
|
|
opErrContext = ogenerrors.OperationContext{
|
|
|
|
Name: ActionSubmissionReleasedOperation,
|
|
|
|
ID: "actionSubmissionReleased",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
params, err := decodeActionSubmissionReleasedParams(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 *ActionSubmissionReleasedNoContent
|
|
|
|
if m := s.cfg.Middleware; m != nil {
|
|
|
|
mreq := middleware.Request{
|
|
|
|
Context: ctx,
|
|
|
|
OperationName: ActionSubmissionReleasedOperation,
|
|
|
|
OperationSummary: "(Internal endpoint) Role Releaser changes status from releasing -> released",
|
|
|
|
OperationID: "actionSubmissionReleased",
|
|
|
|
Body: nil,
|
|
|
|
Params: middleware.Parameters{
|
|
|
|
{
|
|
|
|
Name: "SubmissionID",
|
|
|
|
In: "path",
|
|
|
|
}: params.SubmissionID,
|
|
|
|
},
|
|
|
|
Raw: r,
|
|
|
|
}
|
|
|
|
|
|
|
|
type (
|
|
|
|
Request = struct{}
|
|
|
|
Params = ActionSubmissionReleasedParams
|
|
|
|
Response = *ActionSubmissionReleasedNoContent
|
|
|
|
)
|
|
|
|
response, err = middleware.HookMiddleware[
|
|
|
|
Request,
|
|
|
|
Params,
|
|
|
|
Response,
|
|
|
|
](
|
|
|
|
m,
|
|
|
|
mreq,
|
|
|
|
unpackActionSubmissionReleasedParams,
|
|
|
|
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
|
|
err = s.h.ActionSubmissionReleased(ctx, params)
|
|
|
|
return response, err
|
|
|
|
},
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
err = s.h.ActionSubmissionReleased(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 := encodeActionSubmissionReleasedResponse(response, w, span); err != nil {
|
|
|
|
defer recordError("EncodeResponse", err)
|
|
|
|
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// handleActionSubmissionUploadedRequest handles actionSubmissionUploaded operation.
|
|
|
|
//
|
|
|
|
// (Internal endpoint) Role Validator changes status from Uploading -> Uploaded.
|
|
|
|
//
|
|
|
|
// POST /submissions/{SubmissionID}/status/validator-uploaded
|
|
|
|
func (s *Server) handleActionSubmissionUploadedRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
|
|
statusWriter := &codeRecorder{ResponseWriter: w}
|
|
|
|
w = statusWriter
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("actionSubmissionUploaded"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/validator-uploaded"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a span for this request.
|
|
|
|
ctx, span := s.cfg.Tracer.Start(r.Context(), ActionSubmissionUploadedOperation,
|
|
|
|
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)
|
|
|
|
|
|
|
|
attrSet := labeler.AttributeSet()
|
|
|
|
attrs := attrSet.ToSlice()
|
|
|
|
code := statusWriter.status
|
|
|
|
if code != 0 {
|
|
|
|
codeAttr := semconv.HTTPResponseStatusCode(code)
|
|
|
|
attrs = append(attrs, codeAttr)
|
|
|
|
span.SetAttributes(codeAttr)
|
|
|
|
}
|
|
|
|
attrOpt := metric.WithAttributes(attrs...)
|
|
|
|
|
|
|
|
// 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(elapsedDuration)/float64(time.Millisecond), attrOpt)
|
|
|
|
}()
|
|
|
|
|
|
|
|
var (
|
|
|
|
recordError = func(stage string, err error) {
|
|
|
|
span.RecordError(err)
|
|
|
|
|
|
|
|
// https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status
|
|
|
|
// Span Status MUST be left unset if HTTP status code was in the 1xx, 2xx or 3xx ranges,
|
|
|
|
// unless there was another error (e.g., network error receiving the response body; or 3xx codes with
|
|
|
|
// max redirects exceeded), in which case status MUST be set to Error.
|
|
|
|
code := statusWriter.status
|
|
|
|
if code >= 100 && code < 500 {
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
}
|
|
|
|
|
|
|
|
attrSet := labeler.AttributeSet()
|
|
|
|
attrs := attrSet.ToSlice()
|
|
|
|
if code != 0 {
|
|
|
|
attrs = append(attrs, semconv.HTTPResponseStatusCode(code))
|
|
|
|
}
|
|
|
|
|
|
|
|
s.errors.Add(ctx, 1, metric.WithAttributes(attrs...))
|
|
|
|
}
|
|
|
|
err error
|
|
|
|
opErrContext = ogenerrors.OperationContext{
|
|
|
|
Name: ActionSubmissionUploadedOperation,
|
|
|
|
ID: "actionSubmissionUploaded",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
params, err := decodeActionSubmissionUploadedParams(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 *ActionSubmissionUploadedNoContent
|
|
|
|
if m := s.cfg.Middleware; m != nil {
|
|
|
|
mreq := middleware.Request{
|
|
|
|
Context: ctx,
|
|
|
|
OperationName: ActionSubmissionUploadedOperation,
|
|
|
|
OperationSummary: "(Internal endpoint) Role Validator changes status from Uploading -> Uploaded",
|
|
|
|
OperationID: "actionSubmissionUploaded",
|
|
|
|
Body: nil,
|
|
|
|
Params: middleware.Parameters{
|
|
|
|
{
|
|
|
|
Name: "SubmissionID",
|
|
|
|
In: "path",
|
|
|
|
}: params.SubmissionID,
|
2024-12-15 08:09:19 +00:00
|
|
|
{
|
|
|
|
Name: "TargetAssetID",
|
|
|
|
In: "query",
|
|
|
|
}: params.TargetAssetID,
|
2024-12-14 19:55:56 +00:00
|
|
|
},
|
|
|
|
Raw: r,
|
|
|
|
}
|
|
|
|
|
|
|
|
type (
|
|
|
|
Request = struct{}
|
|
|
|
Params = ActionSubmissionUploadedParams
|
|
|
|
Response = *ActionSubmissionUploadedNoContent
|
|
|
|
)
|
|
|
|
response, err = middleware.HookMiddleware[
|
|
|
|
Request,
|
|
|
|
Params,
|
|
|
|
Response,
|
|
|
|
](
|
|
|
|
m,
|
|
|
|
mreq,
|
|
|
|
unpackActionSubmissionUploadedParams,
|
|
|
|
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
|
|
err = s.h.ActionSubmissionUploaded(ctx, params)
|
|
|
|
return response, err
|
|
|
|
},
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
err = s.h.ActionSubmissionUploaded(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 := encodeActionSubmissionUploadedResponse(response, w, span); err != nil {
|
|
|
|
defer recordError("EncodeResponse", err)
|
|
|
|
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// handleActionSubmissionValidatedRequest handles actionSubmissionValidated operation.
|
|
|
|
//
|
|
|
|
// (Internal endpoint) Role Validator changes status from Validating -> Validated.
|
|
|
|
//
|
|
|
|
// POST /submissions/{SubmissionID}/status/validator-validated
|
|
|
|
func (s *Server) handleActionSubmissionValidatedRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
|
|
statusWriter := &codeRecorder{ResponseWriter: w}
|
|
|
|
w = statusWriter
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("actionSubmissionValidated"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/validator-validated"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a span for this request.
|
|
|
|
ctx, span := s.cfg.Tracer.Start(r.Context(), ActionSubmissionValidatedOperation,
|
|
|
|
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)
|
|
|
|
|
|
|
|
attrSet := labeler.AttributeSet()
|
|
|
|
attrs := attrSet.ToSlice()
|
|
|
|
code := statusWriter.status
|
|
|
|
if code != 0 {
|
|
|
|
codeAttr := semconv.HTTPResponseStatusCode(code)
|
|
|
|
attrs = append(attrs, codeAttr)
|
|
|
|
span.SetAttributes(codeAttr)
|
|
|
|
}
|
|
|
|
attrOpt := metric.WithAttributes(attrs...)
|
|
|
|
|
|
|
|
// 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(elapsedDuration)/float64(time.Millisecond), attrOpt)
|
|
|
|
}()
|
|
|
|
|
|
|
|
var (
|
|
|
|
recordError = func(stage string, err error) {
|
|
|
|
span.RecordError(err)
|
|
|
|
|
|
|
|
// https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status
|
|
|
|
// Span Status MUST be left unset if HTTP status code was in the 1xx, 2xx or 3xx ranges,
|
|
|
|
// unless there was another error (e.g., network error receiving the response body; or 3xx codes with
|
|
|
|
// max redirects exceeded), in which case status MUST be set to Error.
|
|
|
|
code := statusWriter.status
|
|
|
|
if code >= 100 && code < 500 {
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
}
|
|
|
|
|
|
|
|
attrSet := labeler.AttributeSet()
|
|
|
|
attrs := attrSet.ToSlice()
|
|
|
|
if code != 0 {
|
|
|
|
attrs = append(attrs, semconv.HTTPResponseStatusCode(code))
|
|
|
|
}
|
|
|
|
|
|
|
|
s.errors.Add(ctx, 1, metric.WithAttributes(attrs...))
|
|
|
|
}
|
|
|
|
err error
|
|
|
|
opErrContext = ogenerrors.OperationContext{
|
|
|
|
Name: ActionSubmissionValidatedOperation,
|
|
|
|
ID: "actionSubmissionValidated",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
params, err := decodeActionSubmissionValidatedParams(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 *ActionSubmissionValidatedNoContent
|
|
|
|
if m := s.cfg.Middleware; m != nil {
|
|
|
|
mreq := middleware.Request{
|
|
|
|
Context: ctx,
|
|
|
|
OperationName: ActionSubmissionValidatedOperation,
|
|
|
|
OperationSummary: "(Internal endpoint) Role Validator changes status from Validating -> Validated",
|
|
|
|
OperationID: "actionSubmissionValidated",
|
|
|
|
Body: nil,
|
|
|
|
Params: middleware.Parameters{
|
|
|
|
{
|
|
|
|
Name: "SubmissionID",
|
|
|
|
In: "path",
|
|
|
|
}: params.SubmissionID,
|
|
|
|
},
|
|
|
|
Raw: r,
|
|
|
|
}
|
|
|
|
|
|
|
|
type (
|
|
|
|
Request = struct{}
|
|
|
|
Params = ActionSubmissionValidatedParams
|
|
|
|
Response = *ActionSubmissionValidatedNoContent
|
|
|
|
)
|
|
|
|
response, err = middleware.HookMiddleware[
|
|
|
|
Request,
|
|
|
|
Params,
|
|
|
|
Response,
|
|
|
|
](
|
|
|
|
m,
|
|
|
|
mreq,
|
|
|
|
unpackActionSubmissionValidatedParams,
|
|
|
|
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
|
|
err = s.h.ActionSubmissionValidated(ctx, params)
|
|
|
|
return response, err
|
|
|
|
},
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
err = s.h.ActionSubmissionValidated(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 := encodeActionSubmissionValidatedResponse(response, w, span); err != nil {
|
|
|
|
defer recordError("EncodeResponse", err)
|
|
|
|
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|