2024-11-26 01:22:45 +00:00
|
|
|
// Code generated by ogen, DO NOT EDIT.
|
|
|
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/url"
|
|
|
|
"strings"
|
|
|
|
"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"
|
|
|
|
|
|
|
|
"github.com/ogen-go/ogen/conv"
|
|
|
|
ht "github.com/ogen-go/ogen/http"
|
2024-11-29 22:33:48 +00:00
|
|
|
"github.com/ogen-go/ogen/ogenerrors"
|
2024-11-26 01:22:45 +00:00
|
|
|
"github.com/ogen-go/ogen/otelogen"
|
|
|
|
"github.com/ogen-go/ogen/uri"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Invoker invokes operations described by OpenAPI v3 specification.
|
|
|
|
type Invoker interface {
|
2024-11-28 01:46:54 +00:00
|
|
|
// ActionSubmissionPublish invokes actionSubmissionPublish operation.
|
|
|
|
//
|
2024-12-12 01:54:11 +00:00
|
|
|
// (Internal endpoint) Role Validator changes status from Publishing -> Published.
|
2024-11-28 01:46:54 +00:00
|
|
|
//
|
2024-12-12 01:54:11 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/validator-published
|
2024-11-28 01:46:54 +00:00
|
|
|
ActionSubmissionPublish(ctx context.Context, params ActionSubmissionPublishParams) error
|
|
|
|
// ActionSubmissionReject invokes actionSubmissionReject operation.
|
|
|
|
//
|
|
|
|
// Role Reviewer changes status from Submitted -> Rejected.
|
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/reject
|
2024-11-28 01:46:54 +00:00
|
|
|
ActionSubmissionReject(ctx context.Context, params ActionSubmissionRejectParams) error
|
|
|
|
// ActionSubmissionRequestChanges invokes actionSubmissionRequestChanges operation.
|
|
|
|
//
|
|
|
|
// Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested.
|
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/request-changes
|
2024-11-28 01:46:54 +00:00
|
|
|
ActionSubmissionRequestChanges(ctx context.Context, params ActionSubmissionRequestChangesParams) error
|
|
|
|
// ActionSubmissionRevoke invokes actionSubmissionRevoke operation.
|
|
|
|
//
|
|
|
|
// Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction.
|
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/revoke
|
2024-11-28 01:46:54 +00:00
|
|
|
ActionSubmissionRevoke(ctx context.Context, params ActionSubmissionRevokeParams) error
|
|
|
|
// ActionSubmissionSubmit invokes actionSubmissionSubmit operation.
|
|
|
|
//
|
|
|
|
// Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted.
|
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/submit
|
2024-11-28 01:46:54 +00:00
|
|
|
ActionSubmissionSubmit(ctx context.Context, params ActionSubmissionSubmitParams) error
|
|
|
|
// ActionSubmissionTriggerPublish invokes actionSubmissionTriggerPublish operation.
|
|
|
|
//
|
|
|
|
// Role Admin changes status from Validated -> Publishing.
|
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/trigger-publish
|
2024-11-28 01:46:54 +00:00
|
|
|
ActionSubmissionTriggerPublish(ctx context.Context, params ActionSubmissionTriggerPublishParams) error
|
|
|
|
// ActionSubmissionTriggerValidate invokes actionSubmissionTriggerValidate operation.
|
|
|
|
//
|
|
|
|
// Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating.
|
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/trigger-validate
|
2024-11-28 01:46:54 +00:00
|
|
|
ActionSubmissionTriggerValidate(ctx context.Context, params ActionSubmissionTriggerValidateParams) error
|
|
|
|
// ActionSubmissionValidate invokes actionSubmissionValidate operation.
|
|
|
|
//
|
2024-12-12 01:54:11 +00:00
|
|
|
// (Internal endpoint) Role Validator changes status from Validating -> Validated.
|
2024-11-28 01:46:54 +00:00
|
|
|
//
|
2024-12-12 01:54:11 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/validator-validated
|
2024-11-28 01:46:54 +00:00
|
|
|
ActionSubmissionValidate(ctx context.Context, params ActionSubmissionValidateParams) error
|
2024-12-06 00:36:15 +00:00
|
|
|
// CreateScript invokes createScript operation.
|
|
|
|
//
|
|
|
|
// Create a new script.
|
|
|
|
//
|
|
|
|
// POST /scripts
|
2024-12-06 02:48:26 +00:00
|
|
|
CreateScript(ctx context.Context, request *ScriptCreate) (*ID, error)
|
2024-12-06 00:36:15 +00:00
|
|
|
// CreateScriptPolicy invokes createScriptPolicy operation.
|
|
|
|
//
|
|
|
|
// Create a new script policy.
|
|
|
|
//
|
|
|
|
// POST /script-policy
|
2024-12-06 02:48:26 +00:00
|
|
|
CreateScriptPolicy(ctx context.Context, request *ScriptPolicyCreate) (*ID, error)
|
2024-11-26 20:39:10 +00:00
|
|
|
// CreateSubmission invokes 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
|
2024-12-06 02:48:26 +00:00
|
|
|
CreateSubmission(ctx context.Context, request *SubmissionCreate) (*ID, error)
|
2024-12-06 00:36:15 +00:00
|
|
|
// DeleteScript invokes deleteScript operation.
|
|
|
|
//
|
|
|
|
// Delete the specified script by ID.
|
|
|
|
//
|
|
|
|
// DELETE /scripts/{ScriptID}
|
|
|
|
DeleteScript(ctx context.Context, params DeleteScriptParams) error
|
|
|
|
// DeleteScriptPolicy invokes deleteScriptPolicy operation.
|
|
|
|
//
|
|
|
|
// Delete the specified script policy by ID.
|
|
|
|
//
|
|
|
|
// DELETE /script-policy/id/{ScriptPolicyID}
|
|
|
|
DeleteScriptPolicy(ctx context.Context, params DeleteScriptPolicyParams) error
|
|
|
|
// GetScript invokes getScript operation.
|
|
|
|
//
|
|
|
|
// Get the specified script by ID.
|
|
|
|
//
|
|
|
|
// GET /scripts/{ScriptID}
|
|
|
|
GetScript(ctx context.Context, params GetScriptParams) (*Script, error)
|
|
|
|
// GetScriptPolicy invokes getScriptPolicy operation.
|
|
|
|
//
|
|
|
|
// Get the specified script policy by ID.
|
|
|
|
//
|
|
|
|
// GET /script-policy/id/{ScriptPolicyID}
|
|
|
|
GetScriptPolicy(ctx context.Context, params GetScriptPolicyParams) (*ScriptPolicy, error)
|
|
|
|
// GetScriptPolicyFromHash invokes getScriptPolicyFromHash operation.
|
|
|
|
//
|
|
|
|
// Get the policy for the given hash of script source code.
|
|
|
|
//
|
|
|
|
// GET /script-policy/hash/{FromScriptHash}
|
|
|
|
GetScriptPolicyFromHash(ctx context.Context, params GetScriptPolicyFromHashParams) (*ScriptPolicy, error)
|
2024-11-26 20:39:10 +00:00
|
|
|
// GetSubmission invokes getSubmission operation.
|
2024-11-26 01:22:45 +00:00
|
|
|
//
|
2024-11-26 20:39:10 +00:00
|
|
|
// Retrieve map with ID.
|
2024-11-26 01:22:45 +00:00
|
|
|
//
|
2024-11-26 20:39:10 +00:00
|
|
|
// GET /submissions/{SubmissionID}
|
|
|
|
GetSubmission(ctx context.Context, params GetSubmissionParams) (*Submission, error)
|
2024-12-14 06:15:05 +00:00
|
|
|
// ListScriptPolicy invokes listScriptPolicy operation.
|
|
|
|
//
|
|
|
|
// Get list of script policies.
|
|
|
|
//
|
|
|
|
// GET /script-policy
|
|
|
|
ListScriptPolicy(ctx context.Context, params ListScriptPolicyParams) ([]ScriptPolicy, error)
|
2024-11-26 20:39:10 +00:00
|
|
|
// ListSubmissions invokes 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
|
|
|
|
ListSubmissions(ctx context.Context, params ListSubmissionsParams) ([]Submission, error)
|
2024-12-10 06:06:33 +00:00
|
|
|
// SetSubmissionCompleted invokes setSubmissionCompleted operation.
|
2024-11-26 01:22:45 +00:00
|
|
|
//
|
2024-11-26 20:39:10 +00:00
|
|
|
// Retrieve map with ID.
|
2024-11-26 01:22:45 +00:00
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /submissions/{SubmissionID}/completed
|
|
|
|
SetSubmissionCompleted(ctx context.Context, params SetSubmissionCompletedParams) error
|
2024-12-06 00:36:15 +00:00
|
|
|
// UpdateScript invokes updateScript operation.
|
|
|
|
//
|
|
|
|
// Update the specified script by ID.
|
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /scripts/{ScriptID}
|
2024-12-06 02:48:26 +00:00
|
|
|
UpdateScript(ctx context.Context, request *ScriptUpdate, params UpdateScriptParams) error
|
2024-12-06 00:36:15 +00:00
|
|
|
// UpdateScriptPolicy invokes updateScriptPolicy operation.
|
|
|
|
//
|
|
|
|
// Update the specified script policy by ID.
|
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /script-policy/id/{ScriptPolicyID}
|
2024-12-06 02:48:26 +00:00
|
|
|
UpdateScriptPolicy(ctx context.Context, request *ScriptPolicyUpdate, params UpdateScriptPolicyParams) error
|
2024-12-10 06:06:33 +00:00
|
|
|
// UpdateSubmissionModel invokes updateSubmissionModel operation.
|
|
|
|
//
|
|
|
|
// Update model following role restrictions.
|
|
|
|
//
|
|
|
|
// POST /submissions/{SubmissionID}/model
|
|
|
|
UpdateSubmissionModel(ctx context.Context, params UpdateSubmissionModelParams) error
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Client implements OAS client.
|
|
|
|
type Client struct {
|
|
|
|
serverURL *url.URL
|
2024-11-29 22:33:48 +00:00
|
|
|
sec SecuritySource
|
2024-11-26 01:22:45 +00:00
|
|
|
baseClient
|
|
|
|
}
|
|
|
|
type errorHandler interface {
|
|
|
|
NewError(ctx context.Context, err error) *ErrorStatusCode
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ Handler = struct {
|
|
|
|
errorHandler
|
|
|
|
*Client
|
|
|
|
}{}
|
|
|
|
|
|
|
|
func trimTrailingSlashes(u *url.URL) {
|
|
|
|
u.Path = strings.TrimRight(u.Path, "/")
|
|
|
|
u.RawPath = strings.TrimRight(u.RawPath, "/")
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewClient initializes new Client defined by OAS.
|
2024-11-29 22:33:48 +00:00
|
|
|
func NewClient(serverURL string, sec SecuritySource, opts ...ClientOption) (*Client, error) {
|
2024-11-26 01:22:45 +00:00
|
|
|
u, err := url.Parse(serverURL)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
trimTrailingSlashes(u)
|
|
|
|
|
|
|
|
c, err := newClientConfig(opts...).baseClient()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &Client{
|
|
|
|
serverURL: u,
|
2024-11-29 22:33:48 +00:00
|
|
|
sec: sec,
|
2024-11-26 01:22:45 +00:00
|
|
|
baseClient: c,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type serverURLKey struct{}
|
|
|
|
|
|
|
|
// WithServerURL sets context key to override server URL.
|
|
|
|
func WithServerURL(ctx context.Context, u *url.URL) context.Context {
|
|
|
|
return context.WithValue(ctx, serverURLKey{}, u)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) requestURL(ctx context.Context) *url.URL {
|
|
|
|
u, ok := ctx.Value(serverURLKey{}).(*url.URL)
|
|
|
|
if !ok {
|
|
|
|
return c.serverURL
|
|
|
|
}
|
|
|
|
return u
|
|
|
|
}
|
|
|
|
|
2024-11-28 01:46:54 +00:00
|
|
|
// ActionSubmissionPublish invokes actionSubmissionPublish operation.
|
2024-11-26 20:39:10 +00:00
|
|
|
//
|
2024-12-12 01:54:11 +00:00
|
|
|
// (Internal endpoint) Role Validator changes status from Publishing -> Published.
|
2024-11-26 20:39:10 +00:00
|
|
|
//
|
2024-12-12 01:54:11 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/validator-published
|
2024-11-28 01:46:54 +00:00
|
|
|
func (c *Client) ActionSubmissionPublish(ctx context.Context, params ActionSubmissionPublishParams) error {
|
|
|
|
_, err := c.sendActionSubmissionPublish(ctx, params)
|
|
|
|
return err
|
2024-11-26 20:39:10 +00:00
|
|
|
}
|
|
|
|
|
2024-12-11 06:23:08 +00:00
|
|
|
func (c *Client) sendActionSubmissionPublish(ctx context.Context, params ActionSubmissionPublishParams) (res *ActionSubmissionPublishNoContent, err error) {
|
2024-11-26 20:39:10 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-11-28 01:46:54 +00:00
|
|
|
otelogen.OperationID("actionSubmissionPublish"),
|
2024-12-10 06:06:33 +00:00
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
2024-12-12 01:54:11 +00:00
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/validator-published"),
|
2024-11-26 20:39:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
2024-12-06 00:36:15 +00:00
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
2024-11-26 20:39:10 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-11-29 22:33:48 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, ActionSubmissionPublishOperation,
|
2024-11-26 20:39:10 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
2024-11-28 01:46:54 +00:00
|
|
|
var pathParts [3]string
|
|
|
|
pathParts[0] = "/submissions/"
|
|
|
|
{
|
|
|
|
// Encode "SubmissionID" parameter.
|
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
|
|
|
Param: "SubmissionID",
|
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
|
|
|
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
|
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
2024-12-12 01:54:11 +00:00
|
|
|
pathParts[2] = "/status/validator-published"
|
2024-11-26 20:39:10 +00:00
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
2024-12-10 06:06:33 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "POST", u)
|
2024-11-26 20:39:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
2024-11-28 01:46:54 +00:00
|
|
|
result, err := decodeActionSubmissionPublishResponse(resp)
|
2024-11-26 20:39:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-11-28 01:46:54 +00:00
|
|
|
// ActionSubmissionReject invokes actionSubmissionReject operation.
|
2024-11-26 01:22:45 +00:00
|
|
|
//
|
2024-11-28 01:46:54 +00:00
|
|
|
// Role Reviewer changes status from Submitted -> Rejected.
|
2024-11-26 01:22:45 +00:00
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/reject
|
2024-11-28 01:46:54 +00:00
|
|
|
func (c *Client) ActionSubmissionReject(ctx context.Context, params ActionSubmissionRejectParams) error {
|
|
|
|
_, err := c.sendActionSubmissionReject(ctx, params)
|
|
|
|
return err
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
|
|
|
|
2024-12-11 06:23:08 +00:00
|
|
|
func (c *Client) sendActionSubmissionReject(ctx context.Context, params ActionSubmissionRejectParams) (res *ActionSubmissionRejectNoContent, err error) {
|
2024-11-26 01:22:45 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-11-28 01:46:54 +00:00
|
|
|
otelogen.OperationID("actionSubmissionReject"),
|
2024-12-10 06:06:33 +00:00
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
2024-11-28 01:46:54 +00:00
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/reject"),
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
2024-12-06 00:36:15 +00:00
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
2024-11-26 01:22:45 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-11-29 22:33:48 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, ActionSubmissionRejectOperation,
|
2024-11-26 01:22:45 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
2024-11-28 01:46:54 +00:00
|
|
|
var pathParts [3]string
|
2024-11-26 20:39:10 +00:00
|
|
|
pathParts[0] = "/submissions/"
|
2024-11-26 01:22:45 +00:00
|
|
|
{
|
2024-11-26 20:39:10 +00:00
|
|
|
// Encode "SubmissionID" parameter.
|
2024-11-26 01:22:45 +00:00
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
2024-11-26 20:39:10 +00:00
|
|
|
Param: "SubmissionID",
|
2024-11-26 01:22:45 +00:00
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
2024-11-26 20:39:10 +00:00
|
|
|
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
|
2024-11-26 01:22:45 +00:00
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
2024-11-28 01:46:54 +00:00
|
|
|
pathParts[2] = "/status/reject"
|
2024-11-26 01:22:45 +00:00
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
2024-12-10 06:06:33 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "POST", u)
|
2024-11-26 01:22:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
2024-11-29 22:33:48 +00:00
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
|
|
|
switch err := c.securityCookieAuth(ctx, ActionSubmissionRejectOperation, r); {
|
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-26 01:22:45 +00:00
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
2024-11-28 01:46:54 +00:00
|
|
|
result, err := decodeActionSubmissionRejectResponse(resp)
|
2024-11-26 01:22:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-11-28 01:46:54 +00:00
|
|
|
// ActionSubmissionRequestChanges invokes actionSubmissionRequestChanges operation.
|
2024-11-26 01:22:45 +00:00
|
|
|
//
|
2024-11-28 01:46:54 +00:00
|
|
|
// Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested.
|
2024-11-26 01:22:45 +00:00
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/request-changes
|
2024-11-28 01:46:54 +00:00
|
|
|
func (c *Client) ActionSubmissionRequestChanges(ctx context.Context, params ActionSubmissionRequestChangesParams) error {
|
|
|
|
_, err := c.sendActionSubmissionRequestChanges(ctx, params)
|
|
|
|
return err
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
|
|
|
|
2024-12-11 06:23:08 +00:00
|
|
|
func (c *Client) sendActionSubmissionRequestChanges(ctx context.Context, params ActionSubmissionRequestChangesParams) (res *ActionSubmissionRequestChangesNoContent, err error) {
|
2024-11-26 01:22:45 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-11-28 01:46:54 +00:00
|
|
|
otelogen.OperationID("actionSubmissionRequestChanges"),
|
2024-12-10 06:06:33 +00:00
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
2024-11-28 01:46:54 +00:00
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/request-changes"),
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
2024-12-06 00:36:15 +00:00
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
2024-11-26 01:22:45 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-11-29 22:33:48 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, ActionSubmissionRequestChangesOperation,
|
2024-11-26 01:22:45 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
2024-11-28 01:46:54 +00:00
|
|
|
var pathParts [3]string
|
|
|
|
pathParts[0] = "/submissions/"
|
2024-11-26 01:22:45 +00:00
|
|
|
{
|
2024-11-28 01:46:54 +00:00
|
|
|
// Encode "SubmissionID" parameter.
|
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
|
|
|
Param: "SubmissionID",
|
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
|
|
|
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
|
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
2024-11-28 01:46:54 +00:00
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
2024-11-28 01:46:54 +00:00
|
|
|
pathParts[1] = encoded
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
2024-11-28 01:46:54 +00:00
|
|
|
pathParts[2] = "/status/request-changes"
|
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
2024-11-26 20:39:10 +00:00
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
2024-12-10 06:06:33 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "POST", u)
|
2024-11-26 20:39:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
2024-11-29 22:33:48 +00:00
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
|
|
|
switch err := c.securityCookieAuth(ctx, ActionSubmissionRequestChangesOperation, r); {
|
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-26 20:39:10 +00:00
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
2024-11-28 01:46:54 +00:00
|
|
|
result, err := decodeActionSubmissionRequestChangesResponse(resp)
|
2024-11-26 20:39:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-11-28 01:46:54 +00:00
|
|
|
// ActionSubmissionRevoke invokes actionSubmissionRevoke operation.
|
2024-11-26 20:39:10 +00:00
|
|
|
//
|
2024-11-28 01:46:54 +00:00
|
|
|
// Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction.
|
2024-11-26 20:39:10 +00:00
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/revoke
|
2024-11-28 01:46:54 +00:00
|
|
|
func (c *Client) ActionSubmissionRevoke(ctx context.Context, params ActionSubmissionRevokeParams) error {
|
|
|
|
_, err := c.sendActionSubmissionRevoke(ctx, params)
|
2024-11-26 20:39:10 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-12-11 06:23:08 +00:00
|
|
|
func (c *Client) sendActionSubmissionRevoke(ctx context.Context, params ActionSubmissionRevokeParams) (res *ActionSubmissionRevokeNoContent, err error) {
|
2024-11-26 20:39:10 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-11-28 01:46:54 +00:00
|
|
|
otelogen.OperationID("actionSubmissionRevoke"),
|
2024-12-10 06:06:33 +00:00
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
2024-11-28 01:46:54 +00:00
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/revoke"),
|
2024-11-26 20:39:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
2024-12-06 00:36:15 +00:00
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
2024-11-26 20:39:10 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-11-29 22:33:48 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, ActionSubmissionRevokeOperation,
|
2024-11-26 20:39:10 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
|
|
|
var pathParts [3]string
|
|
|
|
pathParts[0] = "/submissions/"
|
2024-11-26 01:22:45 +00:00
|
|
|
{
|
2024-11-26 20:39:10 +00:00
|
|
|
// Encode "SubmissionID" parameter.
|
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
|
|
|
Param: "SubmissionID",
|
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
|
|
|
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
|
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
2024-11-28 01:46:54 +00:00
|
|
|
pathParts[2] = "/status/revoke"
|
2024-11-26 20:39:10 +00:00
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
2024-11-26 01:22:45 +00:00
|
|
|
stage = "EncodeRequest"
|
2024-12-10 06:06:33 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "POST", u)
|
2024-11-26 01:22:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
2024-11-29 22:33:48 +00:00
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
|
|
|
switch err := c.securityCookieAuth(ctx, ActionSubmissionRevokeOperation, r); {
|
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-26 01:22:45 +00:00
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
2024-11-28 01:46:54 +00:00
|
|
|
result, err := decodeActionSubmissionRevokeResponse(resp)
|
2024-11-26 01:22:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-11-28 01:46:54 +00:00
|
|
|
// ActionSubmissionSubmit invokes actionSubmissionSubmit operation.
|
2024-11-26 01:22:45 +00:00
|
|
|
//
|
2024-11-28 01:46:54 +00:00
|
|
|
// Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted.
|
2024-11-26 01:22:45 +00:00
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/submit
|
2024-11-28 01:46:54 +00:00
|
|
|
func (c *Client) ActionSubmissionSubmit(ctx context.Context, params ActionSubmissionSubmitParams) error {
|
|
|
|
_, err := c.sendActionSubmissionSubmit(ctx, params)
|
2024-11-26 20:39:10 +00:00
|
|
|
return err
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
|
|
|
|
2024-12-11 06:23:08 +00:00
|
|
|
func (c *Client) sendActionSubmissionSubmit(ctx context.Context, params ActionSubmissionSubmitParams) (res *ActionSubmissionSubmitNoContent, err error) {
|
2024-11-26 01:22:45 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-11-28 01:46:54 +00:00
|
|
|
otelogen.OperationID("actionSubmissionSubmit"),
|
2024-12-10 06:06:33 +00:00
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
2024-11-28 01:46:54 +00:00
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/submit"),
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
2024-12-06 00:36:15 +00:00
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
2024-11-26 01:22:45 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-11-29 22:33:48 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, ActionSubmissionSubmitOperation,
|
2024-11-26 01:22:45 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
2024-11-26 20:39:10 +00:00
|
|
|
var pathParts [3]string
|
|
|
|
pathParts[0] = "/submissions/"
|
|
|
|
{
|
|
|
|
// Encode "SubmissionID" parameter.
|
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
|
|
|
Param: "SubmissionID",
|
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
|
|
|
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
|
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
2024-11-28 01:46:54 +00:00
|
|
|
pathParts[2] = "/status/submit"
|
2024-11-26 01:22:45 +00:00
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
2024-12-10 06:06:33 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "POST", u)
|
2024-11-26 01:22:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
2024-11-29 22:33:48 +00:00
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
|
|
|
switch err := c.securityCookieAuth(ctx, ActionSubmissionSubmitOperation, r); {
|
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-26 01:22:45 +00:00
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
2024-11-28 01:46:54 +00:00
|
|
|
result, err := decodeActionSubmissionSubmitResponse(resp)
|
2024-11-26 01:22:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-11-28 01:46:54 +00:00
|
|
|
// ActionSubmissionTriggerPublish invokes actionSubmissionTriggerPublish operation.
|
2024-11-26 01:22:45 +00:00
|
|
|
//
|
2024-11-28 01:46:54 +00:00
|
|
|
// Role Admin changes status from Validated -> Publishing.
|
2024-11-26 01:22:45 +00:00
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/trigger-publish
|
2024-11-28 01:46:54 +00:00
|
|
|
func (c *Client) ActionSubmissionTriggerPublish(ctx context.Context, params ActionSubmissionTriggerPublishParams) error {
|
|
|
|
_, err := c.sendActionSubmissionTriggerPublish(ctx, params)
|
2024-11-26 20:39:10 +00:00
|
|
|
return err
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
|
|
|
|
2024-12-11 06:23:08 +00:00
|
|
|
func (c *Client) sendActionSubmissionTriggerPublish(ctx context.Context, params ActionSubmissionTriggerPublishParams) (res *ActionSubmissionTriggerPublishNoContent, err error) {
|
2024-11-26 01:22:45 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-11-28 01:46:54 +00:00
|
|
|
otelogen.OperationID("actionSubmissionTriggerPublish"),
|
2024-12-10 06:06:33 +00:00
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
2024-11-28 01:46:54 +00:00
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/trigger-publish"),
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
2024-12-06 00:36:15 +00:00
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
2024-11-26 01:22:45 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-11-29 22:33:48 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, ActionSubmissionTriggerPublishOperation,
|
2024-11-26 01:22:45 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
2024-11-26 20:39:10 +00:00
|
|
|
var pathParts [3]string
|
|
|
|
pathParts[0] = "/submissions/"
|
2024-11-26 01:22:45 +00:00
|
|
|
{
|
2024-11-26 20:39:10 +00:00
|
|
|
// Encode "SubmissionID" parameter.
|
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
|
|
|
Param: "SubmissionID",
|
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
|
|
|
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
|
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
2024-11-26 20:39:10 +00:00
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
2024-11-26 20:39:10 +00:00
|
|
|
pathParts[1] = encoded
|
2024-11-26 01:22:45 +00:00
|
|
|
}
|
2024-11-28 01:46:54 +00:00
|
|
|
pathParts[2] = "/status/trigger-publish"
|
2024-11-26 20:39:10 +00:00
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
2024-11-26 01:22:45 +00:00
|
|
|
stage = "EncodeRequest"
|
2024-12-10 06:06:33 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "POST", u)
|
2024-11-26 01:22:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
2024-11-29 22:33:48 +00:00
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
|
|
|
switch err := c.securityCookieAuth(ctx, ActionSubmissionTriggerPublishOperation, r); {
|
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-26 01:22:45 +00:00
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
2024-11-28 01:46:54 +00:00
|
|
|
result, err := decodeActionSubmissionTriggerPublishResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ActionSubmissionTriggerValidate invokes actionSubmissionTriggerValidate operation.
|
|
|
|
//
|
|
|
|
// Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating.
|
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/trigger-validate
|
2024-11-28 01:46:54 +00:00
|
|
|
func (c *Client) ActionSubmissionTriggerValidate(ctx context.Context, params ActionSubmissionTriggerValidateParams) error {
|
|
|
|
_, err := c.sendActionSubmissionTriggerValidate(ctx, params)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-12-11 06:23:08 +00:00
|
|
|
func (c *Client) sendActionSubmissionTriggerValidate(ctx context.Context, params ActionSubmissionTriggerValidateParams) (res *ActionSubmissionTriggerValidateNoContent, err error) {
|
2024-11-28 01:46:54 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("actionSubmissionTriggerValidate"),
|
2024-12-10 06:06:33 +00:00
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
2024-11-28 01:46:54 +00:00
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/trigger-validate"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
2024-12-06 00:36:15 +00:00
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
2024-11-28 01:46:54 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-11-29 22:33:48 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, ActionSubmissionTriggerValidateOperation,
|
2024-11-28 01:46:54 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
|
|
|
var pathParts [3]string
|
|
|
|
pathParts[0] = "/submissions/"
|
|
|
|
{
|
|
|
|
// Encode "SubmissionID" parameter.
|
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
|
|
|
Param: "SubmissionID",
|
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
|
|
|
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
|
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
|
|
|
pathParts[2] = "/status/trigger-validate"
|
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
2024-12-10 06:06:33 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "POST", u)
|
2024-11-28 01:46:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
2024-11-29 22:33:48 +00:00
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
|
|
|
switch err := c.securityCookieAuth(ctx, ActionSubmissionTriggerValidateOperation, r); {
|
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-28 01:46:54 +00:00
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
|
|
|
result, err := decodeActionSubmissionTriggerValidateResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ActionSubmissionValidate invokes actionSubmissionValidate operation.
|
|
|
|
//
|
2024-12-12 01:54:11 +00:00
|
|
|
// (Internal endpoint) Role Validator changes status from Validating -> Validated.
|
2024-11-28 01:46:54 +00:00
|
|
|
//
|
2024-12-12 01:54:11 +00:00
|
|
|
// POST /submissions/{SubmissionID}/status/validator-validated
|
2024-11-28 01:46:54 +00:00
|
|
|
func (c *Client) ActionSubmissionValidate(ctx context.Context, params ActionSubmissionValidateParams) error {
|
|
|
|
_, err := c.sendActionSubmissionValidate(ctx, params)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-12-11 06:23:08 +00:00
|
|
|
func (c *Client) sendActionSubmissionValidate(ctx context.Context, params ActionSubmissionValidateParams) (res *ActionSubmissionValidateNoContent, err error) {
|
2024-11-28 01:46:54 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("actionSubmissionValidate"),
|
2024-12-10 06:06:33 +00:00
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
2024-12-12 01:54:11 +00:00
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/validator-validated"),
|
2024-11-28 01:46:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
2024-12-06 00:36:15 +00:00
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
2024-11-28 01:46:54 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-11-29 22:33:48 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, ActionSubmissionValidateOperation,
|
2024-11-28 01:46:54 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
|
|
|
var pathParts [3]string
|
|
|
|
pathParts[0] = "/submissions/"
|
|
|
|
{
|
|
|
|
// Encode "SubmissionID" parameter.
|
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
|
|
|
Param: "SubmissionID",
|
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
|
|
|
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
|
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
2024-12-12 01:54:11 +00:00
|
|
|
pathParts[2] = "/status/validator-validated"
|
2024-11-28 01:46:54 +00:00
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
2024-12-10 06:06:33 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "POST", u)
|
2024-11-28 01:46:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
|
|
|
result, err := decodeActionSubmissionValidateResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-12-06 00:36:15 +00:00
|
|
|
// CreateScript invokes createScript operation.
|
2024-11-28 01:46:54 +00:00
|
|
|
//
|
2024-12-06 00:36:15 +00:00
|
|
|
// Create a new script.
|
2024-11-28 01:46:54 +00:00
|
|
|
//
|
2024-12-06 00:36:15 +00:00
|
|
|
// POST /scripts
|
2024-12-06 02:48:26 +00:00
|
|
|
func (c *Client) CreateScript(ctx context.Context, request *ScriptCreate) (*ID, error) {
|
2024-12-06 00:36:15 +00:00
|
|
|
res, err := c.sendCreateScript(ctx, request)
|
2024-11-28 01:46:54 +00:00
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2024-12-06 02:48:26 +00:00
|
|
|
func (c *Client) sendCreateScript(ctx context.Context, request *ScriptCreate) (res *ID, err error) {
|
2024-11-28 01:46:54 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-12-06 00:36:15 +00:00
|
|
|
otelogen.OperationID("createScript"),
|
2024-11-28 01:46:54 +00:00
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
2024-12-06 00:36:15 +00:00
|
|
|
semconv.HTTPRouteKey.String("/scripts"),
|
2024-11-28 01:46:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
2024-12-06 00:36:15 +00:00
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
2024-11-28 01:46:54 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-12-06 00:36:15 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, CreateScriptOperation,
|
2024-11-28 01:46:54 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
|
|
|
var pathParts [1]string
|
2024-12-06 00:36:15 +00:00
|
|
|
pathParts[0] = "/scripts"
|
2024-11-28 01:46:54 +00:00
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
|
|
|
r, err := ht.NewRequest(ctx, "POST", u)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
2024-12-06 00:36:15 +00:00
|
|
|
if err := encodeCreateScriptRequest(request, r); err != nil {
|
2024-11-28 01:46:54 +00:00
|
|
|
return res, errors.Wrap(err, "encode request")
|
|
|
|
}
|
|
|
|
|
2024-11-29 22:33:48 +00:00
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
2024-12-06 00:36:15 +00:00
|
|
|
switch err := c.securityCookieAuth(ctx, CreateScriptOperation, r); {
|
2024-11-29 22:33:48 +00:00
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-28 01:46:54 +00:00
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
2024-12-06 00:36:15 +00:00
|
|
|
result, err := decodeCreateScriptResponse(resp)
|
2024-11-28 01:46:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-12-06 00:36:15 +00:00
|
|
|
// CreateScriptPolicy invokes createScriptPolicy operation.
|
2024-11-28 01:46:54 +00:00
|
|
|
//
|
2024-12-06 00:36:15 +00:00
|
|
|
// Create a new script policy.
|
2024-11-28 01:46:54 +00:00
|
|
|
//
|
2024-12-06 00:36:15 +00:00
|
|
|
// POST /script-policy
|
2024-12-06 02:48:26 +00:00
|
|
|
func (c *Client) CreateScriptPolicy(ctx context.Context, request *ScriptPolicyCreate) (*ID, error) {
|
2024-12-06 00:36:15 +00:00
|
|
|
res, err := c.sendCreateScriptPolicy(ctx, request)
|
2024-11-28 01:46:54 +00:00
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2024-12-06 02:48:26 +00:00
|
|
|
func (c *Client) sendCreateScriptPolicy(ctx context.Context, request *ScriptPolicyCreate) (res *ID, err error) {
|
2024-11-28 01:46:54 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-12-06 00:36:15 +00:00
|
|
|
otelogen.OperationID("createScriptPolicy"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
|
|
|
semconv.HTTPRouteKey.String("/script-policy"),
|
2024-11-28 01:46:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
2024-12-06 00:36:15 +00:00
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
2024-11-28 01:46:54 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-12-06 00:36:15 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, CreateScriptPolicyOperation,
|
2024-11-28 01:46:54 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
2024-12-06 00:36:15 +00:00
|
|
|
var pathParts [1]string
|
|
|
|
pathParts[0] = "/script-policy"
|
2024-11-28 01:46:54 +00:00
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
2024-12-06 00:36:15 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "POST", u)
|
2024-11-28 01:46:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
2024-12-06 00:36:15 +00:00
|
|
|
if err := encodeCreateScriptPolicyRequest(request, r); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode request")
|
|
|
|
}
|
2024-11-28 01:46:54 +00:00
|
|
|
|
2024-11-29 22:33:48 +00:00
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
2024-12-06 00:36:15 +00:00
|
|
|
switch err := c.securityCookieAuth(ctx, CreateScriptPolicyOperation, r); {
|
2024-11-29 22:33:48 +00:00
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-28 01:46:54 +00:00
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
2024-12-06 00:36:15 +00:00
|
|
|
result, err := decodeCreateScriptPolicyResponse(resp)
|
2024-11-28 01:46:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-12-06 00:36:15 +00:00
|
|
|
// CreateSubmission invokes createSubmission operation.
|
2024-11-28 01:46:54 +00:00
|
|
|
//
|
2024-12-06 00:36:15 +00:00
|
|
|
// Create new submission.
|
2024-11-28 01:46:54 +00:00
|
|
|
//
|
2024-12-06 00:36:15 +00:00
|
|
|
// POST /submissions
|
2024-12-06 02:48:26 +00:00
|
|
|
func (c *Client) CreateSubmission(ctx context.Context, request *SubmissionCreate) (*ID, error) {
|
2024-12-06 00:36:15 +00:00
|
|
|
res, err := c.sendCreateSubmission(ctx, request)
|
2024-11-28 01:46:54 +00:00
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2024-12-06 02:48:26 +00:00
|
|
|
func (c *Client) sendCreateSubmission(ctx context.Context, request *SubmissionCreate) (res *ID, err error) {
|
2024-11-28 01:46:54 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-12-06 00:36:15 +00:00
|
|
|
otelogen.OperationID("createSubmission"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
2024-11-28 01:46:54 +00:00
|
|
|
semconv.HTTPRouteKey.String("/submissions"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
2024-12-06 00:36:15 +00:00
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
2024-11-28 01:46:54 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-12-06 00:36:15 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, CreateSubmissionOperation,
|
2024-11-28 01:46:54 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
|
|
|
var pathParts [1]string
|
|
|
|
pathParts[0] = "/submissions"
|
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
2024-12-06 00:36:15 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "POST", u)
|
2024-11-28 01:46:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
2024-12-06 00:36:15 +00:00
|
|
|
if err := encodeCreateSubmissionRequest(request, r); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode request")
|
|
|
|
}
|
2024-11-28 01:46:54 +00:00
|
|
|
|
2024-11-29 22:33:48 +00:00
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
2024-12-06 00:36:15 +00:00
|
|
|
switch err := c.securityCookieAuth(ctx, CreateSubmissionOperation, r); {
|
2024-11-29 22:33:48 +00:00
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-28 01:46:54 +00:00
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
2024-12-06 00:36:15 +00:00
|
|
|
result, err := decodeCreateSubmissionResponse(resp)
|
2024-11-28 01:46:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-12-06 00:36:15 +00:00
|
|
|
// DeleteScript invokes deleteScript operation.
|
2024-11-28 01:46:54 +00:00
|
|
|
//
|
2024-12-06 00:36:15 +00:00
|
|
|
// Delete the specified script by ID.
|
2024-11-28 01:46:54 +00:00
|
|
|
//
|
2024-12-06 00:36:15 +00:00
|
|
|
// DELETE /scripts/{ScriptID}
|
|
|
|
func (c *Client) DeleteScript(ctx context.Context, params DeleteScriptParams) error {
|
|
|
|
_, err := c.sendDeleteScript(ctx, params)
|
2024-11-28 01:46:54 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-12-11 06:23:08 +00:00
|
|
|
func (c *Client) sendDeleteScript(ctx context.Context, params DeleteScriptParams) (res *DeleteScriptNoContent, err error) {
|
2024-11-28 01:46:54 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-12-06 00:36:15 +00:00
|
|
|
otelogen.OperationID("deleteScript"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("DELETE"),
|
|
|
|
semconv.HTTPRouteKey.String("/scripts/{ScriptID}"),
|
2024-11-28 01:46:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
2024-12-06 00:36:15 +00:00
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
2024-11-28 01:46:54 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-12-06 00:36:15 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, DeleteScriptOperation,
|
2024-11-28 01:46:54 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
2024-12-06 00:36:15 +00:00
|
|
|
var pathParts [2]string
|
|
|
|
pathParts[0] = "/scripts/"
|
2024-11-28 01:46:54 +00:00
|
|
|
{
|
2024-12-06 00:36:15 +00:00
|
|
|
// Encode "ScriptID" parameter.
|
2024-11-28 01:46:54 +00:00
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
2024-12-06 00:36:15 +00:00
|
|
|
Param: "ScriptID",
|
2024-11-28 01:46:54 +00:00
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
2024-12-06 00:36:15 +00:00
|
|
|
return e.EncodeValue(conv.Int64ToString(params.ScriptID))
|
2024-11-28 01:46:54 +00:00
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
2024-12-06 00:36:15 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "DELETE", u)
|
2024-11-28 01:46:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
2024-11-29 22:33:48 +00:00
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
2024-12-06 00:36:15 +00:00
|
|
|
switch err := c.securityCookieAuth(ctx, DeleteScriptOperation, r); {
|
2024-11-29 22:33:48 +00:00
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-28 01:46:54 +00:00
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
2024-12-06 00:36:15 +00:00
|
|
|
result, err := decodeDeleteScriptResponse(resp)
|
2024-11-28 01:46:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-12-06 00:36:15 +00:00
|
|
|
// DeleteScriptPolicy invokes deleteScriptPolicy operation.
|
2024-11-28 01:46:54 +00:00
|
|
|
//
|
2024-12-06 00:36:15 +00:00
|
|
|
// Delete the specified script policy by ID.
|
2024-11-28 01:46:54 +00:00
|
|
|
//
|
2024-12-06 00:36:15 +00:00
|
|
|
// DELETE /script-policy/id/{ScriptPolicyID}
|
|
|
|
func (c *Client) DeleteScriptPolicy(ctx context.Context, params DeleteScriptPolicyParams) error {
|
|
|
|
_, err := c.sendDeleteScriptPolicy(ctx, params)
|
2024-11-28 01:46:54 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-12-11 06:23:08 +00:00
|
|
|
func (c *Client) sendDeleteScriptPolicy(ctx context.Context, params DeleteScriptPolicyParams) (res *DeleteScriptPolicyNoContent, err error) {
|
2024-11-28 01:46:54 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-12-06 00:36:15 +00:00
|
|
|
otelogen.OperationID("deleteScriptPolicy"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("DELETE"),
|
|
|
|
semconv.HTTPRouteKey.String("/script-policy/id/{ScriptPolicyID}"),
|
2024-11-28 01:46:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
2024-12-06 00:36:15 +00:00
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
2024-11-28 01:46:54 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-12-06 00:36:15 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, DeleteScriptPolicyOperation,
|
2024-11-28 01:46:54 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
2024-12-06 00:36:15 +00:00
|
|
|
var pathParts [2]string
|
|
|
|
pathParts[0] = "/script-policy/id/"
|
2024-11-28 01:46:54 +00:00
|
|
|
{
|
2024-12-06 00:36:15 +00:00
|
|
|
// Encode "ScriptPolicyID" parameter.
|
2024-11-28 01:46:54 +00:00
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
2024-12-06 00:36:15 +00:00
|
|
|
Param: "ScriptPolicyID",
|
2024-11-28 01:46:54 +00:00
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
2024-12-06 00:36:15 +00:00
|
|
|
return e.EncodeValue(conv.Int64ToString(params.ScriptPolicyID))
|
2024-11-28 01:46:54 +00:00
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
2024-12-06 00:36:15 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "DELETE", u)
|
2024-11-28 01:46:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
2024-11-29 22:33:48 +00:00
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
2024-12-06 00:36:15 +00:00
|
|
|
switch err := c.securityCookieAuth(ctx, DeleteScriptPolicyOperation, r); {
|
2024-11-29 22:33:48 +00:00
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-28 01:46:54 +00:00
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
2024-12-06 00:36:15 +00:00
|
|
|
result, err := decodeDeleteScriptPolicyResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetScript invokes getScript operation.
|
|
|
|
//
|
|
|
|
// Get the specified script by ID.
|
|
|
|
//
|
|
|
|
// GET /scripts/{ScriptID}
|
|
|
|
func (c *Client) GetScript(ctx context.Context, params GetScriptParams) (*Script, error) {
|
|
|
|
res, err := c.sendGetScript(ctx, params)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) sendGetScript(ctx context.Context, params GetScriptParams) (res *Script, err error) {
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("getScript"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("GET"),
|
|
|
|
semconv.HTTPRouteKey.String("/scripts/{ScriptID}"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, GetScriptOperation,
|
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
|
|
|
var pathParts [2]string
|
|
|
|
pathParts[0] = "/scripts/"
|
|
|
|
{
|
|
|
|
// Encode "ScriptID" parameter.
|
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
|
|
|
Param: "ScriptID",
|
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
|
|
|
return e.EncodeValue(conv.Int64ToString(params.ScriptID))
|
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
|
|
|
r, err := ht.NewRequest(ctx, "GET", u)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
|
|
|
switch err := c.securityCookieAuth(ctx, GetScriptOperation, r); {
|
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
|
|
|
result, err := decodeGetScriptResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetScriptPolicy invokes getScriptPolicy operation.
|
|
|
|
//
|
|
|
|
// Get the specified script policy by ID.
|
|
|
|
//
|
|
|
|
// GET /script-policy/id/{ScriptPolicyID}
|
|
|
|
func (c *Client) GetScriptPolicy(ctx context.Context, params GetScriptPolicyParams) (*ScriptPolicy, error) {
|
|
|
|
res, err := c.sendGetScriptPolicy(ctx, params)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) sendGetScriptPolicy(ctx context.Context, params GetScriptPolicyParams) (res *ScriptPolicy, err error) {
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("getScriptPolicy"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("GET"),
|
|
|
|
semconv.HTTPRouteKey.String("/script-policy/id/{ScriptPolicyID}"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, GetScriptPolicyOperation,
|
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
|
|
|
var pathParts [2]string
|
|
|
|
pathParts[0] = "/script-policy/id/"
|
|
|
|
{
|
|
|
|
// Encode "ScriptPolicyID" parameter.
|
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
|
|
|
Param: "ScriptPolicyID",
|
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
|
|
|
return e.EncodeValue(conv.Int64ToString(params.ScriptPolicyID))
|
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
|
|
|
r, err := ht.NewRequest(ctx, "GET", u)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
|
|
|
switch err := c.securityCookieAuth(ctx, GetScriptPolicyOperation, r); {
|
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
|
|
|
result, err := decodeGetScriptPolicyResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetScriptPolicyFromHash invokes getScriptPolicyFromHash operation.
|
|
|
|
//
|
|
|
|
// Get the policy for the given hash of script source code.
|
|
|
|
//
|
|
|
|
// GET /script-policy/hash/{FromScriptHash}
|
|
|
|
func (c *Client) GetScriptPolicyFromHash(ctx context.Context, params GetScriptPolicyFromHashParams) (*ScriptPolicy, error) {
|
|
|
|
res, err := c.sendGetScriptPolicyFromHash(ctx, params)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) sendGetScriptPolicyFromHash(ctx context.Context, params GetScriptPolicyFromHashParams) (res *ScriptPolicy, err error) {
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("getScriptPolicyFromHash"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("GET"),
|
|
|
|
semconv.HTTPRouteKey.String("/script-policy/hash/{FromScriptHash}"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, GetScriptPolicyFromHashOperation,
|
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
|
|
|
var pathParts [2]string
|
|
|
|
pathParts[0] = "/script-policy/hash/"
|
|
|
|
{
|
|
|
|
// Encode "FromScriptHash" parameter.
|
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
|
|
|
Param: "FromScriptHash",
|
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
|
|
|
return e.EncodeValue(conv.StringToString(params.FromScriptHash))
|
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
|
|
|
r, err := ht.NewRequest(ctx, "GET", u)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
|
|
|
switch err := c.securityCookieAuth(ctx, GetScriptPolicyFromHashOperation, r); {
|
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
|
|
|
result, err := decodeGetScriptPolicyFromHashResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetSubmission invokes getSubmission operation.
|
|
|
|
//
|
|
|
|
// Retrieve map with ID.
|
|
|
|
//
|
|
|
|
// GET /submissions/{SubmissionID}
|
|
|
|
func (c *Client) GetSubmission(ctx context.Context, params GetSubmissionParams) (*Submission, error) {
|
|
|
|
res, err := c.sendGetSubmission(ctx, params)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) sendGetSubmission(ctx context.Context, params GetSubmissionParams) (res *Submission, err error) {
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("getSubmission"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("GET"),
|
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, GetSubmissionOperation,
|
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
|
|
|
var pathParts [2]string
|
|
|
|
pathParts[0] = "/submissions/"
|
|
|
|
{
|
|
|
|
// Encode "SubmissionID" parameter.
|
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
|
|
|
Param: "SubmissionID",
|
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
|
|
|
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
|
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
|
|
|
r, err := ht.NewRequest(ctx, "GET", u)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
|
|
|
switch err := c.securityCookieAuth(ctx, GetSubmissionOperation, r); {
|
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
|
|
|
result, err := decodeGetSubmissionResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-12-14 06:15:05 +00:00
|
|
|
// ListScriptPolicy invokes listScriptPolicy operation.
|
|
|
|
//
|
|
|
|
// Get list of script policies.
|
|
|
|
//
|
|
|
|
// GET /script-policy
|
|
|
|
func (c *Client) ListScriptPolicy(ctx context.Context, params ListScriptPolicyParams) ([]ScriptPolicy, error) {
|
|
|
|
res, err := c.sendListScriptPolicy(ctx, params)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) sendListScriptPolicy(ctx context.Context, params ListScriptPolicyParams) (res []ScriptPolicy, err error) {
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("listScriptPolicy"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("GET"),
|
|
|
|
semconv.HTTPRouteKey.String("/script-policy"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, ListScriptPolicyOperation,
|
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
|
|
|
var pathParts [1]string
|
|
|
|
pathParts[0] = "/script-policy"
|
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeQueryParams"
|
|
|
|
q := uri.NewQueryEncoder()
|
|
|
|
{
|
|
|
|
// Encode "page" parameter.
|
|
|
|
cfg := uri.QueryParameterEncodingConfig{
|
|
|
|
Name: "page",
|
|
|
|
Style: uri.QueryStyleForm,
|
|
|
|
Explode: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
|
|
|
return params.Page.EncodeURI(e)
|
|
|
|
}); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode query")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Encode "filter" parameter.
|
|
|
|
cfg := uri.QueryParameterEncodingConfig{
|
|
|
|
Name: "filter",
|
|
|
|
Style: uri.QueryStyleForm,
|
|
|
|
Explode: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
|
|
|
if val, ok := params.Filter.Get(); ok {
|
|
|
|
return val.EncodeURI(e)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode query")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
u.RawQuery = q.Values().Encode()
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
|
|
|
r, err := ht.NewRequest(ctx, "GET", u)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
|
|
|
switch err := c.securityCookieAuth(ctx, ListScriptPolicyOperation, r); {
|
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
|
|
|
result, err := decodeListScriptPolicyResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-12-06 00:36:15 +00:00
|
|
|
// ListSubmissions invokes listSubmissions operation.
|
|
|
|
//
|
|
|
|
// Get list of submissions.
|
|
|
|
//
|
|
|
|
// GET /submissions
|
|
|
|
func (c *Client) ListSubmissions(ctx context.Context, params ListSubmissionsParams) ([]Submission, error) {
|
|
|
|
res, err := c.sendListSubmissions(ctx, params)
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) sendListSubmissions(ctx context.Context, params ListSubmissionsParams) (res []Submission, err error) {
|
|
|
|
otelAttrs := []attribute.KeyValue{
|
|
|
|
otelogen.OperationID("listSubmissions"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("GET"),
|
|
|
|
semconv.HTTPRouteKey.String("/submissions"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, ListSubmissionsOperation,
|
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
|
|
|
var pathParts [1]string
|
|
|
|
pathParts[0] = "/submissions"
|
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeQueryParams"
|
|
|
|
q := uri.NewQueryEncoder()
|
|
|
|
{
|
|
|
|
// Encode "page" parameter.
|
|
|
|
cfg := uri.QueryParameterEncodingConfig{
|
|
|
|
Name: "page",
|
|
|
|
Style: uri.QueryStyleForm,
|
|
|
|
Explode: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
|
|
|
return params.Page.EncodeURI(e)
|
|
|
|
}); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode query")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Encode "filter" parameter.
|
|
|
|
cfg := uri.QueryParameterEncodingConfig{
|
|
|
|
Name: "filter",
|
|
|
|
Style: uri.QueryStyleForm,
|
|
|
|
Explode: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
|
|
|
if val, ok := params.Filter.Get(); ok {
|
|
|
|
return val.EncodeURI(e)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode query")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
u.RawQuery = q.Values().Encode()
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
|
|
|
r, err := ht.NewRequest(ctx, "GET", u)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
|
|
|
switch err := c.securityCookieAuth(ctx, ListSubmissionsOperation, r); {
|
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
|
|
|
result, err := decodeListSubmissionsResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-12-10 06:06:33 +00:00
|
|
|
// SetSubmissionCompleted invokes setSubmissionCompleted operation.
|
2024-12-06 00:36:15 +00:00
|
|
|
//
|
|
|
|
// Retrieve map with ID.
|
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /submissions/{SubmissionID}/completed
|
|
|
|
func (c *Client) SetSubmissionCompleted(ctx context.Context, params SetSubmissionCompletedParams) error {
|
|
|
|
_, err := c.sendSetSubmissionCompleted(ctx, params)
|
2024-12-06 00:36:15 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-12-11 06:23:08 +00:00
|
|
|
func (c *Client) sendSetSubmissionCompleted(ctx context.Context, params SetSubmissionCompletedParams) (res *SetSubmissionCompletedNoContent, err error) {
|
2024-12-06 00:36:15 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-12-10 06:06:33 +00:00
|
|
|
otelogen.OperationID("setSubmissionCompleted"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
2024-12-06 00:36:15 +00:00
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/completed"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-12-10 06:06:33 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, SetSubmissionCompletedOperation,
|
2024-12-06 00:36:15 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
|
|
|
var pathParts [3]string
|
|
|
|
pathParts[0] = "/submissions/"
|
|
|
|
{
|
|
|
|
// Encode "SubmissionID" parameter.
|
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
|
|
|
Param: "SubmissionID",
|
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
|
|
|
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
|
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
|
|
|
pathParts[2] = "/completed"
|
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
2024-12-10 06:06:33 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "POST", u)
|
2024-12-06 00:36:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
2024-12-10 06:06:33 +00:00
|
|
|
switch err := c.securityCookieAuth(ctx, SetSubmissionCompletedOperation, r); {
|
2024-12-06 00:36:15 +00:00
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
2024-12-10 06:06:33 +00:00
|
|
|
result, err := decodeSetSubmissionCompletedResponse(resp)
|
2024-12-06 00:36:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-12-10 06:06:33 +00:00
|
|
|
// UpdateScript invokes updateScript operation.
|
2024-12-06 00:36:15 +00:00
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// Update the specified script by ID.
|
2024-12-06 00:36:15 +00:00
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /scripts/{ScriptID}
|
|
|
|
func (c *Client) UpdateScript(ctx context.Context, request *ScriptUpdate, params UpdateScriptParams) error {
|
|
|
|
_, err := c.sendUpdateScript(ctx, request, params)
|
2024-12-06 00:36:15 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-12-11 06:23:08 +00:00
|
|
|
func (c *Client) sendUpdateScript(ctx context.Context, request *ScriptUpdate, params UpdateScriptParams) (res *UpdateScriptNoContent, err error) {
|
2024-12-06 00:36:15 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-12-10 06:06:33 +00:00
|
|
|
otelogen.OperationID("updateScript"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
|
|
|
semconv.HTTPRouteKey.String("/scripts/{ScriptID}"),
|
2024-12-06 00:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-12-10 06:06:33 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, UpdateScriptOperation,
|
2024-12-06 00:36:15 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
2024-12-10 06:06:33 +00:00
|
|
|
var pathParts [2]string
|
|
|
|
pathParts[0] = "/scripts/"
|
2024-12-06 00:36:15 +00:00
|
|
|
{
|
2024-12-10 06:06:33 +00:00
|
|
|
// Encode "ScriptID" parameter.
|
2024-12-06 00:36:15 +00:00
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
2024-12-10 06:06:33 +00:00
|
|
|
Param: "ScriptID",
|
2024-12-06 00:36:15 +00:00
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
2024-12-10 06:06:33 +00:00
|
|
|
return e.EncodeValue(conv.Int64ToString(params.ScriptID))
|
2024-12-06 00:36:15 +00:00
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
2024-12-10 06:06:33 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "POST", u)
|
2024-12-06 00:36:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
2024-12-10 06:06:33 +00:00
|
|
|
if err := encodeUpdateScriptRequest(request, r); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode request")
|
|
|
|
}
|
2024-12-06 00:36:15 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
2024-12-10 06:06:33 +00:00
|
|
|
switch err := c.securityCookieAuth(ctx, UpdateScriptOperation, r); {
|
2024-12-06 00:36:15 +00:00
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
2024-12-10 06:06:33 +00:00
|
|
|
result, err := decodeUpdateScriptResponse(resp)
|
2024-12-06 00:36:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-12-10 06:06:33 +00:00
|
|
|
// UpdateScriptPolicy invokes updateScriptPolicy operation.
|
2024-12-06 00:36:15 +00:00
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// Update the specified script policy by ID.
|
2024-12-06 00:36:15 +00:00
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /script-policy/id/{ScriptPolicyID}
|
|
|
|
func (c *Client) UpdateScriptPolicy(ctx context.Context, request *ScriptPolicyUpdate, params UpdateScriptPolicyParams) error {
|
|
|
|
_, err := c.sendUpdateScriptPolicy(ctx, request, params)
|
2024-12-06 00:36:15 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-12-11 06:23:08 +00:00
|
|
|
func (c *Client) sendUpdateScriptPolicy(ctx context.Context, request *ScriptPolicyUpdate, params UpdateScriptPolicyParams) (res *UpdateScriptPolicyNoContent, err error) {
|
2024-12-06 00:36:15 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-12-10 06:06:33 +00:00
|
|
|
otelogen.OperationID("updateScriptPolicy"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
|
|
|
semconv.HTTPRouteKey.String("/script-policy/id/{ScriptPolicyID}"),
|
2024-12-06 00:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-12-10 06:06:33 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, UpdateScriptPolicyOperation,
|
2024-12-06 00:36:15 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
|
|
|
var pathParts [2]string
|
2024-12-10 06:06:33 +00:00
|
|
|
pathParts[0] = "/script-policy/id/"
|
2024-12-06 00:36:15 +00:00
|
|
|
{
|
2024-12-10 06:06:33 +00:00
|
|
|
// Encode "ScriptPolicyID" parameter.
|
2024-12-06 00:36:15 +00:00
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
2024-12-10 06:06:33 +00:00
|
|
|
Param: "ScriptPolicyID",
|
2024-12-06 00:36:15 +00:00
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
2024-12-10 06:06:33 +00:00
|
|
|
return e.EncodeValue(conv.Int64ToString(params.ScriptPolicyID))
|
2024-12-06 00:36:15 +00:00
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
|
|
|
stage = "EncodeRequest"
|
2024-12-10 06:06:33 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "POST", u)
|
2024-12-06 00:36:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
2024-12-10 06:06:33 +00:00
|
|
|
if err := encodeUpdateScriptPolicyRequest(request, r); err != nil {
|
2024-12-06 00:36:15 +00:00
|
|
|
return res, errors.Wrap(err, "encode request")
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
2024-12-10 06:06:33 +00:00
|
|
|
switch err := c.securityCookieAuth(ctx, UpdateScriptPolicyOperation, r); {
|
2024-12-06 00:36:15 +00:00
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
2024-12-10 06:06:33 +00:00
|
|
|
result, err := decodeUpdateScriptPolicyResponse(resp)
|
2024-12-06 00:36:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2024-12-10 06:06:33 +00:00
|
|
|
// UpdateSubmissionModel invokes updateSubmissionModel operation.
|
2024-12-06 00:36:15 +00:00
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// Update model following role restrictions.
|
2024-12-06 00:36:15 +00:00
|
|
|
//
|
2024-12-10 06:06:33 +00:00
|
|
|
// POST /submissions/{SubmissionID}/model
|
|
|
|
func (c *Client) UpdateSubmissionModel(ctx context.Context, params UpdateSubmissionModelParams) error {
|
|
|
|
_, err := c.sendUpdateSubmissionModel(ctx, params)
|
2024-12-06 00:36:15 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-12-11 06:23:08 +00:00
|
|
|
func (c *Client) sendUpdateSubmissionModel(ctx context.Context, params UpdateSubmissionModelParams) (res *UpdateSubmissionModelNoContent, err error) {
|
2024-12-06 00:36:15 +00:00
|
|
|
otelAttrs := []attribute.KeyValue{
|
2024-12-10 06:06:33 +00:00
|
|
|
otelogen.OperationID("updateSubmissionModel"),
|
|
|
|
semconv.HTTPRequestMethodKey.String("POST"),
|
|
|
|
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/model"),
|
2024-12-06 00:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run stopwatch.
|
|
|
|
startTime := time.Now()
|
|
|
|
defer func() {
|
|
|
|
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
|
|
elapsedDuration := time.Since(startTime)
|
|
|
|
c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...))
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Increment request counter.
|
|
|
|
c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
|
|
|
|
// Start a span for this request.
|
2024-12-10 06:06:33 +00:00
|
|
|
ctx, span := c.cfg.Tracer.Start(ctx, UpdateSubmissionModelOperation,
|
2024-12-06 00:36:15 +00:00
|
|
|
trace.WithAttributes(otelAttrs...),
|
|
|
|
clientSpanKind,
|
|
|
|
)
|
|
|
|
// Track stage for error reporting.
|
|
|
|
var stage string
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
span.RecordError(err)
|
|
|
|
span.SetStatus(codes.Error, stage)
|
|
|
|
c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...))
|
|
|
|
}
|
|
|
|
span.End()
|
|
|
|
}()
|
|
|
|
|
|
|
|
stage = "BuildURL"
|
|
|
|
u := uri.Clone(c.requestURL(ctx))
|
2024-12-10 06:06:33 +00:00
|
|
|
var pathParts [3]string
|
|
|
|
pathParts[0] = "/submissions/"
|
2024-12-06 00:36:15 +00:00
|
|
|
{
|
2024-12-10 06:06:33 +00:00
|
|
|
// Encode "SubmissionID" parameter.
|
2024-12-06 00:36:15 +00:00
|
|
|
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
2024-12-10 06:06:33 +00:00
|
|
|
Param: "SubmissionID",
|
2024-12-06 00:36:15 +00:00
|
|
|
Style: uri.PathStyleSimple,
|
|
|
|
Explode: false,
|
|
|
|
})
|
|
|
|
if err := func() error {
|
2024-12-10 06:06:33 +00:00
|
|
|
return e.EncodeValue(conv.Int64ToString(params.SubmissionID))
|
2024-12-06 00:36:15 +00:00
|
|
|
}(); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
encoded, err := e.Result()
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode path")
|
|
|
|
}
|
|
|
|
pathParts[1] = encoded
|
|
|
|
}
|
2024-12-10 06:06:33 +00:00
|
|
|
pathParts[2] = "/model"
|
2024-12-06 00:36:15 +00:00
|
|
|
uri.AddPathParts(u, pathParts[:]...)
|
|
|
|
|
2024-12-10 06:06:33 +00:00
|
|
|
stage = "EncodeQueryParams"
|
|
|
|
q := uri.NewQueryEncoder()
|
|
|
|
{
|
|
|
|
// Encode "ModelID" parameter.
|
|
|
|
cfg := uri.QueryParameterEncodingConfig{
|
|
|
|
Name: "ModelID",
|
|
|
|
Style: uri.QueryStyleForm,
|
|
|
|
Explode: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
|
|
|
return e.EncodeValue(conv.Int64ToString(params.ModelID))
|
|
|
|
}); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode query")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Encode "VersionID" parameter.
|
|
|
|
cfg := uri.QueryParameterEncodingConfig{
|
|
|
|
Name: "VersionID",
|
|
|
|
Style: uri.QueryStyleForm,
|
|
|
|
Explode: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := q.EncodeParam(cfg, func(e uri.Encoder) error {
|
|
|
|
return e.EncodeValue(conv.Int64ToString(params.VersionID))
|
|
|
|
}); err != nil {
|
|
|
|
return res, errors.Wrap(err, "encode query")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
u.RawQuery = q.Values().Encode()
|
|
|
|
|
2024-12-06 00:36:15 +00:00
|
|
|
stage = "EncodeRequest"
|
2024-12-10 06:06:33 +00:00
|
|
|
r, err := ht.NewRequest(ctx, "POST", u)
|
2024-12-06 00:36:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "create request")
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
type bitset = [1]uint8
|
|
|
|
var satisfied bitset
|
|
|
|
{
|
|
|
|
stage = "Security:CookieAuth"
|
2024-12-10 06:06:33 +00:00
|
|
|
switch err := c.securityCookieAuth(ctx, UpdateSubmissionModelOperation, r); {
|
2024-12-06 00:36:15 +00:00
|
|
|
case err == nil: // if NO error
|
|
|
|
satisfied[0] |= 1 << 0
|
|
|
|
case errors.Is(err, ogenerrors.ErrSkipClientSecurity):
|
|
|
|
// Skip this security.
|
|
|
|
default:
|
|
|
|
return res, errors.Wrap(err, "security \"CookieAuth\"")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage = "SendRequest"
|
|
|
|
resp, err := c.cfg.Client.Do(r)
|
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "do request")
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
stage = "DecodeResponse"
|
2024-12-10 06:06:33 +00:00
|
|
|
result, err := decodeUpdateSubmissionModelResponse(resp)
|
2024-11-26 01:22:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return res, errors.Wrap(err, "decode response")
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|