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)
|
|
|
|
}
|
|
|
|
|
2024-12-18 02:12:00 +00:00
|
|
|
// handleActionSubmissionAcceptedRequest handles actionSubmissionAccepted operation.
|
|
|
|
//
|
|
|
|
// (Internal endpoint) Role Validator changes status from Validating -> Accepted.
|
|
|
|
//
|
|
|
|
// POST /submissions/{SubmissionID}/status/validator-failed
|
|
|
|
func (s *Server) handleActionSubmissionAcceptedRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
|
|
statusWriter := &codeRecorder{ResponseWriter: w}
|
|
|
|
w = statusWriter
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("actionSubmissionAccepted"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/validator-failed"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a span for this request.
|
|
|
|
ctx, span := s.cfg.Tracer.Start(r.Context(), ActionSubmissionAcceptedOperation,
|
|
|
|
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: ActionSubmissionAcceptedOperation,
|
|
|
|
ID: "actionSubmissionAccepted",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
params, err := decodeActionSubmissionAcceptedParams(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 *ActionSubmissionAcceptedNoContent
|
|
|
|
if m := s.cfg.Middleware; m != nil {
|
|
|
|
mreq := middleware.Request{
|
|
|
|
Context: ctx,
|
|
|
|
OperationName: ActionSubmissionAcceptedOperation,
|
|
|
|
OperationSummary: "(Internal endpoint) Role Validator changes status from Validating -> Accepted",
|
|
|
|
OperationID: "actionSubmissionAccepted",
|
|
|
|
Body: nil,
|
|
|
|
Params: middleware.Parameters{
|
|
|
|
{
|
|
|
|
Name: "SubmissionID",
|
|
|
|
In: "path",
|
|
|
|
}: params.SubmissionID,
|
|
|
|
},
|
|
|
|
Raw: r,
|
|
|
|
}
|
|
|
|
|
|
|
|
type (
|
|
|
|
Request = struct{}
|
|
|
|
Params = ActionSubmissionAcceptedParams
|
|
|
|
Response = *ActionSubmissionAcceptedNoContent
|
|
|
|
)
|
|
|
|
response, err = middleware.HookMiddleware[
|
|
|
|
Request,
|
|
|
|
Params,
|
|
|
|
Response,
|
|
|
|
](
|
|
|
|
m,
|
|
|
|
mreq,
|
|
|
|
unpackActionSubmissionAcceptedParams,
|
|
|
|
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
|
|
err = s.h.ActionSubmissionAccepted(ctx, params)
|
|
|
|
return response, err
|
|
|
|
},
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
err = s.h.ActionSubmissionAccepted(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 := encodeActionSubmissionAcceptedResponse(response, w, span); err != nil {
|
|
|
|
defer recordError("EncodeResponse", err)
|
|
|
|
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-14 19:55:56 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|
2024-12-18 02:12:00 +00:00
|
|
|
|
|
|
|
// handleCreateScriptRequest handles createScript operation.
|
|
|
|
//
|
|
|
|
// Create a new script.
|
|
|
|
//
|
|
|
|
// POST /scripts
|
|
|
|
func (s *Server) handleCreateScriptRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
|
|
statusWriter := &codeRecorder{ResponseWriter: w}
|
|
|
|
w = statusWriter
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("createScript"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
|
|
|
semconv.HTTPRouteKey.String("/scripts"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a span for this request.
|
|
|
|
ctx, span := s.cfg.Tracer.Start(r.Context(), CreateScriptOperation,
|
|
|
|
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: CreateScriptOperation,
|
|
|
|
ID: "createScript",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
request, close, err := s.decodeCreateScriptRequest(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)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
var response *ID
|
|
|
|
if m := s.cfg.Middleware; m != nil {
|
|
|
|
mreq := middleware.Request{
|
|
|
|
Context: ctx,
|
|
|
|
OperationName: CreateScriptOperation,
|
|
|
|
OperationSummary: "Create a new script",
|
|
|
|
OperationID: "createScript",
|
|
|
|
Body: request,
|
|
|
|
Params: middleware.Parameters{},
|
|
|
|
Raw: r,
|
|
|
|
}
|
|
|
|
|
|
|
|
type (
|
|
|
|
Request = *ScriptCreate
|
|
|
|
Params = struct{}
|
|
|
|
Response = *ID
|
|
|
|
)
|
|
|
|
response, err = middleware.HookMiddleware[
|
|
|
|
Request,
|
|
|
|
Params,
|
|
|
|
Response,
|
|
|
|
](
|
|
|
|
m,
|
|
|
|
mreq,
|
|
|
|
nil,
|
|
|
|
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
|
|
response, err = s.h.CreateScript(ctx, request)
|
|
|
|
return response, err
|
|
|
|
},
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
response, err = s.h.CreateScript(ctx, request)
|
|
|
|
}
|
|
|
|
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 := encodeCreateScriptResponse(response, w, span); err != nil {
|
|
|
|
defer recordError("EncodeResponse", err)
|
|
|
|
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// handleCreateScriptPolicyRequest handles createScriptPolicy operation.
|
|
|
|
//
|
|
|
|
// Create a new script policy.
|
|
|
|
//
|
|
|
|
// POST /script-policy
|
|
|
|
func (s *Server) handleCreateScriptPolicyRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
|
|
statusWriter := &codeRecorder{ResponseWriter: w}
|
|
|
|
w = statusWriter
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("createScriptPolicy"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
|
|
|
semconv.HTTPRouteKey.String("/script-policy"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a span for this request.
|
|
|
|
ctx, span := s.cfg.Tracer.Start(r.Context(), CreateScriptPolicyOperation,
|
|
|
|
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: CreateScriptPolicyOperation,
|
|
|
|
ID: "createScriptPolicy",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
request, close, err := s.decodeCreateScriptPolicyRequest(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)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
var response *ID
|
|
|
|
if m := s.cfg.Middleware; m != nil {
|
|
|
|
mreq := middleware.Request{
|
|
|
|
Context: ctx,
|
|
|
|
OperationName: CreateScriptPolicyOperation,
|
|
|
|
OperationSummary: "Create a new script policy",
|
|
|
|
OperationID: "createScriptPolicy",
|
|
|
|
Body: request,
|
|
|
|
Params: middleware.Parameters{},
|
|
|
|
Raw: r,
|
|
|
|
}
|
|
|
|
|
|
|
|
type (
|
|
|
|
Request = *ScriptPolicyCreate
|
|
|
|
Params = struct{}
|
|
|
|
Response = *ID
|
|
|
|
)
|
|
|
|
response, err = middleware.HookMiddleware[
|
|
|
|
Request,
|
|
|
|
Params,
|
|
|
|
Response,
|
|
|
|
](
|
|
|
|
m,
|
|
|
|
mreq,
|
|
|
|
nil,
|
|
|
|
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
|
|
response, err = s.h.CreateScriptPolicy(ctx, request)
|
|
|
|
return response, err
|
|
|
|
},
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
response, err = s.h.CreateScriptPolicy(ctx, request)
|
|
|
|
}
|
|
|
|
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 := encodeCreateScriptPolicyResponse(response, w, span); err != nil {
|
|
|
|
defer recordError("EncodeResponse", err)
|
|
|
|
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// handleGetScriptRequest handles getScript operation.
|
|
|
|
//
|
|
|
|
// Get the specified script by ID.
|
|
|
|
//
|
|
|
|
// GET /scripts/{ScriptID}
|
|
|
|
func (s *Server) handleGetScriptRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
|
|
statusWriter := &codeRecorder{ResponseWriter: w}
|
|
|
|
w = statusWriter
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("getScript"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("GET"),
|
|
|
|
semconv.HTTPRouteKey.String("/scripts/{ScriptID}"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a span for this request.
|
|
|
|
ctx, span := s.cfg.Tracer.Start(r.Context(), GetScriptOperation,
|
|
|
|
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: GetScriptOperation,
|
|
|
|
ID: "getScript",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
params, err := decodeGetScriptParams(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 *Script
|
|
|
|
if m := s.cfg.Middleware; m != nil {
|
|
|
|
mreq := middleware.Request{
|
|
|
|
Context: ctx,
|
|
|
|
OperationName: GetScriptOperation,
|
|
|
|
OperationSummary: "Get the specified script by ID",
|
|
|
|
OperationID: "getScript",
|
|
|
|
Body: nil,
|
|
|
|
Params: middleware.Parameters{
|
|
|
|
{
|
|
|
|
Name: "ScriptID",
|
|
|
|
In: "path",
|
|
|
|
}: params.ScriptID,
|
|
|
|
},
|
|
|
|
Raw: r,
|
|
|
|
}
|
|
|
|
|
|
|
|
type (
|
|
|
|
Request = struct{}
|
|
|
|
Params = GetScriptParams
|
|
|
|
Response = *Script
|
|
|
|
)
|
|
|
|
response, err = middleware.HookMiddleware[
|
|
|
|
Request,
|
|
|
|
Params,
|
|
|
|
Response,
|
|
|
|
](
|
|
|
|
m,
|
|
|
|
mreq,
|
|
|
|
unpackGetScriptParams,
|
|
|
|
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
|
|
response, err = s.h.GetScript(ctx, params)
|
|
|
|
return response, err
|
|
|
|
},
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
response, err = s.h.GetScript(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 := encodeGetScriptResponse(response, w, span); err != nil {
|
|
|
|
defer recordError("EncodeResponse", err)
|
|
|
|
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-18 23:06:39 +00:00
|
|
|
// handleListScriptPolicyRequest handles listScriptPolicy operation.
|
2024-12-18 02:12:00 +00:00
|
|
|
//
|
2024-12-18 23:06:39 +00:00
|
|
|
// Get list of script policies.
|
2024-12-18 02:12:00 +00:00
|
|
|
//
|
2024-12-18 23:06:39 +00:00
|
|
|
// GET /script-policy
|
|
|
|
func (s *Server) handleListScriptPolicyRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
2024-12-18 02:12:00 +00:00
|
|
|
statusWriter := &codeRecorder{ResponseWriter: w}
|
|
|
|
w = statusWriter
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-12-18 23:06:39 +00:00
|
|
|
otelogen.OperationID("listScriptPolicy"),
|
2024-12-18 02:12:00 +00:00
|
|
|
semconv.HTTPRequestMethodKey.String("GET"),
|
2024-12-18 23:06:39 +00:00
|
|
|
semconv.HTTPRouteKey.String("/script-policy"),
|
2024-12-18 02:12:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-12-18 23:06:39 +00:00
|
|
|
ctx, span := s.cfg.Tracer.Start(r.Context(), ListScriptPolicyOperation,
|
2024-12-18 02:12:00 +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)
|
|
|
|
|
|
|
|
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{
|
2024-12-18 23:06:39 +00:00
|
|
|
Name: ListScriptPolicyOperation,
|
|
|
|
ID: "listScriptPolicy",
|
2024-12-18 02:12:00 +00:00
|
|
|
}
|
|
|
|
)
|
2024-12-18 23:06:39 +00:00
|
|
|
params, err := decodeListScriptPolicyParams(args, argsEscaped, r)
|
2024-12-18 02:12:00 +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-12-18 23:06:39 +00:00
|
|
|
var response []ScriptPolicy
|
2024-12-18 02:12:00 +00:00
|
|
|
if m := s.cfg.Middleware; m != nil {
|
|
|
|
mreq := middleware.Request{
|
|
|
|
Context: ctx,
|
2024-12-18 23:06:39 +00:00
|
|
|
OperationName: ListScriptPolicyOperation,
|
|
|
|
OperationSummary: "Get list of script policies",
|
|
|
|
OperationID: "listScriptPolicy",
|
2024-12-18 02:12:00 +00:00
|
|
|
Body: nil,
|
|
|
|
Params: middleware.Parameters{
|
2024-12-18 23:06:39 +00:00
|
|
|
{
|
|
|
|
Name: "Page",
|
|
|
|
In: "query",
|
|
|
|
}: params.Page,
|
|
|
|
{
|
|
|
|
Name: "Limit",
|
|
|
|
In: "query",
|
|
|
|
}: params.Limit,
|
2024-12-18 02:12:00 +00:00
|
|
|
{
|
|
|
|
Name: "FromScriptHash",
|
2024-12-18 23:06:39 +00:00
|
|
|
In: "query",
|
2024-12-18 02:12:00 +00:00
|
|
|
}: params.FromScriptHash,
|
2024-12-18 23:06:39 +00:00
|
|
|
{
|
|
|
|
Name: "ToScriptID",
|
|
|
|
In: "query",
|
|
|
|
}: params.ToScriptID,
|
|
|
|
{
|
|
|
|
Name: "Policy",
|
|
|
|
In: "query",
|
|
|
|
}: params.Policy,
|
|
|
|
},
|
|
|
|
Raw: r,
|
|
|
|
}
|
|
|
|
|
|
|
|
type (
|
|
|
|
Request = struct{}
|
|
|
|
Params = ListScriptPolicyParams
|
|
|
|
Response = []ScriptPolicy
|
|
|
|
)
|
|
|
|
response, err = middleware.HookMiddleware[
|
|
|
|
Request,
|
|
|
|
Params,
|
|
|
|
Response,
|
|
|
|
](
|
|
|
|
m,
|
|
|
|
mreq,
|
|
|
|
unpackListScriptPolicyParams,
|
|
|
|
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
|
|
response, err = s.h.ListScriptPolicy(ctx, params)
|
|
|
|
return response, err
|
|
|
|
},
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
response, err = s.h.ListScriptPolicy(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 := encodeListScriptPolicyResponse(response, w, span); err != nil {
|
|
|
|
defer recordError("EncodeResponse", err)
|
|
|
|
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// handleListScriptsRequest handles listScripts operation.
|
|
|
|
//
|
|
|
|
// Get list of scripts.
|
|
|
|
//
|
|
|
|
// GET /scripts
|
|
|
|
func (s *Server) handleListScriptsRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
|
|
statusWriter := &codeRecorder{ResponseWriter: w}
|
|
|
|
w = statusWriter
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("listScripts"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("GET"),
|
|
|
|
semconv.HTTPRouteKey.String("/scripts"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a span for this request.
|
|
|
|
ctx, span := s.cfg.Tracer.Start(r.Context(), ListScriptsOperation,
|
|
|
|
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: ListScriptsOperation,
|
|
|
|
ID: "listScripts",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
params, err := decodeListScriptsParams(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 []Script
|
|
|
|
if m := s.cfg.Middleware; m != nil {
|
|
|
|
mreq := middleware.Request{
|
|
|
|
Context: ctx,
|
|
|
|
OperationName: ListScriptsOperation,
|
|
|
|
OperationSummary: "Get list of scripts",
|
|
|
|
OperationID: "listScripts",
|
|
|
|
Body: nil,
|
|
|
|
Params: middleware.Parameters{
|
|
|
|
{
|
|
|
|
Name: "Page",
|
|
|
|
In: "query",
|
|
|
|
}: params.Page,
|
|
|
|
{
|
|
|
|
Name: "Limit",
|
|
|
|
In: "query",
|
|
|
|
}: params.Limit,
|
|
|
|
{
|
|
|
|
Name: "Hash",
|
|
|
|
In: "query",
|
|
|
|
}: params.Hash,
|
|
|
|
{
|
|
|
|
Name: "Name",
|
|
|
|
In: "query",
|
|
|
|
}: params.Name,
|
|
|
|
{
|
|
|
|
Name: "Source",
|
|
|
|
In: "query",
|
|
|
|
}: params.Source,
|
|
|
|
{
|
|
|
|
Name: "SubmissionID",
|
|
|
|
In: "query",
|
|
|
|
}: params.SubmissionID,
|
2024-12-18 02:12:00 +00:00
|
|
|
},
|
|
|
|
Raw: r,
|
|
|
|
}
|
|
|
|
|
|
|
|
type (
|
|
|
|
Request = struct{}
|
2024-12-18 23:06:39 +00:00
|
|
|
Params = ListScriptsParams
|
|
|
|
Response = []Script
|
2024-12-18 02:12:00 +00:00
|
|
|
)
|
|
|
|
response, err = middleware.HookMiddleware[
|
|
|
|
Request,
|
|
|
|
Params,
|
|
|
|
Response,
|
|
|
|
](
|
|
|
|
m,
|
|
|
|
mreq,
|
2024-12-18 23:06:39 +00:00
|
|
|
unpackListScriptsParams,
|
2024-12-18 02:12:00 +00:00
|
|
|
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
2024-12-18 23:06:39 +00:00
|
|
|
response, err = s.h.ListScripts(ctx, params)
|
2024-12-18 02:12:00 +00:00
|
|
|
return response, err
|
|
|
|
},
|
|
|
|
)
|
|
|
|
} else {
|
2024-12-18 23:06:39 +00:00
|
|
|
response, err = s.h.ListScripts(ctx, params)
|
2024-12-18 02:12:00 +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-12-18 23:06:39 +00:00
|
|
|
if err := encodeListScriptsResponse(response, w, span); err != nil {
|
2024-12-18 02:12:00 +00:00
|
|
|
defer recordError("EncodeResponse", err)
|
|
|
|
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// handleUpdateSubmissionModelRequest handles updateSubmissionModel operation.
|
|
|
|
//
|
|
|
|
// Update model following role restrictions.
|
|
|
|
//
|
|
|
|
// POST /submissions/{SubmissionID}/model
|
|
|
|
func (s *Server) handleUpdateSubmissionModelRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
|
|
statusWriter := &codeRecorder{ResponseWriter: w}
|
|
|
|
w = statusWriter
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("updateSubmissionModel"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/model"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a span for this request.
|
|
|
|
ctx, span := s.cfg.Tracer.Start(r.Context(), UpdateSubmissionModelOperation,
|
|
|
|
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: UpdateSubmissionModelOperation,
|
|
|
|
ID: "updateSubmissionModel",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
params, err := decodeUpdateSubmissionModelParams(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 *UpdateSubmissionModelNoContent
|
|
|
|
if m := s.cfg.Middleware; m != nil {
|
|
|
|
mreq := middleware.Request{
|
|
|
|
Context: ctx,
|
|
|
|
OperationName: UpdateSubmissionModelOperation,
|
|
|
|
OperationSummary: "Update model following role restrictions",
|
|
|
|
OperationID: "updateSubmissionModel",
|
|
|
|
Body: nil,
|
|
|
|
Params: middleware.Parameters{
|
|
|
|
{
|
|
|
|
Name: "SubmissionID",
|
|
|
|
In: "path",
|
|
|
|
}: params.SubmissionID,
|
|
|
|
{
|
|
|
|
Name: "ModelID",
|
|
|
|
In: "query",
|
|
|
|
}: params.ModelID,
|
|
|
|
{
|
|
|
|
Name: "VersionID",
|
|
|
|
In: "query",
|
|
|
|
}: params.VersionID,
|
|
|
|
},
|
|
|
|
Raw: r,
|
|
|
|
}
|
|
|
|
|
|
|
|
type (
|
|
|
|
Request = struct{}
|
|
|
|
Params = UpdateSubmissionModelParams
|
|
|
|
Response = *UpdateSubmissionModelNoContent
|
|
|
|
)
|
|
|
|
response, err = middleware.HookMiddleware[
|
|
|
|
Request,
|
|
|
|
Params,
|
|
|
|
Response,
|
|
|
|
](
|
|
|
|
m,
|
|
|
|
mreq,
|
|
|
|
unpackUpdateSubmissionModelParams,
|
|
|
|
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
|
|
err = s.h.UpdateSubmissionModel(ctx, params)
|
|
|
|
return response, err
|
|
|
|
},
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
err = s.h.UpdateSubmissionModel(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 := encodeUpdateSubmissionModelResponse(response, w, span); err != nil {
|
|
|
|
defer recordError("EncodeResponse", err)
|
|
|
|
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
|
|
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|