Compare commits
1 Commits
int
...
hide-reset
| Author | SHA1 | Date | |
|---|---|---|---|
|
c3f497be48
|
857
Cargo.lock
generated
857
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -29,7 +29,7 @@ Prerequisite: bun installed
|
|||||||
The environment variables `API_HOST` and `AUTH_HOST` will need to be set for the middleware.
|
The environment variables `API_HOST` and `AUTH_HOST` will need to be set for the middleware.
|
||||||
Example `.env` in web's root:
|
Example `.env` in web's root:
|
||||||
```
|
```
|
||||||
API_HOST="http://localhost:8082/"
|
API_HOST="http://localhost:8082/v1/"
|
||||||
AUTH_HOST="http://localhost:8083/"
|
AUTH_HOST="http://localhost:8083/"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ services:
|
|||||||
"--auth-rpc-host","authrpc:8081",
|
"--auth-rpc-host","authrpc:8081",
|
||||||
"--data-rpc-host","dataservice:9000",
|
"--data-rpc-host","dataservice:9000",
|
||||||
]
|
]
|
||||||
env_file:
|
|
||||||
- ../auth-compose/strafesnet_staging.env
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- authrpc
|
- authrpc
|
||||||
- nats
|
- nats
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
//go:generate go run github.com/ogen-go/ogen/cmd/ogen@latest --target pkg/api --clean openapi.yaml
|
//go:generate go run github.com/ogen-go/ogen/cmd/ogen@latest --target pkg/api --clean openapi.yaml
|
||||||
|
//go:generate go run github.com/ogen-go/ogen/cmd/ogen@latest --target pkg/internal --clean openapi-internal.yaml
|
||||||
|
|||||||
4
go.mod
4
go.mod
@@ -5,7 +5,7 @@ go 1.22
|
|||||||
toolchain go1.23.3
|
toolchain go1.23.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.itzana.me/strafesnet/go-grpc v0.0.0-20250724030029-845bea991815
|
git.itzana.me/strafesnet/go-grpc v0.0.0-20241129081229-9e166b3d11f7
|
||||||
git.itzana.me/strafesnet/utils v0.0.0-20220716194944-d8ca164052f9
|
git.itzana.me/strafesnet/utils v0.0.0-20220716194944-d8ca164052f9
|
||||||
github.com/dchest/siphash v1.2.3
|
github.com/dchest/siphash v1.2.3
|
||||||
github.com/go-faster/errors v0.7.1
|
github.com/go-faster/errors v0.7.1
|
||||||
@@ -53,7 +53,7 @@ require (
|
|||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/segmentio/asm v1.2.0 // indirect
|
github.com/segmentio/asm v1.2.0 // indirect
|
||||||
go.uber.org/multierr v1.11.0 // indirect
|
go.uber.org/multierr v1.11.0
|
||||||
go.uber.org/zap v1.27.0 // indirect
|
go.uber.org/zap v1.27.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect
|
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect
|
||||||
golang.org/x/net v0.25.0 // indirect
|
golang.org/x/net v0.25.0 // indirect
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,7 +1,7 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
git.itzana.me/strafesnet/go-grpc v0.0.0-20250724030029-845bea991815 h1:hkuOnehphRXUq/2z2UYgoqTq5MJj1GsWfshyc7bXda8=
|
git.itzana.me/strafesnet/go-grpc v0.0.0-20241129081229-9e166b3d11f7 h1:5XzWd3ZZjSw1M60IfHuILty2vRPBYiqM0FZ+E7uHCi8=
|
||||||
git.itzana.me/strafesnet/go-grpc v0.0.0-20250724030029-845bea991815/go.mod h1:X7XTRUScRkBWq8q8bplbeso105RPDlnY7J6Wy1IwBMs=
|
git.itzana.me/strafesnet/go-grpc v0.0.0-20241129081229-9e166b3d11f7/go.mod h1:X7XTRUScRkBWq8q8bplbeso105RPDlnY7J6Wy1IwBMs=
|
||||||
git.itzana.me/strafesnet/utils v0.0.0-20220716194944-d8ca164052f9 h1:7lU6jyR7S7Rhh1dnUp7GyIRHUTBXZagw8F4n4hOyxLw=
|
git.itzana.me/strafesnet/utils v0.0.0-20220716194944-d8ca164052f9 h1:7lU6jyR7S7Rhh1dnUp7GyIRHUTBXZagw8F4n4hOyxLw=
|
||||||
git.itzana.me/strafesnet/utils v0.0.0-20220716194944-d8ca164052f9/go.mod h1:uyYerSieEt4v0MJCdPLppG0LtJ4Yj035vuTetWGsxjY=
|
git.itzana.me/strafesnet/utils v0.0.0-20220716194944-d8ca164052f9/go.mod h1:uyYerSieEt4v0MJCdPLppG0LtJ4Yj035vuTetWGsxjY=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
|
|||||||
862
openapi-internal.yaml
Normal file
862
openapi-internal.yaml
Normal file
@@ -0,0 +1,862 @@
|
|||||||
|
openapi: 3.1.0
|
||||||
|
info:
|
||||||
|
title: StrafesNET Internal - OpenAPI 3.1
|
||||||
|
description: Internal operations inaccessible from the public internet.
|
||||||
|
version: 0.1.0
|
||||||
|
tags:
|
||||||
|
- name: Mapfixes
|
||||||
|
description: Mapfix operations
|
||||||
|
- name: Submissions
|
||||||
|
description: Submission operations
|
||||||
|
paths:
|
||||||
|
/mapfixes:
|
||||||
|
post:
|
||||||
|
summary: Create a mapfix
|
||||||
|
operationId: createMapfix
|
||||||
|
tags:
|
||||||
|
- Mapfixes
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/MapfixCreate'
|
||||||
|
responses:
|
||||||
|
"201":
|
||||||
|
description: Successful response
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/MapfixID"
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/mapfixes/{MapfixID}/validated-model:
|
||||||
|
post:
|
||||||
|
summary: Update validated model
|
||||||
|
operationId: updateMapfixValidatedModel
|
||||||
|
tags:
|
||||||
|
- Mapfixes
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/MapfixID'
|
||||||
|
- name: ValidatedModelID
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
- name: ValidatedModelVersion
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: Successful response
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/mapfixes/{MapfixID}/status/validator-submitted:
|
||||||
|
post:
|
||||||
|
summary: (Internal endpoint) Role Validator changes status from Submitting -> Submitted
|
||||||
|
operationId: actionMapfixSubmitted
|
||||||
|
tags:
|
||||||
|
- Mapfixes
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/MapfixID'
|
||||||
|
- name: ModelVersion
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
- name: DisplayName
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
maxLength: 128
|
||||||
|
- name: Creator
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
maxLength: 128
|
||||||
|
- name: GameID
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
minimum: 0
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: Successful response
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/mapfixes/{MapfixID}/status/validator-request-changes:
|
||||||
|
post:
|
||||||
|
summary: (Internal endpoint) Role Validator changes status from Submitting -> ChangesRequested
|
||||||
|
operationId: actionMapfixRequestChanges
|
||||||
|
tags:
|
||||||
|
- Mapfixes
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/MapfixID'
|
||||||
|
- name: ErrorMessage
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
minLength: 0
|
||||||
|
maxLength: 4096
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: Successful response
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/mapfixes/{MapfixID}/status/validator-validated:
|
||||||
|
post:
|
||||||
|
summary: (Internal endpoint) Role Validator changes status from Validating -> Validated
|
||||||
|
operationId: actionMapfixValidated
|
||||||
|
tags:
|
||||||
|
- Mapfixes
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/MapfixID'
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: Successful response
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/mapfixes/{MapfixID}/status/validator-failed:
|
||||||
|
post:
|
||||||
|
summary: (Internal endpoint) Role Validator changes status from Validating -> Accepted
|
||||||
|
operationId: actionMapfixAccepted
|
||||||
|
tags:
|
||||||
|
- Mapfixes
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/MapfixID'
|
||||||
|
- name: ErrorMessage
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
minLength: 0
|
||||||
|
maxLength: 4096
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: Successful response
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/mapfixes/{MapfixID}/status/validator-uploaded:
|
||||||
|
post:
|
||||||
|
summary: (Internal endpoint) Role Validator changes status from Uploading -> Uploaded
|
||||||
|
operationId: actionMapfixUploaded
|
||||||
|
tags:
|
||||||
|
- Mapfixes
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/MapfixID'
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: Successful response
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/operations/{OperationID}/status/operation-failed:
|
||||||
|
post:
|
||||||
|
summary: (Internal endpoint) Fail an operation and write a StatusMessage
|
||||||
|
operationId: actionOperationFailed
|
||||||
|
tags:
|
||||||
|
- Operations
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/OperationID'
|
||||||
|
- name: StatusMessage
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
minLength: 0
|
||||||
|
maxLength: 4096
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: Successful response
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/submissions:
|
||||||
|
post:
|
||||||
|
summary: Create a new submission
|
||||||
|
operationId: createSubmission
|
||||||
|
tags:
|
||||||
|
- Submissions
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/SubmissionCreate'
|
||||||
|
responses:
|
||||||
|
"201":
|
||||||
|
description: Successful response
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/SubmissionID"
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/submissions/{SubmissionID}/validated-model:
|
||||||
|
post:
|
||||||
|
summary: Update validated model
|
||||||
|
operationId: updateSubmissionValidatedModel
|
||||||
|
tags:
|
||||||
|
- Submissions
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/SubmissionID'
|
||||||
|
- name: ValidatedModelID
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
- name: ValidatedModelVersion
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: Successful response
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/submissions/{SubmissionID}/status/validator-submitted:
|
||||||
|
post:
|
||||||
|
summary: (Internal endpoint) Role Validator changes status from Submitting -> Submitted
|
||||||
|
operationId: actionSubmissionSubmitted
|
||||||
|
tags:
|
||||||
|
- Submissions
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/SubmissionID'
|
||||||
|
- name: ModelVersion
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
- name: DisplayName
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
maxLength: 128
|
||||||
|
- name: Creator
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
maxLength: 128
|
||||||
|
- name: GameID
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
minimum: 0
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: Successful response
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/submissions/{SubmissionID}/status/validator-request-changes:
|
||||||
|
post:
|
||||||
|
summary: (Internal endpoint) Role Validator changes status from Submitting -> ChangesRequested
|
||||||
|
operationId: actionSubmissionRequestChanges
|
||||||
|
tags:
|
||||||
|
- Submissions
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/SubmissionID'
|
||||||
|
- name: ErrorMessage
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
minLength: 0
|
||||||
|
maxLength: 4096
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: Successful response
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/submissions/{SubmissionID}/status/validator-validated:
|
||||||
|
post:
|
||||||
|
summary: (Internal endpoint) Role Validator changes status from Validating -> Validated
|
||||||
|
operationId: actionSubmissionValidated
|
||||||
|
tags:
|
||||||
|
- Submissions
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/SubmissionID'
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: Successful response
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/submissions/{SubmissionID}/status/validator-failed:
|
||||||
|
post:
|
||||||
|
summary: (Internal endpoint) Role Validator changes status from Validating -> Accepted
|
||||||
|
operationId: actionSubmissionAccepted
|
||||||
|
tags:
|
||||||
|
- Submissions
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/SubmissionID'
|
||||||
|
- name: ErrorMessage
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
minLength: 0
|
||||||
|
maxLength: 4096
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: Successful response
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/submissions/{SubmissionID}/status/validator-uploaded:
|
||||||
|
post:
|
||||||
|
summary: (Internal endpoint) Role Validator changes status from Uploading -> Uploaded
|
||||||
|
operationId: actionSubmissionUploaded
|
||||||
|
tags:
|
||||||
|
- Submissions
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/SubmissionID'
|
||||||
|
- name: UploadedAssetID
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: Successful response
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/script-policy:
|
||||||
|
get:
|
||||||
|
summary: Get list of script policies
|
||||||
|
operationId: listScriptPolicy
|
||||||
|
tags:
|
||||||
|
- ScriptPolicy
|
||||||
|
parameters:
|
||||||
|
- $ref: "#/components/parameters/Page"
|
||||||
|
- $ref: "#/components/parameters/Limit"
|
||||||
|
- name: FromScriptHash
|
||||||
|
in: query
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
minLength: 16
|
||||||
|
maxLength: 16
|
||||||
|
- name: ToScriptID
|
||||||
|
in: query
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
- name: Policy
|
||||||
|
in: query
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
minimum: 0
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Successful response
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: "#/components/schemas/ScriptPolicy"
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
post:
|
||||||
|
summary: Create a new script policy
|
||||||
|
operationId: createScriptPolicy
|
||||||
|
tags:
|
||||||
|
- ScriptPolicy
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/ScriptPolicyCreate'
|
||||||
|
responses:
|
||||||
|
"201":
|
||||||
|
description: Successful response
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/ScriptPolicyID"
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/scripts:
|
||||||
|
get:
|
||||||
|
summary: Get list of scripts
|
||||||
|
operationId: listScripts
|
||||||
|
tags:
|
||||||
|
- Script
|
||||||
|
parameters:
|
||||||
|
- $ref: "#/components/parameters/Page"
|
||||||
|
- $ref: "#/components/parameters/Limit"
|
||||||
|
- name: Hash
|
||||||
|
in: query
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
minLength: 16
|
||||||
|
maxLength: 16
|
||||||
|
- name: Name
|
||||||
|
in: query
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
maxLength: 128
|
||||||
|
- name: Source
|
||||||
|
in: query
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
maxLength: 1048576
|
||||||
|
- name: ResourceType
|
||||||
|
in: query
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
minimum: 0
|
||||||
|
- name: ResourceID
|
||||||
|
in: query
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Successful response
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: "#/components/schemas/Script"
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
post:
|
||||||
|
summary: Create a new script
|
||||||
|
operationId: createScript
|
||||||
|
tags:
|
||||||
|
- Scripts
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/ScriptCreate'
|
||||||
|
responses:
|
||||||
|
"201":
|
||||||
|
description: Successful response
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/ScriptID"
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
/scripts/{ScriptID}:
|
||||||
|
get:
|
||||||
|
summary: Get the specified script by ID
|
||||||
|
operationId: getScript
|
||||||
|
tags:
|
||||||
|
- Scripts
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/ScriptID'
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Successful response
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Script"
|
||||||
|
default:
|
||||||
|
description: General Error
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/Error"
|
||||||
|
components:
|
||||||
|
parameters:
|
||||||
|
MapfixID:
|
||||||
|
name: MapfixID
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
description: The unique identifier for a submission.
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
OperationID:
|
||||||
|
name: OperationID
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
description: The unique identifier for a long-running operation.
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
minimum: 0
|
||||||
|
SubmissionID:
|
||||||
|
name: SubmissionID
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
description: The unique identifier for a submission.
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
ScriptID:
|
||||||
|
name: ScriptID
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
description: The unique identifier for a script.
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
Page:
|
||||||
|
name: Page
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
minimum: 1
|
||||||
|
Limit:
|
||||||
|
name: Limit
|
||||||
|
in: query
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
minimum: 1
|
||||||
|
maximum: 100
|
||||||
|
schemas:
|
||||||
|
MapfixID:
|
||||||
|
required:
|
||||||
|
- MapfixID
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
MapfixID:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
SubmissionID:
|
||||||
|
required:
|
||||||
|
- SubmissionID
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
SubmissionID:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
ScriptID:
|
||||||
|
required:
|
||||||
|
- ScriptID
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
ScriptID:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
ScriptPolicyID:
|
||||||
|
required:
|
||||||
|
- ScriptPolicyID
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
ScriptPolicyID:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
MapfixCreate:
|
||||||
|
required:
|
||||||
|
- OperationID
|
||||||
|
- AssetOwner
|
||||||
|
- DisplayName
|
||||||
|
- Creator
|
||||||
|
- GameID
|
||||||
|
- AssetID
|
||||||
|
- AssetVersion
|
||||||
|
- TargetAssetID
|
||||||
|
- Description
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
OperationID:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
minimum: 0
|
||||||
|
AssetOwner:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
DisplayName:
|
||||||
|
type: string
|
||||||
|
maxLength: 128
|
||||||
|
Creator:
|
||||||
|
type: string
|
||||||
|
maxLength: 128
|
||||||
|
GameID:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
minimum: 0
|
||||||
|
AssetID:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
AssetVersion:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
TargetAssetID:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
Description:
|
||||||
|
type: string
|
||||||
|
maxLength: 256
|
||||||
|
SubmissionCreate:
|
||||||
|
required:
|
||||||
|
- OperationID
|
||||||
|
- AssetOwner
|
||||||
|
- DisplayName
|
||||||
|
- Creator
|
||||||
|
- GameID
|
||||||
|
- AssetID
|
||||||
|
- AssetVersion
|
||||||
|
- Status
|
||||||
|
- Roles
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
OperationID:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
minimum: 0
|
||||||
|
AssetOwner:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
DisplayName:
|
||||||
|
type: string
|
||||||
|
maxLength: 128
|
||||||
|
Creator:
|
||||||
|
type: string
|
||||||
|
maxLength: 128
|
||||||
|
GameID:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
minimum: 0
|
||||||
|
AssetID:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
AssetVersion:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
Status:
|
||||||
|
type: integer
|
||||||
|
format: uint32
|
||||||
|
minimum: 0
|
||||||
|
maximum: 9
|
||||||
|
Roles:
|
||||||
|
type: integer
|
||||||
|
format: uint32
|
||||||
|
Script:
|
||||||
|
required:
|
||||||
|
- ID
|
||||||
|
- Name
|
||||||
|
- Hash
|
||||||
|
- Source
|
||||||
|
- ResourceType
|
||||||
|
- ResourceID
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
ID:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
Name:
|
||||||
|
type: string
|
||||||
|
maxLength: 128
|
||||||
|
Hash:
|
||||||
|
type: string
|
||||||
|
minLength: 16
|
||||||
|
maxLength: 16
|
||||||
|
Source:
|
||||||
|
type: string
|
||||||
|
maxLength: 1048576
|
||||||
|
ResourceType:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
minimum: 0
|
||||||
|
ResourceID:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
ScriptCreate:
|
||||||
|
required:
|
||||||
|
- Name
|
||||||
|
- Source
|
||||||
|
- ResourceType
|
||||||
|
# - ResourceID
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
Name:
|
||||||
|
type: string
|
||||||
|
maxLength: 128
|
||||||
|
Source:
|
||||||
|
type: string
|
||||||
|
maxLength: 1048576
|
||||||
|
ResourceType:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
minimum: 0
|
||||||
|
ResourceID:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
ScriptPolicy:
|
||||||
|
required:
|
||||||
|
- ID
|
||||||
|
- FromScriptHash
|
||||||
|
- ToScriptID
|
||||||
|
- Policy
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
ID:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
FromScriptHash:
|
||||||
|
type: string
|
||||||
|
minLength: 16
|
||||||
|
maxLength: 16
|
||||||
|
ToScriptID:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
Policy:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
minimum: 0
|
||||||
|
ScriptPolicyCreate:
|
||||||
|
required:
|
||||||
|
- FromScriptID
|
||||||
|
- ToScriptID
|
||||||
|
- Policy
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
FromScriptID:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
ToScriptID:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
Policy:
|
||||||
|
type: integer
|
||||||
|
format: int32
|
||||||
|
minimum: 0
|
||||||
|
Error:
|
||||||
|
description: Represents error object
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
code:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
minimum: 0
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- code
|
||||||
|
- message
|
||||||
287
openapi.yaml
287
openapi.yaml
@@ -80,21 +80,6 @@ paths:
|
|||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/Error"
|
$ref: "#/components/schemas/Error"
|
||||||
/migrate-maps:
|
|
||||||
post:
|
|
||||||
summary: Perform maps migration
|
|
||||||
operationId: migrateMaps
|
|
||||||
tags:
|
|
||||||
- Maps
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: Successful response
|
|
||||||
default:
|
|
||||||
description: General Error
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
$ref: "#/components/schemas/Error"
|
|
||||||
/maps:
|
/maps:
|
||||||
get:
|
get:
|
||||||
summary: Get list of maps
|
summary: Get list of maps
|
||||||
@@ -119,23 +104,16 @@ paths:
|
|||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 1
|
minimum: 1
|
||||||
maximum: 5
|
maximum: 5
|
||||||
- name: Sort
|
- name: Sort
|
||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
maximum: 4
|
maximum: 4
|
||||||
description: >
|
|
||||||
Sort order:
|
|
||||||
* `0` - Disabled
|
|
||||||
* `1` - DisplayNameAscending
|
|
||||||
* `2` - DisplayNameDescending
|
|
||||||
* `3` - DateAscending
|
|
||||||
* `4` - DateDescending
|
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: Successful response
|
description: Successful response
|
||||||
@@ -173,34 +151,6 @@ paths:
|
|||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/Error"
|
$ref: "#/components/schemas/Error"
|
||||||
/maps/{MapID}/download:
|
|
||||||
get:
|
|
||||||
summary: Download the map asset
|
|
||||||
operationId: downloadMapAsset
|
|
||||||
tags:
|
|
||||||
- Maps
|
|
||||||
parameters:
|
|
||||||
- name: MapID
|
|
||||||
in: path
|
|
||||||
required: true
|
|
||||||
schema:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
minimum: 0
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: Successful response
|
|
||||||
content:
|
|
||||||
application/octet-stream:
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
format: binary
|
|
||||||
default:
|
|
||||||
description: General Error
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
$ref: "#/components/schemas/Error"
|
|
||||||
/mapfixes:
|
/mapfixes:
|
||||||
get:
|
get:
|
||||||
summary: Get list of mapfixes
|
summary: Get list of mapfixes
|
||||||
@@ -225,71 +175,41 @@ paths:
|
|||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 1
|
minimum: 1
|
||||||
maximum: 5
|
maximum: 5
|
||||||
description: >
|
|
||||||
Game ID:
|
|
||||||
* `1` - Bhop
|
|
||||||
* `2` - Surf
|
|
||||||
* `5` - FlyTrials
|
|
||||||
- name: Sort
|
- name: Sort
|
||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
maximum: 4
|
maximum: 4
|
||||||
description: >
|
|
||||||
Sort order:
|
|
||||||
* `0` - Disabled
|
|
||||||
* `1` - DisplayNameAscending
|
|
||||||
* `2` - DisplayNameDescending
|
|
||||||
* `3` - DateAscending
|
|
||||||
* `4` - DateDescending
|
|
||||||
- name: Submitter
|
- name: Submitter
|
||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
- name: AssetID
|
- name: AssetID
|
||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
- name: TargetAssetID
|
- name: TargetAssetID
|
||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
- name: StatusID
|
- name: StatusID
|
||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
maximum: 9
|
maximum: 9
|
||||||
description: >
|
|
||||||
// Phase: Creation
|
|
||||||
* `0` - UnderConstruction
|
|
||||||
* `1` - ChangesRequested
|
|
||||||
|
|
||||||
// Phase: Review
|
|
||||||
* `2` - Submitting
|
|
||||||
* `3` - Submitted
|
|
||||||
|
|
||||||
// Phase: Testing
|
|
||||||
* `4` - AcceptedUnvalidated // pending script review, can re-trigger validation
|
|
||||||
* `5` - Validating
|
|
||||||
* `6` - Validated
|
|
||||||
* `7` - Uploading
|
|
||||||
|
|
||||||
// Phase: Final MapfixStatus
|
|
||||||
* `8` - Uploaded // uploaded to the group, but pending release
|
|
||||||
* `9` - Rejected
|
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: Successful response
|
description: Successful response
|
||||||
@@ -412,14 +332,14 @@ paths:
|
|||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
- name: ModelVersion
|
- name: ModelVersion
|
||||||
in: query
|
in: query
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
responses:
|
responses:
|
||||||
"204":
|
"204":
|
||||||
@@ -464,23 +384,6 @@ paths:
|
|||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/Error"
|
$ref: "#/components/schemas/Error"
|
||||||
/mapfixes/{MapfixID}/status/trigger-submit-unchecked:
|
|
||||||
post:
|
|
||||||
summary: Role Reviewer changes status from ChangesRequested -> Submitting
|
|
||||||
operationId: actionMapfixTriggerSubmitUnchecked
|
|
||||||
tags:
|
|
||||||
- Mapfixes
|
|
||||||
parameters:
|
|
||||||
- $ref: '#/components/parameters/MapfixID'
|
|
||||||
responses:
|
|
||||||
"204":
|
|
||||||
description: Successful response
|
|
||||||
default:
|
|
||||||
description: General Error
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
$ref: "#/components/schemas/Error"
|
|
||||||
/mapfixes/{MapfixID}/status/reset-submitting:
|
/mapfixes/{MapfixID}/status/reset-submitting:
|
||||||
post:
|
post:
|
||||||
summary: Role Submitter manually resets submitting softlock and changes status from Submitting -> UnderConstruction
|
summary: Role Submitter manually resets submitting softlock and changes status from Submitting -> UnderConstruction
|
||||||
@@ -679,72 +582,41 @@ paths:
|
|||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 1
|
minimum: 1
|
||||||
maximum: 5
|
maximum: 5
|
||||||
description: >
|
|
||||||
Game ID:
|
|
||||||
* `1` - Bhop
|
|
||||||
* `2` - Surf
|
|
||||||
* `5` - FlyTrials
|
|
||||||
- name: Sort
|
- name: Sort
|
||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
maximum: 4
|
maximum: 4
|
||||||
description: >
|
|
||||||
Sort order:
|
|
||||||
* `0` - Disabled
|
|
||||||
* `1` - DisplayNameAscending
|
|
||||||
* `2` - DisplayNameDescending
|
|
||||||
* `3` - DateAscending
|
|
||||||
* `4` - DateDescending
|
|
||||||
- name: Submitter
|
- name: Submitter
|
||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
- name: AssetID
|
- name: AssetID
|
||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
- name: UploadedAssetID
|
- name: UploadedAssetID
|
||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
- name: StatusID
|
- name: StatusID
|
||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
maximum: 10
|
maximum: 10
|
||||||
description: >
|
|
||||||
// Phase: Creation
|
|
||||||
* `0` - UnderConstruction
|
|
||||||
* `1` - ChangesRequested
|
|
||||||
|
|
||||||
// Phase: Review
|
|
||||||
* `2` - Submitting
|
|
||||||
* `3` - Submitted
|
|
||||||
|
|
||||||
// Phase: Testing
|
|
||||||
* `4` - AcceptedUnvalidated // pending script review, can re-trigger validation
|
|
||||||
* `5` - Validating
|
|
||||||
* `6` - Validated
|
|
||||||
* `7` - Uploading
|
|
||||||
* `8` - Uploaded // uploaded to the group, but pending release
|
|
||||||
|
|
||||||
// Phase: Final SubmissionStatus
|
|
||||||
* `9` - Rejected
|
|
||||||
* `10` - Released
|
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: Successful response
|
description: Successful response
|
||||||
@@ -892,14 +764,14 @@ paths:
|
|||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
- name: ModelVersion
|
- name: ModelVersion
|
||||||
in: query
|
in: query
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
responses:
|
responses:
|
||||||
"204":
|
"204":
|
||||||
@@ -944,23 +816,6 @@ paths:
|
|||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/Error"
|
$ref: "#/components/schemas/Error"
|
||||||
/submissions/{SubmissionID}/status/trigger-submit-unchecked:
|
|
||||||
post:
|
|
||||||
summary: Role Reviewer changes status from ChangesRequested -> Submitting
|
|
||||||
operationId: actionSubmissionTriggerSubmitUnchecked
|
|
||||||
tags:
|
|
||||||
- Submissions
|
|
||||||
parameters:
|
|
||||||
- $ref: '#/components/parameters/SubmissionID'
|
|
||||||
responses:
|
|
||||||
"204":
|
|
||||||
description: Successful response
|
|
||||||
default:
|
|
||||||
description: General Error
|
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
$ref: "#/components/schemas/Error"
|
|
||||||
/submissions/{SubmissionID}/status/reset-submitting:
|
/submissions/{SubmissionID}/status/reset-submitting:
|
||||||
post:
|
post:
|
||||||
summary: Role Submitter manually resets submitting softlock and changes status from Submitting -> UnderConstruction
|
summary: Role Submitter manually resets submitting softlock and changes status from Submitting -> UnderConstruction
|
||||||
@@ -1165,7 +1020,7 @@ paths:
|
|||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
@@ -1296,7 +1151,7 @@ paths:
|
|||||||
in: query
|
in: query
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
- name: ResourceID
|
- name: ResourceID
|
||||||
in: query
|
in: query
|
||||||
@@ -1470,7 +1325,7 @@ components:
|
|||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 1
|
minimum: 1
|
||||||
Limit:
|
Limit:
|
||||||
name: Limit
|
name: Limit
|
||||||
@@ -1478,7 +1333,7 @@ components:
|
|||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
maximum: 100
|
maximum: 100
|
||||||
schemas:
|
schemas:
|
||||||
@@ -1502,20 +1357,20 @@ components:
|
|||||||
format: int64
|
format: int64
|
||||||
User:
|
User:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
Username:
|
Username:
|
||||||
type: string
|
type: string
|
||||||
maxLength: 64
|
maxLength: 64
|
||||||
ResourceType:
|
ResourceType:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
description: Is this a submission or is it a mapfix
|
description: Is this a submission or is it a mapfix
|
||||||
ResourceID:
|
ResourceID:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
EventType:
|
EventType:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
EventData:
|
EventData:
|
||||||
type: object
|
type: object
|
||||||
description: Arbitrary event data
|
description: Arbitrary event data
|
||||||
@@ -1554,7 +1409,7 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
Roles:
|
Roles:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
User:
|
User:
|
||||||
required:
|
required:
|
||||||
@@ -1565,7 +1420,7 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
UserID:
|
UserID:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
Username:
|
Username:
|
||||||
type: string
|
type: string
|
||||||
@@ -1580,13 +1435,6 @@ components:
|
|||||||
- Creator
|
- Creator
|
||||||
- GameID
|
- GameID
|
||||||
- Date
|
- Date
|
||||||
- CreatedAt
|
|
||||||
- UpdatedAt
|
|
||||||
- Submitter
|
|
||||||
- Thumbnail
|
|
||||||
- AssetVersion
|
|
||||||
- LoadCount
|
|
||||||
- Modes
|
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
ID:
|
ID:
|
||||||
@@ -1601,33 +1449,12 @@ components:
|
|||||||
maxLength: 128
|
maxLength: 128
|
||||||
GameID:
|
GameID:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
Date:
|
Date:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
CreatedAt:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
UpdatedAt:
|
|
||||||
type: integer
|
|
||||||
format: int64
|
|
||||||
Submitter:
|
|
||||||
type: integer
|
|
||||||
format: uint64
|
|
||||||
Thumbnail:
|
|
||||||
type: integer
|
|
||||||
format: uint64
|
|
||||||
AssetVersion:
|
|
||||||
type: integer
|
|
||||||
format: uint64
|
|
||||||
LoadCount:
|
|
||||||
type: integer
|
|
||||||
format: uint32
|
|
||||||
Modes:
|
|
||||||
type: integer
|
|
||||||
format: uint32
|
|
||||||
Mapfix:
|
Mapfix:
|
||||||
required:
|
required:
|
||||||
- ID
|
- ID
|
||||||
@@ -1657,7 +1484,7 @@ components:
|
|||||||
maxLength: 128
|
maxLength: 128
|
||||||
GameID:
|
GameID:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
CreatedAt:
|
CreatedAt:
|
||||||
type: integer
|
type: integer
|
||||||
@@ -1669,25 +1496,25 @@ components:
|
|||||||
minimum: 0
|
minimum: 0
|
||||||
Submitter:
|
Submitter:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
AssetID:
|
AssetID:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
AssetVersion:
|
AssetVersion:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
Completed:
|
Completed:
|
||||||
type: boolean
|
type: boolean
|
||||||
TargetAssetID:
|
TargetAssetID:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
StatusID:
|
StatusID:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
Description:
|
Description:
|
||||||
type: string
|
type: string
|
||||||
@@ -1700,7 +1527,7 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
Total:
|
Total:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
Mapfixes:
|
Mapfixes:
|
||||||
type: array
|
type: array
|
||||||
@@ -1715,11 +1542,11 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
AssetID:
|
AssetID:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
TargetAssetID:
|
TargetAssetID:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
Description:
|
Description:
|
||||||
type: string
|
type: string
|
||||||
@@ -1744,11 +1571,11 @@ components:
|
|||||||
minimum: 0
|
minimum: 0
|
||||||
Owner:
|
Owner:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
Status:
|
Status:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
StatusMessage:
|
StatusMessage:
|
||||||
type: string
|
type: string
|
||||||
@@ -1786,7 +1613,7 @@ components:
|
|||||||
maxLength: 128
|
maxLength: 128
|
||||||
GameID:
|
GameID:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
CreatedAt:
|
CreatedAt:
|
||||||
type: integer
|
type: integer
|
||||||
@@ -1798,33 +1625,33 @@ components:
|
|||||||
minimum: 0
|
minimum: 0
|
||||||
Submitter:
|
Submitter:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
AssetID:
|
AssetID:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
AssetVersion:
|
AssetVersion:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
ValidatedAssetID:
|
ValidatedAssetID:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
ValidatedAssetVersion:
|
ValidatedAssetVersion:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
Completed:
|
Completed:
|
||||||
type: boolean
|
type: boolean
|
||||||
UploadedAssetID:
|
UploadedAssetID:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
StatusID:
|
StatusID:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
Submissions:
|
Submissions:
|
||||||
required:
|
required:
|
||||||
@@ -1834,7 +1661,7 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
Total:
|
Total:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
Submissions:
|
Submissions:
|
||||||
type: array
|
type: array
|
||||||
@@ -1850,7 +1677,7 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
AssetID:
|
AssetID:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
DisplayName:
|
DisplayName:
|
||||||
type: string
|
type: string
|
||||||
@@ -1860,7 +1687,7 @@ components:
|
|||||||
maxLength: 128
|
maxLength: 128
|
||||||
GameID:
|
GameID:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
ReleaseInfo:
|
ReleaseInfo:
|
||||||
required:
|
required:
|
||||||
@@ -1901,7 +1728,7 @@ components:
|
|||||||
maxLength: 1048576
|
maxLength: 1048576
|
||||||
ResourceType:
|
ResourceType:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
ResourceID:
|
ResourceID:
|
||||||
type: integer
|
type: integer
|
||||||
@@ -1923,7 +1750,7 @@ components:
|
|||||||
maxLength: 1048576
|
maxLength: 1048576
|
||||||
ResourceType:
|
ResourceType:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
ResourceID:
|
ResourceID:
|
||||||
type: integer
|
type: integer
|
||||||
@@ -1946,7 +1773,7 @@ components:
|
|||||||
maxLength: 1048576
|
maxLength: 1048576
|
||||||
ResourceType:
|
ResourceType:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
ResourceID:
|
ResourceID:
|
||||||
type: integer
|
type: integer
|
||||||
@@ -1974,7 +1801,7 @@ components:
|
|||||||
minimum: 0
|
minimum: 0
|
||||||
Policy:
|
Policy:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
ScriptPolicyCreate:
|
ScriptPolicyCreate:
|
||||||
required:
|
required:
|
||||||
@@ -1993,7 +1820,7 @@ components:
|
|||||||
minimum: 0
|
minimum: 0
|
||||||
Policy:
|
Policy:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
ScriptPolicyUpdate:
|
ScriptPolicyUpdate:
|
||||||
required:
|
required:
|
||||||
@@ -2014,7 +1841,7 @@ components:
|
|||||||
minimum: 0
|
minimum: 0
|
||||||
Policy:
|
Policy:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int32
|
||||||
minimum: 0
|
minimum: 0
|
||||||
Error:
|
Error:
|
||||||
description: Represents error object
|
description: Represents error object
|
||||||
@@ -2022,7 +1849,7 @@ components:
|
|||||||
properties:
|
properties:
|
||||||
code:
|
code:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint32
|
format: int64
|
||||||
minimum: 0
|
minimum: 0
|
||||||
message:
|
message:
|
||||||
type: string
|
type: string
|
||||||
|
|||||||
@@ -72,12 +72,6 @@ type Invoker interface {
|
|||||||
//
|
//
|
||||||
// POST /mapfixes/{MapfixID}/status/trigger-submit
|
// POST /mapfixes/{MapfixID}/status/trigger-submit
|
||||||
ActionMapfixTriggerSubmit(ctx context.Context, params ActionMapfixTriggerSubmitParams) error
|
ActionMapfixTriggerSubmit(ctx context.Context, params ActionMapfixTriggerSubmitParams) error
|
||||||
// ActionMapfixTriggerSubmitUnchecked invokes actionMapfixTriggerSubmitUnchecked operation.
|
|
||||||
//
|
|
||||||
// Role Reviewer changes status from ChangesRequested -> Submitting.
|
|
||||||
//
|
|
||||||
// POST /mapfixes/{MapfixID}/status/trigger-submit-unchecked
|
|
||||||
ActionMapfixTriggerSubmitUnchecked(ctx context.Context, params ActionMapfixTriggerSubmitUncheckedParams) error
|
|
||||||
// ActionMapfixTriggerUpload invokes actionMapfixTriggerUpload operation.
|
// ActionMapfixTriggerUpload invokes actionMapfixTriggerUpload operation.
|
||||||
//
|
//
|
||||||
// Role Admin changes status from Validated -> Uploading.
|
// Role Admin changes status from Validated -> Uploading.
|
||||||
@@ -139,12 +133,6 @@ type Invoker interface {
|
|||||||
//
|
//
|
||||||
// POST /submissions/{SubmissionID}/status/trigger-submit
|
// POST /submissions/{SubmissionID}/status/trigger-submit
|
||||||
ActionSubmissionTriggerSubmit(ctx context.Context, params ActionSubmissionTriggerSubmitParams) error
|
ActionSubmissionTriggerSubmit(ctx context.Context, params ActionSubmissionTriggerSubmitParams) error
|
||||||
// ActionSubmissionTriggerSubmitUnchecked invokes actionSubmissionTriggerSubmitUnchecked operation.
|
|
||||||
//
|
|
||||||
// Role Reviewer changes status from ChangesRequested -> Submitting.
|
|
||||||
//
|
|
||||||
// POST /submissions/{SubmissionID}/status/trigger-submit-unchecked
|
|
||||||
ActionSubmissionTriggerSubmitUnchecked(ctx context.Context, params ActionSubmissionTriggerSubmitUncheckedParams) error
|
|
||||||
// ActionSubmissionTriggerUpload invokes actionSubmissionTriggerUpload operation.
|
// ActionSubmissionTriggerUpload invokes actionSubmissionTriggerUpload operation.
|
||||||
//
|
//
|
||||||
// Role Admin changes status from Validated -> Uploading.
|
// Role Admin changes status from Validated -> Uploading.
|
||||||
@@ -217,12 +205,6 @@ type Invoker interface {
|
|||||||
//
|
//
|
||||||
// DELETE /script-policy/{ScriptPolicyID}
|
// DELETE /script-policy/{ScriptPolicyID}
|
||||||
DeleteScriptPolicy(ctx context.Context, params DeleteScriptPolicyParams) error
|
DeleteScriptPolicy(ctx context.Context, params DeleteScriptPolicyParams) error
|
||||||
// DownloadMapAsset invokes downloadMapAsset operation.
|
|
||||||
//
|
|
||||||
// Download the map asset.
|
|
||||||
//
|
|
||||||
// GET /maps/{MapID}/download
|
|
||||||
DownloadMapAsset(ctx context.Context, params DownloadMapAssetParams) (DownloadMapAssetOK, error)
|
|
||||||
// GetMap invokes getMap operation.
|
// GetMap invokes getMap operation.
|
||||||
//
|
//
|
||||||
// Retrieve map with ID.
|
// Retrieve map with ID.
|
||||||
@@ -301,12 +283,6 @@ type Invoker interface {
|
|||||||
//
|
//
|
||||||
// GET /submissions
|
// GET /submissions
|
||||||
ListSubmissions(ctx context.Context, params ListSubmissionsParams) (*Submissions, error)
|
ListSubmissions(ctx context.Context, params ListSubmissionsParams) (*Submissions, error)
|
||||||
// MigrateMaps invokes migrateMaps operation.
|
|
||||||
//
|
|
||||||
// Perform maps migration.
|
|
||||||
//
|
|
||||||
// POST /migrate-maps
|
|
||||||
MigrateMaps(ctx context.Context) error
|
|
||||||
// ReleaseSubmissions invokes releaseSubmissions operation.
|
// ReleaseSubmissions invokes releaseSubmissions operation.
|
||||||
//
|
//
|
||||||
// Release a set of uploaded maps.
|
// Release a set of uploaded maps.
|
||||||
@@ -1287,130 +1263,6 @@ func (c *Client) sendActionMapfixTriggerSubmit(ctx context.Context, params Actio
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActionMapfixTriggerSubmitUnchecked invokes actionMapfixTriggerSubmitUnchecked operation.
|
|
||||||
//
|
|
||||||
// Role Reviewer changes status from ChangesRequested -> Submitting.
|
|
||||||
//
|
|
||||||
// POST /mapfixes/{MapfixID}/status/trigger-submit-unchecked
|
|
||||||
func (c *Client) ActionMapfixTriggerSubmitUnchecked(ctx context.Context, params ActionMapfixTriggerSubmitUncheckedParams) error {
|
|
||||||
_, err := c.sendActionMapfixTriggerSubmitUnchecked(ctx, params)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) sendActionMapfixTriggerSubmitUnchecked(ctx context.Context, params ActionMapfixTriggerSubmitUncheckedParams) (res *ActionMapfixTriggerSubmitUncheckedNoContent, err error) {
|
|
||||||
otelAttrs := []attribute.KeyValue{
|
|
||||||
otelogen.OperationID("actionMapfixTriggerSubmitUnchecked"),
|
|
||||||
semconv.HTTPRequestMethodKey.String("POST"),
|
|
||||||
semconv.HTTPRouteKey.String("/mapfixes/{MapfixID}/status/trigger-submit-unchecked"),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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, ActionMapfixTriggerSubmitUncheckedOperation,
|
|
||||||
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] = "/mapfixes/"
|
|
||||||
{
|
|
||||||
// Encode "MapfixID" parameter.
|
|
||||||
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
|
||||||
Param: "MapfixID",
|
|
||||||
Style: uri.PathStyleSimple,
|
|
||||||
Explode: false,
|
|
||||||
})
|
|
||||||
if err := func() error {
|
|
||||||
return e.EncodeValue(conv.Int64ToString(params.MapfixID))
|
|
||||||
}(); 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-submit-unchecked"
|
|
||||||
uri.AddPathParts(u, pathParts[:]...)
|
|
||||||
|
|
||||||
stage = "EncodeRequest"
|
|
||||||
r, err := ht.NewRequest(ctx, "POST", 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, ActionMapfixTriggerSubmitUncheckedOperation, 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 := decodeActionMapfixTriggerSubmitUncheckedResponse(resp)
|
|
||||||
if err != nil {
|
|
||||||
return res, errors.Wrap(err, "decode response")
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionMapfixTriggerUpload invokes actionMapfixTriggerUpload operation.
|
// ActionMapfixTriggerUpload invokes actionMapfixTriggerUpload operation.
|
||||||
//
|
//
|
||||||
// Role Admin changes status from Validated -> Uploading.
|
// Role Admin changes status from Validated -> Uploading.
|
||||||
@@ -2652,130 +2504,6 @@ func (c *Client) sendActionSubmissionTriggerSubmit(ctx context.Context, params A
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActionSubmissionTriggerSubmitUnchecked invokes actionSubmissionTriggerSubmitUnchecked operation.
|
|
||||||
//
|
|
||||||
// Role Reviewer changes status from ChangesRequested -> Submitting.
|
|
||||||
//
|
|
||||||
// POST /submissions/{SubmissionID}/status/trigger-submit-unchecked
|
|
||||||
func (c *Client) ActionSubmissionTriggerSubmitUnchecked(ctx context.Context, params ActionSubmissionTriggerSubmitUncheckedParams) error {
|
|
||||||
_, err := c.sendActionSubmissionTriggerSubmitUnchecked(ctx, params)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) sendActionSubmissionTriggerSubmitUnchecked(ctx context.Context, params ActionSubmissionTriggerSubmitUncheckedParams) (res *ActionSubmissionTriggerSubmitUncheckedNoContent, err error) {
|
|
||||||
otelAttrs := []attribute.KeyValue{
|
|
||||||
otelogen.OperationID("actionSubmissionTriggerSubmitUnchecked"),
|
|
||||||
semconv.HTTPRequestMethodKey.String("POST"),
|
|
||||||
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/trigger-submit-unchecked"),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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, ActionSubmissionTriggerSubmitUncheckedOperation,
|
|
||||||
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-submit-unchecked"
|
|
||||||
uri.AddPathParts(u, pathParts[:]...)
|
|
||||||
|
|
||||||
stage = "EncodeRequest"
|
|
||||||
r, err := ht.NewRequest(ctx, "POST", 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, ActionSubmissionTriggerSubmitUncheckedOperation, 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 := decodeActionSubmissionTriggerSubmitUncheckedResponse(resp)
|
|
||||||
if err != nil {
|
|
||||||
return res, errors.Wrap(err, "decode response")
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionSubmissionTriggerUpload invokes actionSubmissionTriggerUpload operation.
|
// ActionSubmissionTriggerUpload invokes actionSubmissionTriggerUpload operation.
|
||||||
//
|
//
|
||||||
// Role Admin changes status from Validated -> Uploading.
|
// Role Admin changes status from Validated -> Uploading.
|
||||||
@@ -4188,130 +3916,6 @@ func (c *Client) sendDeleteScriptPolicy(ctx context.Context, params DeleteScript
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownloadMapAsset invokes downloadMapAsset operation.
|
|
||||||
//
|
|
||||||
// Download the map asset.
|
|
||||||
//
|
|
||||||
// GET /maps/{MapID}/download
|
|
||||||
func (c *Client) DownloadMapAsset(ctx context.Context, params DownloadMapAssetParams) (DownloadMapAssetOK, error) {
|
|
||||||
res, err := c.sendDownloadMapAsset(ctx, params)
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) sendDownloadMapAsset(ctx context.Context, params DownloadMapAssetParams) (res DownloadMapAssetOK, err error) {
|
|
||||||
otelAttrs := []attribute.KeyValue{
|
|
||||||
otelogen.OperationID("downloadMapAsset"),
|
|
||||||
semconv.HTTPRequestMethodKey.String("GET"),
|
|
||||||
semconv.HTTPRouteKey.String("/maps/{MapID}/download"),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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, DownloadMapAssetOperation,
|
|
||||||
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] = "/maps/"
|
|
||||||
{
|
|
||||||
// Encode "MapID" parameter.
|
|
||||||
e := uri.NewPathEncoder(uri.PathEncoderConfig{
|
|
||||||
Param: "MapID",
|
|
||||||
Style: uri.PathStyleSimple,
|
|
||||||
Explode: false,
|
|
||||||
})
|
|
||||||
if err := func() error {
|
|
||||||
return e.EncodeValue(conv.Int64ToString(params.MapID))
|
|
||||||
}(); 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] = "/download"
|
|
||||||
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, DownloadMapAssetOperation, 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 := decodeDownloadMapAssetResponse(resp)
|
|
||||||
if err != nil {
|
|
||||||
return res, errors.Wrap(err, "decode response")
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMap invokes getMap operation.
|
// GetMap invokes getMap operation.
|
||||||
//
|
//
|
||||||
// Retrieve map with ID.
|
// Retrieve map with ID.
|
||||||
@@ -6127,111 +5731,6 @@ func (c *Client) sendListSubmissions(ctx context.Context, params ListSubmissions
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MigrateMaps invokes migrateMaps operation.
|
|
||||||
//
|
|
||||||
// Perform maps migration.
|
|
||||||
//
|
|
||||||
// POST /migrate-maps
|
|
||||||
func (c *Client) MigrateMaps(ctx context.Context) error {
|
|
||||||
_, err := c.sendMigrateMaps(ctx)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) sendMigrateMaps(ctx context.Context) (res *MigrateMapsOK, err error) {
|
|
||||||
otelAttrs := []attribute.KeyValue{
|
|
||||||
otelogen.OperationID("migrateMaps"),
|
|
||||||
semconv.HTTPRequestMethodKey.String("POST"),
|
|
||||||
semconv.HTTPRouteKey.String("/migrate-maps"),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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, MigrateMapsOperation,
|
|
||||||
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] = "/migrate-maps"
|
|
||||||
uri.AddPathParts(u, pathParts[:]...)
|
|
||||||
|
|
||||||
stage = "EncodeRequest"
|
|
||||||
r, err := ht.NewRequest(ctx, "POST", 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, MigrateMapsOperation, 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 := decodeMigrateMapsResponse(resp)
|
|
||||||
if err != nil {
|
|
||||||
return res, errors.Wrap(err, "decode response")
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReleaseSubmissions invokes releaseSubmissions operation.
|
// ReleaseSubmissions invokes releaseSubmissions operation.
|
||||||
//
|
//
|
||||||
// Release a set of uploaded maps.
|
// Release a set of uploaded maps.
|
||||||
|
|||||||
@@ -1396,201 +1396,6 @@ func (s *Server) handleActionMapfixTriggerSubmitRequest(args [1]string, argsEsca
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleActionMapfixTriggerSubmitUncheckedRequest handles actionMapfixTriggerSubmitUnchecked operation.
|
|
||||||
//
|
|
||||||
// Role Reviewer changes status from ChangesRequested -> Submitting.
|
|
||||||
//
|
|
||||||
// POST /mapfixes/{MapfixID}/status/trigger-submit-unchecked
|
|
||||||
func (s *Server) handleActionMapfixTriggerSubmitUncheckedRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
||||||
statusWriter := &codeRecorder{ResponseWriter: w}
|
|
||||||
w = statusWriter
|
|
||||||
otelAttrs := []attribute.KeyValue{
|
|
||||||
otelogen.OperationID("actionMapfixTriggerSubmitUnchecked"),
|
|
||||||
semconv.HTTPRequestMethodKey.String("POST"),
|
|
||||||
semconv.HTTPRouteKey.String("/mapfixes/{MapfixID}/status/trigger-submit-unchecked"),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start a span for this request.
|
|
||||||
ctx, span := s.cfg.Tracer.Start(r.Context(), ActionMapfixTriggerSubmitUncheckedOperation,
|
|
||||||
trace.WithAttributes(otelAttrs...),
|
|
||||||
serverSpanKind,
|
|
||||||
)
|
|
||||||
defer span.End()
|
|
||||||
|
|
||||||
// Add Labeler to context.
|
|
||||||
labeler := &Labeler{attrs: otelAttrs}
|
|
||||||
ctx = contextWithLabeler(ctx, labeler)
|
|
||||||
|
|
||||||
// Run stopwatch.
|
|
||||||
startTime := time.Now()
|
|
||||||
defer func() {
|
|
||||||
elapsedDuration := time.Since(startTime)
|
|
||||||
|
|
||||||
attrSet := labeler.AttributeSet()
|
|
||||||
attrs := attrSet.ToSlice()
|
|
||||||
code := statusWriter.status
|
|
||||||
if code != 0 {
|
|
||||||
codeAttr := semconv.HTTPResponseStatusCode(code)
|
|
||||||
attrs = append(attrs, codeAttr)
|
|
||||||
span.SetAttributes(codeAttr)
|
|
||||||
}
|
|
||||||
attrOpt := metric.WithAttributes(attrs...)
|
|
||||||
|
|
||||||
// Increment request counter.
|
|
||||||
s.requests.Add(ctx, 1, attrOpt)
|
|
||||||
|
|
||||||
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
||||||
s.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), attrOpt)
|
|
||||||
}()
|
|
||||||
|
|
||||||
var (
|
|
||||||
recordError = func(stage string, err error) {
|
|
||||||
span.RecordError(err)
|
|
||||||
|
|
||||||
// https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status
|
|
||||||
// Span Status MUST be left unset if HTTP status code was in the 1xx, 2xx or 3xx ranges,
|
|
||||||
// unless there was another error (e.g., network error receiving the response body; or 3xx codes with
|
|
||||||
// max redirects exceeded), in which case status MUST be set to Error.
|
|
||||||
code := statusWriter.status
|
|
||||||
if code >= 100 && code < 500 {
|
|
||||||
span.SetStatus(codes.Error, stage)
|
|
||||||
}
|
|
||||||
|
|
||||||
attrSet := labeler.AttributeSet()
|
|
||||||
attrs := attrSet.ToSlice()
|
|
||||||
if code != 0 {
|
|
||||||
attrs = append(attrs, semconv.HTTPResponseStatusCode(code))
|
|
||||||
}
|
|
||||||
|
|
||||||
s.errors.Add(ctx, 1, metric.WithAttributes(attrs...))
|
|
||||||
}
|
|
||||||
err error
|
|
||||||
opErrContext = ogenerrors.OperationContext{
|
|
||||||
Name: ActionMapfixTriggerSubmitUncheckedOperation,
|
|
||||||
ID: "actionMapfixTriggerSubmitUnchecked",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
{
|
|
||||||
type bitset = [1]uint8
|
|
||||||
var satisfied bitset
|
|
||||||
{
|
|
||||||
sctx, ok, err := s.securityCookieAuth(ctx, ActionMapfixTriggerSubmitUncheckedOperation, r)
|
|
||||||
if err != nil {
|
|
||||||
err = &ogenerrors.SecurityError{
|
|
||||||
OperationContext: opErrContext,
|
|
||||||
Security: "CookieAuth",
|
|
||||||
Err: err,
|
|
||||||
}
|
|
||||||
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
|
|
||||||
defer recordError("Security:CookieAuth", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if ok {
|
|
||||||
satisfied[0] |= 1 << 0
|
|
||||||
ctx = sctx
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ok := func() bool {
|
|
||||||
nextRequirement:
|
|
||||||
for _, requirement := range []bitset{
|
|
||||||
{0b00000001},
|
|
||||||
} {
|
|
||||||
for i, mask := range requirement {
|
|
||||||
if satisfied[i]&mask != mask {
|
|
||||||
continue nextRequirement
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}(); !ok {
|
|
||||||
err = &ogenerrors.SecurityError{
|
|
||||||
OperationContext: opErrContext,
|
|
||||||
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
|
|
||||||
}
|
|
||||||
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
|
|
||||||
defer recordError("Security", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
params, err := decodeActionMapfixTriggerSubmitUncheckedParams(args, argsEscaped, r)
|
|
||||||
if err != nil {
|
|
||||||
err = &ogenerrors.DecodeParamsError{
|
|
||||||
OperationContext: opErrContext,
|
|
||||||
Err: err,
|
|
||||||
}
|
|
||||||
defer recordError("DecodeParams", err)
|
|
||||||
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var response *ActionMapfixTriggerSubmitUncheckedNoContent
|
|
||||||
if m := s.cfg.Middleware; m != nil {
|
|
||||||
mreq := middleware.Request{
|
|
||||||
Context: ctx,
|
|
||||||
OperationName: ActionMapfixTriggerSubmitUncheckedOperation,
|
|
||||||
OperationSummary: "Role Reviewer changes status from ChangesRequested -> Submitting",
|
|
||||||
OperationID: "actionMapfixTriggerSubmitUnchecked",
|
|
||||||
Body: nil,
|
|
||||||
Params: middleware.Parameters{
|
|
||||||
{
|
|
||||||
Name: "MapfixID",
|
|
||||||
In: "path",
|
|
||||||
}: params.MapfixID,
|
|
||||||
},
|
|
||||||
Raw: r,
|
|
||||||
}
|
|
||||||
|
|
||||||
type (
|
|
||||||
Request = struct{}
|
|
||||||
Params = ActionMapfixTriggerSubmitUncheckedParams
|
|
||||||
Response = *ActionMapfixTriggerSubmitUncheckedNoContent
|
|
||||||
)
|
|
||||||
response, err = middleware.HookMiddleware[
|
|
||||||
Request,
|
|
||||||
Params,
|
|
||||||
Response,
|
|
||||||
](
|
|
||||||
m,
|
|
||||||
mreq,
|
|
||||||
unpackActionMapfixTriggerSubmitUncheckedParams,
|
|
||||||
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
||||||
err = s.h.ActionMapfixTriggerSubmitUnchecked(ctx, params)
|
|
||||||
return response, err
|
|
||||||
},
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
err = s.h.ActionMapfixTriggerSubmitUnchecked(ctx, params)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
|
|
||||||
if err := encodeErrorResponse(errRes, w, span); err != nil {
|
|
||||||
defer recordError("Internal", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if errors.Is(err, ht.ErrNotImplemented) {
|
|
||||||
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
|
|
||||||
defer recordError("Internal", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := encodeActionMapfixTriggerSubmitUncheckedResponse(response, w, span); err != nil {
|
|
||||||
defer recordError("EncodeResponse", err)
|
|
||||||
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
||||||
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// handleActionMapfixTriggerUploadRequest handles actionMapfixTriggerUpload operation.
|
// handleActionMapfixTriggerUploadRequest handles actionMapfixTriggerUpload operation.
|
||||||
//
|
//
|
||||||
// Role Admin changes status from Validated -> Uploading.
|
// Role Admin changes status from Validated -> Uploading.
|
||||||
@@ -3542,201 +3347,6 @@ func (s *Server) handleActionSubmissionTriggerSubmitRequest(args [1]string, args
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleActionSubmissionTriggerSubmitUncheckedRequest handles actionSubmissionTriggerSubmitUnchecked operation.
|
|
||||||
//
|
|
||||||
// Role Reviewer changes status from ChangesRequested -> Submitting.
|
|
||||||
//
|
|
||||||
// POST /submissions/{SubmissionID}/status/trigger-submit-unchecked
|
|
||||||
func (s *Server) handleActionSubmissionTriggerSubmitUncheckedRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
||||||
statusWriter := &codeRecorder{ResponseWriter: w}
|
|
||||||
w = statusWriter
|
|
||||||
otelAttrs := []attribute.KeyValue{
|
|
||||||
otelogen.OperationID("actionSubmissionTriggerSubmitUnchecked"),
|
|
||||||
semconv.HTTPRequestMethodKey.String("POST"),
|
|
||||||
semconv.HTTPRouteKey.String("/submissions/{SubmissionID}/status/trigger-submit-unchecked"),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start a span for this request.
|
|
||||||
ctx, span := s.cfg.Tracer.Start(r.Context(), ActionSubmissionTriggerSubmitUncheckedOperation,
|
|
||||||
trace.WithAttributes(otelAttrs...),
|
|
||||||
serverSpanKind,
|
|
||||||
)
|
|
||||||
defer span.End()
|
|
||||||
|
|
||||||
// Add Labeler to context.
|
|
||||||
labeler := &Labeler{attrs: otelAttrs}
|
|
||||||
ctx = contextWithLabeler(ctx, labeler)
|
|
||||||
|
|
||||||
// Run stopwatch.
|
|
||||||
startTime := time.Now()
|
|
||||||
defer func() {
|
|
||||||
elapsedDuration := time.Since(startTime)
|
|
||||||
|
|
||||||
attrSet := labeler.AttributeSet()
|
|
||||||
attrs := attrSet.ToSlice()
|
|
||||||
code := statusWriter.status
|
|
||||||
if code != 0 {
|
|
||||||
codeAttr := semconv.HTTPResponseStatusCode(code)
|
|
||||||
attrs = append(attrs, codeAttr)
|
|
||||||
span.SetAttributes(codeAttr)
|
|
||||||
}
|
|
||||||
attrOpt := metric.WithAttributes(attrs...)
|
|
||||||
|
|
||||||
// Increment request counter.
|
|
||||||
s.requests.Add(ctx, 1, attrOpt)
|
|
||||||
|
|
||||||
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
||||||
s.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), attrOpt)
|
|
||||||
}()
|
|
||||||
|
|
||||||
var (
|
|
||||||
recordError = func(stage string, err error) {
|
|
||||||
span.RecordError(err)
|
|
||||||
|
|
||||||
// https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status
|
|
||||||
// Span Status MUST be left unset if HTTP status code was in the 1xx, 2xx or 3xx ranges,
|
|
||||||
// unless there was another error (e.g., network error receiving the response body; or 3xx codes with
|
|
||||||
// max redirects exceeded), in which case status MUST be set to Error.
|
|
||||||
code := statusWriter.status
|
|
||||||
if code >= 100 && code < 500 {
|
|
||||||
span.SetStatus(codes.Error, stage)
|
|
||||||
}
|
|
||||||
|
|
||||||
attrSet := labeler.AttributeSet()
|
|
||||||
attrs := attrSet.ToSlice()
|
|
||||||
if code != 0 {
|
|
||||||
attrs = append(attrs, semconv.HTTPResponseStatusCode(code))
|
|
||||||
}
|
|
||||||
|
|
||||||
s.errors.Add(ctx, 1, metric.WithAttributes(attrs...))
|
|
||||||
}
|
|
||||||
err error
|
|
||||||
opErrContext = ogenerrors.OperationContext{
|
|
||||||
Name: ActionSubmissionTriggerSubmitUncheckedOperation,
|
|
||||||
ID: "actionSubmissionTriggerSubmitUnchecked",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
{
|
|
||||||
type bitset = [1]uint8
|
|
||||||
var satisfied bitset
|
|
||||||
{
|
|
||||||
sctx, ok, err := s.securityCookieAuth(ctx, ActionSubmissionTriggerSubmitUncheckedOperation, r)
|
|
||||||
if err != nil {
|
|
||||||
err = &ogenerrors.SecurityError{
|
|
||||||
OperationContext: opErrContext,
|
|
||||||
Security: "CookieAuth",
|
|
||||||
Err: err,
|
|
||||||
}
|
|
||||||
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
|
|
||||||
defer recordError("Security:CookieAuth", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if ok {
|
|
||||||
satisfied[0] |= 1 << 0
|
|
||||||
ctx = sctx
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ok := func() bool {
|
|
||||||
nextRequirement:
|
|
||||||
for _, requirement := range []bitset{
|
|
||||||
{0b00000001},
|
|
||||||
} {
|
|
||||||
for i, mask := range requirement {
|
|
||||||
if satisfied[i]&mask != mask {
|
|
||||||
continue nextRequirement
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}(); !ok {
|
|
||||||
err = &ogenerrors.SecurityError{
|
|
||||||
OperationContext: opErrContext,
|
|
||||||
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
|
|
||||||
}
|
|
||||||
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
|
|
||||||
defer recordError("Security", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
params, err := decodeActionSubmissionTriggerSubmitUncheckedParams(args, argsEscaped, r)
|
|
||||||
if err != nil {
|
|
||||||
err = &ogenerrors.DecodeParamsError{
|
|
||||||
OperationContext: opErrContext,
|
|
||||||
Err: err,
|
|
||||||
}
|
|
||||||
defer recordError("DecodeParams", err)
|
|
||||||
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var response *ActionSubmissionTriggerSubmitUncheckedNoContent
|
|
||||||
if m := s.cfg.Middleware; m != nil {
|
|
||||||
mreq := middleware.Request{
|
|
||||||
Context: ctx,
|
|
||||||
OperationName: ActionSubmissionTriggerSubmitUncheckedOperation,
|
|
||||||
OperationSummary: "Role Reviewer changes status from ChangesRequested -> Submitting",
|
|
||||||
OperationID: "actionSubmissionTriggerSubmitUnchecked",
|
|
||||||
Body: nil,
|
|
||||||
Params: middleware.Parameters{
|
|
||||||
{
|
|
||||||
Name: "SubmissionID",
|
|
||||||
In: "path",
|
|
||||||
}: params.SubmissionID,
|
|
||||||
},
|
|
||||||
Raw: r,
|
|
||||||
}
|
|
||||||
|
|
||||||
type (
|
|
||||||
Request = struct{}
|
|
||||||
Params = ActionSubmissionTriggerSubmitUncheckedParams
|
|
||||||
Response = *ActionSubmissionTriggerSubmitUncheckedNoContent
|
|
||||||
)
|
|
||||||
response, err = middleware.HookMiddleware[
|
|
||||||
Request,
|
|
||||||
Params,
|
|
||||||
Response,
|
|
||||||
](
|
|
||||||
m,
|
|
||||||
mreq,
|
|
||||||
unpackActionSubmissionTriggerSubmitUncheckedParams,
|
|
||||||
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
||||||
err = s.h.ActionSubmissionTriggerSubmitUnchecked(ctx, params)
|
|
||||||
return response, err
|
|
||||||
},
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
err = s.h.ActionSubmissionTriggerSubmitUnchecked(ctx, params)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
|
|
||||||
if err := encodeErrorResponse(errRes, w, span); err != nil {
|
|
||||||
defer recordError("Internal", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if errors.Is(err, ht.ErrNotImplemented) {
|
|
||||||
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
|
|
||||||
defer recordError("Internal", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := encodeActionSubmissionTriggerSubmitUncheckedResponse(response, w, span); err != nil {
|
|
||||||
defer recordError("EncodeResponse", err)
|
|
||||||
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
||||||
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// handleActionSubmissionTriggerUploadRequest handles actionSubmissionTriggerUpload operation.
|
// handleActionSubmissionTriggerUploadRequest handles actionSubmissionTriggerUpload operation.
|
||||||
//
|
//
|
||||||
// Role Admin changes status from Validated -> Uploading.
|
// Role Admin changes status from Validated -> Uploading.
|
||||||
@@ -6107,201 +5717,6 @@ func (s *Server) handleDeleteScriptPolicyRequest(args [1]string, argsEscaped boo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleDownloadMapAssetRequest handles downloadMapAsset operation.
|
|
||||||
//
|
|
||||||
// Download the map asset.
|
|
||||||
//
|
|
||||||
// GET /maps/{MapID}/download
|
|
||||||
func (s *Server) handleDownloadMapAssetRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
||||||
statusWriter := &codeRecorder{ResponseWriter: w}
|
|
||||||
w = statusWriter
|
|
||||||
otelAttrs := []attribute.KeyValue{
|
|
||||||
otelogen.OperationID("downloadMapAsset"),
|
|
||||||
semconv.HTTPRequestMethodKey.String("GET"),
|
|
||||||
semconv.HTTPRouteKey.String("/maps/{MapID}/download"),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start a span for this request.
|
|
||||||
ctx, span := s.cfg.Tracer.Start(r.Context(), DownloadMapAssetOperation,
|
|
||||||
trace.WithAttributes(otelAttrs...),
|
|
||||||
serverSpanKind,
|
|
||||||
)
|
|
||||||
defer span.End()
|
|
||||||
|
|
||||||
// Add Labeler to context.
|
|
||||||
labeler := &Labeler{attrs: otelAttrs}
|
|
||||||
ctx = contextWithLabeler(ctx, labeler)
|
|
||||||
|
|
||||||
// Run stopwatch.
|
|
||||||
startTime := time.Now()
|
|
||||||
defer func() {
|
|
||||||
elapsedDuration := time.Since(startTime)
|
|
||||||
|
|
||||||
attrSet := labeler.AttributeSet()
|
|
||||||
attrs := attrSet.ToSlice()
|
|
||||||
code := statusWriter.status
|
|
||||||
if code != 0 {
|
|
||||||
codeAttr := semconv.HTTPResponseStatusCode(code)
|
|
||||||
attrs = append(attrs, codeAttr)
|
|
||||||
span.SetAttributes(codeAttr)
|
|
||||||
}
|
|
||||||
attrOpt := metric.WithAttributes(attrs...)
|
|
||||||
|
|
||||||
// Increment request counter.
|
|
||||||
s.requests.Add(ctx, 1, attrOpt)
|
|
||||||
|
|
||||||
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
||||||
s.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), attrOpt)
|
|
||||||
}()
|
|
||||||
|
|
||||||
var (
|
|
||||||
recordError = func(stage string, err error) {
|
|
||||||
span.RecordError(err)
|
|
||||||
|
|
||||||
// https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status
|
|
||||||
// Span Status MUST be left unset if HTTP status code was in the 1xx, 2xx or 3xx ranges,
|
|
||||||
// unless there was another error (e.g., network error receiving the response body; or 3xx codes with
|
|
||||||
// max redirects exceeded), in which case status MUST be set to Error.
|
|
||||||
code := statusWriter.status
|
|
||||||
if code >= 100 && code < 500 {
|
|
||||||
span.SetStatus(codes.Error, stage)
|
|
||||||
}
|
|
||||||
|
|
||||||
attrSet := labeler.AttributeSet()
|
|
||||||
attrs := attrSet.ToSlice()
|
|
||||||
if code != 0 {
|
|
||||||
attrs = append(attrs, semconv.HTTPResponseStatusCode(code))
|
|
||||||
}
|
|
||||||
|
|
||||||
s.errors.Add(ctx, 1, metric.WithAttributes(attrs...))
|
|
||||||
}
|
|
||||||
err error
|
|
||||||
opErrContext = ogenerrors.OperationContext{
|
|
||||||
Name: DownloadMapAssetOperation,
|
|
||||||
ID: "downloadMapAsset",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
{
|
|
||||||
type bitset = [1]uint8
|
|
||||||
var satisfied bitset
|
|
||||||
{
|
|
||||||
sctx, ok, err := s.securityCookieAuth(ctx, DownloadMapAssetOperation, r)
|
|
||||||
if err != nil {
|
|
||||||
err = &ogenerrors.SecurityError{
|
|
||||||
OperationContext: opErrContext,
|
|
||||||
Security: "CookieAuth",
|
|
||||||
Err: err,
|
|
||||||
}
|
|
||||||
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
|
|
||||||
defer recordError("Security:CookieAuth", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if ok {
|
|
||||||
satisfied[0] |= 1 << 0
|
|
||||||
ctx = sctx
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ok := func() bool {
|
|
||||||
nextRequirement:
|
|
||||||
for _, requirement := range []bitset{
|
|
||||||
{0b00000001},
|
|
||||||
} {
|
|
||||||
for i, mask := range requirement {
|
|
||||||
if satisfied[i]&mask != mask {
|
|
||||||
continue nextRequirement
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}(); !ok {
|
|
||||||
err = &ogenerrors.SecurityError{
|
|
||||||
OperationContext: opErrContext,
|
|
||||||
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
|
|
||||||
}
|
|
||||||
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
|
|
||||||
defer recordError("Security", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
params, err := decodeDownloadMapAssetParams(args, argsEscaped, r)
|
|
||||||
if err != nil {
|
|
||||||
err = &ogenerrors.DecodeParamsError{
|
|
||||||
OperationContext: opErrContext,
|
|
||||||
Err: err,
|
|
||||||
}
|
|
||||||
defer recordError("DecodeParams", err)
|
|
||||||
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var response DownloadMapAssetOK
|
|
||||||
if m := s.cfg.Middleware; m != nil {
|
|
||||||
mreq := middleware.Request{
|
|
||||||
Context: ctx,
|
|
||||||
OperationName: DownloadMapAssetOperation,
|
|
||||||
OperationSummary: "Download the map asset",
|
|
||||||
OperationID: "downloadMapAsset",
|
|
||||||
Body: nil,
|
|
||||||
Params: middleware.Parameters{
|
|
||||||
{
|
|
||||||
Name: "MapID",
|
|
||||||
In: "path",
|
|
||||||
}: params.MapID,
|
|
||||||
},
|
|
||||||
Raw: r,
|
|
||||||
}
|
|
||||||
|
|
||||||
type (
|
|
||||||
Request = struct{}
|
|
||||||
Params = DownloadMapAssetParams
|
|
||||||
Response = DownloadMapAssetOK
|
|
||||||
)
|
|
||||||
response, err = middleware.HookMiddleware[
|
|
||||||
Request,
|
|
||||||
Params,
|
|
||||||
Response,
|
|
||||||
](
|
|
||||||
m,
|
|
||||||
mreq,
|
|
||||||
unpackDownloadMapAssetParams,
|
|
||||||
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
||||||
response, err = s.h.DownloadMapAsset(ctx, params)
|
|
||||||
return response, err
|
|
||||||
},
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
response, err = s.h.DownloadMapAsset(ctx, params)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
|
|
||||||
if err := encodeErrorResponse(errRes, w, span); err != nil {
|
|
||||||
defer recordError("Internal", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if errors.Is(err, ht.ErrNotImplemented) {
|
|
||||||
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
|
|
||||||
defer recordError("Internal", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := encodeDownloadMapAssetResponse(response, w, span); err != nil {
|
|
||||||
defer recordError("EncodeResponse", err)
|
|
||||||
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
||||||
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// handleGetMapRequest handles getMap operation.
|
// handleGetMapRequest handles getMap operation.
|
||||||
//
|
//
|
||||||
// Retrieve map with ID.
|
// Retrieve map with ID.
|
||||||
@@ -8433,186 +7848,6 @@ func (s *Server) handleListSubmissionsRequest(args [0]string, argsEscaped bool,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleMigrateMapsRequest handles migrateMaps operation.
|
|
||||||
//
|
|
||||||
// Perform maps migration.
|
|
||||||
//
|
|
||||||
// POST /migrate-maps
|
|
||||||
func (s *Server) handleMigrateMapsRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
|
|
||||||
statusWriter := &codeRecorder{ResponseWriter: w}
|
|
||||||
w = statusWriter
|
|
||||||
otelAttrs := []attribute.KeyValue{
|
|
||||||
otelogen.OperationID("migrateMaps"),
|
|
||||||
semconv.HTTPRequestMethodKey.String("POST"),
|
|
||||||
semconv.HTTPRouteKey.String("/migrate-maps"),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start a span for this request.
|
|
||||||
ctx, span := s.cfg.Tracer.Start(r.Context(), MigrateMapsOperation,
|
|
||||||
trace.WithAttributes(otelAttrs...),
|
|
||||||
serverSpanKind,
|
|
||||||
)
|
|
||||||
defer span.End()
|
|
||||||
|
|
||||||
// Add Labeler to context.
|
|
||||||
labeler := &Labeler{attrs: otelAttrs}
|
|
||||||
ctx = contextWithLabeler(ctx, labeler)
|
|
||||||
|
|
||||||
// Run stopwatch.
|
|
||||||
startTime := time.Now()
|
|
||||||
defer func() {
|
|
||||||
elapsedDuration := time.Since(startTime)
|
|
||||||
|
|
||||||
attrSet := labeler.AttributeSet()
|
|
||||||
attrs := attrSet.ToSlice()
|
|
||||||
code := statusWriter.status
|
|
||||||
if code != 0 {
|
|
||||||
codeAttr := semconv.HTTPResponseStatusCode(code)
|
|
||||||
attrs = append(attrs, codeAttr)
|
|
||||||
span.SetAttributes(codeAttr)
|
|
||||||
}
|
|
||||||
attrOpt := metric.WithAttributes(attrs...)
|
|
||||||
|
|
||||||
// Increment request counter.
|
|
||||||
s.requests.Add(ctx, 1, attrOpt)
|
|
||||||
|
|
||||||
// Use floating point division here for higher precision (instead of Millisecond method).
|
|
||||||
s.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), attrOpt)
|
|
||||||
}()
|
|
||||||
|
|
||||||
var (
|
|
||||||
recordError = func(stage string, err error) {
|
|
||||||
span.RecordError(err)
|
|
||||||
|
|
||||||
// https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status
|
|
||||||
// Span Status MUST be left unset if HTTP status code was in the 1xx, 2xx or 3xx ranges,
|
|
||||||
// unless there was another error (e.g., network error receiving the response body; or 3xx codes with
|
|
||||||
// max redirects exceeded), in which case status MUST be set to Error.
|
|
||||||
code := statusWriter.status
|
|
||||||
if code >= 100 && code < 500 {
|
|
||||||
span.SetStatus(codes.Error, stage)
|
|
||||||
}
|
|
||||||
|
|
||||||
attrSet := labeler.AttributeSet()
|
|
||||||
attrs := attrSet.ToSlice()
|
|
||||||
if code != 0 {
|
|
||||||
attrs = append(attrs, semconv.HTTPResponseStatusCode(code))
|
|
||||||
}
|
|
||||||
|
|
||||||
s.errors.Add(ctx, 1, metric.WithAttributes(attrs...))
|
|
||||||
}
|
|
||||||
err error
|
|
||||||
opErrContext = ogenerrors.OperationContext{
|
|
||||||
Name: MigrateMapsOperation,
|
|
||||||
ID: "migrateMaps",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
{
|
|
||||||
type bitset = [1]uint8
|
|
||||||
var satisfied bitset
|
|
||||||
{
|
|
||||||
sctx, ok, err := s.securityCookieAuth(ctx, MigrateMapsOperation, r)
|
|
||||||
if err != nil {
|
|
||||||
err = &ogenerrors.SecurityError{
|
|
||||||
OperationContext: opErrContext,
|
|
||||||
Security: "CookieAuth",
|
|
||||||
Err: err,
|
|
||||||
}
|
|
||||||
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
|
|
||||||
defer recordError("Security:CookieAuth", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if ok {
|
|
||||||
satisfied[0] |= 1 << 0
|
|
||||||
ctx = sctx
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ok := func() bool {
|
|
||||||
nextRequirement:
|
|
||||||
for _, requirement := range []bitset{
|
|
||||||
{0b00000001},
|
|
||||||
} {
|
|
||||||
for i, mask := range requirement {
|
|
||||||
if satisfied[i]&mask != mask {
|
|
||||||
continue nextRequirement
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}(); !ok {
|
|
||||||
err = &ogenerrors.SecurityError{
|
|
||||||
OperationContext: opErrContext,
|
|
||||||
Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied,
|
|
||||||
}
|
|
||||||
if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil {
|
|
||||||
defer recordError("Security", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var response *MigrateMapsOK
|
|
||||||
if m := s.cfg.Middleware; m != nil {
|
|
||||||
mreq := middleware.Request{
|
|
||||||
Context: ctx,
|
|
||||||
OperationName: MigrateMapsOperation,
|
|
||||||
OperationSummary: "Perform maps migration",
|
|
||||||
OperationID: "migrateMaps",
|
|
||||||
Body: nil,
|
|
||||||
Params: middleware.Parameters{},
|
|
||||||
Raw: r,
|
|
||||||
}
|
|
||||||
|
|
||||||
type (
|
|
||||||
Request = struct{}
|
|
||||||
Params = struct{}
|
|
||||||
Response = *MigrateMapsOK
|
|
||||||
)
|
|
||||||
response, err = middleware.HookMiddleware[
|
|
||||||
Request,
|
|
||||||
Params,
|
|
||||||
Response,
|
|
||||||
](
|
|
||||||
m,
|
|
||||||
mreq,
|
|
||||||
nil,
|
|
||||||
func(ctx context.Context, request Request, params Params) (response Response, err error) {
|
|
||||||
err = s.h.MigrateMaps(ctx)
|
|
||||||
return response, err
|
|
||||||
},
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
err = s.h.MigrateMaps(ctx)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
if errRes, ok := errors.Into[*ErrorStatusCode](err); ok {
|
|
||||||
if err := encodeErrorResponse(errRes, w, span); err != nil {
|
|
||||||
defer recordError("Internal", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if errors.Is(err, ht.ErrNotImplemented) {
|
|
||||||
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil {
|
|
||||||
defer recordError("Internal", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := encodeMigrateMapsResponse(response, w, span); err != nil {
|
|
||||||
defer recordError("EncodeResponse", err)
|
|
||||||
if !errors.Is(err, ht.ErrInternalServerErrorResponse) {
|
|
||||||
s.cfg.ErrorHandler(ctx, w, r, err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// handleReleaseSubmissionsRequest handles releaseSubmissions operation.
|
// handleReleaseSubmissionsRequest handles releaseSubmissions operation.
|
||||||
//
|
//
|
||||||
// Release a set of uploaded maps.
|
// Release a set of uploaded maps.
|
||||||
|
|||||||
@@ -6,60 +6,56 @@ package api
|
|||||||
type OperationName = string
|
type OperationName = string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ActionMapfixAcceptedOperation OperationName = "ActionMapfixAccepted"
|
ActionMapfixAcceptedOperation OperationName = "ActionMapfixAccepted"
|
||||||
ActionMapfixRejectOperation OperationName = "ActionMapfixReject"
|
ActionMapfixRejectOperation OperationName = "ActionMapfixReject"
|
||||||
ActionMapfixRequestChangesOperation OperationName = "ActionMapfixRequestChanges"
|
ActionMapfixRequestChangesOperation OperationName = "ActionMapfixRequestChanges"
|
||||||
ActionMapfixResetSubmittingOperation OperationName = "ActionMapfixResetSubmitting"
|
ActionMapfixResetSubmittingOperation OperationName = "ActionMapfixResetSubmitting"
|
||||||
ActionMapfixRetryValidateOperation OperationName = "ActionMapfixRetryValidate"
|
ActionMapfixRetryValidateOperation OperationName = "ActionMapfixRetryValidate"
|
||||||
ActionMapfixRevokeOperation OperationName = "ActionMapfixRevoke"
|
ActionMapfixRevokeOperation OperationName = "ActionMapfixRevoke"
|
||||||
ActionMapfixTriggerSubmitOperation OperationName = "ActionMapfixTriggerSubmit"
|
ActionMapfixTriggerSubmitOperation OperationName = "ActionMapfixTriggerSubmit"
|
||||||
ActionMapfixTriggerSubmitUncheckedOperation OperationName = "ActionMapfixTriggerSubmitUnchecked"
|
ActionMapfixTriggerUploadOperation OperationName = "ActionMapfixTriggerUpload"
|
||||||
ActionMapfixTriggerUploadOperation OperationName = "ActionMapfixTriggerUpload"
|
ActionMapfixTriggerValidateOperation OperationName = "ActionMapfixTriggerValidate"
|
||||||
ActionMapfixTriggerValidateOperation OperationName = "ActionMapfixTriggerValidate"
|
ActionMapfixValidatedOperation OperationName = "ActionMapfixValidated"
|
||||||
ActionMapfixValidatedOperation OperationName = "ActionMapfixValidated"
|
ActionSubmissionAcceptedOperation OperationName = "ActionSubmissionAccepted"
|
||||||
ActionSubmissionAcceptedOperation OperationName = "ActionSubmissionAccepted"
|
ActionSubmissionRejectOperation OperationName = "ActionSubmissionReject"
|
||||||
ActionSubmissionRejectOperation OperationName = "ActionSubmissionReject"
|
ActionSubmissionRequestChangesOperation OperationName = "ActionSubmissionRequestChanges"
|
||||||
ActionSubmissionRequestChangesOperation OperationName = "ActionSubmissionRequestChanges"
|
ActionSubmissionResetSubmittingOperation OperationName = "ActionSubmissionResetSubmitting"
|
||||||
ActionSubmissionResetSubmittingOperation OperationName = "ActionSubmissionResetSubmitting"
|
ActionSubmissionRetryValidateOperation OperationName = "ActionSubmissionRetryValidate"
|
||||||
ActionSubmissionRetryValidateOperation OperationName = "ActionSubmissionRetryValidate"
|
ActionSubmissionRevokeOperation OperationName = "ActionSubmissionRevoke"
|
||||||
ActionSubmissionRevokeOperation OperationName = "ActionSubmissionRevoke"
|
ActionSubmissionTriggerSubmitOperation OperationName = "ActionSubmissionTriggerSubmit"
|
||||||
ActionSubmissionTriggerSubmitOperation OperationName = "ActionSubmissionTriggerSubmit"
|
ActionSubmissionTriggerUploadOperation OperationName = "ActionSubmissionTriggerUpload"
|
||||||
ActionSubmissionTriggerSubmitUncheckedOperation OperationName = "ActionSubmissionTriggerSubmitUnchecked"
|
ActionSubmissionTriggerValidateOperation OperationName = "ActionSubmissionTriggerValidate"
|
||||||
ActionSubmissionTriggerUploadOperation OperationName = "ActionSubmissionTriggerUpload"
|
ActionSubmissionValidatedOperation OperationName = "ActionSubmissionValidated"
|
||||||
ActionSubmissionTriggerValidateOperation OperationName = "ActionSubmissionTriggerValidate"
|
CreateMapfixOperation OperationName = "CreateMapfix"
|
||||||
ActionSubmissionValidatedOperation OperationName = "ActionSubmissionValidated"
|
CreateMapfixAuditCommentOperation OperationName = "CreateMapfixAuditComment"
|
||||||
CreateMapfixOperation OperationName = "CreateMapfix"
|
CreateScriptOperation OperationName = "CreateScript"
|
||||||
CreateMapfixAuditCommentOperation OperationName = "CreateMapfixAuditComment"
|
CreateScriptPolicyOperation OperationName = "CreateScriptPolicy"
|
||||||
CreateScriptOperation OperationName = "CreateScript"
|
CreateSubmissionOperation OperationName = "CreateSubmission"
|
||||||
CreateScriptPolicyOperation OperationName = "CreateScriptPolicy"
|
CreateSubmissionAdminOperation OperationName = "CreateSubmissionAdmin"
|
||||||
CreateSubmissionOperation OperationName = "CreateSubmission"
|
CreateSubmissionAuditCommentOperation OperationName = "CreateSubmissionAuditComment"
|
||||||
CreateSubmissionAdminOperation OperationName = "CreateSubmissionAdmin"
|
DeleteScriptOperation OperationName = "DeleteScript"
|
||||||
CreateSubmissionAuditCommentOperation OperationName = "CreateSubmissionAuditComment"
|
DeleteScriptPolicyOperation OperationName = "DeleteScriptPolicy"
|
||||||
DeleteScriptOperation OperationName = "DeleteScript"
|
GetMapOperation OperationName = "GetMap"
|
||||||
DeleteScriptPolicyOperation OperationName = "DeleteScriptPolicy"
|
GetMapfixOperation OperationName = "GetMapfix"
|
||||||
DownloadMapAssetOperation OperationName = "DownloadMapAsset"
|
GetOperationOperation OperationName = "GetOperation"
|
||||||
GetMapOperation OperationName = "GetMap"
|
GetScriptOperation OperationName = "GetScript"
|
||||||
GetMapfixOperation OperationName = "GetMapfix"
|
GetScriptPolicyOperation OperationName = "GetScriptPolicy"
|
||||||
GetOperationOperation OperationName = "GetOperation"
|
GetSubmissionOperation OperationName = "GetSubmission"
|
||||||
GetScriptOperation OperationName = "GetScript"
|
ListMapfixAuditEventsOperation OperationName = "ListMapfixAuditEvents"
|
||||||
GetScriptPolicyOperation OperationName = "GetScriptPolicy"
|
ListMapfixesOperation OperationName = "ListMapfixes"
|
||||||
GetSubmissionOperation OperationName = "GetSubmission"
|
ListMapsOperation OperationName = "ListMaps"
|
||||||
ListMapfixAuditEventsOperation OperationName = "ListMapfixAuditEvents"
|
ListScriptPolicyOperation OperationName = "ListScriptPolicy"
|
||||||
ListMapfixesOperation OperationName = "ListMapfixes"
|
ListScriptsOperation OperationName = "ListScripts"
|
||||||
ListMapsOperation OperationName = "ListMaps"
|
ListSubmissionAuditEventsOperation OperationName = "ListSubmissionAuditEvents"
|
||||||
ListScriptPolicyOperation OperationName = "ListScriptPolicy"
|
ListSubmissionsOperation OperationName = "ListSubmissions"
|
||||||
ListScriptsOperation OperationName = "ListScripts"
|
ReleaseSubmissionsOperation OperationName = "ReleaseSubmissions"
|
||||||
ListSubmissionAuditEventsOperation OperationName = "ListSubmissionAuditEvents"
|
SessionRolesOperation OperationName = "SessionRoles"
|
||||||
ListSubmissionsOperation OperationName = "ListSubmissions"
|
SessionUserOperation OperationName = "SessionUser"
|
||||||
MigrateMapsOperation OperationName = "MigrateMaps"
|
SessionValidateOperation OperationName = "SessionValidate"
|
||||||
ReleaseSubmissionsOperation OperationName = "ReleaseSubmissions"
|
SetMapfixCompletedOperation OperationName = "SetMapfixCompleted"
|
||||||
SessionRolesOperation OperationName = "SessionRoles"
|
SetSubmissionCompletedOperation OperationName = "SetSubmissionCompleted"
|
||||||
SessionUserOperation OperationName = "SessionUser"
|
UpdateMapfixModelOperation OperationName = "UpdateMapfixModel"
|
||||||
SessionValidateOperation OperationName = "SessionValidate"
|
UpdateScriptOperation OperationName = "UpdateScript"
|
||||||
SetMapfixCompletedOperation OperationName = "SetMapfixCompleted"
|
UpdateScriptPolicyOperation OperationName = "UpdateScriptPolicy"
|
||||||
SetSubmissionCompletedOperation OperationName = "SetSubmissionCompleted"
|
UpdateSubmissionModelOperation OperationName = "UpdateSubmissionModel"
|
||||||
UpdateMapfixModelOperation OperationName = "UpdateMapfixModel"
|
|
||||||
UpdateScriptOperation OperationName = "UpdateScript"
|
|
||||||
UpdateScriptPolicyOperation OperationName = "UpdateScriptPolicy"
|
|
||||||
UpdateSubmissionModelOperation OperationName = "UpdateSubmissionModel"
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -596,89 +596,6 @@ func decodeActionMapfixTriggerSubmitParams(args [1]string, argsEscaped bool, r *
|
|||||||
return params, nil
|
return params, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActionMapfixTriggerSubmitUncheckedParams is parameters of actionMapfixTriggerSubmitUnchecked operation.
|
|
||||||
type ActionMapfixTriggerSubmitUncheckedParams struct {
|
|
||||||
// The unique identifier for a mapfix.
|
|
||||||
MapfixID int64
|
|
||||||
}
|
|
||||||
|
|
||||||
func unpackActionMapfixTriggerSubmitUncheckedParams(packed middleware.Parameters) (params ActionMapfixTriggerSubmitUncheckedParams) {
|
|
||||||
{
|
|
||||||
key := middleware.ParameterKey{
|
|
||||||
Name: "MapfixID",
|
|
||||||
In: "path",
|
|
||||||
}
|
|
||||||
params.MapfixID = packed[key].(int64)
|
|
||||||
}
|
|
||||||
return params
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeActionMapfixTriggerSubmitUncheckedParams(args [1]string, argsEscaped bool, r *http.Request) (params ActionMapfixTriggerSubmitUncheckedParams, _ error) {
|
|
||||||
// Decode path: MapfixID.
|
|
||||||
if err := func() error {
|
|
||||||
param := args[0]
|
|
||||||
if argsEscaped {
|
|
||||||
unescaped, err := url.PathUnescape(args[0])
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "unescape path")
|
|
||||||
}
|
|
||||||
param = unescaped
|
|
||||||
}
|
|
||||||
if len(param) > 0 {
|
|
||||||
d := uri.NewPathDecoder(uri.PathDecoderConfig{
|
|
||||||
Param: "MapfixID",
|
|
||||||
Value: param,
|
|
||||||
Style: uri.PathStyleSimple,
|
|
||||||
Explode: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err := func() error {
|
|
||||||
val, err := d.DecodeValue()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
c, err := conv.ToInt64(val)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
params.MapfixID = c
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := func() error {
|
|
||||||
if err := (validate.Int{
|
|
||||||
MinSet: true,
|
|
||||||
Min: 0,
|
|
||||||
MaxSet: false,
|
|
||||||
Max: 0,
|
|
||||||
MinExclusive: false,
|
|
||||||
MaxExclusive: false,
|
|
||||||
MultipleOfSet: false,
|
|
||||||
MultipleOf: 0,
|
|
||||||
}).Validate(int64(params.MapfixID)); err != nil {
|
|
||||||
return errors.Wrap(err, "int")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return validate.ErrFieldRequired
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
return params, &ogenerrors.DecodeParamError{
|
|
||||||
Name: "MapfixID",
|
|
||||||
In: "path",
|
|
||||||
Err: err,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return params, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionMapfixTriggerUploadParams is parameters of actionMapfixTriggerUpload operation.
|
// ActionMapfixTriggerUploadParams is parameters of actionMapfixTriggerUpload operation.
|
||||||
type ActionMapfixTriggerUploadParams struct {
|
type ActionMapfixTriggerUploadParams struct {
|
||||||
// The unique identifier for a mapfix.
|
// The unique identifier for a mapfix.
|
||||||
@@ -1509,89 +1426,6 @@ func decodeActionSubmissionTriggerSubmitParams(args [1]string, argsEscaped bool,
|
|||||||
return params, nil
|
return params, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActionSubmissionTriggerSubmitUncheckedParams is parameters of actionSubmissionTriggerSubmitUnchecked operation.
|
|
||||||
type ActionSubmissionTriggerSubmitUncheckedParams struct {
|
|
||||||
// The unique identifier for a submission.
|
|
||||||
SubmissionID int64
|
|
||||||
}
|
|
||||||
|
|
||||||
func unpackActionSubmissionTriggerSubmitUncheckedParams(packed middleware.Parameters) (params ActionSubmissionTriggerSubmitUncheckedParams) {
|
|
||||||
{
|
|
||||||
key := middleware.ParameterKey{
|
|
||||||
Name: "SubmissionID",
|
|
||||||
In: "path",
|
|
||||||
}
|
|
||||||
params.SubmissionID = packed[key].(int64)
|
|
||||||
}
|
|
||||||
return params
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeActionSubmissionTriggerSubmitUncheckedParams(args [1]string, argsEscaped bool, r *http.Request) (params ActionSubmissionTriggerSubmitUncheckedParams, _ error) {
|
|
||||||
// Decode path: SubmissionID.
|
|
||||||
if err := func() error {
|
|
||||||
param := args[0]
|
|
||||||
if argsEscaped {
|
|
||||||
unescaped, err := url.PathUnescape(args[0])
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "unescape path")
|
|
||||||
}
|
|
||||||
param = unescaped
|
|
||||||
}
|
|
||||||
if len(param) > 0 {
|
|
||||||
d := uri.NewPathDecoder(uri.PathDecoderConfig{
|
|
||||||
Param: "SubmissionID",
|
|
||||||
Value: param,
|
|
||||||
Style: uri.PathStyleSimple,
|
|
||||||
Explode: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err := func() error {
|
|
||||||
val, err := d.DecodeValue()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
c, err := conv.ToInt64(val)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
params.SubmissionID = c
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := func() error {
|
|
||||||
if err := (validate.Int{
|
|
||||||
MinSet: true,
|
|
||||||
Min: 0,
|
|
||||||
MaxSet: false,
|
|
||||||
Max: 0,
|
|
||||||
MinExclusive: false,
|
|
||||||
MaxExclusive: false,
|
|
||||||
MultipleOfSet: false,
|
|
||||||
MultipleOf: 0,
|
|
||||||
}).Validate(int64(params.SubmissionID)); err != nil {
|
|
||||||
return errors.Wrap(err, "int")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return validate.ErrFieldRequired
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
return params, &ogenerrors.DecodeParamError{
|
|
||||||
Name: "SubmissionID",
|
|
||||||
In: "path",
|
|
||||||
Err: err,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return params, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionSubmissionTriggerUploadParams is parameters of actionSubmissionTriggerUpload operation.
|
// ActionSubmissionTriggerUploadParams is parameters of actionSubmissionTriggerUpload operation.
|
||||||
type ActionSubmissionTriggerUploadParams struct {
|
type ActionSubmissionTriggerUploadParams struct {
|
||||||
// The unique identifier for a submission.
|
// The unique identifier for a submission.
|
||||||
@@ -2173,88 +2007,6 @@ func decodeDeleteScriptPolicyParams(args [1]string, argsEscaped bool, r *http.Re
|
|||||||
return params, nil
|
return params, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownloadMapAssetParams is parameters of downloadMapAsset operation.
|
|
||||||
type DownloadMapAssetParams struct {
|
|
||||||
MapID int64
|
|
||||||
}
|
|
||||||
|
|
||||||
func unpackDownloadMapAssetParams(packed middleware.Parameters) (params DownloadMapAssetParams) {
|
|
||||||
{
|
|
||||||
key := middleware.ParameterKey{
|
|
||||||
Name: "MapID",
|
|
||||||
In: "path",
|
|
||||||
}
|
|
||||||
params.MapID = packed[key].(int64)
|
|
||||||
}
|
|
||||||
return params
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeDownloadMapAssetParams(args [1]string, argsEscaped bool, r *http.Request) (params DownloadMapAssetParams, _ error) {
|
|
||||||
// Decode path: MapID.
|
|
||||||
if err := func() error {
|
|
||||||
param := args[0]
|
|
||||||
if argsEscaped {
|
|
||||||
unescaped, err := url.PathUnescape(args[0])
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "unescape path")
|
|
||||||
}
|
|
||||||
param = unescaped
|
|
||||||
}
|
|
||||||
if len(param) > 0 {
|
|
||||||
d := uri.NewPathDecoder(uri.PathDecoderConfig{
|
|
||||||
Param: "MapID",
|
|
||||||
Value: param,
|
|
||||||
Style: uri.PathStyleSimple,
|
|
||||||
Explode: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err := func() error {
|
|
||||||
val, err := d.DecodeValue()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
c, err := conv.ToInt64(val)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
params.MapID = c
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := func() error {
|
|
||||||
if err := (validate.Int{
|
|
||||||
MinSet: true,
|
|
||||||
Min: 0,
|
|
||||||
MaxSet: false,
|
|
||||||
Max: 0,
|
|
||||||
MinExclusive: false,
|
|
||||||
MaxExclusive: false,
|
|
||||||
MultipleOfSet: false,
|
|
||||||
MultipleOf: 0,
|
|
||||||
}).Validate(int64(params.MapID)); err != nil {
|
|
||||||
return errors.Wrap(err, "int")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return validate.ErrFieldRequired
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
return params, &ogenerrors.DecodeParamError{
|
|
||||||
Name: "MapID",
|
|
||||||
In: "path",
|
|
||||||
Err: err,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return params, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMapParams is parameters of getMap operation.
|
// GetMapParams is parameters of getMap operation.
|
||||||
type GetMapParams struct {
|
type GetMapParams struct {
|
||||||
// The unique identifier for a map.
|
// The unique identifier for a map.
|
||||||
@@ -2961,25 +2713,16 @@ func decodeListMapfixAuditEventsParams(args [1]string, argsEscaped bool, r *http
|
|||||||
|
|
||||||
// ListMapfixesParams is parameters of listMapfixes operation.
|
// ListMapfixesParams is parameters of listMapfixes operation.
|
||||||
type ListMapfixesParams struct {
|
type ListMapfixesParams struct {
|
||||||
Page int32
|
Page int32
|
||||||
Limit int32
|
Limit int32
|
||||||
DisplayName OptString
|
DisplayName OptString
|
||||||
Creator OptString
|
Creator OptString
|
||||||
// Game ID: * `1` - Bhop * `2` - Surf * `5` - FlyTrials.
|
GameID OptInt32
|
||||||
GameID OptInt32
|
|
||||||
// Sort order: * `0` - Disabled * `1` - DisplayNameAscending * `2` - DisplayNameDescending * `3` -
|
|
||||||
// DateAscending * `4` - DateDescending.
|
|
||||||
Sort OptInt32
|
Sort OptInt32
|
||||||
Submitter OptInt64
|
Submitter OptInt64
|
||||||
AssetID OptInt64
|
AssetID OptInt64
|
||||||
TargetAssetID OptInt64
|
TargetAssetID OptInt64
|
||||||
// // Phase: Creation * `0` - UnderConstruction * `1` - ChangesRequested
|
StatusID OptInt32
|
||||||
// // Phase: Review * `2` - Submitting * `3` - Submitted
|
|
||||||
// // Phase: Testing * `4` - AcceptedUnvalidated // pending script review, can re-trigger validation
|
|
||||||
// * `5` - Validating * `6` - Validated * `7` - Uploading
|
|
||||||
// // Phase: Final MapfixStatus * `8` - Uploaded // uploaded to the group, but pending release * `9`
|
|
||||||
// - Rejected.
|
|
||||||
StatusID OptInt32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func unpackListMapfixesParams(packed middleware.Parameters) (params ListMapfixesParams) {
|
func unpackListMapfixesParams(packed middleware.Parameters) (params ListMapfixesParams) {
|
||||||
@@ -3708,9 +3451,7 @@ type ListMapsParams struct {
|
|||||||
DisplayName OptString
|
DisplayName OptString
|
||||||
Creator OptString
|
Creator OptString
|
||||||
GameID OptInt32
|
GameID OptInt32
|
||||||
// Sort order: * `0` - Disabled * `1` - DisplayNameAscending * `2` - DisplayNameDescending * `3` -
|
Sort OptInt32
|
||||||
// DateAscending * `4` - DateDescending.
|
|
||||||
Sort OptInt32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func unpackListMapsParams(packed middleware.Parameters) (params ListMapsParams) {
|
func unpackListMapsParams(packed middleware.Parameters) (params ListMapsParams) {
|
||||||
@@ -5210,25 +4951,16 @@ func decodeListSubmissionAuditEventsParams(args [1]string, argsEscaped bool, r *
|
|||||||
|
|
||||||
// ListSubmissionsParams is parameters of listSubmissions operation.
|
// ListSubmissionsParams is parameters of listSubmissions operation.
|
||||||
type ListSubmissionsParams struct {
|
type ListSubmissionsParams struct {
|
||||||
Page int32
|
Page int32
|
||||||
Limit int32
|
Limit int32
|
||||||
DisplayName OptString
|
DisplayName OptString
|
||||||
Creator OptString
|
Creator OptString
|
||||||
// Game ID: * `1` - Bhop * `2` - Surf * `5` - FlyTrials.
|
GameID OptInt32
|
||||||
GameID OptInt32
|
|
||||||
// Sort order: * `0` - Disabled * `1` - DisplayNameAscending * `2` - DisplayNameDescending * `3` -
|
|
||||||
// DateAscending * `4` - DateDescending.
|
|
||||||
Sort OptInt32
|
Sort OptInt32
|
||||||
Submitter OptInt64
|
Submitter OptInt64
|
||||||
AssetID OptInt64
|
AssetID OptInt64
|
||||||
UploadedAssetID OptInt64
|
UploadedAssetID OptInt64
|
||||||
// // Phase: Creation * `0` - UnderConstruction * `1` - ChangesRequested
|
StatusID OptInt32
|
||||||
// // Phase: Review * `2` - Submitting * `3` - Submitted
|
|
||||||
// // Phase: Testing * `4` - AcceptedUnvalidated // pending script review, can re-trigger validation
|
|
||||||
// * `5` - Validating * `6` - Validated * `7` - Uploading * `8` - Uploaded // uploaded to the group,
|
|
||||||
// but pending release
|
|
||||||
// // Phase: Final SubmissionStatus * `9` - Rejected * `10` - Released.
|
|
||||||
StatusID OptInt32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func unpackListSubmissionsParams(packed middleware.Parameters) (params ListSubmissionsParams) {
|
func unpackListSubmissionsParams(packed middleware.Parameters) (params ListSubmissionsParams) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/go-faster/errors"
|
"github.com/go-faster/errors"
|
||||||
"github.com/go-faster/jx"
|
"github.com/go-faster/jx"
|
||||||
|
"go.uber.org/multierr"
|
||||||
|
|
||||||
"github.com/ogen-go/ogen/ogenerrors"
|
"github.com/ogen-go/ogen/ogenerrors"
|
||||||
"github.com/ogen-go/ogen/validate"
|
"github.com/ogen-go/ogen/validate"
|
||||||
@@ -26,13 +27,13 @@ func (s *Server) decodeCreateMapfixRequest(r *http.Request) (
|
|||||||
// Close in reverse order, to match defer behavior.
|
// Close in reverse order, to match defer behavior.
|
||||||
for i := len(closers) - 1; i >= 0; i-- {
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
c := closers[i]
|
c := closers[i]
|
||||||
merr = errors.Join(merr, c())
|
merr = multierr.Append(merr, c())
|
||||||
}
|
}
|
||||||
return merr
|
return merr
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
rerr = errors.Join(rerr, close())
|
rerr = multierr.Append(rerr, close())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
@@ -97,13 +98,13 @@ func (s *Server) decodeCreateMapfixAuditCommentRequest(r *http.Request) (
|
|||||||
// Close in reverse order, to match defer behavior.
|
// Close in reverse order, to match defer behavior.
|
||||||
for i := len(closers) - 1; i >= 0; i-- {
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
c := closers[i]
|
c := closers[i]
|
||||||
merr = errors.Join(merr, c())
|
merr = multierr.Append(merr, c())
|
||||||
}
|
}
|
||||||
return merr
|
return merr
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
rerr = errors.Join(rerr, close())
|
rerr = multierr.Append(rerr, close())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
@@ -131,13 +132,13 @@ func (s *Server) decodeCreateScriptRequest(r *http.Request) (
|
|||||||
// Close in reverse order, to match defer behavior.
|
// Close in reverse order, to match defer behavior.
|
||||||
for i := len(closers) - 1; i >= 0; i-- {
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
c := closers[i]
|
c := closers[i]
|
||||||
merr = errors.Join(merr, c())
|
merr = multierr.Append(merr, c())
|
||||||
}
|
}
|
||||||
return merr
|
return merr
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
rerr = errors.Join(rerr, close())
|
rerr = multierr.Append(rerr, close())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
@@ -202,13 +203,13 @@ func (s *Server) decodeCreateScriptPolicyRequest(r *http.Request) (
|
|||||||
// Close in reverse order, to match defer behavior.
|
// Close in reverse order, to match defer behavior.
|
||||||
for i := len(closers) - 1; i >= 0; i-- {
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
c := closers[i]
|
c := closers[i]
|
||||||
merr = errors.Join(merr, c())
|
merr = multierr.Append(merr, c())
|
||||||
}
|
}
|
||||||
return merr
|
return merr
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
rerr = errors.Join(rerr, close())
|
rerr = multierr.Append(rerr, close())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
@@ -273,13 +274,13 @@ func (s *Server) decodeCreateSubmissionRequest(r *http.Request) (
|
|||||||
// Close in reverse order, to match defer behavior.
|
// Close in reverse order, to match defer behavior.
|
||||||
for i := len(closers) - 1; i >= 0; i-- {
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
c := closers[i]
|
c := closers[i]
|
||||||
merr = errors.Join(merr, c())
|
merr = multierr.Append(merr, c())
|
||||||
}
|
}
|
||||||
return merr
|
return merr
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
rerr = errors.Join(rerr, close())
|
rerr = multierr.Append(rerr, close())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
@@ -344,13 +345,13 @@ func (s *Server) decodeCreateSubmissionAdminRequest(r *http.Request) (
|
|||||||
// Close in reverse order, to match defer behavior.
|
// Close in reverse order, to match defer behavior.
|
||||||
for i := len(closers) - 1; i >= 0; i-- {
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
c := closers[i]
|
c := closers[i]
|
||||||
merr = errors.Join(merr, c())
|
merr = multierr.Append(merr, c())
|
||||||
}
|
}
|
||||||
return merr
|
return merr
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
rerr = errors.Join(rerr, close())
|
rerr = multierr.Append(rerr, close())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
@@ -415,13 +416,13 @@ func (s *Server) decodeCreateSubmissionAuditCommentRequest(r *http.Request) (
|
|||||||
// Close in reverse order, to match defer behavior.
|
// Close in reverse order, to match defer behavior.
|
||||||
for i := len(closers) - 1; i >= 0; i-- {
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
c := closers[i]
|
c := closers[i]
|
||||||
merr = errors.Join(merr, c())
|
merr = multierr.Append(merr, c())
|
||||||
}
|
}
|
||||||
return merr
|
return merr
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
rerr = errors.Join(rerr, close())
|
rerr = multierr.Append(rerr, close())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
@@ -449,13 +450,13 @@ func (s *Server) decodeReleaseSubmissionsRequest(r *http.Request) (
|
|||||||
// Close in reverse order, to match defer behavior.
|
// Close in reverse order, to match defer behavior.
|
||||||
for i := len(closers) - 1; i >= 0; i-- {
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
c := closers[i]
|
c := closers[i]
|
||||||
merr = errors.Join(merr, c())
|
merr = multierr.Append(merr, c())
|
||||||
}
|
}
|
||||||
return merr
|
return merr
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
rerr = errors.Join(rerr, close())
|
rerr = multierr.Append(rerr, close())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
@@ -553,13 +554,13 @@ func (s *Server) decodeUpdateScriptRequest(r *http.Request) (
|
|||||||
// Close in reverse order, to match defer behavior.
|
// Close in reverse order, to match defer behavior.
|
||||||
for i := len(closers) - 1; i >= 0; i-- {
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
c := closers[i]
|
c := closers[i]
|
||||||
merr = errors.Join(merr, c())
|
merr = multierr.Append(merr, c())
|
||||||
}
|
}
|
||||||
return merr
|
return merr
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
rerr = errors.Join(rerr, close())
|
rerr = multierr.Append(rerr, close())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
@@ -624,13 +625,13 @@ func (s *Server) decodeUpdateScriptPolicyRequest(r *http.Request) (
|
|||||||
// Close in reverse order, to match defer behavior.
|
// Close in reverse order, to match defer behavior.
|
||||||
for i := len(closers) - 1; i >= 0; i-- {
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
c := closers[i]
|
c := closers[i]
|
||||||
merr = errors.Join(merr, c())
|
merr = multierr.Append(merr, c())
|
||||||
}
|
}
|
||||||
return merr
|
return merr
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
rerr = errors.Join(rerr, close())
|
rerr = multierr.Append(rerr, close())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"mime"
|
"mime"
|
||||||
@@ -436,66 +435,6 @@ func decodeActionMapfixTriggerSubmitResponse(resp *http.Response) (res *ActionMa
|
|||||||
return res, errors.Wrap(defRes, "error")
|
return res, errors.Wrap(defRes, "error")
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeActionMapfixTriggerSubmitUncheckedResponse(resp *http.Response) (res *ActionMapfixTriggerSubmitUncheckedNoContent, _ error) {
|
|
||||||
switch resp.StatusCode {
|
|
||||||
case 204:
|
|
||||||
// Code 204.
|
|
||||||
return &ActionMapfixTriggerSubmitUncheckedNoContent{}, nil
|
|
||||||
}
|
|
||||||
// Convenient error response.
|
|
||||||
defRes, err := func() (res *ErrorStatusCode, err error) {
|
|
||||||
ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type"))
|
|
||||||
if err != nil {
|
|
||||||
return res, errors.Wrap(err, "parse media type")
|
|
||||||
}
|
|
||||||
switch {
|
|
||||||
case ct == "application/json":
|
|
||||||
buf, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
d := jx.DecodeBytes(buf)
|
|
||||||
|
|
||||||
var response Error
|
|
||||||
if err := func() error {
|
|
||||||
if err := response.Decode(d); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := d.Skip(); err != io.EOF {
|
|
||||||
return errors.New("unexpected trailing data")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
err = &ogenerrors.DecodeBodyError{
|
|
||||||
ContentType: ct,
|
|
||||||
Body: buf,
|
|
||||||
Err: err,
|
|
||||||
}
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
// Validate response.
|
|
||||||
if err := func() error {
|
|
||||||
if err := response.Validate(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
return res, errors.Wrap(err, "validate")
|
|
||||||
}
|
|
||||||
return &ErrorStatusCode{
|
|
||||||
StatusCode: resp.StatusCode,
|
|
||||||
Response: response,
|
|
||||||
}, nil
|
|
||||||
default:
|
|
||||||
return res, validate.InvalidContentType(ct)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
if err != nil {
|
|
||||||
return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode)
|
|
||||||
}
|
|
||||||
return res, errors.Wrap(defRes, "error")
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeActionMapfixTriggerUploadResponse(resp *http.Response) (res *ActionMapfixTriggerUploadNoContent, _ error) {
|
func decodeActionMapfixTriggerUploadResponse(resp *http.Response) (res *ActionMapfixTriggerUploadNoContent, _ error) {
|
||||||
switch resp.StatusCode {
|
switch resp.StatusCode {
|
||||||
case 204:
|
case 204:
|
||||||
@@ -1096,66 +1035,6 @@ func decodeActionSubmissionTriggerSubmitResponse(resp *http.Response) (res *Acti
|
|||||||
return res, errors.Wrap(defRes, "error")
|
return res, errors.Wrap(defRes, "error")
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeActionSubmissionTriggerSubmitUncheckedResponse(resp *http.Response) (res *ActionSubmissionTriggerSubmitUncheckedNoContent, _ error) {
|
|
||||||
switch resp.StatusCode {
|
|
||||||
case 204:
|
|
||||||
// Code 204.
|
|
||||||
return &ActionSubmissionTriggerSubmitUncheckedNoContent{}, nil
|
|
||||||
}
|
|
||||||
// Convenient error response.
|
|
||||||
defRes, err := func() (res *ErrorStatusCode, err error) {
|
|
||||||
ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type"))
|
|
||||||
if err != nil {
|
|
||||||
return res, errors.Wrap(err, "parse media type")
|
|
||||||
}
|
|
||||||
switch {
|
|
||||||
case ct == "application/json":
|
|
||||||
buf, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
d := jx.DecodeBytes(buf)
|
|
||||||
|
|
||||||
var response Error
|
|
||||||
if err := func() error {
|
|
||||||
if err := response.Decode(d); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := d.Skip(); err != io.EOF {
|
|
||||||
return errors.New("unexpected trailing data")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
err = &ogenerrors.DecodeBodyError{
|
|
||||||
ContentType: ct,
|
|
||||||
Body: buf,
|
|
||||||
Err: err,
|
|
||||||
}
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
// Validate response.
|
|
||||||
if err := func() error {
|
|
||||||
if err := response.Validate(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
return res, errors.Wrap(err, "validate")
|
|
||||||
}
|
|
||||||
return &ErrorStatusCode{
|
|
||||||
StatusCode: resp.StatusCode,
|
|
||||||
Response: response,
|
|
||||||
}, nil
|
|
||||||
default:
|
|
||||||
return res, validate.InvalidContentType(ct)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
if err != nil {
|
|
||||||
return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode)
|
|
||||||
}
|
|
||||||
return res, errors.Wrap(defRes, "error")
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeActionSubmissionTriggerUploadResponse(resp *http.Response) (res *ActionSubmissionTriggerUploadNoContent, _ error) {
|
func decodeActionSubmissionTriggerUploadResponse(resp *http.Response) (res *ActionSubmissionTriggerUploadNoContent, _ error) {
|
||||||
switch resp.StatusCode {
|
switch resp.StatusCode {
|
||||||
case 204:
|
case 204:
|
||||||
@@ -2081,82 +1960,6 @@ func decodeDeleteScriptPolicyResponse(resp *http.Response) (res *DeleteScriptPol
|
|||||||
return res, errors.Wrap(defRes, "error")
|
return res, errors.Wrap(defRes, "error")
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeDownloadMapAssetResponse(resp *http.Response) (res DownloadMapAssetOK, _ error) {
|
|
||||||
switch resp.StatusCode {
|
|
||||||
case 200:
|
|
||||||
// Code 200.
|
|
||||||
ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type"))
|
|
||||||
if err != nil {
|
|
||||||
return res, errors.Wrap(err, "parse media type")
|
|
||||||
}
|
|
||||||
switch {
|
|
||||||
case ct == "application/octet-stream":
|
|
||||||
reader := resp.Body
|
|
||||||
b, err := io.ReadAll(reader)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
response := DownloadMapAssetOK{Data: bytes.NewReader(b)}
|
|
||||||
return response, nil
|
|
||||||
default:
|
|
||||||
return res, validate.InvalidContentType(ct)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Convenient error response.
|
|
||||||
defRes, err := func() (res *ErrorStatusCode, err error) {
|
|
||||||
ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type"))
|
|
||||||
if err != nil {
|
|
||||||
return res, errors.Wrap(err, "parse media type")
|
|
||||||
}
|
|
||||||
switch {
|
|
||||||
case ct == "application/json":
|
|
||||||
buf, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
d := jx.DecodeBytes(buf)
|
|
||||||
|
|
||||||
var response Error
|
|
||||||
if err := func() error {
|
|
||||||
if err := response.Decode(d); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := d.Skip(); err != io.EOF {
|
|
||||||
return errors.New("unexpected trailing data")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
err = &ogenerrors.DecodeBodyError{
|
|
||||||
ContentType: ct,
|
|
||||||
Body: buf,
|
|
||||||
Err: err,
|
|
||||||
}
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
// Validate response.
|
|
||||||
if err := func() error {
|
|
||||||
if err := response.Validate(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
return res, errors.Wrap(err, "validate")
|
|
||||||
}
|
|
||||||
return &ErrorStatusCode{
|
|
||||||
StatusCode: resp.StatusCode,
|
|
||||||
Response: response,
|
|
||||||
}, nil
|
|
||||||
default:
|
|
||||||
return res, validate.InvalidContentType(ct)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
if err != nil {
|
|
||||||
return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode)
|
|
||||||
}
|
|
||||||
return res, errors.Wrap(defRes, "error")
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeGetMapResponse(resp *http.Response) (res *Map, _ error) {
|
func decodeGetMapResponse(resp *http.Response) (res *Map, _ error) {
|
||||||
switch resp.StatusCode {
|
switch resp.StatusCode {
|
||||||
case 200:
|
case 200:
|
||||||
@@ -3595,66 +3398,6 @@ func decodeListSubmissionsResponse(resp *http.Response) (res *Submissions, _ err
|
|||||||
return res, errors.Wrap(defRes, "error")
|
return res, errors.Wrap(defRes, "error")
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeMigrateMapsResponse(resp *http.Response) (res *MigrateMapsOK, _ error) {
|
|
||||||
switch resp.StatusCode {
|
|
||||||
case 200:
|
|
||||||
// Code 200.
|
|
||||||
return &MigrateMapsOK{}, nil
|
|
||||||
}
|
|
||||||
// Convenient error response.
|
|
||||||
defRes, err := func() (res *ErrorStatusCode, err error) {
|
|
||||||
ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type"))
|
|
||||||
if err != nil {
|
|
||||||
return res, errors.Wrap(err, "parse media type")
|
|
||||||
}
|
|
||||||
switch {
|
|
||||||
case ct == "application/json":
|
|
||||||
buf, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
d := jx.DecodeBytes(buf)
|
|
||||||
|
|
||||||
var response Error
|
|
||||||
if err := func() error {
|
|
||||||
if err := response.Decode(d); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := d.Skip(); err != io.EOF {
|
|
||||||
return errors.New("unexpected trailing data")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
err = &ogenerrors.DecodeBodyError{
|
|
||||||
ContentType: ct,
|
|
||||||
Body: buf,
|
|
||||||
Err: err,
|
|
||||||
}
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
// Validate response.
|
|
||||||
if err := func() error {
|
|
||||||
if err := response.Validate(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}(); err != nil {
|
|
||||||
return res, errors.Wrap(err, "validate")
|
|
||||||
}
|
|
||||||
return &ErrorStatusCode{
|
|
||||||
StatusCode: resp.StatusCode,
|
|
||||||
Response: response,
|
|
||||||
}, nil
|
|
||||||
default:
|
|
||||||
return res, validate.InvalidContentType(ct)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
if err != nil {
|
|
||||||
return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode)
|
|
||||||
}
|
|
||||||
return res, errors.Wrap(defRes, "error")
|
|
||||||
}
|
|
||||||
|
|
||||||
func decodeReleaseSubmissionsResponse(resp *http.Response) (res *ReleaseSubmissionsCreated, _ error) {
|
func decodeReleaseSubmissionsResponse(resp *http.Response) (res *ReleaseSubmissionsCreated, _ error) {
|
||||||
switch resp.StatusCode {
|
switch resp.StatusCode {
|
||||||
case 201:
|
case 201:
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/go-faster/errors"
|
"github.com/go-faster/errors"
|
||||||
@@ -63,13 +62,6 @@ func encodeActionMapfixTriggerSubmitResponse(response *ActionMapfixTriggerSubmit
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeActionMapfixTriggerSubmitUncheckedResponse(response *ActionMapfixTriggerSubmitUncheckedNoContent, w http.ResponseWriter, span trace.Span) error {
|
|
||||||
w.WriteHeader(204)
|
|
||||||
span.SetStatus(codes.Ok, http.StatusText(204))
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeActionMapfixTriggerUploadResponse(response *ActionMapfixTriggerUploadNoContent, w http.ResponseWriter, span trace.Span) error {
|
func encodeActionMapfixTriggerUploadResponse(response *ActionMapfixTriggerUploadNoContent, w http.ResponseWriter, span trace.Span) error {
|
||||||
w.WriteHeader(204)
|
w.WriteHeader(204)
|
||||||
span.SetStatus(codes.Ok, http.StatusText(204))
|
span.SetStatus(codes.Ok, http.StatusText(204))
|
||||||
@@ -140,13 +132,6 @@ func encodeActionSubmissionTriggerSubmitResponse(response *ActionSubmissionTrigg
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeActionSubmissionTriggerSubmitUncheckedResponse(response *ActionSubmissionTriggerSubmitUncheckedNoContent, w http.ResponseWriter, span trace.Span) error {
|
|
||||||
w.WriteHeader(204)
|
|
||||||
span.SetStatus(codes.Ok, http.StatusText(204))
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeActionSubmissionTriggerUploadResponse(response *ActionSubmissionTriggerUploadNoContent, w http.ResponseWriter, span trace.Span) error {
|
func encodeActionSubmissionTriggerUploadResponse(response *ActionSubmissionTriggerUploadNoContent, w http.ResponseWriter, span trace.Span) error {
|
||||||
w.WriteHeader(204)
|
w.WriteHeader(204)
|
||||||
span.SetStatus(codes.Ok, http.StatusText(204))
|
span.SetStatus(codes.Ok, http.StatusText(204))
|
||||||
@@ -266,22 +251,6 @@ func encodeDeleteScriptPolicyResponse(response *DeleteScriptPolicyNoContent, w h
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeDownloadMapAssetResponse(response DownloadMapAssetOK, w http.ResponseWriter, span trace.Span) error {
|
|
||||||
w.Header().Set("Content-Type", "application/octet-stream")
|
|
||||||
w.WriteHeader(200)
|
|
||||||
span.SetStatus(codes.Ok, http.StatusText(200))
|
|
||||||
|
|
||||||
writer := w
|
|
||||||
if closer, ok := response.Data.(io.Closer); ok {
|
|
||||||
defer closer.Close()
|
|
||||||
}
|
|
||||||
if _, err := io.Copy(writer, response); err != nil {
|
|
||||||
return errors.Wrap(err, "write")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeGetMapResponse(response *Map, w http.ResponseWriter, span trace.Span) error {
|
func encodeGetMapResponse(response *Map, w http.ResponseWriter, span trace.Span) error {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
@@ -484,13 +453,6 @@ func encodeListSubmissionsResponse(response *Submissions, w http.ResponseWriter,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeMigrateMapsResponse(response *MigrateMapsOK, w http.ResponseWriter, span trace.Span) error {
|
|
||||||
w.WriteHeader(200)
|
|
||||||
span.SetStatus(codes.Ok, http.StatusText(200))
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func encodeReleaseSubmissionsResponse(response *ReleaseSubmissionsCreated, w http.ResponseWriter, span trace.Span) error {
|
func encodeReleaseSubmissionsResponse(response *ReleaseSubmissionsCreated, w http.ResponseWriter, span trace.Span) error {
|
||||||
w.WriteHeader(201)
|
w.WriteHeader(201)
|
||||||
span.SetStatus(codes.Ok, http.StatusText(201))
|
span.SetStatus(codes.Ok, http.StatusText(201))
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -35,9 +35,6 @@ type ActionMapfixRevokeNoContent struct{}
|
|||||||
// ActionMapfixTriggerSubmitNoContent is response for ActionMapfixTriggerSubmit operation.
|
// ActionMapfixTriggerSubmitNoContent is response for ActionMapfixTriggerSubmit operation.
|
||||||
type ActionMapfixTriggerSubmitNoContent struct{}
|
type ActionMapfixTriggerSubmitNoContent struct{}
|
||||||
|
|
||||||
// ActionMapfixTriggerSubmitUncheckedNoContent is response for ActionMapfixTriggerSubmitUnchecked operation.
|
|
||||||
type ActionMapfixTriggerSubmitUncheckedNoContent struct{}
|
|
||||||
|
|
||||||
// ActionMapfixTriggerUploadNoContent is response for ActionMapfixTriggerUpload operation.
|
// ActionMapfixTriggerUploadNoContent is response for ActionMapfixTriggerUpload operation.
|
||||||
type ActionMapfixTriggerUploadNoContent struct{}
|
type ActionMapfixTriggerUploadNoContent struct{}
|
||||||
|
|
||||||
@@ -68,9 +65,6 @@ type ActionSubmissionRevokeNoContent struct{}
|
|||||||
// ActionSubmissionTriggerSubmitNoContent is response for ActionSubmissionTriggerSubmit operation.
|
// ActionSubmissionTriggerSubmitNoContent is response for ActionSubmissionTriggerSubmit operation.
|
||||||
type ActionSubmissionTriggerSubmitNoContent struct{}
|
type ActionSubmissionTriggerSubmitNoContent struct{}
|
||||||
|
|
||||||
// ActionSubmissionTriggerSubmitUncheckedNoContent is response for ActionSubmissionTriggerSubmitUnchecked operation.
|
|
||||||
type ActionSubmissionTriggerSubmitUncheckedNoContent struct{}
|
|
||||||
|
|
||||||
// ActionSubmissionTriggerUploadNoContent is response for ActionSubmissionTriggerUpload operation.
|
// ActionSubmissionTriggerUploadNoContent is response for ActionSubmissionTriggerUpload operation.
|
||||||
type ActionSubmissionTriggerUploadNoContent struct{}
|
type ActionSubmissionTriggerUploadNoContent struct{}
|
||||||
|
|
||||||
@@ -188,7 +182,6 @@ func (s *AuditEventEventData) init() AuditEventEventData {
|
|||||||
|
|
||||||
type CookieAuth struct {
|
type CookieAuth struct {
|
||||||
APIKey string
|
APIKey string
|
||||||
Roles []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAPIKey returns the value of APIKey.
|
// GetAPIKey returns the value of APIKey.
|
||||||
@@ -196,21 +189,11 @@ func (s *CookieAuth) GetAPIKey() string {
|
|||||||
return s.APIKey
|
return s.APIKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRoles returns the value of Roles.
|
|
||||||
func (s *CookieAuth) GetRoles() []string {
|
|
||||||
return s.Roles
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetAPIKey sets the value of APIKey.
|
// SetAPIKey sets the value of APIKey.
|
||||||
func (s *CookieAuth) SetAPIKey(val string) {
|
func (s *CookieAuth) SetAPIKey(val string) {
|
||||||
s.APIKey = val
|
s.APIKey = val
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetRoles sets the value of Roles.
|
|
||||||
func (s *CookieAuth) SetRoles(val []string) {
|
|
||||||
s.Roles = val
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateMapfixAuditCommentNoContent is response for CreateMapfixAuditComment operation.
|
// CreateMapfixAuditCommentNoContent is response for CreateMapfixAuditComment operation.
|
||||||
type CreateMapfixAuditCommentNoContent struct{}
|
type CreateMapfixAuditCommentNoContent struct{}
|
||||||
|
|
||||||
@@ -251,20 +234,6 @@ type DeleteScriptNoContent struct{}
|
|||||||
// DeleteScriptPolicyNoContent is response for DeleteScriptPolicy operation.
|
// DeleteScriptPolicyNoContent is response for DeleteScriptPolicy operation.
|
||||||
type DeleteScriptPolicyNoContent struct{}
|
type DeleteScriptPolicyNoContent struct{}
|
||||||
|
|
||||||
type DownloadMapAssetOK struct {
|
|
||||||
Data io.Reader
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read reads data from the Data reader.
|
|
||||||
//
|
|
||||||
// Kept to satisfy the io.Reader interface.
|
|
||||||
func (s DownloadMapAssetOK) Read(p []byte) (n int, err error) {
|
|
||||||
if s.Data == nil {
|
|
||||||
return 0, io.EOF
|
|
||||||
}
|
|
||||||
return s.Data.Read(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Represents error object.
|
// Represents error object.
|
||||||
// Ref: #/components/schemas/Error
|
// Ref: #/components/schemas/Error
|
||||||
type Error struct {
|
type Error struct {
|
||||||
@@ -587,9 +556,6 @@ func (s *Mapfixes) SetMapfixes(val []Mapfix) {
|
|||||||
s.Mapfixes = val
|
s.Mapfixes = val
|
||||||
}
|
}
|
||||||
|
|
||||||
// MigrateMapsOK is response for MigrateMaps operation.
|
|
||||||
type MigrateMapsOK struct{}
|
|
||||||
|
|
||||||
// Ref: #/components/schemas/Operation
|
// Ref: #/components/schemas/Operation
|
||||||
type Operation struct {
|
type Operation struct {
|
||||||
OperationID int32 `json:"OperationID"`
|
OperationID int32 `json:"OperationID"`
|
||||||
|
|||||||
@@ -33,53 +33,6 @@ func findAuthorization(h http.Header, prefix string) (string, bool) {
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
var operationRolesCookieAuth = map[string][]string{
|
|
||||||
ActionMapfixAcceptedOperation: []string{},
|
|
||||||
ActionMapfixRejectOperation: []string{},
|
|
||||||
ActionMapfixRequestChangesOperation: []string{},
|
|
||||||
ActionMapfixResetSubmittingOperation: []string{},
|
|
||||||
ActionMapfixRetryValidateOperation: []string{},
|
|
||||||
ActionMapfixRevokeOperation: []string{},
|
|
||||||
ActionMapfixTriggerSubmitOperation: []string{},
|
|
||||||
ActionMapfixTriggerSubmitUncheckedOperation: []string{},
|
|
||||||
ActionMapfixTriggerUploadOperation: []string{},
|
|
||||||
ActionMapfixTriggerValidateOperation: []string{},
|
|
||||||
ActionMapfixValidatedOperation: []string{},
|
|
||||||
ActionSubmissionAcceptedOperation: []string{},
|
|
||||||
ActionSubmissionRejectOperation: []string{},
|
|
||||||
ActionSubmissionRequestChangesOperation: []string{},
|
|
||||||
ActionSubmissionResetSubmittingOperation: []string{},
|
|
||||||
ActionSubmissionRetryValidateOperation: []string{},
|
|
||||||
ActionSubmissionRevokeOperation: []string{},
|
|
||||||
ActionSubmissionTriggerSubmitOperation: []string{},
|
|
||||||
ActionSubmissionTriggerSubmitUncheckedOperation: []string{},
|
|
||||||
ActionSubmissionTriggerUploadOperation: []string{},
|
|
||||||
ActionSubmissionTriggerValidateOperation: []string{},
|
|
||||||
ActionSubmissionValidatedOperation: []string{},
|
|
||||||
CreateMapfixOperation: []string{},
|
|
||||||
CreateMapfixAuditCommentOperation: []string{},
|
|
||||||
CreateScriptOperation: []string{},
|
|
||||||
CreateScriptPolicyOperation: []string{},
|
|
||||||
CreateSubmissionOperation: []string{},
|
|
||||||
CreateSubmissionAdminOperation: []string{},
|
|
||||||
CreateSubmissionAuditCommentOperation: []string{},
|
|
||||||
DeleteScriptOperation: []string{},
|
|
||||||
DeleteScriptPolicyOperation: []string{},
|
|
||||||
DownloadMapAssetOperation: []string{},
|
|
||||||
GetOperationOperation: []string{},
|
|
||||||
MigrateMapsOperation: []string{},
|
|
||||||
ReleaseSubmissionsOperation: []string{},
|
|
||||||
SessionRolesOperation: []string{},
|
|
||||||
SessionUserOperation: []string{},
|
|
||||||
SessionValidateOperation: []string{},
|
|
||||||
SetMapfixCompletedOperation: []string{},
|
|
||||||
SetSubmissionCompletedOperation: []string{},
|
|
||||||
UpdateMapfixModelOperation: []string{},
|
|
||||||
UpdateScriptOperation: []string{},
|
|
||||||
UpdateScriptPolicyOperation: []string{},
|
|
||||||
UpdateSubmissionModelOperation: []string{},
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) securityCookieAuth(ctx context.Context, operationName OperationName, req *http.Request) (context.Context, bool, error) {
|
func (s *Server) securityCookieAuth(ctx context.Context, operationName OperationName, req *http.Request) (context.Context, bool, error) {
|
||||||
var t CookieAuth
|
var t CookieAuth
|
||||||
const parameterName = "session_id"
|
const parameterName = "session_id"
|
||||||
@@ -93,7 +46,6 @@ func (s *Server) securityCookieAuth(ctx context.Context, operationName Operation
|
|||||||
return nil, false, errors.Wrap(err, "get cookie value")
|
return nil, false, errors.Wrap(err, "get cookie value")
|
||||||
}
|
}
|
||||||
t.APIKey = value
|
t.APIKey = value
|
||||||
t.Roles = operationRolesCookieAuth[operationName]
|
|
||||||
rctx, err := s.sec.HandleCookieAuth(ctx, operationName, t)
|
rctx, err := s.sec.HandleCookieAuth(ctx, operationName, t)
|
||||||
if errors.Is(err, ogenerrors.ErrSkipServerSecurity) {
|
if errors.Is(err, ogenerrors.ErrSkipServerSecurity) {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
|
|||||||
@@ -51,12 +51,6 @@ type Handler interface {
|
|||||||
//
|
//
|
||||||
// POST /mapfixes/{MapfixID}/status/trigger-submit
|
// POST /mapfixes/{MapfixID}/status/trigger-submit
|
||||||
ActionMapfixTriggerSubmit(ctx context.Context, params ActionMapfixTriggerSubmitParams) error
|
ActionMapfixTriggerSubmit(ctx context.Context, params ActionMapfixTriggerSubmitParams) error
|
||||||
// ActionMapfixTriggerSubmitUnchecked implements actionMapfixTriggerSubmitUnchecked operation.
|
|
||||||
//
|
|
||||||
// Role Reviewer changes status from ChangesRequested -> Submitting.
|
|
||||||
//
|
|
||||||
// POST /mapfixes/{MapfixID}/status/trigger-submit-unchecked
|
|
||||||
ActionMapfixTriggerSubmitUnchecked(ctx context.Context, params ActionMapfixTriggerSubmitUncheckedParams) error
|
|
||||||
// ActionMapfixTriggerUpload implements actionMapfixTriggerUpload operation.
|
// ActionMapfixTriggerUpload implements actionMapfixTriggerUpload operation.
|
||||||
//
|
//
|
||||||
// Role Admin changes status from Validated -> Uploading.
|
// Role Admin changes status from Validated -> Uploading.
|
||||||
@@ -118,12 +112,6 @@ type Handler interface {
|
|||||||
//
|
//
|
||||||
// POST /submissions/{SubmissionID}/status/trigger-submit
|
// POST /submissions/{SubmissionID}/status/trigger-submit
|
||||||
ActionSubmissionTriggerSubmit(ctx context.Context, params ActionSubmissionTriggerSubmitParams) error
|
ActionSubmissionTriggerSubmit(ctx context.Context, params ActionSubmissionTriggerSubmitParams) error
|
||||||
// ActionSubmissionTriggerSubmitUnchecked implements actionSubmissionTriggerSubmitUnchecked operation.
|
|
||||||
//
|
|
||||||
// Role Reviewer changes status from ChangesRequested -> Submitting.
|
|
||||||
//
|
|
||||||
// POST /submissions/{SubmissionID}/status/trigger-submit-unchecked
|
|
||||||
ActionSubmissionTriggerSubmitUnchecked(ctx context.Context, params ActionSubmissionTriggerSubmitUncheckedParams) error
|
|
||||||
// ActionSubmissionTriggerUpload implements actionSubmissionTriggerUpload operation.
|
// ActionSubmissionTriggerUpload implements actionSubmissionTriggerUpload operation.
|
||||||
//
|
//
|
||||||
// Role Admin changes status from Validated -> Uploading.
|
// Role Admin changes status from Validated -> Uploading.
|
||||||
@@ -196,12 +184,6 @@ type Handler interface {
|
|||||||
//
|
//
|
||||||
// DELETE /script-policy/{ScriptPolicyID}
|
// DELETE /script-policy/{ScriptPolicyID}
|
||||||
DeleteScriptPolicy(ctx context.Context, params DeleteScriptPolicyParams) error
|
DeleteScriptPolicy(ctx context.Context, params DeleteScriptPolicyParams) error
|
||||||
// DownloadMapAsset implements downloadMapAsset operation.
|
|
||||||
//
|
|
||||||
// Download the map asset.
|
|
||||||
//
|
|
||||||
// GET /maps/{MapID}/download
|
|
||||||
DownloadMapAsset(ctx context.Context, params DownloadMapAssetParams) (DownloadMapAssetOK, error)
|
|
||||||
// GetMap implements getMap operation.
|
// GetMap implements getMap operation.
|
||||||
//
|
//
|
||||||
// Retrieve map with ID.
|
// Retrieve map with ID.
|
||||||
@@ -280,12 +262,6 @@ type Handler interface {
|
|||||||
//
|
//
|
||||||
// GET /submissions
|
// GET /submissions
|
||||||
ListSubmissions(ctx context.Context, params ListSubmissionsParams) (*Submissions, error)
|
ListSubmissions(ctx context.Context, params ListSubmissionsParams) (*Submissions, error)
|
||||||
// MigrateMaps implements migrateMaps operation.
|
|
||||||
//
|
|
||||||
// Perform maps migration.
|
|
||||||
//
|
|
||||||
// POST /migrate-maps
|
|
||||||
MigrateMaps(ctx context.Context) error
|
|
||||||
// ReleaseSubmissions implements releaseSubmissions operation.
|
// ReleaseSubmissions implements releaseSubmissions operation.
|
||||||
//
|
//
|
||||||
// Release a set of uploaded maps.
|
// Release a set of uploaded maps.
|
||||||
|
|||||||
@@ -77,15 +77,6 @@ func (UnimplementedHandler) ActionMapfixTriggerSubmit(ctx context.Context, param
|
|||||||
return ht.ErrNotImplemented
|
return ht.ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActionMapfixTriggerSubmitUnchecked implements actionMapfixTriggerSubmitUnchecked operation.
|
|
||||||
//
|
|
||||||
// Role Reviewer changes status from ChangesRequested -> Submitting.
|
|
||||||
//
|
|
||||||
// POST /mapfixes/{MapfixID}/status/trigger-submit-unchecked
|
|
||||||
func (UnimplementedHandler) ActionMapfixTriggerSubmitUnchecked(ctx context.Context, params ActionMapfixTriggerSubmitUncheckedParams) error {
|
|
||||||
return ht.ErrNotImplemented
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionMapfixTriggerUpload implements actionMapfixTriggerUpload operation.
|
// ActionMapfixTriggerUpload implements actionMapfixTriggerUpload operation.
|
||||||
//
|
//
|
||||||
// Role Admin changes status from Validated -> Uploading.
|
// Role Admin changes status from Validated -> Uploading.
|
||||||
@@ -177,15 +168,6 @@ func (UnimplementedHandler) ActionSubmissionTriggerSubmit(ctx context.Context, p
|
|||||||
return ht.ErrNotImplemented
|
return ht.ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActionSubmissionTriggerSubmitUnchecked implements actionSubmissionTriggerSubmitUnchecked operation.
|
|
||||||
//
|
|
||||||
// Role Reviewer changes status from ChangesRequested -> Submitting.
|
|
||||||
//
|
|
||||||
// POST /submissions/{SubmissionID}/status/trigger-submit-unchecked
|
|
||||||
func (UnimplementedHandler) ActionSubmissionTriggerSubmitUnchecked(ctx context.Context, params ActionSubmissionTriggerSubmitUncheckedParams) error {
|
|
||||||
return ht.ErrNotImplemented
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionSubmissionTriggerUpload implements actionSubmissionTriggerUpload operation.
|
// ActionSubmissionTriggerUpload implements actionSubmissionTriggerUpload operation.
|
||||||
//
|
//
|
||||||
// Role Admin changes status from Validated -> Uploading.
|
// Role Admin changes status from Validated -> Uploading.
|
||||||
@@ -294,15 +276,6 @@ func (UnimplementedHandler) DeleteScriptPolicy(ctx context.Context, params Delet
|
|||||||
return ht.ErrNotImplemented
|
return ht.ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownloadMapAsset implements downloadMapAsset operation.
|
|
||||||
//
|
|
||||||
// Download the map asset.
|
|
||||||
//
|
|
||||||
// GET /maps/{MapID}/download
|
|
||||||
func (UnimplementedHandler) DownloadMapAsset(ctx context.Context, params DownloadMapAssetParams) (r DownloadMapAssetOK, _ error) {
|
|
||||||
return r, ht.ErrNotImplemented
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMap implements getMap operation.
|
// GetMap implements getMap operation.
|
||||||
//
|
//
|
||||||
// Retrieve map with ID.
|
// Retrieve map with ID.
|
||||||
@@ -420,15 +393,6 @@ func (UnimplementedHandler) ListSubmissions(ctx context.Context, params ListSubm
|
|||||||
return r, ht.ErrNotImplemented
|
return r, ht.ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
// MigrateMaps implements migrateMaps operation.
|
|
||||||
//
|
|
||||||
// Perform maps migration.
|
|
||||||
//
|
|
||||||
// POST /migrate-maps
|
|
||||||
func (UnimplementedHandler) MigrateMaps(ctx context.Context) error {
|
|
||||||
return ht.ErrNotImplemented
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReleaseSubmissions implements releaseSubmissions operation.
|
// ReleaseSubmissions implements releaseSubmissions operation.
|
||||||
//
|
//
|
||||||
// Release a set of uploaded maps.
|
// Release a set of uploaded maps.
|
||||||
|
|||||||
@@ -2,21 +2,16 @@ package cmds
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/go-grpc/auth"
|
"git.itzana.me/strafesnet/go-grpc/auth"
|
||||||
"git.itzana.me/strafesnet/go-grpc/maps"
|
"git.itzana.me/strafesnet/go-grpc/maps"
|
||||||
"git.itzana.me/strafesnet/go-grpc/maps_extended"
|
|
||||||
"git.itzana.me/strafesnet/go-grpc/users"
|
"git.itzana.me/strafesnet/go-grpc/users"
|
||||||
"git.itzana.me/strafesnet/go-grpc/validator"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/controller"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/datastore/gormstore"
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore/gormstore"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/roblox"
|
internal "git.itzana.me/strafesnet/maps-service/pkg/internal"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/service"
|
"git.itzana.me/strafesnet/maps-service/pkg/service"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/validator_controller"
|
"git.itzana.me/strafesnet/maps-service/pkg/service_internal"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/web_api"
|
|
||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@@ -96,12 +91,6 @@ func NewServeCommand() *cli.Command {
|
|||||||
EnvVars: []string{"NATS_HOST"},
|
EnvVars: []string{"NATS_HOST"},
|
||||||
Value: "nats:4222",
|
Value: "nats:4222",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "rbx-api-key",
|
|
||||||
Usage: "API Key for downloading asset locations",
|
|
||||||
EnvVars: []string{"RBX_API_KEY"},
|
|
||||||
Required: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,67 +123,46 @@ func serve(ctx *cli.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
svc_inner := service.NewService(
|
svc := &service.Service{
|
||||||
db,
|
DB: db,
|
||||||
js,
|
Nats: js,
|
||||||
maps.NewMapsServiceClient(conn),
|
Maps: maps.NewMapsServiceClient(conn),
|
||||||
users.NewUsersServiceClient(conn),
|
Users: users.NewUsersServiceClient(conn),
|
||||||
)
|
}
|
||||||
|
|
||||||
svc_external := web_api.NewService(
|
|
||||||
&svc_inner,
|
|
||||||
roblox.Client{
|
|
||||||
HttpClient: http.DefaultClient,
|
|
||||||
ApiKey: ctx.String("rbx-api-key"),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
conn, err = grpc.Dial(ctx.String("auth-rpc-host"), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
conn, err = grpc.Dial(ctx.String("auth-rpc-host"), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
sec := web_api.SecurityHandler{
|
sec := service.SecurityHandler{
|
||||||
Client: auth.NewAuthServiceClient(conn),
|
Client: auth.NewAuthServiceClient(conn),
|
||||||
}
|
}
|
||||||
|
|
||||||
srv_external, err := api.NewServer(&svc_external, sec, api.WithPathPrefix("/v1"))
|
srv, err := api.NewServer(svc, sec, api.WithPathPrefix("/v1"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Fatal("failed to initialize api server")
|
log.WithError(err).Fatal("failed to initialize api server")
|
||||||
}
|
}
|
||||||
|
|
||||||
grpcServer := grpc.NewServer()
|
svc2 := &service_internal.Service{
|
||||||
|
DB: db,
|
||||||
|
Nats: js,
|
||||||
|
}
|
||||||
|
|
||||||
maps_controller := controller.NewMapsController(&svc_inner)
|
srv2, err := internal.NewServer(svc2, internal.WithPathPrefix("/v1"))
|
||||||
maps_extended.RegisterMapsServiceServer(grpcServer,&maps_controller)
|
|
||||||
|
|
||||||
mapfix_controller := validator_controller.NewMapfixesController(&svc_inner)
|
|
||||||
operation_controller := validator_controller.NewOperationsController(&svc_inner)
|
|
||||||
script_controller := validator_controller.NewScriptsController(&svc_inner)
|
|
||||||
script_policy_controller := validator_controller.NewScriptPolicyController(&svc_inner)
|
|
||||||
submission_controller := validator_controller.NewSubmissionsController(&svc_inner)
|
|
||||||
|
|
||||||
validator.RegisterValidatorMapfixServiceServer(grpcServer,&mapfix_controller)
|
|
||||||
validator.RegisterValidatorOperationServiceServer(grpcServer,&operation_controller)
|
|
||||||
validator.RegisterValidatorScriptServiceServer(grpcServer,&script_controller)
|
|
||||||
validator.RegisterValidatorScriptPolicyServiceServer(grpcServer,&script_policy_controller)
|
|
||||||
validator.RegisterValidatorSubmissionServiceServer(grpcServer,&submission_controller)
|
|
||||||
|
|
||||||
port := ctx.Int("port-internal")
|
|
||||||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithField("error", err).Fatalln("failed to net.Listen")
|
log.WithError(err).Fatal("failed to initialize api server")
|
||||||
}
|
}
|
||||||
// Channel to collect errors
|
// Channel to collect errors
|
||||||
errChan := make(chan error, 2)
|
errChan := make(chan error, 2)
|
||||||
|
|
||||||
// First server
|
// First server
|
||||||
go func(errChan chan error) {
|
go func(errChan chan error) {
|
||||||
errChan <- grpcServer.Serve(lis)
|
errChan <- http.ListenAndServe(fmt.Sprintf(":%d", ctx.Int("port-internal")), srv2)
|
||||||
}(errChan)
|
}(errChan)
|
||||||
|
|
||||||
// Second server
|
// Second server
|
||||||
go func(errChan chan error) {
|
go func(errChan chan error) {
|
||||||
errChan <- http.ListenAndServe(fmt.Sprintf(":%d", ctx.Int("port")), srv_external)
|
errChan <- http.ListenAndServe(fmt.Sprintf(":%d", ctx.Int("port")), srv)
|
||||||
}(errChan)
|
}(errChan)
|
||||||
|
|
||||||
// Wait for the first error or completion of both tasks
|
// Wait for the first error or completion of both tasks
|
||||||
|
|||||||
@@ -1,197 +0,0 @@
|
|||||||
package controller
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/go-grpc/maps_extended"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/service"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
PageError = errors.New("Pagination required")
|
|
||||||
)
|
|
||||||
|
|
||||||
type Maps struct {
|
|
||||||
*maps_extended.UnimplementedMapsServiceServer
|
|
||||||
inner *service.Service
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMapsController(
|
|
||||||
inner *service.Service,
|
|
||||||
) Maps {
|
|
||||||
return Maps{
|
|
||||||
inner: inner,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Maps) Create(ctx context.Context, request *maps_extended.MapCreate) (*maps_extended.MapId, error) {
|
|
||||||
id, err := svc.inner.CreateMap(ctx, model.Map{
|
|
||||||
ID: request.ID,
|
|
||||||
DisplayName: request.DisplayName,
|
|
||||||
Creator: request.Creator,
|
|
||||||
GameID: request.GameID,
|
|
||||||
Submitter: request.Submitter,
|
|
||||||
Date: time.Unix(request.Date, 0),
|
|
||||||
Thumbnail: request.Thumbnail,
|
|
||||||
AssetVersion: request.AssetVersion,
|
|
||||||
LoadCount: 0,
|
|
||||||
Modes: request.Modes,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &maps_extended.MapId{
|
|
||||||
ID: id,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Maps) Delete(ctx context.Context, request *maps_extended.MapId) (*maps_extended.NullResponse, error) {
|
|
||||||
err := svc.inner.DeleteMap(ctx, request.ID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &maps_extended.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
func (svc *Maps) Get(ctx context.Context, request *maps_extended.MapId) (*maps_extended.MapResponse, error) {
|
|
||||||
item, err := svc.inner.GetMap(ctx, request.ID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &maps_extended.MapResponse{
|
|
||||||
ID: item.ID,
|
|
||||||
DisplayName: item.DisplayName,
|
|
||||||
Creator: item.Creator,
|
|
||||||
GameID: uint32(item.GameID),
|
|
||||||
Date: item.Date.Unix(),
|
|
||||||
CreatedAt: item.CreatedAt.Unix(),
|
|
||||||
UpdatedAt: item.UpdatedAt.Unix(),
|
|
||||||
Submitter: uint64(item.Submitter),
|
|
||||||
Thumbnail: uint64(item.Thumbnail),
|
|
||||||
AssetVersion: uint64(item.AssetVersion),
|
|
||||||
LoadCount: item.LoadCount,
|
|
||||||
Modes: item.Modes,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
func (svc *Maps) GetList(ctx context.Context, request *maps_extended.MapIdList) (*maps_extended.MapList, error) {
|
|
||||||
items, err := svc.inner.GetMapList(ctx, request.ID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := maps_extended.MapList{}
|
|
||||||
resp.Maps = make([]*maps_extended.MapResponse, len(items))
|
|
||||||
for i, item := range items {
|
|
||||||
resp.Maps[i] = &maps_extended.MapResponse{
|
|
||||||
ID: item.ID,
|
|
||||||
DisplayName: item.DisplayName,
|
|
||||||
Creator: item.Creator,
|
|
||||||
GameID: uint32(item.GameID),
|
|
||||||
Date: item.Date.Unix(),
|
|
||||||
CreatedAt: item.CreatedAt.Unix(),
|
|
||||||
UpdatedAt: item.UpdatedAt.Unix(),
|
|
||||||
Submitter: uint64(item.Submitter),
|
|
||||||
Thumbnail: uint64(item.Thumbnail),
|
|
||||||
AssetVersion: uint64(item.AssetVersion),
|
|
||||||
LoadCount: item.LoadCount,
|
|
||||||
Modes: item.Modes,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return &resp, nil
|
|
||||||
}
|
|
||||||
func (svc *Maps) List(ctx context.Context, request *maps_extended.ListRequest) (*maps_extended.MapList, error) {
|
|
||||||
if request.Page == nil {
|
|
||||||
return nil, PageError
|
|
||||||
}
|
|
||||||
|
|
||||||
filter := service.NewMapFilter()
|
|
||||||
if request.Filter != nil {
|
|
||||||
if request.Filter.DisplayName != nil {
|
|
||||||
filter.SetDisplayName(*request.Filter.DisplayName)
|
|
||||||
}
|
|
||||||
if request.Filter.Creator != nil {
|
|
||||||
filter.SetCreator(*request.Filter.Creator)
|
|
||||||
}
|
|
||||||
if request.Filter.GameID != nil {
|
|
||||||
filter.SetGameID(*request.Filter.GameID)
|
|
||||||
}
|
|
||||||
if request.Filter.Submitter != nil {
|
|
||||||
filter.SetSubmitter(*request.Filter.Submitter)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
items, err := svc.inner.ListMaps(ctx, filter, model.Page{
|
|
||||||
Number: int32(request.Page.Number),
|
|
||||||
Size: int32(request.Page.Size),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := maps_extended.MapList{}
|
|
||||||
resp.Maps = make([]*maps_extended.MapResponse, len(items))
|
|
||||||
for i, item := range items {
|
|
||||||
resp.Maps[i] = &maps_extended.MapResponse{
|
|
||||||
ID: item.ID,
|
|
||||||
DisplayName: item.DisplayName,
|
|
||||||
Creator: item.Creator,
|
|
||||||
GameID: uint32(item.GameID),
|
|
||||||
Date: item.Date.Unix(),
|
|
||||||
CreatedAt: item.CreatedAt.Unix(),
|
|
||||||
UpdatedAt: item.UpdatedAt.Unix(),
|
|
||||||
Submitter: uint64(item.Submitter),
|
|
||||||
Thumbnail: uint64(item.Thumbnail),
|
|
||||||
AssetVersion: uint64(item.AssetVersion),
|
|
||||||
LoadCount: item.LoadCount,
|
|
||||||
Modes: item.Modes,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return &resp, nil
|
|
||||||
}
|
|
||||||
func (svc *Maps) Update(ctx context.Context, request *maps_extended.MapUpdate) (*maps_extended.NullResponse, error) {
|
|
||||||
update := service.NewMapUpdate()
|
|
||||||
if request.DisplayName != nil {
|
|
||||||
update.SetDisplayName(*request.DisplayName)
|
|
||||||
}
|
|
||||||
if request.Creator != nil {
|
|
||||||
update.SetCreator(*request.Creator)
|
|
||||||
}
|
|
||||||
if request.GameID != nil {
|
|
||||||
update.SetGameID(*request.GameID)
|
|
||||||
}
|
|
||||||
if request.Date != nil {
|
|
||||||
update.SetDate(*request.Date)
|
|
||||||
}
|
|
||||||
if request.Submitter != nil {
|
|
||||||
update.SetSubmitter(*request.Submitter)
|
|
||||||
}
|
|
||||||
if request.Thumbnail != nil {
|
|
||||||
update.SetThumbnail(*request.Thumbnail)
|
|
||||||
}
|
|
||||||
if request.AssetVersion != nil {
|
|
||||||
update.SetAssetVersion(*request.AssetVersion)
|
|
||||||
}
|
|
||||||
if request.Modes != nil {
|
|
||||||
update.SetModes(*request.Modes)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := svc.inner.UpdateMap(ctx, request.ID, update)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &maps_extended.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Maps) IncrementLoadCount(ctx context.Context, request *maps_extended.MapId) (*maps_extended.NullResponse, error) {
|
|
||||||
err := svc.inner.IncrementMapLoadCount(ctx, request.ID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &maps_extended.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
@@ -25,7 +25,6 @@ const (
|
|||||||
|
|
||||||
type Datastore interface {
|
type Datastore interface {
|
||||||
AuditEvents() AuditEvents
|
AuditEvents() AuditEvents
|
||||||
Maps() Maps
|
|
||||||
Mapfixes() Mapfixes
|
Mapfixes() Mapfixes
|
||||||
Operations() Operations
|
Operations() Operations
|
||||||
Submissions() Submissions
|
Submissions() Submissions
|
||||||
@@ -41,16 +40,6 @@ type AuditEvents interface {
|
|||||||
List(ctx context.Context, filters OptionalMap, page model.Page) ([]model.AuditEvent, error)
|
List(ctx context.Context, filters OptionalMap, page model.Page) ([]model.AuditEvent, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Maps interface {
|
|
||||||
Get(ctx context.Context, id int64) (model.Map, error)
|
|
||||||
GetList(ctx context.Context, id []int64) ([]model.Map, error)
|
|
||||||
Create(ctx context.Context, smap model.Map) (model.Map, error)
|
|
||||||
Update(ctx context.Context, id int64, values OptionalMap) error
|
|
||||||
Delete(ctx context.Context, id int64) error
|
|
||||||
List(ctx context.Context, filters OptionalMap, page model.Page) ([]model.Map, error)
|
|
||||||
IncrementLoadCount(ctx context.Context, id int64) error
|
|
||||||
}
|
|
||||||
|
|
||||||
type Mapfixes interface {
|
type Mapfixes interface {
|
||||||
Get(ctx context.Context, id int64) (model.Mapfix, error)
|
Get(ctx context.Context, id int64) (model.Mapfix, error)
|
||||||
GetList(ctx context.Context, id []int64) ([]model.Mapfix, error)
|
GetList(ctx context.Context, id []int64) ([]model.Mapfix, error)
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ func (env *AuditEvents) Delete(ctx context.Context, id int64) error {
|
|||||||
|
|
||||||
func (env *AuditEvents) List(ctx context.Context, filters datastore.OptionalMap, page model.Page) ([]model.AuditEvent, error) {
|
func (env *AuditEvents) List(ctx context.Context, filters datastore.OptionalMap, page model.Page) ([]model.AuditEvent, error) {
|
||||||
var events []model.AuditEvent
|
var events []model.AuditEvent
|
||||||
if err := env.db.Where(filters.Map()).Order("id ASC").Offset(int((page.Number - 1) * page.Size)).Limit(int(page.Size)).Find(&events).Error; err != nil {
|
if err := env.db.Where(filters.Map()).Offset(int((page.Number - 1) * page.Size)).Limit(int(page.Size)).Find(&events).Error; err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ func New(ctx *cli.Context) (datastore.Datastore, error) {
|
|||||||
if ctx.Bool("migrate") {
|
if ctx.Bool("migrate") {
|
||||||
if err := db.AutoMigrate(
|
if err := db.AutoMigrate(
|
||||||
&model.AuditEvent{},
|
&model.AuditEvent{},
|
||||||
&model.Map{},
|
|
||||||
&model.Mapfix{},
|
&model.Mapfix{},
|
||||||
&model.Operation{},
|
&model.Operation{},
|
||||||
&model.Submission{},
|
&model.Submission{},
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ func (g Gormstore) AuditEvents() datastore.AuditEvents {
|
|||||||
return &AuditEvents{db: g.db}
|
return &AuditEvents{db: g.db}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g Gormstore) Maps() datastore.Maps {
|
|
||||||
return &Maps{db: g.db}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g Gormstore) Mapfixes() datastore.Mapfixes {
|
func (g Gormstore) Mapfixes() datastore.Mapfixes {
|
||||||
return &Mapfixes{db: g.db}
|
return &Mapfixes{db: g.db}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,16 +55,11 @@ func (env *Mapfixes) Update(ctx context.Context, id int64, values datastore.Opti
|
|||||||
|
|
||||||
// the update can only occur if the status matches one of the provided values.
|
// the update can only occur if the status matches one of the provided values.
|
||||||
func (env *Mapfixes) IfStatusThenUpdate(ctx context.Context, id int64, statuses []model.MapfixStatus, values datastore.OptionalMap) error {
|
func (env *Mapfixes) IfStatusThenUpdate(ctx context.Context, id int64, statuses []model.MapfixStatus, values datastore.OptionalMap) error {
|
||||||
result := env.db.Model(&model.Mapfix{}).Where("id = ?", id).Where("status_id IN ?", statuses).Updates(values.Map())
|
if err := env.db.Model(&model.Mapfix{}).Where("id = ?", id).Where("status_id IN ?", statuses).Updates(values.Map()).Error; err != nil {
|
||||||
if result.Error != nil {
|
if err == gorm.ErrRecordNotFound {
|
||||||
if result.Error == gorm.ErrRecordNotFound {
|
|
||||||
return datastore.ErrNotExist
|
return datastore.ErrNotExist
|
||||||
}
|
}
|
||||||
return result.Error
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
if result.RowsAffected == 0 {
|
|
||||||
return datastore.ErroNoRowsAffected
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
package gormstore
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Maps struct {
|
|
||||||
db *gorm.DB
|
|
||||||
}
|
|
||||||
|
|
||||||
func (env *Maps) Get(ctx context.Context, id int64) (model.Map, error) {
|
|
||||||
var mdl model.Map
|
|
||||||
if err := env.db.First(&mdl, id).Error; err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
return mdl, datastore.ErrNotExist
|
|
||||||
}
|
|
||||||
return mdl, err
|
|
||||||
}
|
|
||||||
return mdl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (env *Maps) GetList(ctx context.Context, id []int64) ([]model.Map, error) {
|
|
||||||
var mapList []model.Map
|
|
||||||
if err := env.db.Find(&mapList, "id IN ?", id).Error; err != nil {
|
|
||||||
return mapList, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return mapList, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (env *Maps) Create(ctx context.Context, smap model.Map) (model.Map, error) {
|
|
||||||
if err := env.db.Create(&smap).Error; err != nil {
|
|
||||||
return smap, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return smap, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (env *Maps) Update(ctx context.Context, id int64, values datastore.OptionalMap) error {
|
|
||||||
if err := env.db.Model(&model.Map{}).Where("id = ?", id).Updates(values.Map()).Error; err != nil {
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
return datastore.ErrNotExist
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (env *Maps) IncrementLoadCount(ctx context.Context, id int64) error {
|
|
||||||
if err := env.db.Model(&model.Map{}).Where("id = ?", id).UpdateColumn("load_count", gorm.Expr("load_count + ?", 1)).Error; err != nil {
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
return datastore.ErrNotExist
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (env *Maps) Delete(ctx context.Context, id int64) error {
|
|
||||||
if err := env.db.Delete(&model.Map{}, id).Error; err != nil {
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
return datastore.ErrNotExist
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (env *Maps) List(ctx context.Context, filters datastore.OptionalMap, page model.Page) ([]model.Map, error) {
|
|
||||||
var events []model.Map
|
|
||||||
if err := env.db.Where(filters.Map()).Offset(int((page.Number - 1) * page.Size)).Limit(int(page.Size)).Find(&events).Error; err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return events, nil
|
|
||||||
}
|
|
||||||
@@ -55,16 +55,11 @@ func (env *Submissions) Update(ctx context.Context, id int64, values datastore.O
|
|||||||
|
|
||||||
// the update can only occur if the status matches one of the provided values.
|
// the update can only occur if the status matches one of the provided values.
|
||||||
func (env *Submissions) IfStatusThenUpdate(ctx context.Context, id int64, statuses []model.SubmissionStatus, values datastore.OptionalMap) error {
|
func (env *Submissions) IfStatusThenUpdate(ctx context.Context, id int64, statuses []model.SubmissionStatus, values datastore.OptionalMap) error {
|
||||||
result := env.db.Model(&model.Submission{}).Where("id = ?", id).Where("status_id IN ?", statuses).Updates(values.Map())
|
if err := env.db.Model(&model.Submission{}).Where("id = ?", id).Where("status_id IN ?", statuses).Updates(values.Map()).Error; err != nil {
|
||||||
if result.Error != nil {
|
if err == gorm.ErrRecordNotFound {
|
||||||
if result.Error == gorm.ErrRecordNotFound {
|
|
||||||
return datastore.ErrNotExist
|
return datastore.ErrNotExist
|
||||||
}
|
}
|
||||||
return result.Error
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
if result.RowsAffected == 0 {
|
|
||||||
return datastore.ErroNoRowsAffected
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
283
pkg/internal/oas_cfg_gen.go
Normal file
283
pkg/internal/oas_cfg_gen.go
Normal file
@@ -0,0 +1,283 @@
|
|||||||
|
// Code generated by ogen, DO NOT EDIT.
|
||||||
|
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel"
|
||||||
|
"go.opentelemetry.io/otel/metric"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
|
||||||
|
ht "github.com/ogen-go/ogen/http"
|
||||||
|
"github.com/ogen-go/ogen/middleware"
|
||||||
|
"github.com/ogen-go/ogen/ogenerrors"
|
||||||
|
"github.com/ogen-go/ogen/otelogen"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Allocate option closure once.
|
||||||
|
clientSpanKind = trace.WithSpanKind(trace.SpanKindClient)
|
||||||
|
// Allocate option closure once.
|
||||||
|
serverSpanKind = trace.WithSpanKind(trace.SpanKindServer)
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
optionFunc[C any] func(*C)
|
||||||
|
otelOptionFunc func(*otelConfig)
|
||||||
|
)
|
||||||
|
|
||||||
|
type otelConfig struct {
|
||||||
|
TracerProvider trace.TracerProvider
|
||||||
|
Tracer trace.Tracer
|
||||||
|
MeterProvider metric.MeterProvider
|
||||||
|
Meter metric.Meter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cfg *otelConfig) initOTEL() {
|
||||||
|
if cfg.TracerProvider == nil {
|
||||||
|
cfg.TracerProvider = otel.GetTracerProvider()
|
||||||
|
}
|
||||||
|
if cfg.MeterProvider == nil {
|
||||||
|
cfg.MeterProvider = otel.GetMeterProvider()
|
||||||
|
}
|
||||||
|
cfg.Tracer = cfg.TracerProvider.Tracer(otelogen.Name,
|
||||||
|
trace.WithInstrumentationVersion(otelogen.SemVersion()),
|
||||||
|
)
|
||||||
|
cfg.Meter = cfg.MeterProvider.Meter(otelogen.Name,
|
||||||
|
metric.WithInstrumentationVersion(otelogen.SemVersion()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorHandler is error handler.
|
||||||
|
type ErrorHandler = ogenerrors.ErrorHandler
|
||||||
|
|
||||||
|
type serverConfig struct {
|
||||||
|
otelConfig
|
||||||
|
NotFound http.HandlerFunc
|
||||||
|
MethodNotAllowed func(w http.ResponseWriter, r *http.Request, allowed string)
|
||||||
|
ErrorHandler ErrorHandler
|
||||||
|
Prefix string
|
||||||
|
Middleware Middleware
|
||||||
|
MaxMultipartMemory int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServerOption is server config option.
|
||||||
|
type ServerOption interface {
|
||||||
|
applyServer(*serverConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ ServerOption = (optionFunc[serverConfig])(nil)
|
||||||
|
|
||||||
|
func (o optionFunc[C]) applyServer(c *C) {
|
||||||
|
o(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ ServerOption = (otelOptionFunc)(nil)
|
||||||
|
|
||||||
|
func (o otelOptionFunc) applyServer(c *serverConfig) {
|
||||||
|
o(&c.otelConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newServerConfig(opts ...ServerOption) serverConfig {
|
||||||
|
cfg := serverConfig{
|
||||||
|
NotFound: http.NotFound,
|
||||||
|
MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) {
|
||||||
|
status := http.StatusMethodNotAllowed
|
||||||
|
if r.Method == "OPTIONS" {
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", allowed)
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||||
|
status = http.StatusNoContent
|
||||||
|
} else {
|
||||||
|
w.Header().Set("Allow", allowed)
|
||||||
|
}
|
||||||
|
w.WriteHeader(status)
|
||||||
|
},
|
||||||
|
ErrorHandler: ogenerrors.DefaultErrorHandler,
|
||||||
|
Middleware: nil,
|
||||||
|
MaxMultipartMemory: 32 << 20, // 32 MB
|
||||||
|
}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt.applyServer(&cfg)
|
||||||
|
}
|
||||||
|
cfg.initOTEL()
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
|
||||||
|
type baseServer struct {
|
||||||
|
cfg serverConfig
|
||||||
|
requests metric.Int64Counter
|
||||||
|
errors metric.Int64Counter
|
||||||
|
duration metric.Float64Histogram
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s baseServer) notFound(w http.ResponseWriter, r *http.Request) {
|
||||||
|
s.cfg.NotFound(w, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s baseServer) notAllowed(w http.ResponseWriter, r *http.Request, allowed string) {
|
||||||
|
s.cfg.MethodNotAllowed(w, r, allowed)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cfg serverConfig) baseServer() (s baseServer, err error) {
|
||||||
|
s = baseServer{cfg: cfg}
|
||||||
|
if s.requests, err = otelogen.ServerRequestCountCounter(s.cfg.Meter); err != nil {
|
||||||
|
return s, err
|
||||||
|
}
|
||||||
|
if s.errors, err = otelogen.ServerErrorsCountCounter(s.cfg.Meter); err != nil {
|
||||||
|
return s, err
|
||||||
|
}
|
||||||
|
if s.duration, err = otelogen.ServerDurationHistogram(s.cfg.Meter); err != nil {
|
||||||
|
return s, err
|
||||||
|
}
|
||||||
|
return s, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type clientConfig struct {
|
||||||
|
otelConfig
|
||||||
|
Client ht.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClientOption is client config option.
|
||||||
|
type ClientOption interface {
|
||||||
|
applyClient(*clientConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ ClientOption = (optionFunc[clientConfig])(nil)
|
||||||
|
|
||||||
|
func (o optionFunc[C]) applyClient(c *C) {
|
||||||
|
o(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ ClientOption = (otelOptionFunc)(nil)
|
||||||
|
|
||||||
|
func (o otelOptionFunc) applyClient(c *clientConfig) {
|
||||||
|
o(&c.otelConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newClientConfig(opts ...ClientOption) clientConfig {
|
||||||
|
cfg := clientConfig{
|
||||||
|
Client: http.DefaultClient,
|
||||||
|
}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt.applyClient(&cfg)
|
||||||
|
}
|
||||||
|
cfg.initOTEL()
|
||||||
|
return cfg
|
||||||
|
}
|
||||||
|
|
||||||
|
type baseClient struct {
|
||||||
|
cfg clientConfig
|
||||||
|
requests metric.Int64Counter
|
||||||
|
errors metric.Int64Counter
|
||||||
|
duration metric.Float64Histogram
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cfg clientConfig) baseClient() (c baseClient, err error) {
|
||||||
|
c = baseClient{cfg: cfg}
|
||||||
|
if c.requests, err = otelogen.ClientRequestCountCounter(c.cfg.Meter); err != nil {
|
||||||
|
return c, err
|
||||||
|
}
|
||||||
|
if c.errors, err = otelogen.ClientErrorsCountCounter(c.cfg.Meter); err != nil {
|
||||||
|
return c, err
|
||||||
|
}
|
||||||
|
if c.duration, err = otelogen.ClientDurationHistogram(c.cfg.Meter); err != nil {
|
||||||
|
return c, err
|
||||||
|
}
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Option is config option.
|
||||||
|
type Option interface {
|
||||||
|
ServerOption
|
||||||
|
ClientOption
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithTracerProvider specifies a tracer provider to use for creating a tracer.
|
||||||
|
//
|
||||||
|
// If none is specified, the global provider is used.
|
||||||
|
func WithTracerProvider(provider trace.TracerProvider) Option {
|
||||||
|
return otelOptionFunc(func(cfg *otelConfig) {
|
||||||
|
if provider != nil {
|
||||||
|
cfg.TracerProvider = provider
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMeterProvider specifies a meter provider to use for creating a meter.
|
||||||
|
//
|
||||||
|
// If none is specified, the otel.GetMeterProvider() is used.
|
||||||
|
func WithMeterProvider(provider metric.MeterProvider) Option {
|
||||||
|
return otelOptionFunc(func(cfg *otelConfig) {
|
||||||
|
if provider != nil {
|
||||||
|
cfg.MeterProvider = provider
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithClient specifies http client to use.
|
||||||
|
func WithClient(client ht.Client) ClientOption {
|
||||||
|
return optionFunc[clientConfig](func(cfg *clientConfig) {
|
||||||
|
if client != nil {
|
||||||
|
cfg.Client = client
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithNotFound specifies Not Found handler to use.
|
||||||
|
func WithNotFound(notFound http.HandlerFunc) ServerOption {
|
||||||
|
return optionFunc[serverConfig](func(cfg *serverConfig) {
|
||||||
|
if notFound != nil {
|
||||||
|
cfg.NotFound = notFound
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMethodNotAllowed specifies Method Not Allowed handler to use.
|
||||||
|
func WithMethodNotAllowed(methodNotAllowed func(w http.ResponseWriter, r *http.Request, allowed string)) ServerOption {
|
||||||
|
return optionFunc[serverConfig](func(cfg *serverConfig) {
|
||||||
|
if methodNotAllowed != nil {
|
||||||
|
cfg.MethodNotAllowed = methodNotAllowed
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithErrorHandler specifies error handler to use.
|
||||||
|
func WithErrorHandler(h ErrorHandler) ServerOption {
|
||||||
|
return optionFunc[serverConfig](func(cfg *serverConfig) {
|
||||||
|
if h != nil {
|
||||||
|
cfg.ErrorHandler = h
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithPathPrefix specifies server path prefix.
|
||||||
|
func WithPathPrefix(prefix string) ServerOption {
|
||||||
|
return optionFunc[serverConfig](func(cfg *serverConfig) {
|
||||||
|
cfg.Prefix = prefix
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMiddleware specifies middlewares to use.
|
||||||
|
func WithMiddleware(m ...Middleware) ServerOption {
|
||||||
|
return optionFunc[serverConfig](func(cfg *serverConfig) {
|
||||||
|
switch len(m) {
|
||||||
|
case 0:
|
||||||
|
cfg.Middleware = nil
|
||||||
|
case 1:
|
||||||
|
cfg.Middleware = m[0]
|
||||||
|
default:
|
||||||
|
cfg.Middleware = middleware.ChainMiddlewares(m...)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMaxMultipartMemory specifies limit of memory for storing file parts.
|
||||||
|
// File parts which can't be stored in memory will be stored on disk in temporary files.
|
||||||
|
func WithMaxMultipartMemory(max int64) ServerOption {
|
||||||
|
return optionFunc[serverConfig](func(cfg *serverConfig) {
|
||||||
|
if max > 0 {
|
||||||
|
cfg.MaxMultipartMemory = max
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
2407
pkg/internal/oas_client_gen.go
Normal file
2407
pkg/internal/oas_client_gen.go
Normal file
File diff suppressed because it is too large
Load Diff
3123
pkg/internal/oas_handlers_gen.go
Normal file
3123
pkg/internal/oas_handlers_gen.go
Normal file
File diff suppressed because it is too large
Load Diff
1616
pkg/internal/oas_json_gen.go
Normal file
1616
pkg/internal/oas_json_gen.go
Normal file
File diff suppressed because it is too large
Load Diff
42
pkg/internal/oas_labeler_gen.go
Normal file
42
pkg/internal/oas_labeler_gen.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
// Code generated by ogen, DO NOT EDIT.
|
||||||
|
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/attribute"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Labeler is used to allow adding custom attributes to the server request metrics.
|
||||||
|
type Labeler struct {
|
||||||
|
attrs []attribute.KeyValue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add attributes to the Labeler.
|
||||||
|
func (l *Labeler) Add(attrs ...attribute.KeyValue) {
|
||||||
|
l.attrs = append(l.attrs, attrs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AttributeSet returns the attributes added to the Labeler as an attribute.Set.
|
||||||
|
func (l *Labeler) AttributeSet() attribute.Set {
|
||||||
|
return attribute.NewSet(l.attrs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
type labelerContextKey struct{}
|
||||||
|
|
||||||
|
// LabelerFromContext retrieves the Labeler from the provided context, if present.
|
||||||
|
//
|
||||||
|
// If no Labeler was found in the provided context a new, empty Labeler is returned and the second
|
||||||
|
// return value is false. In this case it is safe to use the Labeler but any attributes added to
|
||||||
|
// it will not be used.
|
||||||
|
func LabelerFromContext(ctx context.Context) (*Labeler, bool) {
|
||||||
|
if l, ok := ctx.Value(labelerContextKey{}).(*Labeler); ok {
|
||||||
|
return l, true
|
||||||
|
}
|
||||||
|
return &Labeler{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func contextWithLabeler(ctx context.Context, l *Labeler) context.Context {
|
||||||
|
return context.WithValue(ctx, labelerContextKey{}, l)
|
||||||
|
}
|
||||||
10
pkg/internal/oas_middleware_gen.go
Normal file
10
pkg/internal/oas_middleware_gen.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// Code generated by ogen, DO NOT EDIT.
|
||||||
|
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ogen-go/ogen/middleware"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Middleware is middleware type.
|
||||||
|
type Middleware = middleware.Middleware
|
||||||
29
pkg/internal/oas_operations_gen.go
Normal file
29
pkg/internal/oas_operations_gen.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
// Code generated by ogen, DO NOT EDIT.
|
||||||
|
|
||||||
|
package api
|
||||||
|
|
||||||
|
// OperationName is the ogen operation name
|
||||||
|
type OperationName = string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ActionMapfixAcceptedOperation OperationName = "ActionMapfixAccepted"
|
||||||
|
ActionMapfixRequestChangesOperation OperationName = "ActionMapfixRequestChanges"
|
||||||
|
ActionMapfixSubmittedOperation OperationName = "ActionMapfixSubmitted"
|
||||||
|
ActionMapfixUploadedOperation OperationName = "ActionMapfixUploaded"
|
||||||
|
ActionMapfixValidatedOperation OperationName = "ActionMapfixValidated"
|
||||||
|
ActionOperationFailedOperation OperationName = "ActionOperationFailed"
|
||||||
|
ActionSubmissionAcceptedOperation OperationName = "ActionSubmissionAccepted"
|
||||||
|
ActionSubmissionRequestChangesOperation OperationName = "ActionSubmissionRequestChanges"
|
||||||
|
ActionSubmissionSubmittedOperation OperationName = "ActionSubmissionSubmitted"
|
||||||
|
ActionSubmissionUploadedOperation OperationName = "ActionSubmissionUploaded"
|
||||||
|
ActionSubmissionValidatedOperation OperationName = "ActionSubmissionValidated"
|
||||||
|
CreateMapfixOperation OperationName = "CreateMapfix"
|
||||||
|
CreateScriptOperation OperationName = "CreateScript"
|
||||||
|
CreateScriptPolicyOperation OperationName = "CreateScriptPolicy"
|
||||||
|
CreateSubmissionOperation OperationName = "CreateSubmission"
|
||||||
|
GetScriptOperation OperationName = "GetScript"
|
||||||
|
ListScriptPolicyOperation OperationName = "ListScriptPolicy"
|
||||||
|
ListScriptsOperation OperationName = "ListScripts"
|
||||||
|
UpdateMapfixValidatedModelOperation OperationName = "UpdateMapfixValidatedModel"
|
||||||
|
UpdateSubmissionValidatedModelOperation OperationName = "UpdateSubmissionValidatedModel"
|
||||||
|
)
|
||||||
3143
pkg/internal/oas_parameters_gen.go
Normal file
3143
pkg/internal/oas_parameters_gen.go
Normal file
File diff suppressed because it is too large
Load Diff
300
pkg/internal/oas_request_decoders_gen.go
Normal file
300
pkg/internal/oas_request_decoders_gen.go
Normal file
@@ -0,0 +1,300 @@
|
|||||||
|
// Code generated by ogen, DO NOT EDIT.
|
||||||
|
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"mime"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/go-faster/errors"
|
||||||
|
"github.com/go-faster/jx"
|
||||||
|
"go.uber.org/multierr"
|
||||||
|
|
||||||
|
"github.com/ogen-go/ogen/ogenerrors"
|
||||||
|
"github.com/ogen-go/ogen/validate"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Server) decodeCreateMapfixRequest(r *http.Request) (
|
||||||
|
req *MapfixCreate,
|
||||||
|
close func() error,
|
||||||
|
rerr error,
|
||||||
|
) {
|
||||||
|
var closers []func() error
|
||||||
|
close = func() error {
|
||||||
|
var merr error
|
||||||
|
// Close in reverse order, to match defer behavior.
|
||||||
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
|
c := closers[i]
|
||||||
|
merr = multierr.Append(merr, c())
|
||||||
|
}
|
||||||
|
return merr
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if rerr != nil {
|
||||||
|
rerr = multierr.Append(rerr, close())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
|
if err != nil {
|
||||||
|
return req, close, errors.Wrap(err, "parse media type")
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case ct == "application/json":
|
||||||
|
if r.ContentLength == 0 {
|
||||||
|
return req, close, validate.ErrBodyRequired
|
||||||
|
}
|
||||||
|
buf, err := io.ReadAll(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
return req, close, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(buf) == 0 {
|
||||||
|
return req, close, validate.ErrBodyRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
d := jx.DecodeBytes(buf)
|
||||||
|
|
||||||
|
var request MapfixCreate
|
||||||
|
if err := func() error {
|
||||||
|
if err := request.Decode(d); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := d.Skip(); err != io.EOF {
|
||||||
|
return errors.New("unexpected trailing data")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
err = &ogenerrors.DecodeBodyError{
|
||||||
|
ContentType: ct,
|
||||||
|
Body: buf,
|
||||||
|
Err: err,
|
||||||
|
}
|
||||||
|
return req, close, err
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := request.Validate(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
return req, close, errors.Wrap(err, "validate")
|
||||||
|
}
|
||||||
|
return &request, close, nil
|
||||||
|
default:
|
||||||
|
return req, close, validate.InvalidContentType(ct)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) decodeCreateScriptRequest(r *http.Request) (
|
||||||
|
req *ScriptCreate,
|
||||||
|
close func() error,
|
||||||
|
rerr error,
|
||||||
|
) {
|
||||||
|
var closers []func() error
|
||||||
|
close = func() error {
|
||||||
|
var merr error
|
||||||
|
// Close in reverse order, to match defer behavior.
|
||||||
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
|
c := closers[i]
|
||||||
|
merr = multierr.Append(merr, c())
|
||||||
|
}
|
||||||
|
return merr
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if rerr != nil {
|
||||||
|
rerr = multierr.Append(rerr, close())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
|
if err != nil {
|
||||||
|
return req, close, errors.Wrap(err, "parse media type")
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case ct == "application/json":
|
||||||
|
if r.ContentLength == 0 {
|
||||||
|
return req, close, validate.ErrBodyRequired
|
||||||
|
}
|
||||||
|
buf, err := io.ReadAll(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
return req, close, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(buf) == 0 {
|
||||||
|
return req, close, validate.ErrBodyRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
d := jx.DecodeBytes(buf)
|
||||||
|
|
||||||
|
var request ScriptCreate
|
||||||
|
if err := func() error {
|
||||||
|
if err := request.Decode(d); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := d.Skip(); err != io.EOF {
|
||||||
|
return errors.New("unexpected trailing data")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
err = &ogenerrors.DecodeBodyError{
|
||||||
|
ContentType: ct,
|
||||||
|
Body: buf,
|
||||||
|
Err: err,
|
||||||
|
}
|
||||||
|
return req, close, err
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := request.Validate(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
return req, close, errors.Wrap(err, "validate")
|
||||||
|
}
|
||||||
|
return &request, close, nil
|
||||||
|
default:
|
||||||
|
return req, close, validate.InvalidContentType(ct)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) decodeCreateScriptPolicyRequest(r *http.Request) (
|
||||||
|
req *ScriptPolicyCreate,
|
||||||
|
close func() error,
|
||||||
|
rerr error,
|
||||||
|
) {
|
||||||
|
var closers []func() error
|
||||||
|
close = func() error {
|
||||||
|
var merr error
|
||||||
|
// Close in reverse order, to match defer behavior.
|
||||||
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
|
c := closers[i]
|
||||||
|
merr = multierr.Append(merr, c())
|
||||||
|
}
|
||||||
|
return merr
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if rerr != nil {
|
||||||
|
rerr = multierr.Append(rerr, close())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
|
if err != nil {
|
||||||
|
return req, close, errors.Wrap(err, "parse media type")
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case ct == "application/json":
|
||||||
|
if r.ContentLength == 0 {
|
||||||
|
return req, close, validate.ErrBodyRequired
|
||||||
|
}
|
||||||
|
buf, err := io.ReadAll(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
return req, close, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(buf) == 0 {
|
||||||
|
return req, close, validate.ErrBodyRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
d := jx.DecodeBytes(buf)
|
||||||
|
|
||||||
|
var request ScriptPolicyCreate
|
||||||
|
if err := func() error {
|
||||||
|
if err := request.Decode(d); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := d.Skip(); err != io.EOF {
|
||||||
|
return errors.New("unexpected trailing data")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
err = &ogenerrors.DecodeBodyError{
|
||||||
|
ContentType: ct,
|
||||||
|
Body: buf,
|
||||||
|
Err: err,
|
||||||
|
}
|
||||||
|
return req, close, err
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := request.Validate(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
return req, close, errors.Wrap(err, "validate")
|
||||||
|
}
|
||||||
|
return &request, close, nil
|
||||||
|
default:
|
||||||
|
return req, close, validate.InvalidContentType(ct)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) decodeCreateSubmissionRequest(r *http.Request) (
|
||||||
|
req *SubmissionCreate,
|
||||||
|
close func() error,
|
||||||
|
rerr error,
|
||||||
|
) {
|
||||||
|
var closers []func() error
|
||||||
|
close = func() error {
|
||||||
|
var merr error
|
||||||
|
// Close in reverse order, to match defer behavior.
|
||||||
|
for i := len(closers) - 1; i >= 0; i-- {
|
||||||
|
c := closers[i]
|
||||||
|
merr = multierr.Append(merr, c())
|
||||||
|
}
|
||||||
|
return merr
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if rerr != nil {
|
||||||
|
rerr = multierr.Append(rerr, close())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
||||||
|
if err != nil {
|
||||||
|
return req, close, errors.Wrap(err, "parse media type")
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case ct == "application/json":
|
||||||
|
if r.ContentLength == 0 {
|
||||||
|
return req, close, validate.ErrBodyRequired
|
||||||
|
}
|
||||||
|
buf, err := io.ReadAll(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
return req, close, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(buf) == 0 {
|
||||||
|
return req, close, validate.ErrBodyRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
d := jx.DecodeBytes(buf)
|
||||||
|
|
||||||
|
var request SubmissionCreate
|
||||||
|
if err := func() error {
|
||||||
|
if err := request.Decode(d); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := d.Skip(); err != io.EOF {
|
||||||
|
return errors.New("unexpected trailing data")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
err = &ogenerrors.DecodeBodyError{
|
||||||
|
ContentType: ct,
|
||||||
|
Body: buf,
|
||||||
|
Err: err,
|
||||||
|
}
|
||||||
|
return req, close, err
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := request.Validate(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
return req, close, errors.Wrap(err, "validate")
|
||||||
|
}
|
||||||
|
return &request, close, nil
|
||||||
|
default:
|
||||||
|
return req, close, validate.InvalidContentType(ct)
|
||||||
|
}
|
||||||
|
}
|
||||||
68
pkg/internal/oas_request_encoders_gen.go
Normal file
68
pkg/internal/oas_request_encoders_gen.go
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
// Code generated by ogen, DO NOT EDIT.
|
||||||
|
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/go-faster/jx"
|
||||||
|
|
||||||
|
ht "github.com/ogen-go/ogen/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func encodeCreateMapfixRequest(
|
||||||
|
req *MapfixCreate,
|
||||||
|
r *http.Request,
|
||||||
|
) error {
|
||||||
|
const contentType = "application/json"
|
||||||
|
e := new(jx.Encoder)
|
||||||
|
{
|
||||||
|
req.Encode(e)
|
||||||
|
}
|
||||||
|
encoded := e.Bytes()
|
||||||
|
ht.SetBody(r, bytes.NewReader(encoded), contentType)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeCreateScriptRequest(
|
||||||
|
req *ScriptCreate,
|
||||||
|
r *http.Request,
|
||||||
|
) error {
|
||||||
|
const contentType = "application/json"
|
||||||
|
e := new(jx.Encoder)
|
||||||
|
{
|
||||||
|
req.Encode(e)
|
||||||
|
}
|
||||||
|
encoded := e.Bytes()
|
||||||
|
ht.SetBody(r, bytes.NewReader(encoded), contentType)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeCreateScriptPolicyRequest(
|
||||||
|
req *ScriptPolicyCreate,
|
||||||
|
r *http.Request,
|
||||||
|
) error {
|
||||||
|
const contentType = "application/json"
|
||||||
|
e := new(jx.Encoder)
|
||||||
|
{
|
||||||
|
req.Encode(e)
|
||||||
|
}
|
||||||
|
encoded := e.Bytes()
|
||||||
|
ht.SetBody(r, bytes.NewReader(encoded), contentType)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeCreateSubmissionRequest(
|
||||||
|
req *SubmissionCreate,
|
||||||
|
r *http.Request,
|
||||||
|
) error {
|
||||||
|
const contentType = "application/json"
|
||||||
|
e := new(jx.Encoder)
|
||||||
|
{
|
||||||
|
req.Encode(e)
|
||||||
|
}
|
||||||
|
encoded := e.Bytes()
|
||||||
|
ht.SetBody(r, bytes.NewReader(encoded), contentType)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
1553
pkg/internal/oas_response_decoders_gen.go
Normal file
1553
pkg/internal/oas_response_decoders_gen.go
Normal file
File diff suppressed because it is too large
Load Diff
238
pkg/internal/oas_response_encoders_gen.go
Normal file
238
pkg/internal/oas_response_encoders_gen.go
Normal file
@@ -0,0 +1,238 @@
|
|||||||
|
// Code generated by ogen, DO NOT EDIT.
|
||||||
|
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/go-faster/errors"
|
||||||
|
"github.com/go-faster/jx"
|
||||||
|
"go.opentelemetry.io/otel/codes"
|
||||||
|
"go.opentelemetry.io/otel/trace"
|
||||||
|
|
||||||
|
ht "github.com/ogen-go/ogen/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func encodeActionMapfixAcceptedResponse(response *ActionMapfixAcceptedNoContent, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.WriteHeader(204)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(204))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeActionMapfixRequestChangesResponse(response *ActionMapfixRequestChangesNoContent, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.WriteHeader(204)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(204))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeActionMapfixSubmittedResponse(response *ActionMapfixSubmittedNoContent, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.WriteHeader(204)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(204))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeActionMapfixUploadedResponse(response *ActionMapfixUploadedNoContent, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.WriteHeader(204)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(204))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeActionMapfixValidatedResponse(response *ActionMapfixValidatedNoContent, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.WriteHeader(204)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(204))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeActionOperationFailedResponse(response *ActionOperationFailedNoContent, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.WriteHeader(204)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(204))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeActionSubmissionAcceptedResponse(response *ActionSubmissionAcceptedNoContent, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.WriteHeader(204)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(204))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeActionSubmissionRequestChangesResponse(response *ActionSubmissionRequestChangesNoContent, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.WriteHeader(204)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(204))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeActionSubmissionSubmittedResponse(response *ActionSubmissionSubmittedNoContent, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.WriteHeader(204)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(204))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeActionSubmissionUploadedResponse(response *ActionSubmissionUploadedNoContent, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.WriteHeader(204)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(204))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeActionSubmissionValidatedResponse(response *ActionSubmissionValidatedNoContent, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.WriteHeader(204)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(204))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeCreateMapfixResponse(response *MapfixID, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
w.WriteHeader(201)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(201))
|
||||||
|
|
||||||
|
e := new(jx.Encoder)
|
||||||
|
response.Encode(e)
|
||||||
|
if _, err := e.WriteTo(w); err != nil {
|
||||||
|
return errors.Wrap(err, "write")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeCreateScriptResponse(response *ScriptID, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
w.WriteHeader(201)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(201))
|
||||||
|
|
||||||
|
e := new(jx.Encoder)
|
||||||
|
response.Encode(e)
|
||||||
|
if _, err := e.WriteTo(w); err != nil {
|
||||||
|
return errors.Wrap(err, "write")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeCreateScriptPolicyResponse(response *ScriptPolicyID, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
w.WriteHeader(201)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(201))
|
||||||
|
|
||||||
|
e := new(jx.Encoder)
|
||||||
|
response.Encode(e)
|
||||||
|
if _, err := e.WriteTo(w); err != nil {
|
||||||
|
return errors.Wrap(err, "write")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeCreateSubmissionResponse(response *SubmissionID, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
w.WriteHeader(201)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(201))
|
||||||
|
|
||||||
|
e := new(jx.Encoder)
|
||||||
|
response.Encode(e)
|
||||||
|
if _, err := e.WriteTo(w); err != nil {
|
||||||
|
return errors.Wrap(err, "write")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeGetScriptResponse(response *Script, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
w.WriteHeader(200)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(200))
|
||||||
|
|
||||||
|
e := new(jx.Encoder)
|
||||||
|
response.Encode(e)
|
||||||
|
if _, err := e.WriteTo(w); err != nil {
|
||||||
|
return errors.Wrap(err, "write")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeListScriptPolicyResponse(response []ScriptPolicy, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
w.WriteHeader(200)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(200))
|
||||||
|
|
||||||
|
e := new(jx.Encoder)
|
||||||
|
e.ArrStart()
|
||||||
|
for _, elem := range response {
|
||||||
|
elem.Encode(e)
|
||||||
|
}
|
||||||
|
e.ArrEnd()
|
||||||
|
if _, err := e.WriteTo(w); err != nil {
|
||||||
|
return errors.Wrap(err, "write")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeListScriptsResponse(response []Script, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
w.WriteHeader(200)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(200))
|
||||||
|
|
||||||
|
e := new(jx.Encoder)
|
||||||
|
e.ArrStart()
|
||||||
|
for _, elem := range response {
|
||||||
|
elem.Encode(e)
|
||||||
|
}
|
||||||
|
e.ArrEnd()
|
||||||
|
if _, err := e.WriteTo(w); err != nil {
|
||||||
|
return errors.Wrap(err, "write")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeUpdateMapfixValidatedModelResponse(response *UpdateMapfixValidatedModelNoContent, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.WriteHeader(204)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(204))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeUpdateSubmissionValidatedModelResponse(response *UpdateSubmissionValidatedModelNoContent, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.WriteHeader(204)
|
||||||
|
span.SetStatus(codes.Ok, http.StatusText(204))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func encodeErrorResponse(response *ErrorStatusCode, w http.ResponseWriter, span trace.Span) error {
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
code := response.StatusCode
|
||||||
|
if code == 0 {
|
||||||
|
// Set default status code.
|
||||||
|
code = http.StatusOK
|
||||||
|
}
|
||||||
|
w.WriteHeader(code)
|
||||||
|
if st := http.StatusText(code); code >= http.StatusBadRequest {
|
||||||
|
span.SetStatus(codes.Error, st)
|
||||||
|
} else {
|
||||||
|
span.SetStatus(codes.Ok, st)
|
||||||
|
}
|
||||||
|
|
||||||
|
e := new(jx.Encoder)
|
||||||
|
response.Response.Encode(e)
|
||||||
|
if _, err := e.WriteTo(w); err != nil {
|
||||||
|
return errors.Wrap(err, "write")
|
||||||
|
}
|
||||||
|
|
||||||
|
if code >= http.StatusInternalServerError {
|
||||||
|
return errors.Wrapf(ht.ErrInternalServerErrorResponse, "code: %d, message: %s", code, http.StatusText(code))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
1333
pkg/internal/oas_router_gen.go
Normal file
1333
pkg/internal/oas_router_gen.go
Normal file
File diff suppressed because it is too large
Load Diff
710
pkg/internal/oas_schemas_gen.go
Normal file
710
pkg/internal/oas_schemas_gen.go
Normal file
@@ -0,0 +1,710 @@
|
|||||||
|
// Code generated by ogen, DO NOT EDIT.
|
||||||
|
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *ErrorStatusCode) Error() string {
|
||||||
|
return fmt.Sprintf("code %d: %+v", s.StatusCode, s.Response)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionMapfixAcceptedNoContent is response for ActionMapfixAccepted operation.
|
||||||
|
type ActionMapfixAcceptedNoContent struct{}
|
||||||
|
|
||||||
|
// ActionMapfixRequestChangesNoContent is response for ActionMapfixRequestChanges operation.
|
||||||
|
type ActionMapfixRequestChangesNoContent struct{}
|
||||||
|
|
||||||
|
// ActionMapfixSubmittedNoContent is response for ActionMapfixSubmitted operation.
|
||||||
|
type ActionMapfixSubmittedNoContent struct{}
|
||||||
|
|
||||||
|
// ActionMapfixUploadedNoContent is response for ActionMapfixUploaded operation.
|
||||||
|
type ActionMapfixUploadedNoContent struct{}
|
||||||
|
|
||||||
|
// ActionMapfixValidatedNoContent is response for ActionMapfixValidated operation.
|
||||||
|
type ActionMapfixValidatedNoContent struct{}
|
||||||
|
|
||||||
|
// ActionOperationFailedNoContent is response for ActionOperationFailed operation.
|
||||||
|
type ActionOperationFailedNoContent struct{}
|
||||||
|
|
||||||
|
// ActionSubmissionAcceptedNoContent is response for ActionSubmissionAccepted operation.
|
||||||
|
type ActionSubmissionAcceptedNoContent struct{}
|
||||||
|
|
||||||
|
// ActionSubmissionRequestChangesNoContent is response for ActionSubmissionRequestChanges operation.
|
||||||
|
type ActionSubmissionRequestChangesNoContent struct{}
|
||||||
|
|
||||||
|
// ActionSubmissionSubmittedNoContent is response for ActionSubmissionSubmitted operation.
|
||||||
|
type ActionSubmissionSubmittedNoContent struct{}
|
||||||
|
|
||||||
|
// ActionSubmissionUploadedNoContent is response for ActionSubmissionUploaded operation.
|
||||||
|
type ActionSubmissionUploadedNoContent struct{}
|
||||||
|
|
||||||
|
// ActionSubmissionValidatedNoContent is response for ActionSubmissionValidated operation.
|
||||||
|
type ActionSubmissionValidatedNoContent struct{}
|
||||||
|
|
||||||
|
// Represents error object.
|
||||||
|
// Ref: #/components/schemas/Error
|
||||||
|
type Error struct {
|
||||||
|
Code int64 `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCode returns the value of Code.
|
||||||
|
func (s *Error) GetCode() int64 {
|
||||||
|
return s.Code
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMessage returns the value of Message.
|
||||||
|
func (s *Error) GetMessage() string {
|
||||||
|
return s.Message
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCode sets the value of Code.
|
||||||
|
func (s *Error) SetCode(val int64) {
|
||||||
|
s.Code = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMessage sets the value of Message.
|
||||||
|
func (s *Error) SetMessage(val string) {
|
||||||
|
s.Message = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrorStatusCode wraps Error with StatusCode.
|
||||||
|
type ErrorStatusCode struct {
|
||||||
|
StatusCode int
|
||||||
|
Response Error
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetStatusCode returns the value of StatusCode.
|
||||||
|
func (s *ErrorStatusCode) GetStatusCode() int {
|
||||||
|
return s.StatusCode
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetResponse returns the value of Response.
|
||||||
|
func (s *ErrorStatusCode) GetResponse() Error {
|
||||||
|
return s.Response
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatusCode sets the value of StatusCode.
|
||||||
|
func (s *ErrorStatusCode) SetStatusCode(val int) {
|
||||||
|
s.StatusCode = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetResponse sets the value of Response.
|
||||||
|
func (s *ErrorStatusCode) SetResponse(val Error) {
|
||||||
|
s.Response = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ref: #/components/schemas/MapfixCreate
|
||||||
|
type MapfixCreate struct {
|
||||||
|
OperationID int32 `json:"OperationID"`
|
||||||
|
AssetOwner int64 `json:"AssetOwner"`
|
||||||
|
DisplayName string `json:"DisplayName"`
|
||||||
|
Creator string `json:"Creator"`
|
||||||
|
GameID int32 `json:"GameID"`
|
||||||
|
AssetID int64 `json:"AssetID"`
|
||||||
|
AssetVersion int64 `json:"AssetVersion"`
|
||||||
|
TargetAssetID int64 `json:"TargetAssetID"`
|
||||||
|
Description string `json:"Description"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOperationID returns the value of OperationID.
|
||||||
|
func (s *MapfixCreate) GetOperationID() int32 {
|
||||||
|
return s.OperationID
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAssetOwner returns the value of AssetOwner.
|
||||||
|
func (s *MapfixCreate) GetAssetOwner() int64 {
|
||||||
|
return s.AssetOwner
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDisplayName returns the value of DisplayName.
|
||||||
|
func (s *MapfixCreate) GetDisplayName() string {
|
||||||
|
return s.DisplayName
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCreator returns the value of Creator.
|
||||||
|
func (s *MapfixCreate) GetCreator() string {
|
||||||
|
return s.Creator
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGameID returns the value of GameID.
|
||||||
|
func (s *MapfixCreate) GetGameID() int32 {
|
||||||
|
return s.GameID
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAssetID returns the value of AssetID.
|
||||||
|
func (s *MapfixCreate) GetAssetID() int64 {
|
||||||
|
return s.AssetID
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAssetVersion returns the value of AssetVersion.
|
||||||
|
func (s *MapfixCreate) GetAssetVersion() int64 {
|
||||||
|
return s.AssetVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTargetAssetID returns the value of TargetAssetID.
|
||||||
|
func (s *MapfixCreate) GetTargetAssetID() int64 {
|
||||||
|
return s.TargetAssetID
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDescription returns the value of Description.
|
||||||
|
func (s *MapfixCreate) GetDescription() string {
|
||||||
|
return s.Description
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOperationID sets the value of OperationID.
|
||||||
|
func (s *MapfixCreate) SetOperationID(val int32) {
|
||||||
|
s.OperationID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAssetOwner sets the value of AssetOwner.
|
||||||
|
func (s *MapfixCreate) SetAssetOwner(val int64) {
|
||||||
|
s.AssetOwner = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDisplayName sets the value of DisplayName.
|
||||||
|
func (s *MapfixCreate) SetDisplayName(val string) {
|
||||||
|
s.DisplayName = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreator sets the value of Creator.
|
||||||
|
func (s *MapfixCreate) SetCreator(val string) {
|
||||||
|
s.Creator = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGameID sets the value of GameID.
|
||||||
|
func (s *MapfixCreate) SetGameID(val int32) {
|
||||||
|
s.GameID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAssetID sets the value of AssetID.
|
||||||
|
func (s *MapfixCreate) SetAssetID(val int64) {
|
||||||
|
s.AssetID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAssetVersion sets the value of AssetVersion.
|
||||||
|
func (s *MapfixCreate) SetAssetVersion(val int64) {
|
||||||
|
s.AssetVersion = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTargetAssetID sets the value of TargetAssetID.
|
||||||
|
func (s *MapfixCreate) SetTargetAssetID(val int64) {
|
||||||
|
s.TargetAssetID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the value of Description.
|
||||||
|
func (s *MapfixCreate) SetDescription(val string) {
|
||||||
|
s.Description = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ref: #/components/schemas/MapfixID
|
||||||
|
type MapfixID struct {
|
||||||
|
MapfixID int64 `json:"MapfixID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMapfixID returns the value of MapfixID.
|
||||||
|
func (s *MapfixID) GetMapfixID() int64 {
|
||||||
|
return s.MapfixID
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMapfixID sets the value of MapfixID.
|
||||||
|
func (s *MapfixID) SetMapfixID(val int64) {
|
||||||
|
s.MapfixID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewOptInt32 returns new OptInt32 with value set to v.
|
||||||
|
func NewOptInt32(v int32) OptInt32 {
|
||||||
|
return OptInt32{
|
||||||
|
Value: v,
|
||||||
|
Set: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OptInt32 is optional int32.
|
||||||
|
type OptInt32 struct {
|
||||||
|
Value int32
|
||||||
|
Set bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsSet returns true if OptInt32 was set.
|
||||||
|
func (o OptInt32) IsSet() bool { return o.Set }
|
||||||
|
|
||||||
|
// Reset unsets value.
|
||||||
|
func (o *OptInt32) Reset() {
|
||||||
|
var v int32
|
||||||
|
o.Value = v
|
||||||
|
o.Set = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTo sets value to v.
|
||||||
|
func (o *OptInt32) SetTo(v int32) {
|
||||||
|
o.Set = true
|
||||||
|
o.Value = v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns value and boolean that denotes whether value was set.
|
||||||
|
func (o OptInt32) Get() (v int32, ok bool) {
|
||||||
|
if !o.Set {
|
||||||
|
return v, false
|
||||||
|
}
|
||||||
|
return o.Value, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or returns value if set, or given parameter if does not.
|
||||||
|
func (o OptInt32) Or(d int32) int32 {
|
||||||
|
if v, ok := o.Get(); ok {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewOptInt64 returns new OptInt64 with value set to v.
|
||||||
|
func NewOptInt64(v int64) OptInt64 {
|
||||||
|
return OptInt64{
|
||||||
|
Value: v,
|
||||||
|
Set: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OptInt64 is optional int64.
|
||||||
|
type OptInt64 struct {
|
||||||
|
Value int64
|
||||||
|
Set bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsSet returns true if OptInt64 was set.
|
||||||
|
func (o OptInt64) IsSet() bool { return o.Set }
|
||||||
|
|
||||||
|
// Reset unsets value.
|
||||||
|
func (o *OptInt64) Reset() {
|
||||||
|
var v int64
|
||||||
|
o.Value = v
|
||||||
|
o.Set = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTo sets value to v.
|
||||||
|
func (o *OptInt64) SetTo(v int64) {
|
||||||
|
o.Set = true
|
||||||
|
o.Value = v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns value and boolean that denotes whether value was set.
|
||||||
|
func (o OptInt64) Get() (v int64, ok bool) {
|
||||||
|
if !o.Set {
|
||||||
|
return v, false
|
||||||
|
}
|
||||||
|
return o.Value, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or returns value if set, or given parameter if does not.
|
||||||
|
func (o OptInt64) Or(d int64) int64 {
|
||||||
|
if v, ok := o.Get(); ok {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewOptString returns new OptString with value set to v.
|
||||||
|
func NewOptString(v string) OptString {
|
||||||
|
return OptString{
|
||||||
|
Value: v,
|
||||||
|
Set: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OptString is optional string.
|
||||||
|
type OptString struct {
|
||||||
|
Value string
|
||||||
|
Set bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsSet returns true if OptString was set.
|
||||||
|
func (o OptString) IsSet() bool { return o.Set }
|
||||||
|
|
||||||
|
// Reset unsets value.
|
||||||
|
func (o *OptString) Reset() {
|
||||||
|
var v string
|
||||||
|
o.Value = v
|
||||||
|
o.Set = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTo sets value to v.
|
||||||
|
func (o *OptString) SetTo(v string) {
|
||||||
|
o.Set = true
|
||||||
|
o.Value = v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns value and boolean that denotes whether value was set.
|
||||||
|
func (o OptString) Get() (v string, ok bool) {
|
||||||
|
if !o.Set {
|
||||||
|
return v, false
|
||||||
|
}
|
||||||
|
return o.Value, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or returns value if set, or given parameter if does not.
|
||||||
|
func (o OptString) Or(d string) string {
|
||||||
|
if v, ok := o.Get(); ok {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ref: #/components/schemas/Script
|
||||||
|
type Script struct {
|
||||||
|
ID int64 `json:"ID"`
|
||||||
|
Name string `json:"Name"`
|
||||||
|
Hash string `json:"Hash"`
|
||||||
|
Source string `json:"Source"`
|
||||||
|
ResourceType int32 `json:"ResourceType"`
|
||||||
|
ResourceID int64 `json:"ResourceID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetID returns the value of ID.
|
||||||
|
func (s *Script) GetID() int64 {
|
||||||
|
return s.ID
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName returns the value of Name.
|
||||||
|
func (s *Script) GetName() string {
|
||||||
|
return s.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHash returns the value of Hash.
|
||||||
|
func (s *Script) GetHash() string {
|
||||||
|
return s.Hash
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSource returns the value of Source.
|
||||||
|
func (s *Script) GetSource() string {
|
||||||
|
return s.Source
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetResourceType returns the value of ResourceType.
|
||||||
|
func (s *Script) GetResourceType() int32 {
|
||||||
|
return s.ResourceType
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetResourceID returns the value of ResourceID.
|
||||||
|
func (s *Script) GetResourceID() int64 {
|
||||||
|
return s.ResourceID
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the value of ID.
|
||||||
|
func (s *Script) SetID(val int64) {
|
||||||
|
s.ID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the value of Name.
|
||||||
|
func (s *Script) SetName(val string) {
|
||||||
|
s.Name = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetHash sets the value of Hash.
|
||||||
|
func (s *Script) SetHash(val string) {
|
||||||
|
s.Hash = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSource sets the value of Source.
|
||||||
|
func (s *Script) SetSource(val string) {
|
||||||
|
s.Source = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetResourceType sets the value of ResourceType.
|
||||||
|
func (s *Script) SetResourceType(val int32) {
|
||||||
|
s.ResourceType = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetResourceID sets the value of ResourceID.
|
||||||
|
func (s *Script) SetResourceID(val int64) {
|
||||||
|
s.ResourceID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ref: #/components/schemas/ScriptCreate
|
||||||
|
type ScriptCreate struct {
|
||||||
|
Name string `json:"Name"`
|
||||||
|
Source string `json:"Source"`
|
||||||
|
ResourceType int32 `json:"ResourceType"`
|
||||||
|
ResourceID OptInt64 `json:"ResourceID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName returns the value of Name.
|
||||||
|
func (s *ScriptCreate) GetName() string {
|
||||||
|
return s.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSource returns the value of Source.
|
||||||
|
func (s *ScriptCreate) GetSource() string {
|
||||||
|
return s.Source
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetResourceType returns the value of ResourceType.
|
||||||
|
func (s *ScriptCreate) GetResourceType() int32 {
|
||||||
|
return s.ResourceType
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetResourceID returns the value of ResourceID.
|
||||||
|
func (s *ScriptCreate) GetResourceID() OptInt64 {
|
||||||
|
return s.ResourceID
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the value of Name.
|
||||||
|
func (s *ScriptCreate) SetName(val string) {
|
||||||
|
s.Name = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSource sets the value of Source.
|
||||||
|
func (s *ScriptCreate) SetSource(val string) {
|
||||||
|
s.Source = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetResourceType sets the value of ResourceType.
|
||||||
|
func (s *ScriptCreate) SetResourceType(val int32) {
|
||||||
|
s.ResourceType = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetResourceID sets the value of ResourceID.
|
||||||
|
func (s *ScriptCreate) SetResourceID(val OptInt64) {
|
||||||
|
s.ResourceID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ref: #/components/schemas/ScriptID
|
||||||
|
type ScriptID struct {
|
||||||
|
ScriptID int64 `json:"ScriptID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetScriptID returns the value of ScriptID.
|
||||||
|
func (s *ScriptID) GetScriptID() int64 {
|
||||||
|
return s.ScriptID
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetScriptID sets the value of ScriptID.
|
||||||
|
func (s *ScriptID) SetScriptID(val int64) {
|
||||||
|
s.ScriptID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ref: #/components/schemas/ScriptPolicy
|
||||||
|
type ScriptPolicy struct {
|
||||||
|
ID int64 `json:"ID"`
|
||||||
|
FromScriptHash string `json:"FromScriptHash"`
|
||||||
|
ToScriptID int64 `json:"ToScriptID"`
|
||||||
|
Policy int32 `json:"Policy"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetID returns the value of ID.
|
||||||
|
func (s *ScriptPolicy) GetID() int64 {
|
||||||
|
return s.ID
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetFromScriptHash returns the value of FromScriptHash.
|
||||||
|
func (s *ScriptPolicy) GetFromScriptHash() string {
|
||||||
|
return s.FromScriptHash
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetToScriptID returns the value of ToScriptID.
|
||||||
|
func (s *ScriptPolicy) GetToScriptID() int64 {
|
||||||
|
return s.ToScriptID
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPolicy returns the value of Policy.
|
||||||
|
func (s *ScriptPolicy) GetPolicy() int32 {
|
||||||
|
return s.Policy
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the value of ID.
|
||||||
|
func (s *ScriptPolicy) SetID(val int64) {
|
||||||
|
s.ID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetFromScriptHash sets the value of FromScriptHash.
|
||||||
|
func (s *ScriptPolicy) SetFromScriptHash(val string) {
|
||||||
|
s.FromScriptHash = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetToScriptID sets the value of ToScriptID.
|
||||||
|
func (s *ScriptPolicy) SetToScriptID(val int64) {
|
||||||
|
s.ToScriptID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPolicy sets the value of Policy.
|
||||||
|
func (s *ScriptPolicy) SetPolicy(val int32) {
|
||||||
|
s.Policy = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ref: #/components/schemas/ScriptPolicyCreate
|
||||||
|
type ScriptPolicyCreate struct {
|
||||||
|
FromScriptID int64 `json:"FromScriptID"`
|
||||||
|
ToScriptID int64 `json:"ToScriptID"`
|
||||||
|
Policy int32 `json:"Policy"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetFromScriptID returns the value of FromScriptID.
|
||||||
|
func (s *ScriptPolicyCreate) GetFromScriptID() int64 {
|
||||||
|
return s.FromScriptID
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetToScriptID returns the value of ToScriptID.
|
||||||
|
func (s *ScriptPolicyCreate) GetToScriptID() int64 {
|
||||||
|
return s.ToScriptID
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPolicy returns the value of Policy.
|
||||||
|
func (s *ScriptPolicyCreate) GetPolicy() int32 {
|
||||||
|
return s.Policy
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetFromScriptID sets the value of FromScriptID.
|
||||||
|
func (s *ScriptPolicyCreate) SetFromScriptID(val int64) {
|
||||||
|
s.FromScriptID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetToScriptID sets the value of ToScriptID.
|
||||||
|
func (s *ScriptPolicyCreate) SetToScriptID(val int64) {
|
||||||
|
s.ToScriptID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPolicy sets the value of Policy.
|
||||||
|
func (s *ScriptPolicyCreate) SetPolicy(val int32) {
|
||||||
|
s.Policy = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ref: #/components/schemas/ScriptPolicyID
|
||||||
|
type ScriptPolicyID struct {
|
||||||
|
ScriptPolicyID int64 `json:"ScriptPolicyID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetScriptPolicyID returns the value of ScriptPolicyID.
|
||||||
|
func (s *ScriptPolicyID) GetScriptPolicyID() int64 {
|
||||||
|
return s.ScriptPolicyID
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetScriptPolicyID sets the value of ScriptPolicyID.
|
||||||
|
func (s *ScriptPolicyID) SetScriptPolicyID(val int64) {
|
||||||
|
s.ScriptPolicyID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ref: #/components/schemas/SubmissionCreate
|
||||||
|
type SubmissionCreate struct {
|
||||||
|
OperationID int32 `json:"OperationID"`
|
||||||
|
AssetOwner int64 `json:"AssetOwner"`
|
||||||
|
DisplayName string `json:"DisplayName"`
|
||||||
|
Creator string `json:"Creator"`
|
||||||
|
GameID int32 `json:"GameID"`
|
||||||
|
AssetID int64 `json:"AssetID"`
|
||||||
|
AssetVersion int64 `json:"AssetVersion"`
|
||||||
|
Status uint32 `json:"Status"`
|
||||||
|
Roles uint32 `json:"Roles"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOperationID returns the value of OperationID.
|
||||||
|
func (s *SubmissionCreate) GetOperationID() int32 {
|
||||||
|
return s.OperationID
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAssetOwner returns the value of AssetOwner.
|
||||||
|
func (s *SubmissionCreate) GetAssetOwner() int64 {
|
||||||
|
return s.AssetOwner
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDisplayName returns the value of DisplayName.
|
||||||
|
func (s *SubmissionCreate) GetDisplayName() string {
|
||||||
|
return s.DisplayName
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCreator returns the value of Creator.
|
||||||
|
func (s *SubmissionCreate) GetCreator() string {
|
||||||
|
return s.Creator
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGameID returns the value of GameID.
|
||||||
|
func (s *SubmissionCreate) GetGameID() int32 {
|
||||||
|
return s.GameID
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAssetID returns the value of AssetID.
|
||||||
|
func (s *SubmissionCreate) GetAssetID() int64 {
|
||||||
|
return s.AssetID
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAssetVersion returns the value of AssetVersion.
|
||||||
|
func (s *SubmissionCreate) GetAssetVersion() int64 {
|
||||||
|
return s.AssetVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetStatus returns the value of Status.
|
||||||
|
func (s *SubmissionCreate) GetStatus() uint32 {
|
||||||
|
return s.Status
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRoles returns the value of Roles.
|
||||||
|
func (s *SubmissionCreate) GetRoles() uint32 {
|
||||||
|
return s.Roles
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOperationID sets the value of OperationID.
|
||||||
|
func (s *SubmissionCreate) SetOperationID(val int32) {
|
||||||
|
s.OperationID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAssetOwner sets the value of AssetOwner.
|
||||||
|
func (s *SubmissionCreate) SetAssetOwner(val int64) {
|
||||||
|
s.AssetOwner = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDisplayName sets the value of DisplayName.
|
||||||
|
func (s *SubmissionCreate) SetDisplayName(val string) {
|
||||||
|
s.DisplayName = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreator sets the value of Creator.
|
||||||
|
func (s *SubmissionCreate) SetCreator(val string) {
|
||||||
|
s.Creator = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGameID sets the value of GameID.
|
||||||
|
func (s *SubmissionCreate) SetGameID(val int32) {
|
||||||
|
s.GameID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAssetID sets the value of AssetID.
|
||||||
|
func (s *SubmissionCreate) SetAssetID(val int64) {
|
||||||
|
s.AssetID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAssetVersion sets the value of AssetVersion.
|
||||||
|
func (s *SubmissionCreate) SetAssetVersion(val int64) {
|
||||||
|
s.AssetVersion = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the value of Status.
|
||||||
|
func (s *SubmissionCreate) SetStatus(val uint32) {
|
||||||
|
s.Status = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRoles sets the value of Roles.
|
||||||
|
func (s *SubmissionCreate) SetRoles(val uint32) {
|
||||||
|
s.Roles = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ref: #/components/schemas/SubmissionID
|
||||||
|
type SubmissionID struct {
|
||||||
|
SubmissionID int64 `json:"SubmissionID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSubmissionID returns the value of SubmissionID.
|
||||||
|
func (s *SubmissionID) GetSubmissionID() int64 {
|
||||||
|
return s.SubmissionID
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSubmissionID sets the value of SubmissionID.
|
||||||
|
func (s *SubmissionID) SetSubmissionID(val int64) {
|
||||||
|
s.SubmissionID = val
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateMapfixValidatedModelNoContent is response for UpdateMapfixValidatedModel operation.
|
||||||
|
type UpdateMapfixValidatedModelNoContent struct{}
|
||||||
|
|
||||||
|
// UpdateSubmissionValidatedModelNoContent is response for UpdateSubmissionValidatedModel operation.
|
||||||
|
type UpdateSubmissionValidatedModelNoContent struct{}
|
||||||
154
pkg/internal/oas_server_gen.go
Normal file
154
pkg/internal/oas_server_gen.go
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
// Code generated by ogen, DO NOT EDIT.
|
||||||
|
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Handler handles operations described by OpenAPI v3 specification.
|
||||||
|
type Handler interface {
|
||||||
|
// ActionMapfixAccepted implements actionMapfixAccepted operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Validating -> Accepted.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/status/validator-failed
|
||||||
|
ActionMapfixAccepted(ctx context.Context, params ActionMapfixAcceptedParams) error
|
||||||
|
// ActionMapfixRequestChanges implements actionMapfixRequestChanges operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Submitting -> ChangesRequested.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/status/validator-request-changes
|
||||||
|
ActionMapfixRequestChanges(ctx context.Context, params ActionMapfixRequestChangesParams) error
|
||||||
|
// ActionMapfixSubmitted implements actionMapfixSubmitted operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Submitting -> Submitted.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/status/validator-submitted
|
||||||
|
ActionMapfixSubmitted(ctx context.Context, params ActionMapfixSubmittedParams) error
|
||||||
|
// ActionMapfixUploaded implements actionMapfixUploaded operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Uploading -> Uploaded.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/status/validator-uploaded
|
||||||
|
ActionMapfixUploaded(ctx context.Context, params ActionMapfixUploadedParams) error
|
||||||
|
// ActionMapfixValidated implements actionMapfixValidated operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Validating -> Validated.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/status/validator-validated
|
||||||
|
ActionMapfixValidated(ctx context.Context, params ActionMapfixValidatedParams) error
|
||||||
|
// ActionOperationFailed implements actionOperationFailed operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Fail an operation and write a StatusMessage.
|
||||||
|
//
|
||||||
|
// POST /operations/{OperationID}/status/operation-failed
|
||||||
|
ActionOperationFailed(ctx context.Context, params ActionOperationFailedParams) error
|
||||||
|
// ActionSubmissionAccepted implements actionSubmissionAccepted operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Validating -> Accepted.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/status/validator-failed
|
||||||
|
ActionSubmissionAccepted(ctx context.Context, params ActionSubmissionAcceptedParams) error
|
||||||
|
// ActionSubmissionRequestChanges implements actionSubmissionRequestChanges operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Submitting -> ChangesRequested.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/status/validator-request-changes
|
||||||
|
ActionSubmissionRequestChanges(ctx context.Context, params ActionSubmissionRequestChangesParams) error
|
||||||
|
// ActionSubmissionSubmitted implements actionSubmissionSubmitted operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Submitting -> Submitted.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/status/validator-submitted
|
||||||
|
ActionSubmissionSubmitted(ctx context.Context, params ActionSubmissionSubmittedParams) error
|
||||||
|
// ActionSubmissionUploaded implements actionSubmissionUploaded operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Uploading -> Uploaded.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/status/validator-uploaded
|
||||||
|
ActionSubmissionUploaded(ctx context.Context, params ActionSubmissionUploadedParams) error
|
||||||
|
// ActionSubmissionValidated implements actionSubmissionValidated operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Validating -> Validated.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/status/validator-validated
|
||||||
|
ActionSubmissionValidated(ctx context.Context, params ActionSubmissionValidatedParams) error
|
||||||
|
// CreateMapfix implements createMapfix operation.
|
||||||
|
//
|
||||||
|
// Create a mapfix.
|
||||||
|
//
|
||||||
|
// POST /mapfixes
|
||||||
|
CreateMapfix(ctx context.Context, req *MapfixCreate) (*MapfixID, error)
|
||||||
|
// CreateScript implements createScript operation.
|
||||||
|
//
|
||||||
|
// Create a new script.
|
||||||
|
//
|
||||||
|
// POST /scripts
|
||||||
|
CreateScript(ctx context.Context, req *ScriptCreate) (*ScriptID, error)
|
||||||
|
// CreateScriptPolicy implements createScriptPolicy operation.
|
||||||
|
//
|
||||||
|
// Create a new script policy.
|
||||||
|
//
|
||||||
|
// POST /script-policy
|
||||||
|
CreateScriptPolicy(ctx context.Context, req *ScriptPolicyCreate) (*ScriptPolicyID, error)
|
||||||
|
// CreateSubmission implements createSubmission operation.
|
||||||
|
//
|
||||||
|
// Create a new submission.
|
||||||
|
//
|
||||||
|
// POST /submissions
|
||||||
|
CreateSubmission(ctx context.Context, req *SubmissionCreate) (*SubmissionID, error)
|
||||||
|
// GetScript implements getScript operation.
|
||||||
|
//
|
||||||
|
// Get the specified script by ID.
|
||||||
|
//
|
||||||
|
// GET /scripts/{ScriptID}
|
||||||
|
GetScript(ctx context.Context, params GetScriptParams) (*Script, error)
|
||||||
|
// ListScriptPolicy implements listScriptPolicy operation.
|
||||||
|
//
|
||||||
|
// Get list of script policies.
|
||||||
|
//
|
||||||
|
// GET /script-policy
|
||||||
|
ListScriptPolicy(ctx context.Context, params ListScriptPolicyParams) ([]ScriptPolicy, error)
|
||||||
|
// ListScripts implements listScripts operation.
|
||||||
|
//
|
||||||
|
// Get list of scripts.
|
||||||
|
//
|
||||||
|
// GET /scripts
|
||||||
|
ListScripts(ctx context.Context, params ListScriptsParams) ([]Script, error)
|
||||||
|
// UpdateMapfixValidatedModel implements updateMapfixValidatedModel operation.
|
||||||
|
//
|
||||||
|
// Update validated model.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/validated-model
|
||||||
|
UpdateMapfixValidatedModel(ctx context.Context, params UpdateMapfixValidatedModelParams) error
|
||||||
|
// UpdateSubmissionValidatedModel implements updateSubmissionValidatedModel operation.
|
||||||
|
//
|
||||||
|
// Update validated model.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/validated-model
|
||||||
|
UpdateSubmissionValidatedModel(ctx context.Context, params UpdateSubmissionValidatedModelParams) error
|
||||||
|
// NewError creates *ErrorStatusCode from error returned by handler.
|
||||||
|
//
|
||||||
|
// Used for common default response.
|
||||||
|
NewError(ctx context.Context, err error) *ErrorStatusCode
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server implements http server based on OpenAPI v3 specification and
|
||||||
|
// calls Handler to handle requests.
|
||||||
|
type Server struct {
|
||||||
|
h Handler
|
||||||
|
baseServer
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewServer creates new Server.
|
||||||
|
func NewServer(h Handler, opts ...ServerOption) (*Server, error) {
|
||||||
|
s, err := newServerConfig(opts...).baseServer()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &Server{
|
||||||
|
h: h,
|
||||||
|
baseServer: s,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
202
pkg/internal/oas_unimplemented_gen.go
Normal file
202
pkg/internal/oas_unimplemented_gen.go
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
// Code generated by ogen, DO NOT EDIT.
|
||||||
|
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
ht "github.com/ogen-go/ogen/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UnimplementedHandler is no-op Handler which returns http.ErrNotImplemented.
|
||||||
|
type UnimplementedHandler struct{}
|
||||||
|
|
||||||
|
var _ Handler = UnimplementedHandler{}
|
||||||
|
|
||||||
|
// ActionMapfixAccepted implements actionMapfixAccepted operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Validating -> Accepted.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/status/validator-failed
|
||||||
|
func (UnimplementedHandler) ActionMapfixAccepted(ctx context.Context, params ActionMapfixAcceptedParams) error {
|
||||||
|
return ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionMapfixRequestChanges implements actionMapfixRequestChanges operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Submitting -> ChangesRequested.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/status/validator-request-changes
|
||||||
|
func (UnimplementedHandler) ActionMapfixRequestChanges(ctx context.Context, params ActionMapfixRequestChangesParams) error {
|
||||||
|
return ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionMapfixSubmitted implements actionMapfixSubmitted operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Submitting -> Submitted.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/status/validator-submitted
|
||||||
|
func (UnimplementedHandler) ActionMapfixSubmitted(ctx context.Context, params ActionMapfixSubmittedParams) error {
|
||||||
|
return ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionMapfixUploaded implements actionMapfixUploaded operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Uploading -> Uploaded.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/status/validator-uploaded
|
||||||
|
func (UnimplementedHandler) ActionMapfixUploaded(ctx context.Context, params ActionMapfixUploadedParams) error {
|
||||||
|
return ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionMapfixValidated implements actionMapfixValidated operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Validating -> Validated.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/status/validator-validated
|
||||||
|
func (UnimplementedHandler) ActionMapfixValidated(ctx context.Context, params ActionMapfixValidatedParams) error {
|
||||||
|
return ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionOperationFailed implements actionOperationFailed operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Fail an operation and write a StatusMessage.
|
||||||
|
//
|
||||||
|
// POST /operations/{OperationID}/status/operation-failed
|
||||||
|
func (UnimplementedHandler) ActionOperationFailed(ctx context.Context, params ActionOperationFailedParams) error {
|
||||||
|
return ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionSubmissionAccepted implements actionSubmissionAccepted operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Validating -> Accepted.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/status/validator-failed
|
||||||
|
func (UnimplementedHandler) ActionSubmissionAccepted(ctx context.Context, params ActionSubmissionAcceptedParams) error {
|
||||||
|
return ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionSubmissionRequestChanges implements actionSubmissionRequestChanges operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Submitting -> ChangesRequested.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/status/validator-request-changes
|
||||||
|
func (UnimplementedHandler) ActionSubmissionRequestChanges(ctx context.Context, params ActionSubmissionRequestChangesParams) error {
|
||||||
|
return ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionSubmissionSubmitted implements actionSubmissionSubmitted operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Submitting -> Submitted.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/status/validator-submitted
|
||||||
|
func (UnimplementedHandler) ActionSubmissionSubmitted(ctx context.Context, params ActionSubmissionSubmittedParams) error {
|
||||||
|
return ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionSubmissionUploaded implements actionSubmissionUploaded operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Uploading -> Uploaded.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/status/validator-uploaded
|
||||||
|
func (UnimplementedHandler) ActionSubmissionUploaded(ctx context.Context, params ActionSubmissionUploadedParams) error {
|
||||||
|
return ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionSubmissionValidated implements actionSubmissionValidated operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Validating -> Validated.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/status/validator-validated
|
||||||
|
func (UnimplementedHandler) ActionSubmissionValidated(ctx context.Context, params ActionSubmissionValidatedParams) error {
|
||||||
|
return ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateMapfix implements createMapfix operation.
|
||||||
|
//
|
||||||
|
// Create a mapfix.
|
||||||
|
//
|
||||||
|
// POST /mapfixes
|
||||||
|
func (UnimplementedHandler) CreateMapfix(ctx context.Context, req *MapfixCreate) (r *MapfixID, _ error) {
|
||||||
|
return r, ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateScript implements createScript operation.
|
||||||
|
//
|
||||||
|
// Create a new script.
|
||||||
|
//
|
||||||
|
// POST /scripts
|
||||||
|
func (UnimplementedHandler) CreateScript(ctx context.Context, req *ScriptCreate) (r *ScriptID, _ error) {
|
||||||
|
return r, ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateScriptPolicy implements createScriptPolicy operation.
|
||||||
|
//
|
||||||
|
// Create a new script policy.
|
||||||
|
//
|
||||||
|
// POST /script-policy
|
||||||
|
func (UnimplementedHandler) CreateScriptPolicy(ctx context.Context, req *ScriptPolicyCreate) (r *ScriptPolicyID, _ error) {
|
||||||
|
return r, ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateSubmission implements createSubmission operation.
|
||||||
|
//
|
||||||
|
// Create a new submission.
|
||||||
|
//
|
||||||
|
// POST /submissions
|
||||||
|
func (UnimplementedHandler) CreateSubmission(ctx context.Context, req *SubmissionCreate) (r *SubmissionID, _ error) {
|
||||||
|
return r, ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetScript implements getScript operation.
|
||||||
|
//
|
||||||
|
// Get the specified script by ID.
|
||||||
|
//
|
||||||
|
// GET /scripts/{ScriptID}
|
||||||
|
func (UnimplementedHandler) GetScript(ctx context.Context, params GetScriptParams) (r *Script, _ error) {
|
||||||
|
return r, ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListScriptPolicy implements listScriptPolicy operation.
|
||||||
|
//
|
||||||
|
// Get list of script policies.
|
||||||
|
//
|
||||||
|
// GET /script-policy
|
||||||
|
func (UnimplementedHandler) ListScriptPolicy(ctx context.Context, params ListScriptPolicyParams) (r []ScriptPolicy, _ error) {
|
||||||
|
return r, ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListScripts implements listScripts operation.
|
||||||
|
//
|
||||||
|
// Get list of scripts.
|
||||||
|
//
|
||||||
|
// GET /scripts
|
||||||
|
func (UnimplementedHandler) ListScripts(ctx context.Context, params ListScriptsParams) (r []Script, _ error) {
|
||||||
|
return r, ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateMapfixValidatedModel implements updateMapfixValidatedModel operation.
|
||||||
|
//
|
||||||
|
// Update validated model.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/validated-model
|
||||||
|
func (UnimplementedHandler) UpdateMapfixValidatedModel(ctx context.Context, params UpdateMapfixValidatedModelParams) error {
|
||||||
|
return ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateSubmissionValidatedModel implements updateSubmissionValidatedModel operation.
|
||||||
|
//
|
||||||
|
// Update validated model.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/validated-model
|
||||||
|
func (UnimplementedHandler) UpdateSubmissionValidatedModel(ctx context.Context, params UpdateSubmissionValidatedModelParams) error {
|
||||||
|
return ht.ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewError creates *ErrorStatusCode from error returned by handler.
|
||||||
|
//
|
||||||
|
// Used for common default response.
|
||||||
|
func (UnimplementedHandler) NewError(ctx context.Context, err error) (r *ErrorStatusCode) {
|
||||||
|
r = new(ErrorStatusCode)
|
||||||
|
return r
|
||||||
|
}
|
||||||
940
pkg/internal/oas_validators_gen.go
Normal file
940
pkg/internal/oas_validators_gen.go
Normal file
@@ -0,0 +1,940 @@
|
|||||||
|
// Code generated by ogen, DO NOT EDIT.
|
||||||
|
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/go-faster/errors"
|
||||||
|
|
||||||
|
"github.com/ogen-go/ogen/validate"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Error) Validate() error {
|
||||||
|
if s == nil {
|
||||||
|
return validate.ErrNilPointer
|
||||||
|
}
|
||||||
|
|
||||||
|
var failures []validate.FieldError
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.Code)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "code",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(failures) > 0 {
|
||||||
|
return &validate.Error{Fields: failures}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ErrorStatusCode) Validate() error {
|
||||||
|
if s == nil {
|
||||||
|
return validate.ErrNilPointer
|
||||||
|
}
|
||||||
|
|
||||||
|
var failures []validate.FieldError
|
||||||
|
if err := func() error {
|
||||||
|
if err := s.Response.Validate(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "Response",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(failures) > 0 {
|
||||||
|
return &validate.Error{Fields: failures}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MapfixCreate) Validate() error {
|
||||||
|
if s == nil {
|
||||||
|
return validate.ErrNilPointer
|
||||||
|
}
|
||||||
|
|
||||||
|
var failures []validate.FieldError
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.OperationID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "OperationID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.AssetOwner)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "AssetOwner",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.String{
|
||||||
|
MinLength: 0,
|
||||||
|
MinLengthSet: false,
|
||||||
|
MaxLength: 128,
|
||||||
|
MaxLengthSet: true,
|
||||||
|
Email: false,
|
||||||
|
Hostname: false,
|
||||||
|
Regex: nil,
|
||||||
|
}).Validate(string(s.DisplayName)); err != nil {
|
||||||
|
return errors.Wrap(err, "string")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "DisplayName",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.String{
|
||||||
|
MinLength: 0,
|
||||||
|
MinLengthSet: false,
|
||||||
|
MaxLength: 128,
|
||||||
|
MaxLengthSet: true,
|
||||||
|
Email: false,
|
||||||
|
Hostname: false,
|
||||||
|
Regex: nil,
|
||||||
|
}).Validate(string(s.Creator)); err != nil {
|
||||||
|
return errors.Wrap(err, "string")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "Creator",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.GameID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "GameID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.AssetID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "AssetID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.AssetVersion)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "AssetVersion",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.TargetAssetID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "TargetAssetID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.String{
|
||||||
|
MinLength: 0,
|
||||||
|
MinLengthSet: false,
|
||||||
|
MaxLength: 256,
|
||||||
|
MaxLengthSet: true,
|
||||||
|
Email: false,
|
||||||
|
Hostname: false,
|
||||||
|
Regex: nil,
|
||||||
|
}).Validate(string(s.Description)); err != nil {
|
||||||
|
return errors.Wrap(err, "string")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "Description",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(failures) > 0 {
|
||||||
|
return &validate.Error{Fields: failures}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MapfixID) Validate() error {
|
||||||
|
if s == nil {
|
||||||
|
return validate.ErrNilPointer
|
||||||
|
}
|
||||||
|
|
||||||
|
var failures []validate.FieldError
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.MapfixID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "MapfixID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(failures) > 0 {
|
||||||
|
return &validate.Error{Fields: failures}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Script) Validate() error {
|
||||||
|
if s == nil {
|
||||||
|
return validate.ErrNilPointer
|
||||||
|
}
|
||||||
|
|
||||||
|
var failures []validate.FieldError
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.ID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "ID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.String{
|
||||||
|
MinLength: 0,
|
||||||
|
MinLengthSet: false,
|
||||||
|
MaxLength: 128,
|
||||||
|
MaxLengthSet: true,
|
||||||
|
Email: false,
|
||||||
|
Hostname: false,
|
||||||
|
Regex: nil,
|
||||||
|
}).Validate(string(s.Name)); err != nil {
|
||||||
|
return errors.Wrap(err, "string")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "Name",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.String{
|
||||||
|
MinLength: 16,
|
||||||
|
MinLengthSet: true,
|
||||||
|
MaxLength: 16,
|
||||||
|
MaxLengthSet: true,
|
||||||
|
Email: false,
|
||||||
|
Hostname: false,
|
||||||
|
Regex: nil,
|
||||||
|
}).Validate(string(s.Hash)); err != nil {
|
||||||
|
return errors.Wrap(err, "string")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "Hash",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.String{
|
||||||
|
MinLength: 0,
|
||||||
|
MinLengthSet: false,
|
||||||
|
MaxLength: 1048576,
|
||||||
|
MaxLengthSet: true,
|
||||||
|
Email: false,
|
||||||
|
Hostname: false,
|
||||||
|
Regex: nil,
|
||||||
|
}).Validate(string(s.Source)); err != nil {
|
||||||
|
return errors.Wrap(err, "string")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "Source",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.ResourceType)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "ResourceType",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.ResourceID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "ResourceID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(failures) > 0 {
|
||||||
|
return &validate.Error{Fields: failures}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ScriptCreate) Validate() error {
|
||||||
|
if s == nil {
|
||||||
|
return validate.ErrNilPointer
|
||||||
|
}
|
||||||
|
|
||||||
|
var failures []validate.FieldError
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.String{
|
||||||
|
MinLength: 0,
|
||||||
|
MinLengthSet: false,
|
||||||
|
MaxLength: 128,
|
||||||
|
MaxLengthSet: true,
|
||||||
|
Email: false,
|
||||||
|
Hostname: false,
|
||||||
|
Regex: nil,
|
||||||
|
}).Validate(string(s.Name)); err != nil {
|
||||||
|
return errors.Wrap(err, "string")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "Name",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.String{
|
||||||
|
MinLength: 0,
|
||||||
|
MinLengthSet: false,
|
||||||
|
MaxLength: 1048576,
|
||||||
|
MaxLengthSet: true,
|
||||||
|
Email: false,
|
||||||
|
Hostname: false,
|
||||||
|
Regex: nil,
|
||||||
|
}).Validate(string(s.Source)); err != nil {
|
||||||
|
return errors.Wrap(err, "string")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "Source",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.ResourceType)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "ResourceType",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if value, ok := s.ResourceID.Get(); ok {
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(value)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "ResourceID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(failures) > 0 {
|
||||||
|
return &validate.Error{Fields: failures}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ScriptID) Validate() error {
|
||||||
|
if s == nil {
|
||||||
|
return validate.ErrNilPointer
|
||||||
|
}
|
||||||
|
|
||||||
|
var failures []validate.FieldError
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.ScriptID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "ScriptID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(failures) > 0 {
|
||||||
|
return &validate.Error{Fields: failures}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ScriptPolicy) Validate() error {
|
||||||
|
if s == nil {
|
||||||
|
return validate.ErrNilPointer
|
||||||
|
}
|
||||||
|
|
||||||
|
var failures []validate.FieldError
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.ID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "ID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.String{
|
||||||
|
MinLength: 16,
|
||||||
|
MinLengthSet: true,
|
||||||
|
MaxLength: 16,
|
||||||
|
MaxLengthSet: true,
|
||||||
|
Email: false,
|
||||||
|
Hostname: false,
|
||||||
|
Regex: nil,
|
||||||
|
}).Validate(string(s.FromScriptHash)); err != nil {
|
||||||
|
return errors.Wrap(err, "string")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "FromScriptHash",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.ToScriptID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "ToScriptID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.Policy)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "Policy",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(failures) > 0 {
|
||||||
|
return &validate.Error{Fields: failures}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ScriptPolicyCreate) Validate() error {
|
||||||
|
if s == nil {
|
||||||
|
return validate.ErrNilPointer
|
||||||
|
}
|
||||||
|
|
||||||
|
var failures []validate.FieldError
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.FromScriptID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "FromScriptID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.ToScriptID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "ToScriptID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.Policy)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "Policy",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(failures) > 0 {
|
||||||
|
return &validate.Error{Fields: failures}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ScriptPolicyID) Validate() error {
|
||||||
|
if s == nil {
|
||||||
|
return validate.ErrNilPointer
|
||||||
|
}
|
||||||
|
|
||||||
|
var failures []validate.FieldError
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.ScriptPolicyID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "ScriptPolicyID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(failures) > 0 {
|
||||||
|
return &validate.Error{Fields: failures}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SubmissionCreate) Validate() error {
|
||||||
|
if s == nil {
|
||||||
|
return validate.ErrNilPointer
|
||||||
|
}
|
||||||
|
|
||||||
|
var failures []validate.FieldError
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.OperationID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "OperationID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.AssetOwner)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "AssetOwner",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.String{
|
||||||
|
MinLength: 0,
|
||||||
|
MinLengthSet: false,
|
||||||
|
MaxLength: 128,
|
||||||
|
MaxLengthSet: true,
|
||||||
|
Email: false,
|
||||||
|
Hostname: false,
|
||||||
|
Regex: nil,
|
||||||
|
}).Validate(string(s.DisplayName)); err != nil {
|
||||||
|
return errors.Wrap(err, "string")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "DisplayName",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.String{
|
||||||
|
MinLength: 0,
|
||||||
|
MinLengthSet: false,
|
||||||
|
MaxLength: 128,
|
||||||
|
MaxLengthSet: true,
|
||||||
|
Email: false,
|
||||||
|
Hostname: false,
|
||||||
|
Regex: nil,
|
||||||
|
}).Validate(string(s.Creator)); err != nil {
|
||||||
|
return errors.Wrap(err, "string")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "Creator",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.GameID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "GameID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.AssetID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "AssetID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.AssetVersion)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "AssetVersion",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: true,
|
||||||
|
Max: 9,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.Status)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "Status",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(failures) > 0 {
|
||||||
|
return &validate.Error{Fields: failures}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SubmissionID) Validate() error {
|
||||||
|
if s == nil {
|
||||||
|
return validate.ErrNilPointer
|
||||||
|
}
|
||||||
|
|
||||||
|
var failures []validate.FieldError
|
||||||
|
if err := func() error {
|
||||||
|
if err := (validate.Int{
|
||||||
|
MinSet: true,
|
||||||
|
Min: 0,
|
||||||
|
MaxSet: false,
|
||||||
|
Max: 0,
|
||||||
|
MinExclusive: false,
|
||||||
|
MaxExclusive: false,
|
||||||
|
MultipleOfSet: false,
|
||||||
|
MultipleOf: 0,
|
||||||
|
}).Validate(int64(s.SubmissionID)); err != nil {
|
||||||
|
return errors.Wrap(err, "int")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}(); err != nil {
|
||||||
|
failures = append(failures, validate.FieldError{
|
||||||
|
Name: "SubmissionID",
|
||||||
|
Error: err,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(failures) > 0 {
|
||||||
|
return &validate.Error{Fields: failures}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -2,12 +2,9 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"math"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ValidatorUserID uint64 = uint64(math.MaxInt64)
|
|
||||||
|
|
||||||
type AuditEventType int32
|
type AuditEventType int32
|
||||||
|
|
||||||
// User clicked "Submit", "Accept" etc
|
// User clicked "Submit", "Accept" etc
|
||||||
@@ -51,19 +48,6 @@ type AuditEventDataError struct {
|
|||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Check struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Summary string `json:"summary"`
|
|
||||||
Passed bool `json:"passed"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validator map checks details
|
|
||||||
const AuditEventTypeCheckList AuditEventType = 7
|
|
||||||
|
|
||||||
type AuditEventDataCheckList struct {
|
|
||||||
CheckList []Check `json:"check_list"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AuditEvent struct {
|
type AuditEvent struct {
|
||||||
ID int64 `gorm:"primaryKey"`
|
ID int64 `gorm:"primaryKey"`
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
type Map struct {
|
|
||||||
ID int64
|
|
||||||
DisplayName string
|
|
||||||
Creator string
|
|
||||||
GameID uint32
|
|
||||||
Date time.Time // Release date
|
|
||||||
CreatedAt time.Time
|
|
||||||
UpdatedAt time.Time
|
|
||||||
Submitter uint64 // UserID of submitter
|
|
||||||
Thumbnail uint64 // AssetID of thumbnail
|
|
||||||
AssetVersion uint64 // Version number for LoadAssetVersion
|
|
||||||
LoadCount uint32 // How many times the map has been loaded
|
|
||||||
Modes uint32 // Number of modes (always at least one)
|
|
||||||
}
|
|
||||||
@@ -27,13 +27,11 @@ type CreateMapfixRequest struct {
|
|||||||
type CheckSubmissionRequest struct{
|
type CheckSubmissionRequest struct{
|
||||||
SubmissionID int64
|
SubmissionID int64
|
||||||
ModelID uint64
|
ModelID uint64
|
||||||
SkipChecks bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type CheckMapfixRequest struct{
|
type CheckMapfixRequest struct{
|
||||||
MapfixID int64
|
MapfixID int64
|
||||||
ModelID uint64
|
ModelID uint64
|
||||||
SkipChecks bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ValidateSubmissionRequest struct {
|
type ValidateSubmissionRequest struct {
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
type ResourceType int32
|
|
||||||
const (
|
|
||||||
ResourceUnknown ResourceType = 0
|
|
||||||
ResourceMapfix ResourceType = 1
|
|
||||||
ResourceSubmission ResourceType = 2
|
|
||||||
)
|
|
||||||
|
|
||||||
type Resource struct{
|
|
||||||
ID int64
|
|
||||||
Type ResourceType
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
// Submissions roles bitflag
|
|
||||||
type Roles int32
|
|
||||||
var (
|
|
||||||
RolesSubmissionUpload Roles = 1<<6
|
|
||||||
RolesSubmissionReview Roles = 1<<5
|
|
||||||
RolesSubmissionRelease Roles = 1<<4
|
|
||||||
RolesScriptWrite Roles = 1<<3
|
|
||||||
RolesMapfixUpload Roles = 1<<2
|
|
||||||
RolesMapfixReview Roles = 1<<1
|
|
||||||
RolesMapDownload Roles = 1<<0
|
|
||||||
RolesEmpty Roles = 0
|
|
||||||
)
|
|
||||||
|
|
||||||
// StrafesNET group roles
|
|
||||||
type GroupRole int32
|
|
||||||
var (
|
|
||||||
// has ScriptWrite
|
|
||||||
RoleQuat GroupRole = 255
|
|
||||||
RoleItzaname GroupRole = 254
|
|
||||||
RoleStagingDeveloper GroupRole = 240
|
|
||||||
RolesAll Roles = ^RolesEmpty
|
|
||||||
// has SubmissionUpload
|
|
||||||
RoleMapAdmin GroupRole = 128
|
|
||||||
RolesMapAdmin Roles = RolesSubmissionRelease|RolesSubmissionUpload|RolesSubmissionReview|RolesMapCouncil
|
|
||||||
// has MapfixReview
|
|
||||||
RoleMapCouncil GroupRole = 64
|
|
||||||
RolesMapCouncil Roles = RolesMapfixReview|RolesMapfixUpload|RolesMapAccess
|
|
||||||
// access to downloading maps
|
|
||||||
RoleMapAccess GroupRole = 32
|
|
||||||
RolesMapAccess Roles = RolesMapDownload
|
|
||||||
)
|
|
||||||
@@ -23,6 +23,13 @@ func HashParse(hash string) (uint64, error){
|
|||||||
return strconv.ParseUint(hash, 16, 64)
|
return strconv.ParseUint(hash, 16, 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ResourceType int32
|
||||||
|
const (
|
||||||
|
ResourceUnknown ResourceType = 0
|
||||||
|
ResourceMapfix ResourceType = 1
|
||||||
|
ResourceSubmission ResourceType = 2
|
||||||
|
)
|
||||||
|
|
||||||
type Script struct {
|
type Script struct {
|
||||||
ID int64 `gorm:"primaryKey"`
|
ID int64 `gorm:"primaryKey"`
|
||||||
Name string
|
Name string
|
||||||
|
|||||||
@@ -1,95 +0,0 @@
|
|||||||
package roblox
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
)
|
|
||||||
|
|
||||||
type AssetMetadata struct {
|
|
||||||
MetadataType uint32 `json:"metadataType"`
|
|
||||||
Value string `json:"value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Struct equivalent to Rust's AssetLocationInfo
|
|
||||||
type AssetLocationInfo struct {
|
|
||||||
Location string `json:"location"`
|
|
||||||
RequestId string `json:"requestId"`
|
|
||||||
IsArchived bool `json:"isArchived"`
|
|
||||||
AssetTypeId uint32 `json:"assetTypeId"`
|
|
||||||
AssetMetadatas []AssetMetadata `json:"assetMetadatas"`
|
|
||||||
IsRecordable bool `json:"isRecordable"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Input struct for getAssetLocation
|
|
||||||
type GetAssetLatestRequest struct {
|
|
||||||
AssetID uint64
|
|
||||||
}
|
|
||||||
|
|
||||||
// Custom error type if needed
|
|
||||||
type GetError string
|
|
||||||
|
|
||||||
func (e GetError) Error() string { return string(e) }
|
|
||||||
|
|
||||||
// Example client with a Get method
|
|
||||||
type Client struct {
|
|
||||||
HttpClient *http.Client
|
|
||||||
ApiKey string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) GetAssetLocation(config GetAssetLatestRequest) (*AssetLocationInfo, error) {
|
|
||||||
rawURL := fmt.Sprintf("https://apis.roblox.com/asset-delivery-api/v1/assetId/%d", config.AssetID)
|
|
||||||
parsedURL, err := url.Parse(rawURL)
|
|
||||||
if err != nil {
|
|
||||||
return nil, GetError("ParseError: " + err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", parsedURL.String(), nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, GetError("RequestCreationError: " + err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
req.Header.Set("x-api-key", c.ApiKey)
|
|
||||||
|
|
||||||
resp, err := c.HttpClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, GetError("RequestError: " + err.Error())
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
return nil, GetError(fmt.Sprintf("ResponseError: status code %d", resp.StatusCode))
|
|
||||||
}
|
|
||||||
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, GetError("ReadBodyError: " + err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
var info AssetLocationInfo
|
|
||||||
if err := json.Unmarshal(body, &info); err != nil {
|
|
||||||
return nil, GetError("JSONError: " + err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
return &info, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) DownloadAsset(info *AssetLocationInfo) (io.Reader, error) {
|
|
||||||
req, err := http.NewRequest("GET", info.Location, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, GetError("RequestCreationError: " + err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := c.HttpClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, GetError("RequestError: " + err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
return nil, GetError(fmt.Sprintf("ResponseError: status code %d", resp.StatusCode))
|
|
||||||
}
|
|
||||||
|
|
||||||
return resp.Body, nil
|
|
||||||
}
|
|
||||||
@@ -10,13 +10,76 @@ import (
|
|||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (svc *Service) ListAuditEvents(ctx context.Context, resource model.Resource, page model.Page) ([]api.AuditEvent, error){
|
// CreateMapfixAuditComment implements createMapfixAuditComment operation.
|
||||||
|
//
|
||||||
|
// Post a comment to the audit log
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/comment
|
||||||
|
func (svc *Service) CreateMapfixAuditComment(ctx context.Context, req api.CreateMapfixAuditCommentReq, params api.CreateMapfixAuditCommentParams) (error) {
|
||||||
|
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
|
||||||
|
if !ok {
|
||||||
|
return ErrUserInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
has_role, err := userInfo.HasRoleMapfixReview()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !has_role {
|
||||||
|
return ErrPermissionDeniedNeedRoleMapfixReview
|
||||||
|
}
|
||||||
|
|
||||||
|
userId, err := userInfo.GetUserID()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
data := []byte{}
|
||||||
|
_, err = req.Read(data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
Comment := string(data)
|
||||||
|
|
||||||
|
event_data := model.AuditEventDataComment{
|
||||||
|
Comment: Comment,
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: userId,
|
||||||
|
ResourceType: model.ResourceMapfix,
|
||||||
|
ResourceID: params.MapfixID,
|
||||||
|
EventType: model.AuditEventTypeComment,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListMapfixAuditEvents invokes listMapfixAuditEvents operation.
|
||||||
|
//
|
||||||
|
// Retrieve a list of audit events.
|
||||||
|
//
|
||||||
|
// GET /mapfixes/{MapfixID}/audit-events
|
||||||
|
func (svc *Service) ListMapfixAuditEvents(ctx context.Context, params api.ListMapfixAuditEventsParams) ([]api.AuditEvent, error) {
|
||||||
filter := datastore.Optional()
|
filter := datastore.Optional()
|
||||||
|
|
||||||
filter.Add("resource_type", resource.Type)
|
filter.Add("resource_type", model.ResourceMapfix)
|
||||||
filter.Add("resource_id", resource.ID)
|
filter.Add("resource_id", params.MapfixID)
|
||||||
|
|
||||||
items, err := svc.db.AuditEvents().List(ctx, filter, page)
|
items, err := svc.DB.AuditEvents().List(ctx, filter, model.Page{
|
||||||
|
Number: params.Page,
|
||||||
|
Size: params.Limit,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -32,7 +95,7 @@ func (svc *Service) ListAuditEvents(ctx context.Context, resource model.Resource
|
|||||||
idList.ID = append(idList.ID, userId)
|
idList.ID = append(idList.ID, userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
userList, err := svc.users.GetList(ctx, &idList)
|
userList, err := svc.Users.GetList(ctx, &idList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -68,38 +131,51 @@ func (svc *Service) ListAuditEvents(ctx context.Context, resource model.Resource
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *Service) CreateAuditEventAction(ctx context.Context, userId uint64, resource model.Resource, event_data model.AuditEventDataAction) error {
|
// CreateSubmissionAuditComment implements createSubmissionAuditComment operation.
|
||||||
|
//
|
||||||
|
// Post a comment to the audit log
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/comment
|
||||||
|
func (svc *Service) CreateSubmissionAuditComment(ctx context.Context, req api.CreateSubmissionAuditCommentReq, params api.CreateSubmissionAuditCommentParams) (error) {
|
||||||
|
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
|
||||||
|
if !ok {
|
||||||
|
return ErrUserInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
has_role, err := userInfo.HasRoleSubmissionReview()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !has_role {
|
||||||
|
return ErrPermissionDeniedNeedRoleSubmissionReview
|
||||||
|
}
|
||||||
|
|
||||||
|
userId, err := userInfo.GetUserID()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
data := []byte{}
|
||||||
|
_, err = req.Read(data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
Comment := string(data)
|
||||||
|
|
||||||
|
event_data := model.AuditEventDataComment{
|
||||||
|
Comment: Comment,
|
||||||
|
}
|
||||||
|
|
||||||
EventData, err := json.Marshal(event_data)
|
EventData, err := json.Marshal(event_data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = svc.db.AuditEvents().Create(ctx, model.AuditEvent{
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
ID: 0,
|
ID: 0,
|
||||||
User: userId,
|
User: userId,
|
||||||
ResourceType: resource.Type,
|
ResourceType: model.ResourceSubmission,
|
||||||
ResourceID: resource.ID,
|
ResourceID: params.SubmissionID,
|
||||||
EventType: model.AuditEventTypeAction,
|
|
||||||
EventData: EventData,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) CreateAuditEventComment(ctx context.Context, userId uint64, resource model.Resource, event_data model.AuditEventDataComment) error {
|
|
||||||
EventData, err := json.Marshal(event_data)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = svc.db.AuditEvents().Create(ctx, model.AuditEvent{
|
|
||||||
ID: 0,
|
|
||||||
User: userId,
|
|
||||||
ResourceType: resource.Type,
|
|
||||||
ResourceID: resource.ID,
|
|
||||||
EventType: model.AuditEventTypeComment,
|
EventType: model.AuditEventTypeComment,
|
||||||
EventData: EventData,
|
EventData: EventData,
|
||||||
})
|
})
|
||||||
@@ -110,129 +186,68 @@ func (svc *Service) CreateAuditEventComment(ctx context.Context, userId uint64,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *Service) CreateAuditEventChangeModel(ctx context.Context, userId uint64, resource model.Resource, event_data model.AuditEventDataChangeModel) error {
|
// ListSubmissionAuditEvents invokes listSubmissionAuditEvents operation.
|
||||||
EventData, err := json.Marshal(event_data)
|
//
|
||||||
if err != nil {
|
// Retrieve a list of audit events.
|
||||||
return err
|
//
|
||||||
}
|
// GET /submissions/{SubmissionID}/audit-events
|
||||||
|
func (svc *Service) ListSubmissionAuditEvents(ctx context.Context, params api.ListSubmissionAuditEventsParams) ([]api.AuditEvent, error) {
|
||||||
|
filter := datastore.Optional()
|
||||||
|
|
||||||
_, err = svc.db.AuditEvents().Create(ctx, model.AuditEvent{
|
filter.Add("resource_type", model.ResourceSubmission)
|
||||||
ID: 0,
|
filter.Add("resource_id", params.SubmissionID)
|
||||||
User: userId,
|
|
||||||
ResourceType: resource.Type,
|
items, err := svc.DB.AuditEvents().List(ctx, filter, model.Page{
|
||||||
ResourceID: resource.ID,
|
Number: params.Page,
|
||||||
EventType: model.AuditEventTypeChangeModel,
|
Size: params.Limit,
|
||||||
EventData: EventData,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
idMap := make(map[int64]bool)
|
||||||
}
|
for _, item := range items {
|
||||||
|
idMap[int64(item.User)] = true
|
||||||
|
}
|
||||||
func (svc *Service) CreateAuditEventChangeValidatedModel(ctx context.Context, userId uint64, resource model.Resource, event_data model.AuditEventDataChangeValidatedModel) error {
|
|
||||||
EventData, err := json.Marshal(event_data)
|
var idList users.IdList
|
||||||
if err != nil {
|
idList.ID = make([]int64,len(idMap))
|
||||||
return err
|
for userId := range idMap {
|
||||||
}
|
idList.ID = append(idList.ID, userId)
|
||||||
|
}
|
||||||
_, err = svc.db.AuditEvents().Create(ctx, model.AuditEvent{
|
|
||||||
ID: 0,
|
userList, err := svc.Users.GetList(ctx, &idList)
|
||||||
User: userId,
|
if err != nil {
|
||||||
ResourceType: resource.Type,
|
return nil, err
|
||||||
ResourceID: resource.ID,
|
}
|
||||||
EventType: model.AuditEventTypeChangeValidatedModel,
|
|
||||||
EventData: EventData,
|
userMap := make(map[int64]*users.UserResponse)
|
||||||
})
|
for _,user := range userList.Users {
|
||||||
if err != nil {
|
userMap[user.ID] = user
|
||||||
return err
|
}
|
||||||
}
|
|
||||||
|
var resp []api.AuditEvent
|
||||||
return nil
|
for _, item := range items {
|
||||||
}
|
EventData := api.AuditEventEventData{}
|
||||||
|
err = EventData.UnmarshalJSON(item.EventData)
|
||||||
func (svc *Service) CreateAuditEventError(ctx context.Context, userId uint64, resource model.Resource, event_data model.AuditEventDataError) error {
|
if err != nil {
|
||||||
EventData, err := json.Marshal(event_data)
|
return nil, err
|
||||||
if err != nil {
|
}
|
||||||
return err
|
username := ""
|
||||||
}
|
if userMap[int64(item.User)] != nil {
|
||||||
|
username = userMap[int64(item.User)].Username
|
||||||
_, err = svc.db.AuditEvents().Create(ctx, model.AuditEvent{
|
}
|
||||||
ID: 0,
|
resp = append(resp, api.AuditEvent{
|
||||||
User: userId,
|
ID: item.ID,
|
||||||
ResourceType: resource.Type,
|
Date: item.CreatedAt.Unix(),
|
||||||
ResourceID: resource.ID,
|
User: int64(item.User),
|
||||||
EventType: model.AuditEventTypeError,
|
Username: username,
|
||||||
EventData: EventData,
|
ResourceType: int32(item.ResourceType),
|
||||||
})
|
ResourceID: item.ResourceID,
|
||||||
if err != nil {
|
EventType: int32(item.EventType),
|
||||||
return err
|
EventData: EventData,
|
||||||
}
|
})
|
||||||
|
}
|
||||||
return nil
|
|
||||||
}
|
return resp, nil
|
||||||
|
|
||||||
func (svc *Service) CreateAuditEventCheckList(ctx context.Context, userId uint64, resource model.Resource, event_data model.AuditEventDataCheckList) error {
|
|
||||||
EventData, err := json.Marshal(event_data)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = svc.db.AuditEvents().Create(ctx, model.AuditEvent{
|
|
||||||
ID: 0,
|
|
||||||
User: userId,
|
|
||||||
ResourceType: resource.Type,
|
|
||||||
ResourceID: resource.ID,
|
|
||||||
EventType: model.AuditEventTypeCheckList,
|
|
||||||
EventData: EventData,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) CreateAuditEventChangeDisplayName(ctx context.Context, userId uint64, resource model.Resource, event_data model.AuditEventDataChangeName) error {
|
|
||||||
EventData, err := json.Marshal(event_data)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = svc.db.AuditEvents().Create(ctx, model.AuditEvent{
|
|
||||||
ID: 0,
|
|
||||||
User: userId,
|
|
||||||
ResourceType: resource.Type,
|
|
||||||
ResourceID: resource.ID,
|
|
||||||
EventType: model.AuditEventTypeChangeDisplayName,
|
|
||||||
EventData: EventData,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) CreateAuditEventChangeCreator(ctx context.Context, userId uint64, resource model.Resource, event_data model.AuditEventDataChangeName) error {
|
|
||||||
EventData, err := json.Marshal(event_data)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = svc.db.AuditEvents().Create(ctx, model.AuditEvent{
|
|
||||||
ID: 0,
|
|
||||||
User: userId,
|
|
||||||
ResourceType: resource.Type,
|
|
||||||
ResourceID: resource.ID,
|
|
||||||
EventType: model.AuditEventTypeChangeCreator,
|
|
||||||
EventData: EventData,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2,187 +2,72 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/go-grpc/maps"
|
"git.itzana.me/strafesnet/go-grpc/maps"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Optional map used to update an object
|
// ListMaps implements listMaps operation.
|
||||||
type MapUpdate datastore.OptionalMap
|
//
|
||||||
|
// Get list of maps.
|
||||||
|
//
|
||||||
|
// GET /maps
|
||||||
|
func (svc *Service) ListMaps(ctx context.Context, params api.ListMapsParams) ([]api.Map, error) {
|
||||||
|
filter := maps.MapFilter{}
|
||||||
|
|
||||||
func NewMapUpdate() MapUpdate {
|
if params.DisplayName.IsSet(){
|
||||||
update := datastore.Optional()
|
filter.DisplayName = ¶ms.DisplayName.Value
|
||||||
return MapUpdate(update)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (update MapUpdate) SetDisplayName(display_name string) {
|
|
||||||
datastore.OptionalMap(update).Add("display_name", display_name)
|
|
||||||
}
|
|
||||||
func (update MapUpdate) SetCreator(creator string) {
|
|
||||||
datastore.OptionalMap(update).Add("creator", creator)
|
|
||||||
}
|
|
||||||
func (update MapUpdate) SetGameID(game_id uint32) {
|
|
||||||
datastore.OptionalMap(update).Add("game_id", game_id)
|
|
||||||
}
|
|
||||||
func (update MapUpdate) SetDate(date int64) {
|
|
||||||
datastore.OptionalMap(update).Add("date", date)
|
|
||||||
}
|
|
||||||
func (update MapUpdate) SetSubmitter(submitter uint64) {
|
|
||||||
datastore.OptionalMap(update).Add("submitter", submitter)
|
|
||||||
}
|
|
||||||
func (update MapUpdate) SetThumbnail(thumbnail uint64) {
|
|
||||||
datastore.OptionalMap(update).Add("thumbnail", thumbnail)
|
|
||||||
}
|
|
||||||
func (update MapUpdate) SetAssetVersion(asset_version uint64) {
|
|
||||||
datastore.OptionalMap(update).Add("asset_version", asset_version)
|
|
||||||
}
|
|
||||||
func (update MapUpdate) SetModes(modes uint32) {
|
|
||||||
datastore.OptionalMap(update).Add("modes", modes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// getters
|
|
||||||
func (update MapUpdate) GetDisplayName() (string, bool) {
|
|
||||||
value, ok := datastore.OptionalMap(update).Map()["display_name"].(string)
|
|
||||||
return value, ok
|
|
||||||
}
|
|
||||||
func (update MapUpdate) GetCreator() (string, bool) {
|
|
||||||
value, ok := datastore.OptionalMap(update).Map()["creator"].(string)
|
|
||||||
return value, ok
|
|
||||||
}
|
|
||||||
func (update MapUpdate) GetGameID() (uint32, bool) {
|
|
||||||
value, ok := datastore.OptionalMap(update).Map()["game_id"].(uint32)
|
|
||||||
return value, ok
|
|
||||||
}
|
|
||||||
func (update MapUpdate) GetDate() (int64, bool) {
|
|
||||||
value, ok := datastore.OptionalMap(update).Map()["date"].(int64)
|
|
||||||
return value, ok
|
|
||||||
}
|
|
||||||
|
|
||||||
// Optional map used to find matching objects
|
|
||||||
type MapFilter datastore.OptionalMap
|
|
||||||
|
|
||||||
func NewMapFilter(
|
|
||||||
) MapFilter {
|
|
||||||
filter := datastore.Optional()
|
|
||||||
return MapFilter(filter)
|
|
||||||
}
|
|
||||||
func (update MapFilter) SetDisplayName(display_name string) {
|
|
||||||
datastore.OptionalMap(update).Add("display_name", display_name)
|
|
||||||
}
|
|
||||||
func (update MapFilter) SetCreator(creator string) {
|
|
||||||
datastore.OptionalMap(update).Add("creator", creator)
|
|
||||||
}
|
|
||||||
func (update MapFilter) SetGameID(game_id uint32) {
|
|
||||||
datastore.OptionalMap(update).Add("game_id", game_id)
|
|
||||||
}
|
|
||||||
func (update MapFilter) SetSubmitter(submitter uint64) {
|
|
||||||
datastore.OptionalMap(update).Add("submitter", submitter)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) TEMP_DoMapsMigration(ctx context.Context) (error) {
|
|
||||||
// get all maps
|
|
||||||
maps, err := svc.maps.List(ctx, &maps.ListRequest{})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
// create all maps
|
if params.Creator.IsSet(){
|
||||||
for _, item := range maps.Maps {
|
filter.Creator = ¶ms.Creator.Value
|
||||||
migrated := model.Map{
|
}
|
||||||
|
if params.GameID.IsSet(){
|
||||||
|
filter.GameID = ¶ms.GameID.Value
|
||||||
|
}
|
||||||
|
|
||||||
|
mapList, err := svc.Maps.List(ctx, &maps.ListRequest{
|
||||||
|
Filter: &filter,
|
||||||
|
Page: &maps.Pagination{
|
||||||
|
Size: params.Limit,
|
||||||
|
Number: params.Page,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []api.Map
|
||||||
|
for _, item := range mapList.Maps {
|
||||||
|
resp = append(resp, api.Map{
|
||||||
ID: item.ID,
|
ID: item.ID,
|
||||||
DisplayName: item.DisplayName,
|
DisplayName: item.DisplayName,
|
||||||
Creator: item.Creator,
|
Creator: item.Creator,
|
||||||
GameID: uint32(item.GameID),
|
GameID: item.GameID,
|
||||||
Date: time.Unix(item.Date, 0),
|
Date: item.Date,
|
||||||
// CreatedAt: time.Time{},
|
})
|
||||||
// UpdatedAt: time.Time{},
|
|
||||||
// Submitter: 0,
|
|
||||||
// Thumbnail: 0,
|
|
||||||
// AssetVersion: 0,
|
|
||||||
// LoadCount: 0,
|
|
||||||
// Modes: 0,
|
|
||||||
}
|
|
||||||
_, err := svc.db.Maps().Create(ctx, migrated)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
|
return resp, nil
|
||||||
}
|
}
|
||||||
func (svc *Service) CreateMap(ctx context.Context, item model.Map) (int64, error) {
|
|
||||||
// 2 jobs:
|
// GetMap implements getScript operation.
|
||||||
// create map on maps-service
|
//
|
||||||
map_item, err := svc.db.Maps().Create(ctx, item)
|
// Get the specified script by ID.
|
||||||
if err != nil {
|
//
|
||||||
return 0, err
|
// GET /maps/{MapID}
|
||||||
}
|
func (svc *Service) GetMap(ctx context.Context, params api.GetMapParams) (*api.Map, error) {
|
||||||
// create map on data-service
|
mapResponse, err := svc.Maps.Get(ctx, &maps.IdMessage{
|
||||||
date := item.Date.Unix()
|
ID: params.MapID,
|
||||||
game_id := int32(item.GameID)
|
|
||||||
_, err = svc.maps.Create(ctx, &maps.MapRequest{
|
|
||||||
ID: item.ID,
|
|
||||||
DisplayName: &item.DisplayName,
|
|
||||||
Creator: &item.Creator,
|
|
||||||
GameID: &game_id,
|
|
||||||
Date: &date,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return map_item.ID, nil
|
return &api.Map{
|
||||||
}
|
ID: mapResponse.ID,
|
||||||
|
DisplayName: mapResponse.DisplayName,
|
||||||
func (svc *Service) ListMaps(ctx context.Context, filter MapFilter, page model.Page) ([]model.Map, error) {
|
Creator: mapResponse.Creator,
|
||||||
return svc.db.Maps().List(ctx, datastore.OptionalMap(filter), page)
|
GameID: mapResponse.GameID,
|
||||||
}
|
Date: mapResponse.Date,
|
||||||
|
}, nil
|
||||||
func (svc *Service) GetMapList(ctx context.Context, ids []int64) ([]model.Map, error) {
|
|
||||||
return svc.db.Maps().GetList(ctx, ids)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) DeleteMap(ctx context.Context, id int64) error {
|
|
||||||
// Do not delete the "embedded" map, since it deletes times.
|
|
||||||
// _, err := svc.maps.Delete(ctx, &maps.IdMessage{ID: id})
|
|
||||||
return svc.db.Maps().Delete(ctx, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) GetMap(ctx context.Context, id int64) (model.Map, error) {
|
|
||||||
return svc.db.Maps().Get(ctx, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) UpdateMap(ctx context.Context, id int64, pmap MapUpdate) error {
|
|
||||||
// 2 jobs:
|
|
||||||
// update map on maps-service
|
|
||||||
err := svc.db.Maps().Update(ctx, id, datastore.OptionalMap(pmap))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// update map on data-service
|
|
||||||
update := maps.MapRequest{
|
|
||||||
ID: id,
|
|
||||||
}
|
|
||||||
if display_name, ok := pmap.GetDisplayName(); ok {
|
|
||||||
update.DisplayName = &display_name
|
|
||||||
}
|
|
||||||
if creator, ok := pmap.GetCreator(); ok {
|
|
||||||
update.Creator = &creator
|
|
||||||
}
|
|
||||||
if game_id, ok := pmap.GetGameID(); ok {
|
|
||||||
game_id_int32 := int32(game_id)
|
|
||||||
update.GameID = &game_id_int32
|
|
||||||
}
|
|
||||||
if date, ok := pmap.GetDate(); ok {
|
|
||||||
update.Date = &date
|
|
||||||
}
|
|
||||||
_, err = svc.maps.Update(ctx, &update)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) IncrementMapLoadCount(ctx context.Context, id int64) error {
|
|
||||||
return svc.db.Maps().IncrementLoadCount(ctx, id)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,114 +0,0 @@
|
|||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (svc *Service) NatsCreateMapfix(
|
|
||||||
OperationID int32,
|
|
||||||
ModelID uint64,
|
|
||||||
TargetAssetID uint64,
|
|
||||||
Description string,
|
|
||||||
) error {
|
|
||||||
create_request := model.CreateMapfixRequest{
|
|
||||||
OperationID: OperationID,
|
|
||||||
ModelID: ModelID,
|
|
||||||
TargetAssetID: TargetAssetID,
|
|
||||||
Description: Description,
|
|
||||||
}
|
|
||||||
|
|
||||||
j, err := json.Marshal(create_request)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = svc.nats.Publish("maptest.mapfixes.create", []byte(j))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) NatsCheckMapfix(
|
|
||||||
MapfixID int64,
|
|
||||||
ModelID uint64,
|
|
||||||
SkipChecks bool,
|
|
||||||
) error {
|
|
||||||
validate_request := model.CheckMapfixRequest{
|
|
||||||
MapfixID: MapfixID,
|
|
||||||
ModelID: ModelID,
|
|
||||||
SkipChecks: SkipChecks,
|
|
||||||
}
|
|
||||||
|
|
||||||
j, err := json.Marshal(validate_request)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = svc.nats.Publish("maptest.mapfixes.check", []byte(j))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) NatsUploadMapfix(
|
|
||||||
MapfixID int64,
|
|
||||||
ModelID uint64,
|
|
||||||
ModelVersion uint64,
|
|
||||||
TargetAssetID uint64,
|
|
||||||
) error {
|
|
||||||
upload_fix_request := model.UploadMapfixRequest{
|
|
||||||
MapfixID: MapfixID,
|
|
||||||
ModelID: ModelID,
|
|
||||||
ModelVersion: ModelVersion,
|
|
||||||
TargetAssetID: TargetAssetID,
|
|
||||||
}
|
|
||||||
|
|
||||||
j, err := json.Marshal(upload_fix_request)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = svc.nats.Publish("maptest.mapfixes.upload", []byte(j))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) NatsValidateMapfix(
|
|
||||||
MapfixID int64,
|
|
||||||
ModelID uint64,
|
|
||||||
ModelVersion uint64,
|
|
||||||
ValidatedAssetID uint64,
|
|
||||||
) error {
|
|
||||||
validate_request := model.ValidateMapfixRequest{
|
|
||||||
MapfixID: MapfixID,
|
|
||||||
ModelID: ModelID,
|
|
||||||
ModelVersion: ModelVersion,
|
|
||||||
ValidatedModelID: nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
// sentinel values because we're not using rust
|
|
||||||
if ValidatedAssetID != 0 {
|
|
||||||
validate_request.ValidatedModelID = &ValidatedAssetID
|
|
||||||
}
|
|
||||||
|
|
||||||
j, err := json.Marshal(validate_request)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = svc.nats.Publish("maptest.mapfixes.validate", []byte(j))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (svc *Service) NatsCreateSubmission(
|
|
||||||
OperationID int32,
|
|
||||||
ModelID uint64,
|
|
||||||
DisplayName string,
|
|
||||||
Creator string,
|
|
||||||
GameID uint32,
|
|
||||||
Status uint32,
|
|
||||||
Roles uint32,
|
|
||||||
) error {
|
|
||||||
create_request := model.CreateSubmissionRequest{
|
|
||||||
OperationID: OperationID,
|
|
||||||
ModelID: ModelID,
|
|
||||||
DisplayName: DisplayName,
|
|
||||||
Creator: Creator,
|
|
||||||
GameID: GameID,
|
|
||||||
Status: Status,
|
|
||||||
Roles: Roles,
|
|
||||||
}
|
|
||||||
|
|
||||||
j, err := json.Marshal(create_request)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = svc.nats.Publish("maptest.submissions.create", []byte(j))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) NatsCheckSubmission(
|
|
||||||
SubmissionID int64,
|
|
||||||
ModelID uint64,
|
|
||||||
SkipChecks bool,
|
|
||||||
) error {
|
|
||||||
validate_request := model.CheckSubmissionRequest{
|
|
||||||
SubmissionID: SubmissionID,
|
|
||||||
ModelID: ModelID,
|
|
||||||
SkipChecks: SkipChecks,
|
|
||||||
}
|
|
||||||
|
|
||||||
j, err := json.Marshal(validate_request)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = svc.nats.Publish("maptest.submissions.check", []byte(j))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) NatsUploadSubmission(
|
|
||||||
SubmissionID int64,
|
|
||||||
ModelID uint64,
|
|
||||||
ModelVersion uint64,
|
|
||||||
ModelName string,
|
|
||||||
) error {
|
|
||||||
upload_new_request := model.UploadSubmissionRequest{
|
|
||||||
SubmissionID: SubmissionID,
|
|
||||||
ModelID: ModelID,
|
|
||||||
ModelVersion: ModelVersion,
|
|
||||||
ModelName: ModelName,
|
|
||||||
}
|
|
||||||
|
|
||||||
j, err := json.Marshal(upload_new_request)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = svc.nats.Publish("maptest.submissions.upload", []byte(j))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) NatsValidateSubmission(
|
|
||||||
SubmissionID int64,
|
|
||||||
ModelID uint64,
|
|
||||||
ModelVersion uint64,
|
|
||||||
ValidatedModelID uint64,
|
|
||||||
) error {
|
|
||||||
validate_request := model.ValidateSubmissionRequest{
|
|
||||||
SubmissionID: SubmissionID,
|
|
||||||
ModelID: ModelID,
|
|
||||||
ModelVersion: ModelVersion,
|
|
||||||
ValidatedModelID: nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
// sentinel values because we're not using rust
|
|
||||||
if ValidatedModelID != 0 {
|
|
||||||
validate_request.ValidatedModelID = &ValidatedModelID
|
|
||||||
}
|
|
||||||
|
|
||||||
j, err := json.Marshal(validate_request)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = svc.nats.Publish("maptest.submissions.validate", []byte(j))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -2,54 +2,45 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type OperationFailParams datastore.OptionalMap
|
// GetOperation implements getOperation operation.
|
||||||
|
//
|
||||||
|
// Get the specified operation by ID.
|
||||||
|
//
|
||||||
|
// GET /operations/{OperationID}
|
||||||
|
func (svc *Service) GetOperation(ctx context.Context, params api.GetOperationParams) (*api.Operation, error) {
|
||||||
|
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrUserInfo
|
||||||
|
}
|
||||||
|
|
||||||
func NewOperationFailParams(
|
// You must be the operation owner to read it
|
||||||
status_message string,
|
|
||||||
) OperationFailParams {
|
operation, err := svc.DB.Operations().Get(ctx, params.OperationID)
|
||||||
filter := datastore.Optional()
|
if err != nil {
|
||||||
filter.Add("status_id", model.OperationStatusFailed)
|
return nil, err
|
||||||
filter.Add("status_message", status_message)
|
}
|
||||||
return OperationFailParams(filter)
|
|
||||||
}
|
userId, err := userInfo.GetUserID()
|
||||||
|
if err != nil {
|
||||||
type OperationCompleteParams datastore.OptionalMap
|
return nil, err
|
||||||
|
}
|
||||||
func NewOperationCompleteParams(
|
|
||||||
path string,
|
// check if caller is the submitter
|
||||||
) OperationCompleteParams {
|
has_role := userId == operation.Owner
|
||||||
filter := datastore.Optional()
|
if !has_role {
|
||||||
filter.Add("status_id", model.OperationStatusCompleted)
|
return nil, ErrPermissionDeniedNotSubmitter
|
||||||
filter.Add("path", path)
|
}
|
||||||
return OperationCompleteParams(filter)
|
|
||||||
}
|
return &api.Operation{
|
||||||
|
OperationID: operation.ID,
|
||||||
func (svc *Service) CreateOperation(ctx context.Context, operation model.Operation) (model.Operation, error) {
|
Date: operation.CreatedAt.Unix(),
|
||||||
return svc.db.Operations().Create(ctx, operation)
|
Owner: int64(operation.Owner),
|
||||||
}
|
Status: int32(operation.StatusID),
|
||||||
|
StatusMessage: operation.StatusMessage,
|
||||||
func (svc *Service) CountOperationsSince(ctx context.Context, owner int64, since time.Time) (int64, error) {
|
Path: operation.Path,
|
||||||
return svc.db.Operations().CountSince(ctx, owner, since)
|
}, nil
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) DeleteOperation(ctx context.Context, id int32) error {
|
|
||||||
return svc.db.Operations().Delete(ctx, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) GetOperation(ctx context.Context, id int32) (model.Operation, error) {
|
|
||||||
return svc.db.Operations().Get(ctx, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) FailOperation(ctx context.Context, id int32, params OperationFailParams) error {
|
|
||||||
return svc.db.Operations().Update(ctx, id, datastore.OptionalMap(params))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (svc *Service) CompleteOperation(ctx context.Context, id int32, params OperationCompleteParams) error {
|
|
||||||
return svc.db.Operations().Update(ctx, id, datastore.OptionalMap(params))
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,43 +3,169 @@ package service
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ScriptPolicyFilter datastore.OptionalMap
|
// CreateScriptPolicy implements createScriptPolicy operation.
|
||||||
|
//
|
||||||
|
// Create a new script policy.
|
||||||
|
//
|
||||||
|
// POST /script-policy
|
||||||
|
func (svc *Service) CreateScriptPolicy(ctx context.Context, req *api.ScriptPolicyCreate) (*api.ScriptPolicyID, error) {
|
||||||
|
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrUserInfo
|
||||||
|
}
|
||||||
|
|
||||||
func NewScriptPolicyFilter() ScriptPolicyFilter {
|
has_role, err := userInfo.HasRoleScriptWrite()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !has_role {
|
||||||
|
return nil, ErrPermissionDenied
|
||||||
|
}
|
||||||
|
|
||||||
|
from_script, err := svc.DB.Scripts().Get(ctx, req.FromScriptID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// the existence of ToScriptID does not need to be validated because it's checked by a foreign key constraint.
|
||||||
|
|
||||||
|
script, err := svc.DB.ScriptPolicy().Create(ctx, model.ScriptPolicy{
|
||||||
|
ID: 0,
|
||||||
|
FromScriptHash: from_script.Hash,
|
||||||
|
ToScriptID: req.ToScriptID,
|
||||||
|
Policy: model.Policy(req.Policy),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &api.ScriptPolicyID{
|
||||||
|
ScriptPolicyID: script.ID,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ListScriptPolicy implements listScriptPolicy operation.
|
||||||
|
//
|
||||||
|
// Get list of script policies.
|
||||||
|
//
|
||||||
|
// GET /script-policy
|
||||||
|
func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptPolicyParams) ([]api.ScriptPolicy, error) {
|
||||||
filter := datastore.Optional()
|
filter := datastore.Optional()
|
||||||
return ScriptPolicyFilter(filter)
|
|
||||||
}
|
if params.FromScriptHash.IsSet(){
|
||||||
func (filter ScriptPolicyFilter) SetFromScriptHash(from_script_hash int64) {
|
hash, err := model.HashParse(params.FromScriptHash.Value)
|
||||||
// Finally, type safety!
|
if err != nil {
|
||||||
datastore.OptionalMap(filter).Add("from_script_hash", from_script_hash)
|
return nil, err
|
||||||
}
|
}
|
||||||
func (filter ScriptPolicyFilter) SetToScriptID(to_script_id int64) {
|
filter.Add("from_script_hash", int64(hash)) // No type safety!
|
||||||
datastore.OptionalMap(filter).Add("to_script_id", to_script_id)
|
}
|
||||||
}
|
if params.ToScriptID.IsSet(){
|
||||||
func (filter ScriptPolicyFilter) SetPolicy(policy int32) {
|
filter.Add("to_script_id", params.ToScriptID.Value)
|
||||||
datastore.OptionalMap(filter).Add("policy", policy)
|
}
|
||||||
|
if params.Policy.IsSet(){
|
||||||
|
filter.Add("policy", params.Policy.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
items, err := svc.DB.ScriptPolicy().List(ctx, filter, model.Page{
|
||||||
|
Number: params.Page,
|
||||||
|
Size: params.Limit,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []api.ScriptPolicy
|
||||||
|
for _, item := range items {
|
||||||
|
resp = append(resp, api.ScriptPolicy{
|
||||||
|
ID: item.ID,
|
||||||
|
FromScriptHash: model.HashFormat(uint64(item.FromScriptHash)),
|
||||||
|
ToScriptID: item.ToScriptID,
|
||||||
|
Policy: int32(item.Policy),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *Service) CreateScriptPolicy(ctx context.Context, script model.ScriptPolicy) (model.ScriptPolicy, error) {
|
// DeleteScriptPolicy implements deleteScriptPolicy operation.
|
||||||
return svc.db.ScriptPolicy().Create(ctx, script)
|
//
|
||||||
|
// Delete the specified script policy by ID.
|
||||||
|
//
|
||||||
|
// DELETE /script-policy/{ScriptPolicyID}
|
||||||
|
func (svc *Service) DeleteScriptPolicy(ctx context.Context, params api.DeleteScriptPolicyParams) error {
|
||||||
|
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
|
||||||
|
if !ok {
|
||||||
|
return ErrUserInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
has_role, err := userInfo.HasRoleScriptWrite()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !has_role {
|
||||||
|
return ErrPermissionDenied
|
||||||
|
}
|
||||||
|
|
||||||
|
return svc.DB.ScriptPolicy().Delete(ctx, params.ScriptPolicyID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *Service) ListScriptPolicies(ctx context.Context, filter ScriptPolicyFilter, page model.Page) ([]model.ScriptPolicy, error) {
|
// GetScriptPolicy implements getScriptPolicy operation.
|
||||||
return svc.db.ScriptPolicy().List(ctx, datastore.OptionalMap(filter), page)
|
//
|
||||||
|
// Get the specified script policy by ID.
|
||||||
|
//
|
||||||
|
// GET /script-policy/{ScriptPolicyID}
|
||||||
|
func (svc *Service) GetScriptPolicy(ctx context.Context, params api.GetScriptPolicyParams) (*api.ScriptPolicy, error) {
|
||||||
|
policy, err := svc.DB.ScriptPolicy().Get(ctx, params.ScriptPolicyID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &api.ScriptPolicy{
|
||||||
|
ID: policy.ID,
|
||||||
|
FromScriptHash: model.HashFormat(uint64(policy.FromScriptHash)),
|
||||||
|
ToScriptID: policy.ToScriptID,
|
||||||
|
Policy: int32(policy.Policy),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *Service) DeleteScriptPolicy(ctx context.Context, id int64) error {
|
// UpdateScriptPolicy implements updateScriptPolicy operation.
|
||||||
return svc.db.ScriptPolicy().Delete(ctx, id)
|
//
|
||||||
}
|
// Update the specified script policy by ID.
|
||||||
|
//
|
||||||
|
// POST /script-policy/{ScriptPolicyID}
|
||||||
|
func (svc *Service) UpdateScriptPolicy(ctx context.Context, req *api.ScriptPolicyUpdate, params api.UpdateScriptPolicyParams) error {
|
||||||
|
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
|
||||||
|
if !ok {
|
||||||
|
return ErrUserInfo
|
||||||
|
}
|
||||||
|
|
||||||
func (svc *Service) GetScriptPolicy(ctx context.Context, id int64) (model.ScriptPolicy, error) {
|
has_role, err := userInfo.HasRoleScriptWrite()
|
||||||
return svc.db.ScriptPolicy().Get(ctx, id)
|
if err != nil {
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
|
if !has_role {
|
||||||
|
return ErrPermissionDenied
|
||||||
|
}
|
||||||
|
|
||||||
func (svc *Service) UpdateScriptPolicy(ctx context.Context, id int64, pmap ScriptPolicyFilter) error {
|
pmap := datastore.Optional()
|
||||||
return svc.db.ScriptPolicy().Update(ctx, id, datastore.OptionalMap(pmap))
|
if from_script_id, ok := req.FromScriptID.Get(); ok {
|
||||||
|
from_script, err := svc.DB.Scripts().Get(ctx, from_script_id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pmap.Add("from_script_hash", from_script.Hash)
|
||||||
|
}
|
||||||
|
if to_script_id, ok := req.ToScriptID.Get(); ok {
|
||||||
|
pmap.Add("to_script_id", to_script_id)
|
||||||
|
}
|
||||||
|
if policy, ok := req.Policy.Get(); ok {
|
||||||
|
pmap.Add("policy", policy)
|
||||||
|
}
|
||||||
|
return svc.DB.ScriptPolicy().Update(ctx, req.ID, pmap)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,48 +3,172 @@ package service
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ScriptFilter datastore.OptionalMap
|
// CreateScript implements createScript operation.
|
||||||
|
//
|
||||||
|
// Create a new script.
|
||||||
|
//
|
||||||
|
// POST /scripts
|
||||||
|
func (svc *Service) CreateScript(ctx context.Context, req *api.ScriptCreate) (*api.ScriptID, error) {
|
||||||
|
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrUserInfo
|
||||||
|
}
|
||||||
|
|
||||||
func NewScriptFilter() ScriptFilter {
|
has_role, err := userInfo.HasRoleScriptWrite()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !has_role {
|
||||||
|
return nil, ErrPermissionDenied
|
||||||
|
}
|
||||||
|
|
||||||
|
script, err := svc.DB.Scripts().Create(ctx, model.Script{
|
||||||
|
ID: 0,
|
||||||
|
Name: req.Name,
|
||||||
|
Hash: int64(model.HashSource(req.Source)),
|
||||||
|
Source: req.Source,
|
||||||
|
ResourceType: model.ResourceType(req.ResourceType),
|
||||||
|
ResourceID: req.ResourceID.Or(0),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &api.ScriptID{
|
||||||
|
ScriptID: script.ID,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListScripts implements listScripts operation.
|
||||||
|
//
|
||||||
|
// Get list of scripts.
|
||||||
|
//
|
||||||
|
// GET /scripts
|
||||||
|
func (svc *Service) ListScripts(ctx context.Context, params api.ListScriptsParams) ([]api.Script, error) {
|
||||||
filter := datastore.Optional()
|
filter := datastore.Optional()
|
||||||
return ScriptFilter(filter)
|
|
||||||
}
|
if params.Hash.IsSet(){
|
||||||
func (filter ScriptFilter) SetName(name string) {
|
hash, err := model.HashParse(params.Hash.Value)
|
||||||
datastore.OptionalMap(filter).Add("name", name)
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
func (filter ScriptFilter) SetSource(source string) {
|
}
|
||||||
datastore.OptionalMap(filter).Add("source", source)
|
filter.Add("hash", int64(hash)) // No type safety!
|
||||||
}
|
}
|
||||||
func (filter ScriptFilter) SetHash(hash int64) {
|
if params.Name.IsSet(){
|
||||||
datastore.OptionalMap(filter).Add("hash", hash)
|
filter.Add("name", params.Name.Value)
|
||||||
}
|
}
|
||||||
func (filter ScriptFilter) SetResourceType(resource_type int32) {
|
if params.Source.IsSet(){
|
||||||
datastore.OptionalMap(filter).Add("resource_type", resource_type)
|
filter.Add("source", params.Source.Value)
|
||||||
}
|
}
|
||||||
func (filter ScriptFilter) SetResourceID(resource_id int64) {
|
if params.ResourceType.IsSet(){
|
||||||
datastore.OptionalMap(filter).Add("resource_id", resource_id)
|
filter.Add("resource_type", params.ResourceType.Value)
|
||||||
|
}
|
||||||
|
if params.ResourceID.IsSet(){
|
||||||
|
filter.Add("resource_id", params.ResourceID.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
items, err := svc.DB.Scripts().List(ctx, filter, model.Page{
|
||||||
|
Number: params.Page,
|
||||||
|
Size: params.Limit,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []api.Script
|
||||||
|
for _, item := range items {
|
||||||
|
resp = append(resp, api.Script{
|
||||||
|
ID: item.ID,
|
||||||
|
Hash: model.HashFormat(uint64(item.Hash)),
|
||||||
|
Source: item.Source,
|
||||||
|
ResourceType: int32(item.ResourceType),
|
||||||
|
ResourceID: item.ResourceID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *Service) CreateScript(ctx context.Context, script model.Script) (model.Script, error) {
|
// DeleteScript implements deleteScript operation.
|
||||||
return svc.db.Scripts().Create(ctx, script)
|
//
|
||||||
|
// Delete the specified script by ID.
|
||||||
|
//
|
||||||
|
// DELETE /scripts/{ScriptID}
|
||||||
|
func (svc *Service) DeleteScript(ctx context.Context, params api.DeleteScriptParams) error {
|
||||||
|
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
|
||||||
|
if !ok {
|
||||||
|
return ErrUserInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
has_role, err := userInfo.HasRoleScriptWrite()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !has_role {
|
||||||
|
return ErrPermissionDenied
|
||||||
|
}
|
||||||
|
|
||||||
|
return svc.DB.Scripts().Delete(ctx, params.ScriptID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *Service) ListScripts(ctx context.Context, filter ScriptFilter, page model.Page) ([]model.Script, error) {
|
// GetScript implements getScript operation.
|
||||||
return svc.db.Scripts().List(ctx, datastore.OptionalMap(filter), page)
|
//
|
||||||
|
// Get the specified script by ID.
|
||||||
|
//
|
||||||
|
// GET /scripts/{ScriptID}
|
||||||
|
func (svc *Service) GetScript(ctx context.Context, params api.GetScriptParams) (*api.Script, error) {
|
||||||
|
script, err := svc.DB.Scripts().Get(ctx, params.ScriptID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &api.Script{
|
||||||
|
ID: script.ID,
|
||||||
|
Name: script.Name,
|
||||||
|
Hash: model.HashFormat(uint64(script.Hash)),
|
||||||
|
Source: script.Source,
|
||||||
|
ResourceType: int32(script.ResourceType),
|
||||||
|
ResourceID: script.ResourceID,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *Service) DeleteScript(ctx context.Context, id int64) error {
|
// UpdateScript implements updateScript operation.
|
||||||
return svc.db.Scripts().Delete(ctx, id)
|
//
|
||||||
}
|
// Update the specified script by ID.
|
||||||
|
//
|
||||||
|
// PATCH /scripts/{ScriptID}
|
||||||
|
func (svc *Service) UpdateScript(ctx context.Context, req *api.ScriptUpdate, params api.UpdateScriptParams) error {
|
||||||
|
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
|
||||||
|
if !ok {
|
||||||
|
return ErrUserInfo
|
||||||
|
}
|
||||||
|
|
||||||
func (svc *Service) GetScript(ctx context.Context, id int64) (model.Script, error) {
|
has_role, err := userInfo.HasRoleScriptWrite()
|
||||||
return svc.db.Scripts().Get(ctx, id)
|
if err != nil {
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
|
if !has_role {
|
||||||
|
return ErrPermissionDenied
|
||||||
|
}
|
||||||
|
|
||||||
func (svc *Service) UpdateScript(ctx context.Context, id int64, pmap ScriptFilter) error {
|
pmap := datastore.Optional()
|
||||||
return svc.db.Scripts().Update(ctx, id, datastore.OptionalMap(pmap))
|
if Name, ok := req.Name.Get(); ok {
|
||||||
|
pmap.Add("name", Name)
|
||||||
|
}
|
||||||
|
if source, ok := req.Source.Get(); ok {
|
||||||
|
pmap.Add("source", source)
|
||||||
|
pmap.Add("hash", int64(model.HashSource(source))) // No type safety!
|
||||||
|
}
|
||||||
|
if ResourceType, ok := req.ResourceType.Get(); ok {
|
||||||
|
pmap.Add("resource_type", ResourceType)
|
||||||
|
}
|
||||||
|
if ResourceID, ok := req.ResourceID.Get(); ok {
|
||||||
|
pmap.Add("resource_id", ResourceID)
|
||||||
|
}
|
||||||
|
return svc.DB.Scripts().Update(ctx, req.ID, pmap)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package web_api
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/go-grpc/auth"
|
"git.itzana.me/strafesnet/go-grpc/auth"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -16,6 +14,38 @@ var (
|
|||||||
ErrInvalidSession = errors.New("Session invalid")
|
ErrInvalidSession = errors.New("Session invalid")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Submissions roles bitflag
|
||||||
|
type Roles int32
|
||||||
|
var (
|
||||||
|
RolesSubmissionUpload Roles = 1<<6
|
||||||
|
RolesSubmissionReview Roles = 1<<5
|
||||||
|
RolesSubmissionRelease Roles = 1<<4
|
||||||
|
RolesScriptWrite Roles = 1<<3
|
||||||
|
RolesMapfixUpload Roles = 1<<2
|
||||||
|
RolesMapfixReview Roles = 1<<1
|
||||||
|
RolesMapDownload Roles = 1<<0
|
||||||
|
RolesEmpty Roles = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
// StrafesNET group roles
|
||||||
|
type GroupRole int32
|
||||||
|
var (
|
||||||
|
// has ScriptWrite
|
||||||
|
RoleQuat GroupRole = 255
|
||||||
|
RoleItzaname GroupRole = 254
|
||||||
|
RoleStagingDeveloper GroupRole = 240
|
||||||
|
RolesAll Roles = ^RolesEmpty
|
||||||
|
// has SubmissionUpload
|
||||||
|
RoleMapAdmin GroupRole = 128
|
||||||
|
RolesMapAdmin Roles = RolesSubmissionRelease|RolesSubmissionUpload|RolesSubmissionReview|RolesMapCouncil
|
||||||
|
// has MapfixReview
|
||||||
|
RoleMapCouncil GroupRole = 64
|
||||||
|
RolesMapCouncil Roles = RolesMapfixReview|RolesMapfixUpload|RolesMapAccess
|
||||||
|
// access to downloading maps
|
||||||
|
RoleMapAccess GroupRole = 32
|
||||||
|
RolesMapAccess Roles = RolesMapDownload
|
||||||
|
)
|
||||||
|
|
||||||
type UserInfoHandle struct {
|
type UserInfoHandle struct {
|
||||||
// Would love to know a better way to do this
|
// Would love to know a better way to do this
|
||||||
svc *SecurityHandler
|
svc *SecurityHandler
|
||||||
@@ -58,7 +88,7 @@ func (usr UserInfoHandle) Validate() (bool, error) {
|
|||||||
}
|
}
|
||||||
return validate.Valid, nil
|
return validate.Valid, nil
|
||||||
}
|
}
|
||||||
func (usr UserInfoHandle) hasRoles(wantRoles model.Roles) (bool, error) {
|
func (usr UserInfoHandle) hasRoles(wantRoles Roles) (bool, error) {
|
||||||
haveroles, err := usr.GetRoles()
|
haveroles, err := usr.GetRoles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -66,27 +96,27 @@ func (usr UserInfoHandle) hasRoles(wantRoles model.Roles) (bool, error) {
|
|||||||
|
|
||||||
return haveroles & wantRoles == wantRoles, nil
|
return haveroles & wantRoles == wantRoles, nil
|
||||||
}
|
}
|
||||||
func (usr UserInfoHandle) GetRoles() (model.Roles, error) {
|
func (usr UserInfoHandle) GetRoles() (Roles, error) {
|
||||||
roles, err := usr.svc.Client.GetGroupRole(*usr.ctx, &auth.IdMessage{
|
roles, err := usr.svc.Client.GetGroupRole(*usr.ctx, &auth.IdMessage{
|
||||||
SessionID: usr.sessionId,
|
SessionID: usr.sessionId,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return model.RolesEmpty, err
|
return RolesEmpty, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// map roles into bitflag
|
// map roles into bitflag
|
||||||
rolesBitflag := model.RolesEmpty;
|
rolesBitflag := RolesEmpty;
|
||||||
for _, r := range roles.Roles {
|
for _, r := range roles.Roles {
|
||||||
switch model.GroupRole(r.Rank){
|
switch GroupRole(r.Rank){
|
||||||
case model.RoleQuat, model.RoleItzaname, model.RoleStagingDeveloper:
|
case RoleQuat, RoleItzaname, RoleStagingDeveloper:
|
||||||
rolesBitflag|=model.RolesAll
|
rolesBitflag|=RolesAll
|
||||||
case model.RoleMapAdmin:
|
case RoleMapAdmin:
|
||||||
rolesBitflag|=model.RolesMapAdmin
|
rolesBitflag|=RolesMapAdmin
|
||||||
case model.RoleMapCouncil:
|
case RoleMapCouncil:
|
||||||
rolesBitflag|=model.RolesMapCouncil
|
rolesBitflag|=RolesMapCouncil
|
||||||
case model.RoleMapAccess:
|
case RoleMapAccess:
|
||||||
rolesBitflag|=model.RolesMapAccess
|
rolesBitflag|=RolesMapAccess
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rolesBitflag, nil
|
return rolesBitflag, nil
|
||||||
@@ -94,25 +124,25 @@ func (usr UserInfoHandle) GetRoles() (model.Roles, error) {
|
|||||||
|
|
||||||
// RoleThumbnail
|
// RoleThumbnail
|
||||||
func (usr UserInfoHandle) HasRoleMapfixUpload() (bool, error) {
|
func (usr UserInfoHandle) HasRoleMapfixUpload() (bool, error) {
|
||||||
return usr.hasRoles(model.RolesMapfixUpload)
|
return usr.hasRoles(RolesMapfixUpload)
|
||||||
}
|
}
|
||||||
func (usr UserInfoHandle) HasRoleMapfixReview() (bool, error) {
|
func (usr UserInfoHandle) HasRoleMapfixReview() (bool, error) {
|
||||||
return usr.hasRoles(model.RolesMapfixReview)
|
return usr.hasRoles(RolesMapfixReview)
|
||||||
}
|
}
|
||||||
func (usr UserInfoHandle) HasRoleMapDownload() (bool, error) {
|
func (usr UserInfoHandle) HasRoleMapDownload() (bool, error) {
|
||||||
return usr.hasRoles(model.RolesMapDownload)
|
return usr.hasRoles(RolesMapDownload)
|
||||||
}
|
}
|
||||||
func (usr UserInfoHandle) HasRoleSubmissionRelease() (bool, error) {
|
func (usr UserInfoHandle) HasRoleSubmissionRelease() (bool, error) {
|
||||||
return usr.hasRoles(model.RolesSubmissionRelease)
|
return usr.hasRoles(RolesSubmissionRelease)
|
||||||
}
|
}
|
||||||
func (usr UserInfoHandle) HasRoleSubmissionUpload() (bool, error) {
|
func (usr UserInfoHandle) HasRoleSubmissionUpload() (bool, error) {
|
||||||
return usr.hasRoles(model.RolesSubmissionUpload)
|
return usr.hasRoles(RolesSubmissionUpload)
|
||||||
}
|
}
|
||||||
func (usr UserInfoHandle) HasRoleSubmissionReview() (bool, error) {
|
func (usr UserInfoHandle) HasRoleSubmissionReview() (bool, error) {
|
||||||
return usr.hasRoles(model.RolesSubmissionReview)
|
return usr.hasRoles(RolesSubmissionReview)
|
||||||
}
|
}
|
||||||
func (usr UserInfoHandle) HasRoleScriptWrite() (bool, error) {
|
func (usr UserInfoHandle) HasRoleScriptWrite() (bool, error) {
|
||||||
return usr.hasRoles(model.RolesScriptWrite)
|
return usr.hasRoles(RolesScriptWrite)
|
||||||
}
|
}
|
||||||
/// Not implemented
|
/// Not implemented
|
||||||
func (usr UserInfoHandle) HasRoleMaptest() (bool, error) {
|
func (usr UserInfoHandle) HasRoleMaptest() (bool, error) {
|
||||||
@@ -1,29 +1,61 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/go-grpc/maps"
|
"git.itzana.me/strafesnet/go-grpc/maps"
|
||||||
"git.itzana.me/strafesnet/go-grpc/users"
|
"git.itzana.me/strafesnet/go-grpc/users"
|
||||||
|
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrPermissionDenied caller does not have the required role
|
||||||
|
ErrPermissionDenied = errors.New("Permission denied")
|
||||||
|
// ErrUserInfo user info is missing for some reason
|
||||||
|
ErrUserInfo = errors.New("Missing user info")
|
||||||
|
ErrDelayReset = errors.New("Please give the validator at least 10 seconds to operate before attempting to reset the status")
|
||||||
|
ErrPermissionDeniedNotSubmitter = fmt.Errorf("%w: You must be the submitter to perform this action", ErrPermissionDenied)
|
||||||
|
ErrPermissionDeniedNeedRoleSubmissionRelease = fmt.Errorf("%w: Need Role SubmissionRelease", ErrPermissionDenied)
|
||||||
|
ErrPermissionDeniedNeedRoleMapfixUpload = fmt.Errorf("%w: Need Role MapfixUpload", ErrPermissionDenied)
|
||||||
|
ErrPermissionDeniedNeedRoleMapfixReview = fmt.Errorf("%w: Need Role MapfixReview", ErrPermissionDenied)
|
||||||
|
ErrPermissionDeniedNeedRoleSubmissionUpload = fmt.Errorf("%w: Need Role SubmissionUpload", ErrPermissionDenied)
|
||||||
|
ErrPermissionDeniedNeedRoleSubmissionReview = fmt.Errorf("%w: Need Role SubmissionReview", ErrPermissionDenied)
|
||||||
|
ErrPermissionDeniedNeedRoleMapDownload = fmt.Errorf("%w: Need Role MapDownload", ErrPermissionDenied)
|
||||||
|
ErrPermissionDeniedNeedRoleScriptWrite = fmt.Errorf("%w: Need Role ScriptWrite", ErrPermissionDenied)
|
||||||
|
ErrPermissionDeniedNeedRoleMaptest = fmt.Errorf("%w: Need Role Maptest", ErrPermissionDenied)
|
||||||
|
ErrNegativeID = errors.New("A negative ID was provided")
|
||||||
|
)
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
db datastore.Datastore
|
DB datastore.Datastore
|
||||||
nats nats.JetStreamContext
|
Nats nats.JetStreamContext
|
||||||
maps maps.MapsServiceClient
|
Maps maps.MapsServiceClient
|
||||||
users users.UsersServiceClient
|
Users users.UsersServiceClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(
|
// NewError creates *ErrorStatusCode from error returned by handler.
|
||||||
db datastore.Datastore,
|
//
|
||||||
nats nats.JetStreamContext,
|
// Used for common default response.
|
||||||
maps maps.MapsServiceClient,
|
func (svc *Service) NewError(ctx context.Context, err error) *api.ErrorStatusCode {
|
||||||
users users.UsersServiceClient,
|
status := 500
|
||||||
) Service {
|
if errors.Is(err, datastore.ErrNotExist) {
|
||||||
return Service{
|
status = 404
|
||||||
db: db,
|
}
|
||||||
nats: nats,
|
if errors.Is(err, ErrPermissionDenied) {
|
||||||
maps: maps,
|
status = 403
|
||||||
users: users,
|
}
|
||||||
|
if errors.Is(err, ErrUserInfo) {
|
||||||
|
status = 401
|
||||||
|
}
|
||||||
|
return &api.ErrorStatusCode{
|
||||||
|
StatusCode: status,
|
||||||
|
Response: api.Error{
|
||||||
|
Code: int64(status),
|
||||||
|
Message: err.Error(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package web_api
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
File diff suppressed because it is too large
Load Diff
371
pkg/service_internal/mapfixes.go
Normal file
371
pkg/service_internal/mapfixes.go
Normal file
@@ -0,0 +1,371 @@
|
|||||||
|
package service_internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
||||||
|
internal "git.itzana.me/strafesnet/maps-service/pkg/internal"
|
||||||
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
var(
|
||||||
|
// prevent two mapfixes with same asset id
|
||||||
|
ActiveMapfixStatuses = []model.MapfixStatus{
|
||||||
|
model.MapfixStatusUploading,
|
||||||
|
model.MapfixStatusValidated,
|
||||||
|
model.MapfixStatusValidating,
|
||||||
|
model.MapfixStatusAcceptedUnvalidated,
|
||||||
|
model.MapfixStatusChangesRequested,
|
||||||
|
model.MapfixStatusSubmitted,
|
||||||
|
model.MapfixStatusUnderConstruction,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
var(
|
||||||
|
ErrActiveMapfixSameAssetID = errors.New("There is an active mapfix with the same AssetID")
|
||||||
|
ErrNotAssetOwner = errors.New("You can only submit an asset you own")
|
||||||
|
)
|
||||||
|
|
||||||
|
// UpdateMapfixValidatedModel implements patchMapfixModel operation.
|
||||||
|
//
|
||||||
|
// Update model following role restrictions.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/validated-model
|
||||||
|
func (svc *Service) UpdateMapfixValidatedModel(ctx context.Context, params internal.UpdateMapfixValidatedModelParams) error {
|
||||||
|
ValidatedModelID := uint64(params.ValidatedModelID)
|
||||||
|
ValidatedModelVersion := uint64(params.ValidatedModelVersion)
|
||||||
|
|
||||||
|
// check if Status is ChangesRequested|Submitted|UnderConstruction
|
||||||
|
pmap := datastore.Optional()
|
||||||
|
pmap.Add("validated_asset_id", ValidatedModelID)
|
||||||
|
pmap.Add("validated_asset_version", ValidatedModelVersion)
|
||||||
|
// DO NOT reset completed when validated model is updated
|
||||||
|
// pmap.Add("completed", false)
|
||||||
|
err := svc.DB.Mapfixes().IfStatusThenUpdate(ctx, params.MapfixID, []model.MapfixStatus{model.MapfixStatusValidating}, pmap)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
event_data := model.AuditEventDataChangeValidatedModel{
|
||||||
|
ValidatedModelID: ValidatedModelID,
|
||||||
|
ValidatedModelVersion: ValidatedModelVersion,
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: ValidtorUserID,
|
||||||
|
ResourceType: model.ResourceMapfix,
|
||||||
|
ResourceID: params.MapfixID,
|
||||||
|
EventType: model.AuditEventTypeChangeValidatedModel,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionMapfixSubmitted invokes actionMapfixSubmitted operation.
|
||||||
|
//
|
||||||
|
// Role Validator changes status from Submitting -> Submitted.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/status/validator-submitted
|
||||||
|
func (svc *Service) ActionMapfixSubmitted(ctx context.Context, params internal.ActionMapfixSubmittedParams) error {
|
||||||
|
// transaction
|
||||||
|
target_status := model.MapfixStatusSubmitted
|
||||||
|
smap := datastore.Optional()
|
||||||
|
smap.Add("status_id", target_status)
|
||||||
|
smap.Add("asset_version", params.ModelVersion)
|
||||||
|
smap.Add("display_name", params.DisplayName)
|
||||||
|
smap.Add("creator", params.Creator)
|
||||||
|
smap.Add("game_id", params.GameID)
|
||||||
|
err := svc.DB.Mapfixes().IfStatusThenUpdate(ctx, params.MapfixID, []model.MapfixStatus{model.MapfixStatusSubmitting}, smap)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
event_data := model.AuditEventDataAction{
|
||||||
|
TargetStatus: uint32(target_status),
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: ValidtorUserID,
|
||||||
|
ResourceType: model.ResourceMapfix,
|
||||||
|
ResourceID: params.MapfixID,
|
||||||
|
EventType: model.AuditEventTypeAction,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionMapfixRequestChanges implements actionMapfixRequestChanges operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Submitting -> RequestChanges.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/status/validator-request-changes
|
||||||
|
func (svc *Service) ActionMapfixRequestChanges(ctx context.Context, params internal.ActionMapfixRequestChangesParams) error {
|
||||||
|
// transaction
|
||||||
|
target_status := model.MapfixStatusChangesRequested
|
||||||
|
smap := datastore.Optional()
|
||||||
|
smap.Add("status_id", target_status)
|
||||||
|
err := svc.DB.Mapfixes().IfStatusThenUpdate(ctx, params.MapfixID, []model.MapfixStatus{model.MapfixStatusSubmitting}, smap)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
event_data := model.AuditEventDataError{
|
||||||
|
Error: params.ErrorMessage,
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: ValidtorUserID,
|
||||||
|
ResourceType: model.ResourceMapfix,
|
||||||
|
ResourceID: params.MapfixID,
|
||||||
|
EventType: model.AuditEventTypeError,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event_data := model.AuditEventDataAction{
|
||||||
|
TargetStatus: uint32(target_status),
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: ValidtorUserID,
|
||||||
|
ResourceType: model.ResourceMapfix,
|
||||||
|
ResourceID: params.MapfixID,
|
||||||
|
EventType: model.AuditEventTypeAction,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionMapfixValidate invokes actionMapfixValidate operation.
|
||||||
|
//
|
||||||
|
// Role Validator changes status from Validating -> Validated.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/status/validator-validated
|
||||||
|
func (svc *Service) ActionMapfixValidated(ctx context.Context, params internal.ActionMapfixValidatedParams) error {
|
||||||
|
// transaction
|
||||||
|
smap := datastore.Optional()
|
||||||
|
smap.Add("status_id", model.MapfixStatusValidated)
|
||||||
|
return svc.DB.Mapfixes().IfStatusThenUpdate(ctx, params.MapfixID, []model.MapfixStatus{model.MapfixStatusValidating}, smap)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionMapfixAccepted implements actionMapfixAccepted operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Validating -> Accepted.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/status/validator-failed
|
||||||
|
func (svc *Service) ActionMapfixAccepted(ctx context.Context, params internal.ActionMapfixAcceptedParams) error {
|
||||||
|
// transaction
|
||||||
|
target_status := model.MapfixStatusAcceptedUnvalidated
|
||||||
|
smap := datastore.Optional()
|
||||||
|
smap.Add("status_id", target_status)
|
||||||
|
err := svc.DB.Mapfixes().IfStatusThenUpdate(ctx, params.MapfixID, []model.MapfixStatus{model.MapfixStatusValidating}, smap)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
//push an error audit event
|
||||||
|
{
|
||||||
|
event_data := model.AuditEventDataError{
|
||||||
|
Error: params.ErrorMessage,
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: ValidtorUserID,
|
||||||
|
ResourceType: model.ResourceMapfix,
|
||||||
|
ResourceID: params.MapfixID,
|
||||||
|
EventType: model.AuditEventTypeError,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// push an action audit event
|
||||||
|
event_data := model.AuditEventDataAction{
|
||||||
|
TargetStatus: uint32(target_status),
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: ValidtorUserID,
|
||||||
|
ResourceType: model.ResourceMapfix,
|
||||||
|
ResourceID: params.MapfixID,
|
||||||
|
EventType: model.AuditEventTypeAction,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionMapfixUploaded implements actionMapfixUploaded operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Uploading -> Uploaded.
|
||||||
|
//
|
||||||
|
// POST /mapfixes/{MapfixID}/status/validator-uploaded
|
||||||
|
func (svc *Service) ActionMapfixUploaded(ctx context.Context, params internal.ActionMapfixUploadedParams) error {
|
||||||
|
// transaction
|
||||||
|
target_status := model.MapfixStatusUploaded
|
||||||
|
smap := datastore.Optional()
|
||||||
|
smap.Add("status_id", target_status)
|
||||||
|
err := svc.DB.Mapfixes().IfStatusThenUpdate(ctx, params.MapfixID, []model.MapfixStatus{model.MapfixStatusUploading}, smap)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
event_data := model.AuditEventDataAction{
|
||||||
|
TargetStatus: uint32(target_status),
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: ValidtorUserID,
|
||||||
|
ResourceType: model.ResourceMapfix,
|
||||||
|
ResourceID: params.MapfixID,
|
||||||
|
EventType: model.AuditEventTypeAction,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST /mapfixes
|
||||||
|
func (svc *Service) CreateMapfix(ctx context.Context, request *internal.MapfixCreate) (*internal.MapfixID, error) {
|
||||||
|
// sanitization
|
||||||
|
if request.GameID<0||
|
||||||
|
request.AssetOwner<0||
|
||||||
|
request.AssetID<0||
|
||||||
|
request.AssetVersion<0||
|
||||||
|
request.TargetAssetID<0{
|
||||||
|
return nil, ErrNegativeID
|
||||||
|
}
|
||||||
|
var GameID=uint32(request.GameID);
|
||||||
|
var Submitter=uint64(request.AssetOwner);
|
||||||
|
var AssetID=uint64(request.AssetID);
|
||||||
|
var AssetVersion=uint64(request.AssetVersion);
|
||||||
|
var TargetAssetID=uint64(request.TargetAssetID);
|
||||||
|
|
||||||
|
// Check if an active mapfix with the same asset id exists
|
||||||
|
{
|
||||||
|
filter := datastore.Optional()
|
||||||
|
filter.Add("asset_id", request.AssetID)
|
||||||
|
filter.Add("asset_version", request.AssetVersion)
|
||||||
|
filter.Add("status_id", ActiveMapfixStatuses)
|
||||||
|
active_mapfixes, err := svc.DB.Mapfixes().List(ctx, filter, model.Page{
|
||||||
|
Number: 1,
|
||||||
|
Size: 1,
|
||||||
|
},datastore.ListSortDisabled)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(active_mapfixes) != 0{
|
||||||
|
return nil, ErrActiveMapfixSameAssetID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
operation, err := svc.DB.Operations().Get(ctx, request.OperationID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if user owns asset
|
||||||
|
// TODO: allow bypass by admin
|
||||||
|
if operation.Owner != Submitter {
|
||||||
|
return nil, ErrNotAssetOwner
|
||||||
|
}
|
||||||
|
|
||||||
|
mapfix, err := svc.DB.Mapfixes().Create(ctx, model.Mapfix{
|
||||||
|
ID: 0,
|
||||||
|
DisplayName: request.DisplayName,
|
||||||
|
Creator: request.Creator,
|
||||||
|
GameID: GameID,
|
||||||
|
Submitter: Submitter,
|
||||||
|
AssetID: AssetID,
|
||||||
|
AssetVersion: AssetVersion,
|
||||||
|
Completed: false,
|
||||||
|
TargetAssetID: TargetAssetID,
|
||||||
|
StatusID: model.MapfixStatusUnderConstruction,
|
||||||
|
Description: request.Description,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// mark the operation as completed and provide the path
|
||||||
|
pmap := datastore.Optional()
|
||||||
|
pmap.Add("status_id", model.OperationStatusCompleted)
|
||||||
|
pmap.Add("path", fmt.Sprintf("/mapfixes/%d", mapfix.ID))
|
||||||
|
err = svc.DB.Operations().Update(ctx, request.OperationID, pmap)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &internal.MapfixID{
|
||||||
|
MapfixID: mapfix.ID,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
21
pkg/service_internal/operations.go
Normal file
21
pkg/service_internal/operations.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package service_internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
||||||
|
internal "git.itzana.me/strafesnet/maps-service/pkg/internal"
|
||||||
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ActionOperationFailed implements actionOperationFailed operation.
|
||||||
|
//
|
||||||
|
// Fail the specified OperationID with a StatusMessage.
|
||||||
|
//
|
||||||
|
// POST /operations/{OperationID}/status/operation-failed
|
||||||
|
func (svc *Service) ActionOperationFailed(ctx context.Context, params internal.ActionOperationFailedParams) (error) {
|
||||||
|
pmap := datastore.Optional()
|
||||||
|
pmap.Add("status_id", model.OperationStatusFailed)
|
||||||
|
pmap.Add("status_message", params.StatusMessage)
|
||||||
|
return svc.DB.Operations().Update(ctx, params.OperationID, pmap)
|
||||||
|
}
|
||||||
80
pkg/service_internal/script_policy.go
Normal file
80
pkg/service_internal/script_policy.go
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package service_internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
||||||
|
api "git.itzana.me/strafesnet/maps-service/pkg/internal"
|
||||||
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CreateScriptPolicy implements createScriptPolicy operation.
|
||||||
|
//
|
||||||
|
// Create a new script policy.
|
||||||
|
//
|
||||||
|
// POST /script-policy
|
||||||
|
func (svc *Service) CreateScriptPolicy(ctx context.Context, req *api.ScriptPolicyCreate) (*api.ScriptPolicyID, error) {
|
||||||
|
from_script, err := svc.DB.Scripts().Get(ctx, req.FromScriptID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// the existence of ToScriptID does not need to be validated because it's checked by a foreign key constraint.
|
||||||
|
|
||||||
|
script, err := svc.DB.ScriptPolicy().Create(ctx, model.ScriptPolicy{
|
||||||
|
ID: 0,
|
||||||
|
FromScriptHash: from_script.Hash,
|
||||||
|
ToScriptID: req.ToScriptID,
|
||||||
|
Policy: model.Policy(req.Policy),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &api.ScriptPolicyID{
|
||||||
|
ScriptPolicyID: script.ID,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListScriptPolicy implements listScriptPolicy operation.
|
||||||
|
//
|
||||||
|
// Get list of script policies.
|
||||||
|
//
|
||||||
|
// GET /script-policy
|
||||||
|
func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptPolicyParams) ([]api.ScriptPolicy, error) {
|
||||||
|
filter := datastore.Optional()
|
||||||
|
|
||||||
|
if params.FromScriptHash.IsSet(){
|
||||||
|
hash, err := model.HashParse(params.FromScriptHash.Value)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
filter.Add("from_script_hash", int64(hash)) // No type safety!
|
||||||
|
}
|
||||||
|
if params.ToScriptID.IsSet(){
|
||||||
|
filter.Add("to_script_id", params.ToScriptID.Value)
|
||||||
|
}
|
||||||
|
if params.Policy.IsSet(){
|
||||||
|
filter.Add("policy", params.Policy.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
items, err := svc.DB.ScriptPolicy().List(ctx, filter, model.Page{
|
||||||
|
Number: params.Page,
|
||||||
|
Size: params.Limit,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []api.ScriptPolicy
|
||||||
|
for _, item := range items {
|
||||||
|
resp = append(resp, api.ScriptPolicy{
|
||||||
|
ID: item.ID,
|
||||||
|
FromScriptHash: model.HashFormat(uint64(item.FromScriptHash)),
|
||||||
|
ToScriptID: item.ToScriptID,
|
||||||
|
Policy: int32(item.Policy),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
103
pkg/service_internal/scripts.go
Normal file
103
pkg/service_internal/scripts.go
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
package service_internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
||||||
|
api "git.itzana.me/strafesnet/maps-service/pkg/internal"
|
||||||
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CreateScript implements createScript operation.
|
||||||
|
//
|
||||||
|
// Create a new script.
|
||||||
|
//
|
||||||
|
// POST /scripts
|
||||||
|
func (svc *Service) CreateScript(ctx context.Context, req *api.ScriptCreate) (*api.ScriptID, error) {
|
||||||
|
script, err := svc.DB.Scripts().Create(ctx, model.Script{
|
||||||
|
ID: 0,
|
||||||
|
Name: req.Name,
|
||||||
|
Hash: int64(model.HashSource(req.Source)),
|
||||||
|
Source: req.Source,
|
||||||
|
ResourceType: model.ResourceType(req.ResourceType),
|
||||||
|
ResourceID: req.ResourceID.Or(0),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &api.ScriptID{
|
||||||
|
ScriptID: script.ID,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListScripts implements listScripts operation.
|
||||||
|
//
|
||||||
|
// Get list of scripts.
|
||||||
|
//
|
||||||
|
// GET /scripts
|
||||||
|
func (svc *Service) ListScripts(ctx context.Context, params api.ListScriptsParams) ([]api.Script, error) {
|
||||||
|
filter := datastore.Optional()
|
||||||
|
|
||||||
|
if params.Hash.IsSet(){
|
||||||
|
hash, err := model.HashParse(params.Hash.Value)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
filter.Add("hash", int64(hash)) // No type safety!
|
||||||
|
}
|
||||||
|
if params.Name.IsSet(){
|
||||||
|
filter.Add("name", params.Name.Value)
|
||||||
|
}
|
||||||
|
if params.Source.IsSet(){
|
||||||
|
filter.Add("source", params.Source.Value)
|
||||||
|
}
|
||||||
|
if params.ResourceType.IsSet(){
|
||||||
|
filter.Add("resource_type", params.ResourceType.Value)
|
||||||
|
}
|
||||||
|
if params.ResourceID.IsSet(){
|
||||||
|
filter.Add("resource_id", params.ResourceID.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
items, err := svc.DB.Scripts().List(ctx, filter, model.Page{
|
||||||
|
Number: params.Page,
|
||||||
|
Size: params.Limit,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []api.Script
|
||||||
|
for _, item := range items {
|
||||||
|
resp = append(resp, api.Script{
|
||||||
|
ID: item.ID,
|
||||||
|
Hash: model.HashFormat(uint64(item.Hash)),
|
||||||
|
Source: item.Source,
|
||||||
|
ResourceType: int32(item.ResourceType),
|
||||||
|
ResourceID: item.ResourceID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetScript implements getScript operation.
|
||||||
|
//
|
||||||
|
// Get the specified script by ID.
|
||||||
|
//
|
||||||
|
// GET /scripts/{ScriptID}
|
||||||
|
func (svc *Service) GetScript(ctx context.Context, params api.GetScriptParams) (*api.Script, error) {
|
||||||
|
script, err := svc.DB.Scripts().Get(ctx, params.ScriptID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &api.Script{
|
||||||
|
ID: script.ID,
|
||||||
|
Name: script.Name,
|
||||||
|
Hash: model.HashFormat(uint64(script.Hash)),
|
||||||
|
Source: script.Source,
|
||||||
|
ResourceType: int32(script.ResourceType),
|
||||||
|
ResourceID: script.ResourceID,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
39
pkg/service_internal/service_internal.go
Normal file
39
pkg/service_internal/service_internal.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package service_internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
||||||
|
internal "git.itzana.me/strafesnet/maps-service/pkg/internal"
|
||||||
|
"github.com/nats-io/nats.go"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ValidtorUserID uint64 = uint64(math.MaxInt64)
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrNegativeID = errors.New("A negative ID was provided")
|
||||||
|
)
|
||||||
|
|
||||||
|
type Service struct {
|
||||||
|
DB datastore.Datastore
|
||||||
|
Nats nats.JetStreamContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// yay duplicate code
|
||||||
|
func (svc *Service) NewError(ctx context.Context, err error) *internal.ErrorStatusCode {
|
||||||
|
status := 500
|
||||||
|
if errors.Is(err, datastore.ErrNotExist) {
|
||||||
|
status = 404
|
||||||
|
}
|
||||||
|
return &internal.ErrorStatusCode{
|
||||||
|
StatusCode: status,
|
||||||
|
Response: internal.Error{
|
||||||
|
Code: int64(status),
|
||||||
|
Message: err.Error(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
403
pkg/service_internal/submissions.go
Normal file
403
pkg/service_internal/submissions.go
Normal file
@@ -0,0 +1,403 @@
|
|||||||
|
package service_internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
||||||
|
internal "git.itzana.me/strafesnet/maps-service/pkg/internal"
|
||||||
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
||||||
|
"git.itzana.me/strafesnet/maps-service/pkg/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
var(
|
||||||
|
// prevent two mapfixes with same asset id
|
||||||
|
ActiveSubmissionStatuses = []model.SubmissionStatus{
|
||||||
|
model.SubmissionStatusUploading,
|
||||||
|
model.SubmissionStatusValidated,
|
||||||
|
model.SubmissionStatusValidating,
|
||||||
|
model.SubmissionStatusAcceptedUnvalidated,
|
||||||
|
model.SubmissionStatusChangesRequested,
|
||||||
|
model.SubmissionStatusSubmitted,
|
||||||
|
model.SubmissionStatusUnderConstruction,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
var(
|
||||||
|
ErrActiveSubmissionSameAssetID = errors.New("There is an active submission with the same AssetID")
|
||||||
|
)
|
||||||
|
|
||||||
|
// UpdateSubmissionValidatedModel implements patchSubmissionModel operation.
|
||||||
|
//
|
||||||
|
// Update model following role restrictions.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/validated-model
|
||||||
|
func (svc *Service) UpdateSubmissionValidatedModel(ctx context.Context, params internal.UpdateSubmissionValidatedModelParams) error {
|
||||||
|
ValidatedModelID := uint64(params.ValidatedModelID)
|
||||||
|
ValidatedModelVersion := uint64(params.ValidatedModelVersion)
|
||||||
|
|
||||||
|
// check if Status is ChangesRequested|Submitted|UnderConstruction
|
||||||
|
pmap := datastore.Optional()
|
||||||
|
pmap.Add("validated_asset_id", ValidatedModelID)
|
||||||
|
pmap.Add("validated_asset_version", ValidatedModelVersion)
|
||||||
|
// DO NOT reset completed when validated model is updated
|
||||||
|
// pmap.Add("completed", false)
|
||||||
|
err := svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.SubmissionStatus{model.SubmissionStatusValidating}, pmap)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
event_data := model.AuditEventDataChangeValidatedModel{
|
||||||
|
ValidatedModelID: ValidatedModelID,
|
||||||
|
ValidatedModelVersion: ValidatedModelVersion,
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: ValidtorUserID,
|
||||||
|
ResourceType: model.ResourceSubmission,
|
||||||
|
ResourceID: params.SubmissionID,
|
||||||
|
EventType: model.AuditEventTypeChangeValidatedModel,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionSubmissionSubmitted invokes actionSubmissionSubmitted operation.
|
||||||
|
//
|
||||||
|
// Role Validator changes status from Submitting -> Submitted.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/status/validator-submitted
|
||||||
|
func (svc *Service) ActionSubmissionSubmitted(ctx context.Context, params internal.ActionSubmissionSubmittedParams) error {
|
||||||
|
// transaction
|
||||||
|
target_status := model.SubmissionStatusSubmitted
|
||||||
|
smap := datastore.Optional()
|
||||||
|
smap.Add("status_id", target_status)
|
||||||
|
smap.Add("asset_version", params.ModelVersion)
|
||||||
|
smap.Add("display_name", params.DisplayName)
|
||||||
|
smap.Add("creator", params.Creator)
|
||||||
|
smap.Add("game_id", params.GameID)
|
||||||
|
err := svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.SubmissionStatus{model.SubmissionStatusSubmitting}, smap)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
event_data := model.AuditEventDataAction{
|
||||||
|
TargetStatus: uint32(target_status),
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: ValidtorUserID,
|
||||||
|
ResourceType: model.ResourceSubmission,
|
||||||
|
ResourceID: params.SubmissionID,
|
||||||
|
EventType: model.AuditEventTypeAction,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionSubmissionRequestChanges implements actionSubmissionRequestChanges operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Submitting -> RequestChanges.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/status/validator-request-changes
|
||||||
|
func (svc *Service) ActionSubmissionRequestChanges(ctx context.Context, params internal.ActionSubmissionRequestChangesParams) error {
|
||||||
|
// transaction
|
||||||
|
target_status := model.SubmissionStatusChangesRequested
|
||||||
|
smap := datastore.Optional()
|
||||||
|
smap.Add("status_id", target_status)
|
||||||
|
err := svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.SubmissionStatus{model.SubmissionStatusSubmitting}, smap)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
//push an error audit event
|
||||||
|
{
|
||||||
|
event_data := model.AuditEventDataError{
|
||||||
|
Error: params.ErrorMessage,
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: ValidtorUserID,
|
||||||
|
ResourceType: model.ResourceSubmission,
|
||||||
|
ResourceID: params.SubmissionID,
|
||||||
|
EventType: model.AuditEventTypeError,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// push an action audit event
|
||||||
|
event_data := model.AuditEventDataAction{
|
||||||
|
TargetStatus: uint32(target_status),
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: ValidtorUserID,
|
||||||
|
ResourceType: model.ResourceSubmission,
|
||||||
|
ResourceID: params.SubmissionID,
|
||||||
|
EventType: model.AuditEventTypeAction,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionSubmissionValidate invokes actionSubmissionValidate operation.
|
||||||
|
//
|
||||||
|
// Role Validator changes status from Validating -> Validated.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/status/validator-validated
|
||||||
|
func (svc *Service) ActionSubmissionValidated(ctx context.Context, params internal.ActionSubmissionValidatedParams) error {
|
||||||
|
// transaction
|
||||||
|
target_status := model.SubmissionStatusValidated
|
||||||
|
smap := datastore.Optional()
|
||||||
|
smap.Add("status_id", target_status)
|
||||||
|
err := svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.SubmissionStatus{model.SubmissionStatusValidating}, smap)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
event_data := model.AuditEventDataAction{
|
||||||
|
TargetStatus: uint32(target_status),
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: ValidtorUserID,
|
||||||
|
ResourceType: model.ResourceSubmission,
|
||||||
|
ResourceID: params.SubmissionID,
|
||||||
|
EventType: model.AuditEventTypeAction,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionSubmissionAccepted implements actionSubmissionAccepted operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Validating -> Accepted.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/status/validator-failed
|
||||||
|
func (svc *Service) ActionSubmissionAccepted(ctx context.Context, params internal.ActionSubmissionAcceptedParams) error {
|
||||||
|
// transaction
|
||||||
|
target_status := model.SubmissionStatusAcceptedUnvalidated
|
||||||
|
smap := datastore.Optional()
|
||||||
|
smap.Add("status_id", target_status)
|
||||||
|
err := svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.SubmissionStatus{model.SubmissionStatusValidating}, smap)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//push an error audit event
|
||||||
|
{
|
||||||
|
event_data := model.AuditEventDataError{
|
||||||
|
Error: params.ErrorMessage,
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: ValidtorUserID,
|
||||||
|
ResourceType: model.ResourceSubmission,
|
||||||
|
ResourceID: params.SubmissionID,
|
||||||
|
EventType: model.AuditEventTypeError,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// push an action audit event
|
||||||
|
event_data := model.AuditEventDataAction{
|
||||||
|
TargetStatus: uint32(target_status),
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: ValidtorUserID,
|
||||||
|
ResourceType: model.ResourceSubmission,
|
||||||
|
ResourceID: params.SubmissionID,
|
||||||
|
EventType: model.AuditEventTypeAction,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionSubmissionUploaded implements actionSubmissionUploaded operation.
|
||||||
|
//
|
||||||
|
// (Internal endpoint) Role Validator changes status from Uploading -> Uploaded.
|
||||||
|
//
|
||||||
|
// POST /submissions/{SubmissionID}/status/validator-uploaded
|
||||||
|
func (svc *Service) ActionSubmissionUploaded(ctx context.Context, params internal.ActionSubmissionUploadedParams) error {
|
||||||
|
// transaction
|
||||||
|
target_status := model.SubmissionStatusUploaded
|
||||||
|
smap := datastore.Optional()
|
||||||
|
smap.Add("status_id", target_status)
|
||||||
|
smap.Add("uploaded_asset_id", params.UploadedAssetID)
|
||||||
|
err := svc.DB.Submissions().IfStatusThenUpdate(ctx, params.SubmissionID, []model.SubmissionStatus{model.SubmissionStatusUploading}, smap)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
event_data := model.AuditEventDataAction{
|
||||||
|
TargetStatus: uint32(target_status),
|
||||||
|
}
|
||||||
|
|
||||||
|
EventData, err := json.Marshal(event_data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = svc.DB.AuditEvents().Create(ctx, model.AuditEvent{
|
||||||
|
ID: 0,
|
||||||
|
User: ValidtorUserID,
|
||||||
|
ResourceType: model.ResourceSubmission,
|
||||||
|
ResourceID: params.SubmissionID,
|
||||||
|
EventType: model.AuditEventTypeAction,
|
||||||
|
EventData: EventData,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST /submissions
|
||||||
|
func (svc *Service) CreateSubmission(ctx context.Context, request *internal.SubmissionCreate) (*internal.SubmissionID, error) {
|
||||||
|
// sanitization
|
||||||
|
if request.GameID<0||
|
||||||
|
request.AssetOwner<0||
|
||||||
|
request.AssetID<0||
|
||||||
|
request.AssetVersion<0{
|
||||||
|
return nil, ErrNegativeID
|
||||||
|
}
|
||||||
|
var GameID=uint32(request.GameID);
|
||||||
|
var Submitter=uint64(request.AssetOwner);
|
||||||
|
var AssetID=uint64(request.AssetID);
|
||||||
|
var AssetVersion=uint64(request.AssetVersion);
|
||||||
|
var Status=model.SubmissionStatus(request.Status);
|
||||||
|
var roles=service.Roles(request.Roles);
|
||||||
|
|
||||||
|
// Check if an active submission with the same asset id exists
|
||||||
|
{
|
||||||
|
filter := datastore.Optional()
|
||||||
|
filter.Add("asset_id", request.AssetID)
|
||||||
|
filter.Add("asset_version", request.AssetVersion)
|
||||||
|
filter.Add("status_id", ActiveSubmissionStatuses)
|
||||||
|
active_submissions, err := svc.DB.Submissions().List(ctx, filter, model.Page{
|
||||||
|
Number: 1,
|
||||||
|
Size: 1,
|
||||||
|
},datastore.ListSortDisabled)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(active_submissions) != 0{
|
||||||
|
return nil, ErrActiveSubmissionSameAssetID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
operation, err := svc.DB.Operations().Get(ctx, request.OperationID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if user owns asset
|
||||||
|
is_submitter := operation.Owner == Submitter
|
||||||
|
// check if user is map admin
|
||||||
|
has_submission_review := roles & service.RolesSubmissionReview == service.RolesSubmissionReview
|
||||||
|
// if neither, u not allowed
|
||||||
|
if !is_submitter && !has_submission_review {
|
||||||
|
return nil, ErrNotAssetOwner
|
||||||
|
}
|
||||||
|
|
||||||
|
submission, err := svc.DB.Submissions().Create(ctx, model.Submission{
|
||||||
|
ID: 0,
|
||||||
|
DisplayName: request.DisplayName,
|
||||||
|
Creator: request.Creator,
|
||||||
|
GameID: GameID,
|
||||||
|
Submitter: Submitter,
|
||||||
|
AssetID: AssetID,
|
||||||
|
AssetVersion: AssetVersion,
|
||||||
|
Completed: false,
|
||||||
|
StatusID: Status,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// mark the operation as completed and provide the path
|
||||||
|
pmap := datastore.Optional()
|
||||||
|
pmap.Add("status_id", model.OperationStatusCompleted)
|
||||||
|
pmap.Add("path", fmt.Sprintf("/submissions/%d", submission.ID))
|
||||||
|
err = svc.DB.Operations().Update(ctx, request.OperationID, pmap)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &internal.SubmissionID{
|
||||||
|
SubmissionID: submission.ID,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -1,380 +0,0 @@
|
|||||||
package validator_controller
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/go-grpc/validator"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/service"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Mapfixes struct {
|
|
||||||
*validator.UnimplementedValidatorMapfixServiceServer
|
|
||||||
inner *service.Service
|
|
||||||
}
|
|
||||||
func NewMapfixesController(
|
|
||||||
inner *service.Service,
|
|
||||||
) Mapfixes {
|
|
||||||
return Mapfixes{
|
|
||||||
inner: inner,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var(
|
|
||||||
// prevent two mapfixes with same asset id
|
|
||||||
ActiveMapfixStatuses = []model.MapfixStatus{
|
|
||||||
model.MapfixStatusUploading,
|
|
||||||
model.MapfixStatusValidated,
|
|
||||||
model.MapfixStatusValidating,
|
|
||||||
model.MapfixStatusAcceptedUnvalidated,
|
|
||||||
model.MapfixStatusChangesRequested,
|
|
||||||
model.MapfixStatusSubmitted,
|
|
||||||
model.MapfixStatusUnderConstruction,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
var(
|
|
||||||
ErrActiveMapfixSameAssetID = errors.New("There is an active mapfix with the same AssetID")
|
|
||||||
ErrNotAssetOwner = errors.New("You can only submit an asset you own")
|
|
||||||
)
|
|
||||||
|
|
||||||
// UpdateMapfixValidatedModel implements patchMapfixModel operation.
|
|
||||||
//
|
|
||||||
// Update model following role restrictions.
|
|
||||||
//
|
|
||||||
// POST /mapfixes/{MapfixID}/validated-model
|
|
||||||
func (svc *Mapfixes) SetValidatedModel(ctx context.Context, params *validator.ValidatedModelRequest) (*validator.NullResponse, error) {
|
|
||||||
MapfixID := int64(params.ID)
|
|
||||||
|
|
||||||
// check if Status is ChangesRequested|Submitted|UnderConstruction
|
|
||||||
update := service.NewMapfixUpdate()
|
|
||||||
update.SetValidatedAssetID(params.ValidatedModelID)
|
|
||||||
update.SetValidatedAssetVersion(params.ValidatedModelVersion)
|
|
||||||
// DO NOT reset completed when validated model is updated
|
|
||||||
// update.Add("completed", false)
|
|
||||||
allow_statuses := []model.MapfixStatus{model.MapfixStatusValidating}
|
|
||||||
err := svc.inner.UpdateMapfixIfStatus(ctx, MapfixID, allow_statuses, update)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
event_data := model.AuditEventDataChangeValidatedModel{
|
|
||||||
ValidatedModelID: params.ValidatedModelID,
|
|
||||||
ValidatedModelVersion: params.ValidatedModelVersion,
|
|
||||||
}
|
|
||||||
|
|
||||||
err = svc.inner.CreateAuditEventChangeValidatedModel(
|
|
||||||
ctx,
|
|
||||||
model.ValidatorUserID,
|
|
||||||
model.Resource{
|
|
||||||
ID: MapfixID,
|
|
||||||
Type: model.ResourceMapfix,
|
|
||||||
},
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionMapfixSubmitted invokes actionMapfixSubmitted operation.
|
|
||||||
//
|
|
||||||
// Role Validator changes status from Submitting -> Submitted.
|
|
||||||
//
|
|
||||||
// POST /mapfixes/{MapfixID}/status/validator-submitted
|
|
||||||
func (svc *Mapfixes) SetStatusSubmitted(ctx context.Context, params *validator.SubmittedRequest) (*validator.NullResponse, error) {
|
|
||||||
MapfixID := int64(params.ID)
|
|
||||||
// transaction
|
|
||||||
target_status := model.MapfixStatusSubmitted
|
|
||||||
update := service.NewMapfixUpdate()
|
|
||||||
update.SetStatusID(target_status)
|
|
||||||
update.SetAssetVersion(uint64(params.ModelVersion))
|
|
||||||
update.SetDisplayName(params.DisplayName)
|
|
||||||
update.SetCreator(params.Creator)
|
|
||||||
update.SetGameID(uint32(params.GameID))
|
|
||||||
allow_statuses := []model.MapfixStatus{model.MapfixStatusSubmitting}
|
|
||||||
err := svc.inner.UpdateMapfixIfStatus(ctx, MapfixID, allow_statuses, update)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
event_data := model.AuditEventDataAction{
|
|
||||||
TargetStatus: uint32(target_status),
|
|
||||||
}
|
|
||||||
|
|
||||||
err = svc.inner.CreateAuditEventAction(
|
|
||||||
ctx,
|
|
||||||
model.ValidatorUserID,
|
|
||||||
model.Resource{
|
|
||||||
ID: MapfixID,
|
|
||||||
Type: model.ResourceMapfix,
|
|
||||||
},
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionMapfixRequestChanges implements actionMapfixRequestChanges operation.
|
|
||||||
//
|
|
||||||
// (Internal endpoint) Role Validator changes status from Submitting -> RequestChanges.
|
|
||||||
//
|
|
||||||
// POST /mapfixes/{MapfixID}/status/validator-request-changes
|
|
||||||
func (svc *Mapfixes) SetStatusRequestChanges(ctx context.Context, params *validator.MapfixID) (*validator.NullResponse, error) {
|
|
||||||
MapfixID := int64(params.ID)
|
|
||||||
// transaction
|
|
||||||
target_status := model.MapfixStatusChangesRequested
|
|
||||||
update := service.NewMapfixUpdate()
|
|
||||||
update.SetStatusID(target_status)
|
|
||||||
allow_statuses := []model.MapfixStatus{model.MapfixStatusSubmitting}
|
|
||||||
err := svc.inner.UpdateMapfixIfStatus(ctx, MapfixID, allow_statuses, update)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
event_data := model.AuditEventDataAction{
|
|
||||||
TargetStatus: uint32(target_status),
|
|
||||||
}
|
|
||||||
|
|
||||||
err = svc.inner.CreateAuditEventAction(
|
|
||||||
ctx,
|
|
||||||
model.ValidatorUserID,
|
|
||||||
model.Resource{
|
|
||||||
ID: MapfixID,
|
|
||||||
Type: model.ResourceMapfix,
|
|
||||||
},
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionMapfixValidate invokes actionMapfixValidate operation.
|
|
||||||
//
|
|
||||||
// Role Validator changes status from Validating -> Validated.
|
|
||||||
//
|
|
||||||
// POST /mapfixes/{MapfixID}/status/validator-validated
|
|
||||||
func (svc *Mapfixes) SetStatusValidated(ctx context.Context, params *validator.MapfixID) (*validator.NullResponse, error) {
|
|
||||||
MapfixID := int64(params.ID)
|
|
||||||
// transaction
|
|
||||||
update := service.NewMapfixUpdate()
|
|
||||||
update.SetStatusID(model.MapfixStatusValidated)
|
|
||||||
allow_statuses := []model.MapfixStatus{model.MapfixStatusValidating}
|
|
||||||
err := svc.inner.UpdateMapfixIfStatus(ctx, MapfixID, allow_statuses, update)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionMapfixAccepted implements actionMapfixAccepted operation.
|
|
||||||
//
|
|
||||||
// (Internal endpoint) Role Validator changes status from Validating -> Accepted.
|
|
||||||
//
|
|
||||||
// POST /mapfixes/{MapfixID}/status/validator-failed
|
|
||||||
func (svc *Mapfixes) SetStatusFailed(ctx context.Context, params *validator.MapfixID) (*validator.NullResponse, error) {
|
|
||||||
MapfixID := int64(params.ID)
|
|
||||||
// transaction
|
|
||||||
target_status := model.MapfixStatusAcceptedUnvalidated
|
|
||||||
update := service.NewMapfixUpdate()
|
|
||||||
update.SetStatusID(target_status)
|
|
||||||
allow_statuses := []model.MapfixStatus{model.MapfixStatusValidating}
|
|
||||||
err := svc.inner.UpdateMapfixIfStatus(ctx, MapfixID, allow_statuses, update)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// push an action audit event
|
|
||||||
event_data := model.AuditEventDataAction{
|
|
||||||
TargetStatus: uint32(target_status),
|
|
||||||
}
|
|
||||||
|
|
||||||
err = svc.inner.CreateAuditEventAction(
|
|
||||||
ctx,
|
|
||||||
model.ValidatorUserID,
|
|
||||||
model.Resource{
|
|
||||||
ID: MapfixID,
|
|
||||||
Type: model.ResourceMapfix,
|
|
||||||
},
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionMapfixUploaded implements actionMapfixUploaded operation.
|
|
||||||
//
|
|
||||||
// (Internal endpoint) Role Validator changes status from Uploading -> Uploaded.
|
|
||||||
//
|
|
||||||
// POST /mapfixes/{MapfixID}/status/validator-uploaded
|
|
||||||
func (svc *Mapfixes) SetStatusUploaded(ctx context.Context, params *validator.MapfixID) (*validator.NullResponse, error) {
|
|
||||||
MapfixID := int64(params.ID)
|
|
||||||
// transaction
|
|
||||||
target_status := model.MapfixStatusUploaded
|
|
||||||
update := service.NewMapfixUpdate()
|
|
||||||
update.SetStatusID(target_status)
|
|
||||||
allow_statuses := []model.MapfixStatus{model.MapfixStatusUploading}
|
|
||||||
err := svc.inner.UpdateMapfixIfStatus(ctx, MapfixID, allow_statuses, update)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
event_data := model.AuditEventDataAction{
|
|
||||||
TargetStatus: uint32(target_status),
|
|
||||||
}
|
|
||||||
|
|
||||||
err = svc.inner.CreateAuditEventAction(
|
|
||||||
ctx,
|
|
||||||
model.ValidatorUserID,
|
|
||||||
model.Resource{
|
|
||||||
ID: MapfixID,
|
|
||||||
Type: model.ResourceMapfix,
|
|
||||||
},
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateMapfixAuditError implements createMapfixAuditError operation.
|
|
||||||
//
|
|
||||||
// Post an error to the audit log
|
|
||||||
//
|
|
||||||
// POST /mapfixes/{MapfixID}/error
|
|
||||||
func (svc *Mapfixes) CreateAuditError(ctx context.Context, params *validator.AuditErrorRequest) (*validator.NullResponse, error) {
|
|
||||||
MapfixID := int64(params.ID)
|
|
||||||
event_data := model.AuditEventDataError{
|
|
||||||
Error: params.ErrorMessage,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := svc.inner.CreateAuditEventError(
|
|
||||||
ctx,
|
|
||||||
model.ValidatorUserID,
|
|
||||||
model.Resource{
|
|
||||||
ID: MapfixID,
|
|
||||||
Type: model.ResourceMapfix,
|
|
||||||
},
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateMapfixAuditCheckList implements createMapfixAuditCheckList operation.
|
|
||||||
//
|
|
||||||
// Post a checklist to the audit log
|
|
||||||
//
|
|
||||||
// POST /mapfixes/{MapfixID}/checklist
|
|
||||||
func (svc *Mapfixes) CreateAuditChecklist(ctx context.Context, params *validator.AuditChecklistRequest) (*validator.NullResponse, error) {
|
|
||||||
MapfixID := int64(params.ID)
|
|
||||||
check_list := make([]model.Check, len(params.CheckList))
|
|
||||||
for i, check := range params.CheckList {
|
|
||||||
check_list[i] = model.Check{
|
|
||||||
Name: check.Name,
|
|
||||||
Summary: check.Summary,
|
|
||||||
Passed: check.Passed,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
event_data := model.AuditEventDataCheckList{
|
|
||||||
CheckList: check_list,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := svc.inner.CreateAuditEventCheckList(
|
|
||||||
ctx,
|
|
||||||
model.ValidatorUserID,
|
|
||||||
model.Resource{
|
|
||||||
ID: MapfixID,
|
|
||||||
Type: model.ResourceMapfix,
|
|
||||||
},
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST /mapfixes
|
|
||||||
func (svc *Mapfixes) Create(ctx context.Context, request *validator.MapfixCreate) (*validator.MapfixID, error) {
|
|
||||||
var Submitter=request.AssetOwner;
|
|
||||||
// Check if an active mapfix with the same asset id exists
|
|
||||||
{
|
|
||||||
filter := service.NewMapfixFilter()
|
|
||||||
filter.SetAssetID(request.AssetID)
|
|
||||||
filter.SetAssetVersion(request.AssetVersion)
|
|
||||||
filter.SetStatuses(ActiveMapfixStatuses)
|
|
||||||
active_mapfixes, err := svc.inner.ListMapfixes(ctx, filter, model.Page{
|
|
||||||
Number: 1,
|
|
||||||
Size: 1,
|
|
||||||
},datastore.ListSortDisabled)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(active_mapfixes) != 0{
|
|
||||||
return nil, ErrActiveMapfixSameAssetID
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
OperationID := int32(request.OperationID)
|
|
||||||
operation, err := svc.inner.GetOperation(ctx, OperationID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if user owns asset
|
|
||||||
// TODO: allow bypass by admin
|
|
||||||
if operation.Owner != Submitter {
|
|
||||||
return nil, ErrNotAssetOwner
|
|
||||||
}
|
|
||||||
|
|
||||||
mapfix, err := svc.inner.CreateMapfix(ctx, model.Mapfix{
|
|
||||||
ID: 0,
|
|
||||||
DisplayName: request.DisplayName,
|
|
||||||
Creator: request.Creator,
|
|
||||||
GameID: request.GameID,
|
|
||||||
Submitter: Submitter,
|
|
||||||
AssetID: request.AssetID,
|
|
||||||
AssetVersion: request.AssetVersion,
|
|
||||||
Completed: false,
|
|
||||||
TargetAssetID: request.TargetAssetID,
|
|
||||||
StatusID: model.MapfixStatusUnderConstruction,
|
|
||||||
Description: request.Description,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// mark the operation as completed and provide the path
|
|
||||||
params := service.NewOperationCompleteParams(fmt.Sprintf("/mapfixes/%d", mapfix.ID))
|
|
||||||
err = svc.inner.CompleteOperation(ctx, OperationID, params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.MapfixID{
|
|
||||||
ID: uint64(mapfix.ID),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package validator_controller
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/go-grpc/validator"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/service"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Operations struct {
|
|
||||||
*validator.UnimplementedValidatorOperationServiceServer
|
|
||||||
inner *service.Service
|
|
||||||
}
|
|
||||||
func NewOperationsController(
|
|
||||||
inner *service.Service,
|
|
||||||
) Operations {
|
|
||||||
return Operations{
|
|
||||||
inner: inner,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionOperationFailed implements actionOperationFailed operation.
|
|
||||||
//
|
|
||||||
// Fail the specified OperationID with a StatusMessage.
|
|
||||||
//
|
|
||||||
// POST /operations/{OperationID}/status/operation-failed
|
|
||||||
func (svc *Operations) Fail(ctx context.Context, params *validator.OperationFailRequest) (*validator.NullResponse, error) {
|
|
||||||
fail_params := service.NewOperationFailParams(
|
|
||||||
params.StatusMessage,
|
|
||||||
)
|
|
||||||
err := svc.inner.FailOperation(ctx, int32(params.OperationID), fail_params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
package validator_controller
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/go-grpc/validator"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/service"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ScriptPolicy struct {
|
|
||||||
*validator.UnimplementedValidatorScriptPolicyServiceServer
|
|
||||||
inner *service.Service
|
|
||||||
}
|
|
||||||
func NewScriptPolicyController(
|
|
||||||
inner *service.Service,
|
|
||||||
) ScriptPolicy {
|
|
||||||
return ScriptPolicy{
|
|
||||||
inner: inner,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateScriptPolicy implements createScriptPolicy operation.
|
|
||||||
//
|
|
||||||
// Create a new script policy.
|
|
||||||
//
|
|
||||||
// POST /script-policy
|
|
||||||
func (svc *ScriptPolicy) Create(ctx context.Context, req *validator.ScriptPolicyCreate) (*validator.ScriptPolicyID, error) {
|
|
||||||
from_script, err := svc.inner.GetScript(ctx, int64(req.FromScriptID))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// the existence of ToScriptID does not need to be validated because it's checked by a foreign key constraint.
|
|
||||||
|
|
||||||
script, err := svc.inner.CreateScriptPolicy(ctx, model.ScriptPolicy{
|
|
||||||
ID: 0,
|
|
||||||
FromScriptHash: from_script.Hash,
|
|
||||||
ToScriptID: int64(req.ToScriptID),
|
|
||||||
Policy: model.Policy(req.Policy),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.ScriptPolicyID{
|
|
||||||
ID: uint64(script.ID),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListScriptPolicy implements listScriptPolicy operation.
|
|
||||||
//
|
|
||||||
// Get list of script policies.
|
|
||||||
//
|
|
||||||
// GET /script-policy
|
|
||||||
func (svc *ScriptPolicy) List(ctx context.Context, params *validator.ScriptPolicyListRequest) (*validator.ScriptPolicyListResponse, error) {
|
|
||||||
filter := service.NewScriptPolicyFilter()
|
|
||||||
|
|
||||||
if params.Filter.FromScriptHash != nil {
|
|
||||||
filter.SetFromScriptHash(int64(*params.Filter.FromScriptHash))
|
|
||||||
}
|
|
||||||
if params.Filter.ToScriptID != nil {
|
|
||||||
filter.SetToScriptID(int64(*params.Filter.ToScriptID))
|
|
||||||
}
|
|
||||||
if params.Filter.Policy != nil {
|
|
||||||
filter.SetPolicy(int32(*params.Filter.Policy))
|
|
||||||
}
|
|
||||||
|
|
||||||
items, err := svc.inner.ListScriptPolicies(ctx, filter, model.Page{
|
|
||||||
Number: int32(params.Page.Number),
|
|
||||||
Size: int32(params.Page.Size),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := validator.ScriptPolicyListResponse{}
|
|
||||||
resp.ScriptPolicies = make([]*validator.ScriptPolicy, len(items))
|
|
||||||
for i, item := range items {
|
|
||||||
resp.ScriptPolicies[i] = &validator.ScriptPolicy{
|
|
||||||
ID: uint64(item.ID),
|
|
||||||
FromScriptHash: uint64(item.FromScriptHash),
|
|
||||||
ToScriptID: uint64(item.ToScriptID),
|
|
||||||
Policy: validator.Policy(int32(item.Policy)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return &resp, nil
|
|
||||||
}
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
package validator_controller
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/go-grpc/validator"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/service"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Scripts struct {
|
|
||||||
*validator.UnimplementedValidatorScriptServiceServer
|
|
||||||
inner *service.Service
|
|
||||||
}
|
|
||||||
func NewScriptsController(
|
|
||||||
inner *service.Service,
|
|
||||||
) Scripts {
|
|
||||||
return Scripts{
|
|
||||||
inner: inner,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateScript implements createScript operation.
|
|
||||||
//
|
|
||||||
// Create a new script.
|
|
||||||
//
|
|
||||||
// POST /scripts
|
|
||||||
func (svc *Scripts) Create(ctx context.Context, req *validator.ScriptCreate) (*validator.ScriptID, error) {
|
|
||||||
ResourceID := int64(0)
|
|
||||||
if req.ResourceID != nil {
|
|
||||||
ResourceID = int64(*req.ResourceID)
|
|
||||||
}
|
|
||||||
script, err := svc.inner.CreateScript(ctx, model.Script{
|
|
||||||
ID: 0,
|
|
||||||
Name: req.Name,
|
|
||||||
Hash: int64(model.HashSource(req.Source)),
|
|
||||||
Source: req.Source,
|
|
||||||
ResourceType: model.ResourceType(req.ResourceType),
|
|
||||||
ResourceID: ResourceID,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.ScriptID{
|
|
||||||
ID: uint64(script.ID),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListScripts implements listScripts operation.
|
|
||||||
//
|
|
||||||
// Get list of scripts.
|
|
||||||
//
|
|
||||||
// GET /scripts
|
|
||||||
func (svc *Scripts) List(ctx context.Context, params *validator.ScriptListRequest) (*validator.ScriptListResponse, error) {
|
|
||||||
filter := service.NewScriptFilter()
|
|
||||||
if params.Filter.Hash != nil {
|
|
||||||
filter.SetHash(int64(*params.Filter.Hash))
|
|
||||||
}
|
|
||||||
if params.Filter.Name != nil {
|
|
||||||
filter.SetName(*params.Filter.Name)
|
|
||||||
}
|
|
||||||
if params.Filter.Source != nil {
|
|
||||||
filter.SetSource(*params.Filter.Source)
|
|
||||||
}
|
|
||||||
if params.Filter.ResourceType != nil {
|
|
||||||
filter.SetResourceType(int32(*params.Filter.ResourceType))
|
|
||||||
}
|
|
||||||
if params.Filter.ResourceID != nil {
|
|
||||||
filter.SetResourceID(int64(*params.Filter.ResourceID))
|
|
||||||
}
|
|
||||||
|
|
||||||
items, err := svc.inner.ListScripts(ctx, filter, model.Page{
|
|
||||||
Number: int32(params.Page.Number),
|
|
||||||
Size: int32(params.Page.Size),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := validator.ScriptListResponse{}
|
|
||||||
resp.Scripts = make([]*validator.Script, len(items))
|
|
||||||
for i, item := range items {
|
|
||||||
resource_id := uint64(item.ResourceID)
|
|
||||||
resp.Scripts[i] = &validator.Script{
|
|
||||||
ID: uint64(item.ID),
|
|
||||||
Name: item.Name,
|
|
||||||
Hash: uint64(item.Hash),
|
|
||||||
Source: item.Source,
|
|
||||||
ResourceType: validator.ResourceType(item.ResourceType),
|
|
||||||
ResourceID: &resource_id,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return &resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetScript implements getScript operation.
|
|
||||||
//
|
|
||||||
// Get the specified script by ID.
|
|
||||||
//
|
|
||||||
// GET /scripts/{ScriptID}
|
|
||||||
func (svc *Scripts) Get(ctx context.Context, params *validator.ScriptID) (*validator.Script, error) {
|
|
||||||
ScriptID := int64(params.ID)
|
|
||||||
script, err := svc.inner.GetScript(ctx, ScriptID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
ResourceID := uint64(script.ResourceID)
|
|
||||||
return &validator.Script{
|
|
||||||
ID: uint64(script.ID),
|
|
||||||
Name: script.Name,
|
|
||||||
Hash: uint64(script.Hash),
|
|
||||||
Source: script.Source,
|
|
||||||
ResourceType: validator.ResourceType(script.ResourceType),
|
|
||||||
ResourceID: &ResourceID,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
@@ -1,403 +0,0 @@
|
|||||||
package validator_controller
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/go-grpc/validator"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/service"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Submissions struct {
|
|
||||||
*validator.UnimplementedValidatorSubmissionServiceServer
|
|
||||||
inner *service.Service
|
|
||||||
}
|
|
||||||
func NewSubmissionsController(
|
|
||||||
inner *service.Service,
|
|
||||||
) Submissions {
|
|
||||||
return Submissions{
|
|
||||||
inner: inner,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var(
|
|
||||||
// prevent two mapfixes with same asset id
|
|
||||||
ActiveSubmissionStatuses = []model.SubmissionStatus{
|
|
||||||
model.SubmissionStatusUploading,
|
|
||||||
model.SubmissionStatusValidated,
|
|
||||||
model.SubmissionStatusValidating,
|
|
||||||
model.SubmissionStatusAcceptedUnvalidated,
|
|
||||||
model.SubmissionStatusChangesRequested,
|
|
||||||
model.SubmissionStatusSubmitted,
|
|
||||||
model.SubmissionStatusUnderConstruction,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
var(
|
|
||||||
ErrActiveSubmissionSameAssetID = errors.New("There is an active submission with the same AssetID")
|
|
||||||
)
|
|
||||||
|
|
||||||
// UpdateSubmissionValidatedModel implements patchSubmissionModel operation.
|
|
||||||
//
|
|
||||||
// Update model following role restrictions.
|
|
||||||
//
|
|
||||||
// POST /submissions/{SubmissionID}/validated-model
|
|
||||||
func (svc *Submissions) SetValidatedModel(ctx context.Context, params *validator.ValidatedModelRequest) (*validator.NullResponse, error) {
|
|
||||||
SubmissionID := int64(params.ID)
|
|
||||||
|
|
||||||
// check if Status is ChangesRequested|Submitted|UnderConstruction
|
|
||||||
update := service.NewSubmissionUpdate()
|
|
||||||
update.SetValidatedAssetID(params.ValidatedModelID)
|
|
||||||
update.SetValidatedAssetVersion(params.ValidatedModelVersion)
|
|
||||||
// DO NOT reset completed when validated model is updated
|
|
||||||
// update.Add("completed", false)
|
|
||||||
allowed_statuses := []model.SubmissionStatus{model.SubmissionStatusValidating}
|
|
||||||
err := svc.inner.UpdateSubmissionIfStatus(ctx, SubmissionID, allowed_statuses, update)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
event_data := model.AuditEventDataChangeValidatedModel{
|
|
||||||
ValidatedModelID: params.ValidatedModelID,
|
|
||||||
ValidatedModelVersion: params.ValidatedModelVersion,
|
|
||||||
}
|
|
||||||
|
|
||||||
err = svc.inner.CreateAuditEventChangeValidatedModel(
|
|
||||||
ctx,
|
|
||||||
model.ValidatorUserID,
|
|
||||||
model.Resource{
|
|
||||||
ID: SubmissionID,
|
|
||||||
Type: model.ResourceSubmission,
|
|
||||||
},
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionSubmissionSubmitted invokes actionSubmissionSubmitted operation.
|
|
||||||
//
|
|
||||||
// Role Validator changes status from Submitting -> Submitted.
|
|
||||||
//
|
|
||||||
// POST /submissions/{SubmissionID}/status/validator-submitted
|
|
||||||
func (svc *Submissions) SetStatusSubmitted(ctx context.Context, params *validator.SubmittedRequest) (*validator.NullResponse, error) {
|
|
||||||
SubmissionID := int64(params.ID)
|
|
||||||
// transaction
|
|
||||||
target_status := model.SubmissionStatusSubmitted
|
|
||||||
update := service.NewSubmissionUpdate()
|
|
||||||
update.SetStatusID(target_status)
|
|
||||||
update.SetAssetVersion(uint64(params.ModelVersion))
|
|
||||||
update.SetDisplayName(params.DisplayName)
|
|
||||||
update.SetCreator(params.Creator)
|
|
||||||
update.SetGameID(uint32(params.GameID))
|
|
||||||
allowed_statuses := []model.SubmissionStatus{model.SubmissionStatusSubmitting}
|
|
||||||
err := svc.inner.UpdateSubmissionIfStatus(ctx, SubmissionID, allowed_statuses, update)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
event_data := model.AuditEventDataAction{
|
|
||||||
TargetStatus: uint32(target_status),
|
|
||||||
}
|
|
||||||
|
|
||||||
err = svc.inner.CreateAuditEventAction(
|
|
||||||
ctx,
|
|
||||||
model.ValidatorUserID,
|
|
||||||
model.Resource{
|
|
||||||
ID: SubmissionID,
|
|
||||||
Type: model.ResourceSubmission,
|
|
||||||
},
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionSubmissionRequestChanges implements actionSubmissionRequestChanges operation.
|
|
||||||
//
|
|
||||||
// (Internal endpoint) Role Validator changes status from Submitting -> RequestChanges.
|
|
||||||
//
|
|
||||||
// POST /submissions/{SubmissionID}/status/validator-request-changes
|
|
||||||
func (svc *Submissions) SetStatusRequestChanges(ctx context.Context, params *validator.SubmissionID) (*validator.NullResponse, error) {
|
|
||||||
SubmissionID := int64(params.ID)
|
|
||||||
// transaction
|
|
||||||
target_status := model.SubmissionStatusChangesRequested
|
|
||||||
update := service.NewSubmissionUpdate()
|
|
||||||
update.SetStatusID(target_status)
|
|
||||||
allowed_statuses :=[]model.SubmissionStatus{model.SubmissionStatusSubmitting}
|
|
||||||
err := svc.inner.UpdateSubmissionIfStatus(ctx, SubmissionID, allowed_statuses, update)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// push an action audit event
|
|
||||||
event_data := model.AuditEventDataAction{
|
|
||||||
TargetStatus: uint32(target_status),
|
|
||||||
}
|
|
||||||
|
|
||||||
err = svc.inner.CreateAuditEventAction(
|
|
||||||
ctx,
|
|
||||||
model.ValidatorUserID,
|
|
||||||
model.Resource{
|
|
||||||
ID: SubmissionID,
|
|
||||||
Type: model.ResourceSubmission,
|
|
||||||
},
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionSubmissionValidate invokes actionSubmissionValidate operation.
|
|
||||||
//
|
|
||||||
// Role Validator changes status from Validating -> Validated.
|
|
||||||
//
|
|
||||||
// POST /submissions/{SubmissionID}/status/validator-validated
|
|
||||||
func (svc *Submissions) SetStatusValidated(ctx context.Context, params *validator.SubmissionID) (*validator.NullResponse, error) {
|
|
||||||
SubmissionID := int64(params.ID)
|
|
||||||
// transaction
|
|
||||||
target_status := model.SubmissionStatusValidated
|
|
||||||
update := service.NewSubmissionUpdate()
|
|
||||||
update.SetStatusID(target_status)
|
|
||||||
allowed_statuses :=[]model.SubmissionStatus{model.SubmissionStatusValidating}
|
|
||||||
err := svc.inner.UpdateSubmissionIfStatus(ctx, SubmissionID, allowed_statuses, update)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
event_data := model.AuditEventDataAction{
|
|
||||||
TargetStatus: uint32(target_status),
|
|
||||||
}
|
|
||||||
|
|
||||||
err = svc.inner.CreateAuditEventAction(
|
|
||||||
ctx,
|
|
||||||
model.ValidatorUserID,
|
|
||||||
model.Resource{
|
|
||||||
ID: SubmissionID,
|
|
||||||
Type: model.ResourceSubmission,
|
|
||||||
},
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionSubmissionAccepted implements actionSubmissionAccepted operation.
|
|
||||||
//
|
|
||||||
// (Internal endpoint) Role Validator changes status from Validating -> Accepted.
|
|
||||||
//
|
|
||||||
// POST /submissions/{SubmissionID}/status/validator-failed
|
|
||||||
func (svc *Submissions) SetStatusFailed(ctx context.Context, params *validator.SubmissionID) (*validator.NullResponse, error) {
|
|
||||||
SubmissionID := int64(params.ID)
|
|
||||||
// transaction
|
|
||||||
target_status := model.SubmissionStatusAcceptedUnvalidated
|
|
||||||
update := service.NewSubmissionUpdate()
|
|
||||||
update.SetStatusID(target_status)
|
|
||||||
allowed_statuses :=[]model.SubmissionStatus{model.SubmissionStatusValidating}
|
|
||||||
err := svc.inner.UpdateSubmissionIfStatus(ctx, SubmissionID, allowed_statuses, update)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// push an action audit event
|
|
||||||
event_data := model.AuditEventDataAction{
|
|
||||||
TargetStatus: uint32(target_status),
|
|
||||||
}
|
|
||||||
|
|
||||||
err = svc.inner.CreateAuditEventAction(
|
|
||||||
ctx,
|
|
||||||
model.ValidatorUserID,
|
|
||||||
model.Resource{
|
|
||||||
ID: SubmissionID,
|
|
||||||
Type: model.ResourceSubmission,
|
|
||||||
},
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ActionSubmissionUploaded implements actionSubmissionUploaded operation.
|
|
||||||
//
|
|
||||||
// (Internal endpoint) Role Validator changes status from Uploading -> Uploaded.
|
|
||||||
//
|
|
||||||
// POST /submissions/{SubmissionID}/status/validator-uploaded
|
|
||||||
func (svc *Submissions) SetStatusUploaded(ctx context.Context, params *validator.StatusUploadedRequest) (*validator.NullResponse, error) {
|
|
||||||
SubmissionID := int64(params.ID)
|
|
||||||
// transaction
|
|
||||||
target_status := model.SubmissionStatusUploaded
|
|
||||||
update := service.NewSubmissionUpdate()
|
|
||||||
update.SetStatusID(target_status)
|
|
||||||
update.SetUploadedAssetID(params.UploadedAssetID)
|
|
||||||
allowed_statuses :=[]model.SubmissionStatus{model.SubmissionStatusUploading}
|
|
||||||
err := svc.inner.UpdateSubmissionIfStatus(ctx, SubmissionID, allowed_statuses, update)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
event_data := model.AuditEventDataAction{
|
|
||||||
TargetStatus: uint32(target_status),
|
|
||||||
}
|
|
||||||
|
|
||||||
err = svc.inner.CreateAuditEventAction(
|
|
||||||
ctx,
|
|
||||||
model.ValidatorUserID,
|
|
||||||
model.Resource{
|
|
||||||
ID: SubmissionID,
|
|
||||||
Type: model.ResourceSubmission,
|
|
||||||
},
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateSubmissionAuditError implements createSubmissionAuditError operation.
|
|
||||||
//
|
|
||||||
// Post an error to the audit log
|
|
||||||
//
|
|
||||||
// POST /submissions/{SubmissionID}/error
|
|
||||||
func (svc *Submissions) CreateAuditError(ctx context.Context, params *validator.AuditErrorRequest) (*validator.NullResponse, error) {
|
|
||||||
SubmissionID := int64(params.ID)
|
|
||||||
event_data := model.AuditEventDataError{
|
|
||||||
Error: params.ErrorMessage,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := svc.inner.CreateAuditEventError(
|
|
||||||
ctx,
|
|
||||||
model.ValidatorUserID,
|
|
||||||
model.Resource{
|
|
||||||
ID: SubmissionID,
|
|
||||||
Type: model.ResourceSubmission,
|
|
||||||
},
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateSubmissionAuditCheckList implements createSubmissionAuditCheckList operation.
|
|
||||||
//
|
|
||||||
// Post a checklist to the audit log
|
|
||||||
//
|
|
||||||
// POST /submissions/{SubmissionID}/checklist
|
|
||||||
func (svc *Submissions) CreateAuditChecklist(ctx context.Context, params *validator.AuditChecklistRequest) (*validator.NullResponse, error) {
|
|
||||||
SubmissionID := int64(params.ID)
|
|
||||||
check_list := make([]model.Check, len(params.CheckList))
|
|
||||||
for i, check := range params.CheckList {
|
|
||||||
check_list[i] = model.Check{
|
|
||||||
Name: check.Name,
|
|
||||||
Summary: check.Summary,
|
|
||||||
Passed: check.Passed,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
event_data := model.AuditEventDataCheckList{
|
|
||||||
CheckList: check_list,
|
|
||||||
}
|
|
||||||
|
|
||||||
err := svc.inner.CreateAuditEventCheckList(
|
|
||||||
ctx,
|
|
||||||
model.ValidatorUserID,
|
|
||||||
model.Resource{
|
|
||||||
ID: SubmissionID,
|
|
||||||
Type: model.ResourceSubmission,
|
|
||||||
},
|
|
||||||
event_data,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.NullResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST /submissions
|
|
||||||
func (svc *Submissions) Create(ctx context.Context, request *validator.SubmissionCreate) (*validator.SubmissionID, error) {
|
|
||||||
var Submitter=uint64(request.AssetOwner);
|
|
||||||
var Status=model.SubmissionStatus(request.Status);
|
|
||||||
var roles=model.Roles(request.Roles);
|
|
||||||
|
|
||||||
// Check if an active submission with the same asset id exists
|
|
||||||
{
|
|
||||||
filter := service.NewSubmissionFilter()
|
|
||||||
filter.SetAssetID(request.AssetID)
|
|
||||||
filter.SetAssetVersion(request.AssetVersion)
|
|
||||||
filter.SetStatuses(ActiveSubmissionStatuses)
|
|
||||||
active_submissions, err := svc.inner.ListSubmissions(ctx, filter, model.Page{
|
|
||||||
Number: 1,
|
|
||||||
Size: 1,
|
|
||||||
},datastore.ListSortDisabled)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(active_submissions) != 0{
|
|
||||||
return nil, ErrActiveSubmissionSameAssetID
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
operation_id := int32(request.OperationID)
|
|
||||||
operation, err := svc.inner.GetOperation(ctx, operation_id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if user owns asset
|
|
||||||
is_submitter := operation.Owner == Submitter
|
|
||||||
// check if user is map admin
|
|
||||||
has_submission_review := roles & model.RolesSubmissionReview == model.RolesSubmissionReview
|
|
||||||
// if neither, u not allowed
|
|
||||||
if !is_submitter && !has_submission_review {
|
|
||||||
return nil, ErrNotAssetOwner
|
|
||||||
}
|
|
||||||
|
|
||||||
submission, err := svc.inner.CreateSubmission(ctx, model.Submission{
|
|
||||||
ID: 0,
|
|
||||||
DisplayName: request.DisplayName,
|
|
||||||
Creator: request.Creator,
|
|
||||||
GameID: request.GameID,
|
|
||||||
Submitter: Submitter,
|
|
||||||
AssetID: request.AssetID,
|
|
||||||
AssetVersion: request.AssetVersion,
|
|
||||||
Completed: false,
|
|
||||||
StatusID: Status,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// mark the operation as completed and provide the path
|
|
||||||
params := service.NewOperationCompleteParams(fmt.Sprintf("/submissions/%d", submission.ID))
|
|
||||||
err = svc.inner.CompleteOperation(ctx, operation_id, params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &validator.SubmissionID{
|
|
||||||
ID: uint64(submission.ID),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,140 +0,0 @@
|
|||||||
package web_api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/roblox"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/service"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MigrateMaps implements migrateMaps operation.
|
|
||||||
//
|
|
||||||
// Perform maps migration.
|
|
||||||
//
|
|
||||||
// POST /migrate
|
|
||||||
func (svc *Service) MigrateMaps(ctx context.Context) (error) {
|
|
||||||
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
|
|
||||||
if !ok {
|
|
||||||
return ErrUserInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
has_role, err := userInfo.HasRoleSubmissionRelease()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !has_role {
|
|
||||||
return ErrPermissionDeniedNeedRoleSubmissionRelease
|
|
||||||
}
|
|
||||||
|
|
||||||
return svc.inner.TEMP_DoMapsMigration(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListMaps implements listMaps operation.
|
|
||||||
//
|
|
||||||
// Get list of maps.
|
|
||||||
//
|
|
||||||
// GET /maps
|
|
||||||
func (svc *Service) ListMaps(ctx context.Context, params api.ListMapsParams) ([]api.Map, error) {
|
|
||||||
filter := service.NewMapFilter()
|
|
||||||
|
|
||||||
if display_name, display_name_ok := params.DisplayName.Get(); display_name_ok{
|
|
||||||
filter.SetDisplayName(display_name)
|
|
||||||
}
|
|
||||||
if creator, creator_ok := params.Creator.Get(); creator_ok{
|
|
||||||
filter.SetCreator(creator)
|
|
||||||
}
|
|
||||||
if game_id, game_id_ok := params.GameID.Get(); game_id_ok{
|
|
||||||
filter.SetGameID(uint32(game_id))
|
|
||||||
}
|
|
||||||
|
|
||||||
items, err := svc.inner.ListMaps(ctx,
|
|
||||||
filter,
|
|
||||||
model.Page{
|
|
||||||
Size: params.Limit,
|
|
||||||
Number: params.Page,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp []api.Map
|
|
||||||
for _, item := range items {
|
|
||||||
resp = append(resp, api.Map{
|
|
||||||
ID: item.ID,
|
|
||||||
DisplayName: item.DisplayName,
|
|
||||||
Creator: item.Creator,
|
|
||||||
GameID: int32(item.GameID),
|
|
||||||
Date: item.Date.Unix(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMap implements getScript operation.
|
|
||||||
//
|
|
||||||
// Get the specified script by ID.
|
|
||||||
//
|
|
||||||
// GET /maps/{MapID}
|
|
||||||
func (svc *Service) GetMap(ctx context.Context, params api.GetMapParams) (*api.Map, error) {
|
|
||||||
mapResponse, err := svc.inner.GetMap(ctx, params.MapID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &api.Map{
|
|
||||||
ID: mapResponse.ID,
|
|
||||||
DisplayName: mapResponse.DisplayName,
|
|
||||||
Creator: mapResponse.Creator,
|
|
||||||
GameID: int32(mapResponse.GameID),
|
|
||||||
Date: mapResponse.Date.Unix(),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DownloadMapAsset invokes downloadMapAsset operation.
|
|
||||||
//
|
|
||||||
// Download the map asset.
|
|
||||||
//
|
|
||||||
// GET /maps/{MapID}/download
|
|
||||||
func (svc *Service) DownloadMapAsset(ctx context.Context, params api.DownloadMapAssetParams) (ok api.DownloadMapAssetOK, err error) {
|
|
||||||
userInfo, success := ctx.Value("UserInfo").(UserInfoHandle)
|
|
||||||
if !success {
|
|
||||||
return ok, ErrUserInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
has_role, err := userInfo.HasRoleMapDownload()
|
|
||||||
if err != nil {
|
|
||||||
return ok, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !has_role {
|
|
||||||
return ok, ErrPermissionDeniedNeedRoleMapDownload
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure map exists in the db!
|
|
||||||
// This could otherwise be used to access any asset
|
|
||||||
_, err = svc.inner.GetMap(ctx, params.MapID)
|
|
||||||
if err != nil {
|
|
||||||
return ok, err
|
|
||||||
}
|
|
||||||
|
|
||||||
info, err := svc.roblox.GetAssetLocation(roblox.GetAssetLatestRequest{
|
|
||||||
AssetID: uint64(params.MapID),
|
|
||||||
})
|
|
||||||
if err != nil{
|
|
||||||
return ok, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// download the complete file
|
|
||||||
asset, err := svc.roblox.DownloadAsset(info)
|
|
||||||
if err != nil{
|
|
||||||
return ok, err
|
|
||||||
}
|
|
||||||
|
|
||||||
ok.Data = asset
|
|
||||||
return ok, nil
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package web_api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetOperation implements getOperation operation.
|
|
||||||
//
|
|
||||||
// Get the specified operation by ID.
|
|
||||||
//
|
|
||||||
// GET /operations/{OperationID}
|
|
||||||
func (svc *Service) GetOperation(ctx context.Context, params api.GetOperationParams) (*api.Operation, error) {
|
|
||||||
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
|
|
||||||
if !ok {
|
|
||||||
return nil, ErrUserInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
// You must be the operation owner to read it
|
|
||||||
|
|
||||||
operation, err := svc.inner.GetOperation(ctx, params.OperationID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
userId, err := userInfo.GetUserID()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if caller is the submitter
|
|
||||||
has_role := userId == operation.Owner
|
|
||||||
if !has_role {
|
|
||||||
return nil, ErrPermissionDeniedNotSubmitter
|
|
||||||
}
|
|
||||||
|
|
||||||
return &api.Operation{
|
|
||||||
OperationID: operation.ID,
|
|
||||||
Date: operation.CreatedAt.Unix(),
|
|
||||||
Owner: int64(operation.Owner),
|
|
||||||
Status: int32(operation.StatusID),
|
|
||||||
StatusMessage: operation.StatusMessage,
|
|
||||||
Path: operation.Path,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
package web_api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/service"
|
|
||||||
)
|
|
||||||
|
|
||||||
// CreateScriptPolicy implements createScriptPolicy operation.
|
|
||||||
//
|
|
||||||
// Create a new script policy.
|
|
||||||
//
|
|
||||||
// POST /script-policy
|
|
||||||
func (svc *Service) CreateScriptPolicy(ctx context.Context, req *api.ScriptPolicyCreate) (*api.ScriptPolicyID, error) {
|
|
||||||
err := CheckHasRoleScriptWrite(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
from_script, err := svc.inner.GetScript(ctx, req.FromScriptID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// the existence of ToScriptID does not need to be validated because it's checked by a foreign key constraint.
|
|
||||||
|
|
||||||
script, err := svc.inner.CreateScriptPolicy(ctx, model.ScriptPolicy{
|
|
||||||
ID: 0,
|
|
||||||
FromScriptHash: from_script.Hash,
|
|
||||||
ToScriptID: req.ToScriptID,
|
|
||||||
Policy: model.Policy(req.Policy),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &api.ScriptPolicyID{
|
|
||||||
ScriptPolicyID: script.ID,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ListScriptPolicy implements listScriptPolicy operation.
|
|
||||||
//
|
|
||||||
// Get list of script policies.
|
|
||||||
//
|
|
||||||
// GET /script-policy
|
|
||||||
func (svc *Service) ListScriptPolicy(ctx context.Context, params api.ListScriptPolicyParams) ([]api.ScriptPolicy, error) {
|
|
||||||
filter := service.NewScriptPolicyFilter()
|
|
||||||
|
|
||||||
if hash_hex, ok := params.FromScriptHash.Get(); ok{
|
|
||||||
hash_parsed, err := model.HashParse(hash_hex)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
filter.SetFromScriptHash(int64(hash_parsed))
|
|
||||||
}
|
|
||||||
if to_script_id, to_script_id_ok := params.ToScriptID.Get(); to_script_id_ok{
|
|
||||||
filter.SetToScriptID(to_script_id)
|
|
||||||
}
|
|
||||||
if policy, policy_ok := params.Policy.Get(); policy_ok{
|
|
||||||
filter.SetPolicy(policy)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
items, err := svc.inner.ListScriptPolicies(ctx, filter, model.Page{
|
|
||||||
Number: params.Page,
|
|
||||||
Size: params.Limit,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp []api.ScriptPolicy
|
|
||||||
for _, item := range items {
|
|
||||||
resp = append(resp, api.ScriptPolicy{
|
|
||||||
ID: item.ID,
|
|
||||||
FromScriptHash: model.HashFormat(uint64(item.FromScriptHash)),
|
|
||||||
ToScriptID: item.ToScriptID,
|
|
||||||
Policy: int32(item.Policy),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteScriptPolicy implements deleteScriptPolicy operation.
|
|
||||||
//
|
|
||||||
// Delete the specified script policy by ID.
|
|
||||||
//
|
|
||||||
// DELETE /script-policy/{ScriptPolicyID}
|
|
||||||
func (svc *Service) DeleteScriptPolicy(ctx context.Context, params api.DeleteScriptPolicyParams) error {
|
|
||||||
err := CheckHasRoleScriptWrite(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return svc.inner.DeleteScriptPolicy(ctx, params.ScriptPolicyID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetScriptPolicy implements getScriptPolicy operation.
|
|
||||||
//
|
|
||||||
// Get the specified script policy by ID.
|
|
||||||
//
|
|
||||||
// GET /script-policy/{ScriptPolicyID}
|
|
||||||
func (svc *Service) GetScriptPolicy(ctx context.Context, params api.GetScriptPolicyParams) (*api.ScriptPolicy, error) {
|
|
||||||
policy, err := svc.inner.GetScriptPolicy(ctx, params.ScriptPolicyID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &api.ScriptPolicy{
|
|
||||||
ID: policy.ID,
|
|
||||||
FromScriptHash: model.HashFormat(uint64(policy.FromScriptHash)),
|
|
||||||
ToScriptID: policy.ToScriptID,
|
|
||||||
Policy: int32(policy.Policy),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateScriptPolicy implements updateScriptPolicy operation.
|
|
||||||
//
|
|
||||||
// Update the specified script policy by ID.
|
|
||||||
//
|
|
||||||
// POST /script-policy/{ScriptPolicyID}
|
|
||||||
func (svc *Service) UpdateScriptPolicy(ctx context.Context, req *api.ScriptPolicyUpdate, params api.UpdateScriptPolicyParams) error {
|
|
||||||
err := CheckHasRoleScriptWrite(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
filter := service.NewScriptPolicyFilter()
|
|
||||||
if from_script_id, ok := req.FromScriptID.Get(); ok {
|
|
||||||
from_script, err := svc.inner.GetScript(ctx, from_script_id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
filter.SetFromScriptHash(from_script.Hash)
|
|
||||||
}
|
|
||||||
if to_script_id, to_script_id_ok := req.ToScriptID.Get(); to_script_id_ok{
|
|
||||||
filter.SetToScriptID(to_script_id)
|
|
||||||
}
|
|
||||||
if policy, policy_ok := req.Policy.Get(); policy_ok{
|
|
||||||
filter.SetPolicy(policy)
|
|
||||||
}
|
|
||||||
|
|
||||||
return svc.inner.UpdateScriptPolicy(ctx, req.ID, filter)
|
|
||||||
}
|
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
package web_api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/service"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CheckHasRoleScriptWrite(ctx context.Context) error {
|
|
||||||
userInfo, ok := ctx.Value("UserInfo").(UserInfoHandle)
|
|
||||||
if !ok {
|
|
||||||
return ErrUserInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
has_role, err := userInfo.HasRoleScriptWrite()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !has_role {
|
|
||||||
return ErrPermissionDeniedNeedRoleScriptWrite
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateScript implements createScript operation.
|
|
||||||
//
|
|
||||||
// Create a new script.
|
|
||||||
//
|
|
||||||
// POST /scripts
|
|
||||||
func (svc *Service) CreateScript(ctx context.Context, req *api.ScriptCreate) (*api.ScriptID, error) {
|
|
||||||
err := CheckHasRoleScriptWrite(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
script, err := svc.inner.CreateScript(ctx, model.Script{
|
|
||||||
ID: 0,
|
|
||||||
Name: req.Name,
|
|
||||||
Hash: int64(model.HashSource(req.Source)),
|
|
||||||
Source: req.Source,
|
|
||||||
ResourceType: model.ResourceType(req.ResourceType),
|
|
||||||
ResourceID: req.ResourceID.Or(0),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &api.ScriptID{
|
|
||||||
ScriptID: script.ID,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListScripts implements listScripts operation.
|
|
||||||
//
|
|
||||||
// Get list of scripts.
|
|
||||||
//
|
|
||||||
// GET /scripts
|
|
||||||
func (svc *Service) ListScripts(ctx context.Context, params api.ListScriptsParams) ([]api.Script, error) {
|
|
||||||
filter := service.NewScriptFilter()
|
|
||||||
|
|
||||||
if hash_hex, ok := params.Hash.Get(); ok{
|
|
||||||
hash_parsed, err := model.HashParse(hash_hex)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
filter.SetHash(int64(hash_parsed))
|
|
||||||
}
|
|
||||||
if name, name_ok := params.Name.Get(); name_ok{
|
|
||||||
filter.SetName(name)
|
|
||||||
}
|
|
||||||
if source, source_ok := params.Source.Get(); source_ok{
|
|
||||||
filter.SetSource(source)
|
|
||||||
}
|
|
||||||
if resource_type, resource_type_ok := params.ResourceType.Get(); resource_type_ok{
|
|
||||||
filter.SetResourceType(resource_type)
|
|
||||||
}
|
|
||||||
if resource_id, resource_id_ok := params.ResourceID.Get(); resource_id_ok{
|
|
||||||
filter.SetResourceID(resource_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
items, err := svc.inner.ListScripts(ctx, filter, model.Page{
|
|
||||||
Number: params.Page,
|
|
||||||
Size: params.Limit,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp []api.Script
|
|
||||||
for _, item := range items {
|
|
||||||
resp = append(resp, api.Script{
|
|
||||||
ID: item.ID,
|
|
||||||
Name: item.Name,
|
|
||||||
Hash: model.HashFormat(uint64(item.Hash)),
|
|
||||||
Source: item.Source,
|
|
||||||
ResourceType: int32(item.ResourceType),
|
|
||||||
ResourceID: item.ResourceID,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteScript implements deleteScript operation.
|
|
||||||
//
|
|
||||||
// Delete the specified script by ID.
|
|
||||||
//
|
|
||||||
// DELETE /scripts/{ScriptID}
|
|
||||||
func (svc *Service) DeleteScript(ctx context.Context, params api.DeleteScriptParams) error {
|
|
||||||
err := CheckHasRoleScriptWrite(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return svc.inner.DeleteScript(ctx, params.ScriptID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetScript implements getScript operation.
|
|
||||||
//
|
|
||||||
// Get the specified script by ID.
|
|
||||||
//
|
|
||||||
// GET /scripts/{ScriptID}
|
|
||||||
func (svc *Service) GetScript(ctx context.Context, params api.GetScriptParams) (*api.Script, error) {
|
|
||||||
script, err := svc.inner.GetScript(ctx, params.ScriptID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &api.Script{
|
|
||||||
ID: script.ID,
|
|
||||||
Name: script.Name,
|
|
||||||
Hash: model.HashFormat(uint64(script.Hash)),
|
|
||||||
Source: script.Source,
|
|
||||||
ResourceType: int32(script.ResourceType),
|
|
||||||
ResourceID: script.ResourceID,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateScript implements updateScript operation.
|
|
||||||
//
|
|
||||||
// Update the specified script by ID.
|
|
||||||
//
|
|
||||||
// PATCH /scripts/{ScriptID}
|
|
||||||
func (svc *Service) UpdateScript(ctx context.Context, req *api.ScriptUpdate, params api.UpdateScriptParams) error {
|
|
||||||
err := CheckHasRoleScriptWrite(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
filter := service.NewScriptFilter()
|
|
||||||
if name, name_ok := req.Name.Get(); name_ok{
|
|
||||||
filter.SetName(name)
|
|
||||||
}
|
|
||||||
if source, source_ok := req.Source.Get(); source_ok{
|
|
||||||
filter.SetSource(source)
|
|
||||||
filter.SetHash(int64(model.HashSource(source)))
|
|
||||||
}
|
|
||||||
if resource_type, resource_type_ok := req.ResourceType.Get(); resource_type_ok{
|
|
||||||
filter.SetResourceType(resource_type)
|
|
||||||
}
|
|
||||||
if resource_id, resource_id_ok := req.ResourceID.Get(); resource_id_ok{
|
|
||||||
filter.SetResourceID(resource_id)
|
|
||||||
}
|
|
||||||
|
|
||||||
return svc.inner.UpdateScript(ctx, req.ID, filter)
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
package web_api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/roblox"
|
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/service"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// ErrPermissionDenied caller does not have the required role
|
|
||||||
ErrPermissionDenied = errors.New("Permission denied")
|
|
||||||
// ErrUserInfo user info is missing for some reason
|
|
||||||
ErrUserInfo = errors.New("Missing user info")
|
|
||||||
ErrDelayReset = errors.New("Please give the validator at least 10 seconds to operate before attempting to reset the status")
|
|
||||||
ErrPermissionDeniedNotSubmitter = fmt.Errorf("%w: You must be the submitter to perform this action", ErrPermissionDenied)
|
|
||||||
ErrPermissionDeniedNeedRoleSubmissionRelease = fmt.Errorf("%w: Need Role SubmissionRelease", ErrPermissionDenied)
|
|
||||||
ErrPermissionDeniedNeedRoleMapfixUpload = fmt.Errorf("%w: Need Role MapfixUpload", ErrPermissionDenied)
|
|
||||||
ErrPermissionDeniedNeedRoleMapfixReview = fmt.Errorf("%w: Need Role MapfixReview", ErrPermissionDenied)
|
|
||||||
ErrPermissionDeniedNeedRoleSubmissionUpload = fmt.Errorf("%w: Need Role SubmissionUpload", ErrPermissionDenied)
|
|
||||||
ErrPermissionDeniedNeedRoleSubmissionReview = fmt.Errorf("%w: Need Role SubmissionReview", ErrPermissionDenied)
|
|
||||||
ErrPermissionDeniedNeedRoleMapDownload = fmt.Errorf("%w: Need Role MapDownload", ErrPermissionDenied)
|
|
||||||
ErrPermissionDeniedNeedRoleScriptWrite = fmt.Errorf("%w: Need Role ScriptWrite", ErrPermissionDenied)
|
|
||||||
ErrPermissionDeniedNeedRoleMaptest = fmt.Errorf("%w: Need Role Maptest", ErrPermissionDenied)
|
|
||||||
ErrNegativeID = errors.New("A negative ID was provided")
|
|
||||||
)
|
|
||||||
|
|
||||||
type Service struct {
|
|
||||||
inner *service.Service
|
|
||||||
roblox roblox.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewService(
|
|
||||||
inner *service.Service,
|
|
||||||
roblox roblox.Client,
|
|
||||||
) Service {
|
|
||||||
return Service{
|
|
||||||
inner: inner,
|
|
||||||
roblox: roblox,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewError creates *ErrorStatusCode from error returned by handler.
|
|
||||||
//
|
|
||||||
// Used for common default response.
|
|
||||||
func (svc *Service) NewError(ctx context.Context, err error) *api.ErrorStatusCode {
|
|
||||||
status := 500
|
|
||||||
if errors.Is(err, datastore.ErrNotExist) {
|
|
||||||
status = 404
|
|
||||||
}
|
|
||||||
if errors.Is(err, ErrPermissionDenied) {
|
|
||||||
status = 403
|
|
||||||
}
|
|
||||||
if errors.Is(err, ErrUserInfo) {
|
|
||||||
status = 401
|
|
||||||
}
|
|
||||||
return &api.ErrorStatusCode{
|
|
||||||
StatusCode: status,
|
|
||||||
Response: api.Error{
|
|
||||||
Code: int64(status),
|
|
||||||
Message: err.Error(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,21 +1,20 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "maps-validation"
|
name = "maps-validation"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
edition = "2024"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-nats = "0.42.0"
|
submissions-api = { path = "api", features = ["internal"], default-features = false, registry = "strafesnet" }
|
||||||
|
async-nats = "0.40.0"
|
||||||
futures = "0.3.31"
|
futures = "0.3.31"
|
||||||
rbx_asset = { version = "0.4.7", registry = "strafesnet" }
|
rbx_asset = { version = "0.4.4-pre2", registry = "strafesnet" }
|
||||||
rbx_binary = "1.0.0"
|
rbx_binary = { version = "0.7.4", registry = "strafesnet"}
|
||||||
rbx_dom_weak = "3.0.0"
|
rbx_dom_weak = { version = "2.9.0", registry = "strafesnet"}
|
||||||
rbx_reflection_database = "1.0.3"
|
rbx_reflection_database = { version = "0.2.12", registry = "strafesnet"}
|
||||||
rbx_xml = "1.0.0"
|
rbx_xml = { version = "0.13.3", registry = "strafesnet"}
|
||||||
serde = { version = "1.0.215", features = ["derive"] }
|
serde = { version = "1.0.215", features = ["derive"] }
|
||||||
serde_json = "1.0.133"
|
serde_json = "1.0.133"
|
||||||
siphasher = "1.0.1"
|
siphasher = "1.0.1"
|
||||||
tokio = { version = "1.41.1", features = ["macros", "rt-multi-thread", "signal"] }
|
tokio = { version = "1.41.1", features = ["macros", "rt-multi-thread", "signal"] }
|
||||||
heck = "0.5.0"
|
heck = "0.5.0"
|
||||||
lazy-regex = "3.4.1"
|
lazy-regex = "3.4.1"
|
||||||
rust-grpc = { version = "1.2.1", registry = "strafesnet" }
|
|
||||||
tonic = "0.13.1"
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "submissions-api"
|
name = "submissions-api"
|
||||||
version = "0.8.2"
|
version = "0.7.0"
|
||||||
edition = "2024"
|
edition = "2021"
|
||||||
publish = ["strafesnet"]
|
publish = ["strafesnet"]
|
||||||
repository = "https://git.itzana.me/StrafesNET/maps-service"
|
repository = "https://git.itzana.me/StrafesNET/maps-service"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
@@ -11,9 +11,13 @@ authors = ["Rhys Lloyd <krakow20@gmail.com>"]
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = { version = "0.4.41", features = ["serde"] }
|
|
||||||
reqwest = { version = "0", features = ["json"] }
|
reqwest = { version = "0", features = ["json"] }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
serde_repr = "0.1.19"
|
serde_repr = "0.1.19"
|
||||||
url = "2"
|
url = "2"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["external"]
|
||||||
|
internal = []
|
||||||
|
external = []
|
||||||
|
|||||||
@@ -33,14 +33,15 @@ impl Context{
|
|||||||
self.client.get(url)
|
self.client.get(url)
|
||||||
.send().await
|
.send().await
|
||||||
}
|
}
|
||||||
|
#[cfg(feature="internal")]
|
||||||
|
pub async fn post_empty_body(&self,url:impl reqwest::IntoUrl)->Result<reqwest::Response,reqwest::Error>{
|
||||||
|
self.client.post(url)
|
||||||
|
.send().await
|
||||||
|
}
|
||||||
pub async fn post(&self,url:impl reqwest::IntoUrl,body:impl Into<reqwest::Body>)->Result<reqwest::Response,reqwest::Error>{
|
pub async fn post(&self,url:impl reqwest::IntoUrl,body:impl Into<reqwest::Body>)->Result<reqwest::Response,reqwest::Error>{
|
||||||
self.client.post(url)
|
self.client.post(url)
|
||||||
.header("Content-Type","application/json")
|
.header("Content-Type","application/json")
|
||||||
.body(body)
|
.body(body)
|
||||||
.send().await
|
.send().await
|
||||||
}
|
}
|
||||||
pub async fn delete(&self,url:impl reqwest::IntoUrl)->Result<reqwest::Response,reqwest::Error>{
|
|
||||||
self.client.delete(url)
|
|
||||||
.send().await
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ impl Context{
|
|||||||
).await.map_err(Error::Response)?
|
).await.map_err(Error::Response)?
|
||||||
.json().await.map_err(Error::ReqwestJson)
|
.json().await.map_err(Error::ReqwestJson)
|
||||||
}
|
}
|
||||||
pub async fn get_scripts(&self,config:GetScriptsRequest<'_>)->Result<Vec<ScriptResponse>,Error>{
|
pub async fn get_scripts<'a>(&self,config:GetScriptsRequest<'a>)->Result<Vec<ScriptResponse>,Error>{
|
||||||
let url_raw=format!("{}/scripts",self.0.base_url);
|
let url_raw=format!("{}/scripts",self.0.base_url);
|
||||||
let mut url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
let mut url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ impl Context{
|
|||||||
if let Some(resource_type)=config.ResourceType{
|
if let Some(resource_type)=config.ResourceType{
|
||||||
query_pairs.append_pair("ResourceType",(resource_type as i32).to_string().as_str());
|
query_pairs.append_pair("ResourceType",(resource_type as i32).to_string().as_str());
|
||||||
}
|
}
|
||||||
if let Some(ResourceID(resource_id))=config.ResourceID{
|
if let Some(resource_id)=config.ResourceID{
|
||||||
query_pairs.append_pair("ResourceID",resource_id.to_string().as_str());
|
query_pairs.append_pair("ResourceID",resource_id.to_string().as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ impl Context{
|
|||||||
).await.map_err(Error::Response)?
|
).await.map_err(Error::Response)?
|
||||||
.json().await.map_err(Error::ReqwestJson)
|
.json().await.map_err(Error::ReqwestJson)
|
||||||
}
|
}
|
||||||
pub async fn get_script_from_hash(&self,config:HashRequest<'_>)->Result<Option<ScriptResponse>,ScriptSingleItemError>{
|
pub async fn get_script_from_hash<'a>(&self,config:HashRequest<'a>)->Result<Option<ScriptResponse>,SingleItemError>{
|
||||||
let scripts=self.get_scripts(GetScriptsRequest{
|
let scripts=self.get_scripts(GetScriptsRequest{
|
||||||
Page:1,
|
Page:1,
|
||||||
Limit:2,
|
Limit:2,
|
||||||
@@ -57,11 +57,11 @@ impl Context{
|
|||||||
ResourceID:None,
|
ResourceID:None,
|
||||||
}).await.map_err(SingleItemError::Other)?;
|
}).await.map_err(SingleItemError::Other)?;
|
||||||
if 1<scripts.len(){
|
if 1<scripts.len(){
|
||||||
return Err(SingleItemError::DuplicateItems(scripts.into_iter().map(|item|item.ID).collect()));
|
return Err(SingleItemError::DuplicateItems);
|
||||||
}
|
}
|
||||||
Ok(scripts.into_iter().next())
|
Ok(scripts.into_iter().next())
|
||||||
}
|
}
|
||||||
pub async fn create_script(&self,config:CreateScriptRequest<'_>)->Result<ScriptIDResponse,Error>{
|
pub async fn create_script<'a>(&self,config:CreateScriptRequest<'a>)->Result<ScriptIDResponse,Error>{
|
||||||
let url_raw=format!("{}/scripts",self.0.base_url);
|
let url_raw=format!("{}/scripts",self.0.base_url);
|
||||||
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
||||||
|
|
||||||
@@ -72,17 +72,7 @@ impl Context{
|
|||||||
).await.map_err(Error::Response)?
|
).await.map_err(Error::Response)?
|
||||||
.json().await.map_err(Error::ReqwestJson)
|
.json().await.map_err(Error::ReqwestJson)
|
||||||
}
|
}
|
||||||
pub async fn delete_script(&self,config:GetScriptRequest)->Result<(),Error>{
|
pub async fn get_script_policies<'a>(&self,config:GetScriptPoliciesRequest<'a>)->Result<Vec<ScriptPolicyResponse>,Error>{
|
||||||
let url_raw=format!("{}/scripts/{}",self.0.base_url,config.ScriptID.0);
|
|
||||||
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
|
||||||
|
|
||||||
response_ok(
|
|
||||||
self.0.delete(url).await.map_err(Error::Reqwest)?
|
|
||||||
).await.map_err(Error::Response)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
pub async fn get_script_policies(&self,config:GetScriptPoliciesRequest<'_>)->Result<Vec<ScriptPolicyResponse>,Error>{
|
|
||||||
let url_raw=format!("{}/script-policy",self.0.base_url);
|
let url_raw=format!("{}/script-policy",self.0.base_url);
|
||||||
let mut url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
let mut url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
||||||
|
|
||||||
@@ -106,7 +96,7 @@ impl Context{
|
|||||||
).await.map_err(Error::Response)?
|
).await.map_err(Error::Response)?
|
||||||
.json().await.map_err(Error::ReqwestJson)
|
.json().await.map_err(Error::ReqwestJson)
|
||||||
}
|
}
|
||||||
pub async fn get_script_policy_from_hash(&self,config:HashRequest<'_>)->Result<Option<ScriptPolicyResponse>,ScriptPolicySingleItemError>{
|
pub async fn get_script_policy_from_hash<'a>(&self,config:HashRequest<'a>)->Result<Option<ScriptPolicyResponse>,SingleItemError>{
|
||||||
let policies=self.get_script_policies(GetScriptPoliciesRequest{
|
let policies=self.get_script_policies(GetScriptPoliciesRequest{
|
||||||
Page:1,
|
Page:1,
|
||||||
Limit:2,
|
Limit:2,
|
||||||
@@ -115,7 +105,7 @@ impl Context{
|
|||||||
Policy:None,
|
Policy:None,
|
||||||
}).await.map_err(SingleItemError::Other)?;
|
}).await.map_err(SingleItemError::Other)?;
|
||||||
if 1<policies.len(){
|
if 1<policies.len(){
|
||||||
return Err(SingleItemError::DuplicateItems(policies.into_iter().map(|item|item.ID).collect()));
|
return Err(SingleItemError::DuplicateItems);
|
||||||
}
|
}
|
||||||
Ok(policies.into_iter().next())
|
Ok(policies.into_iter().next())
|
||||||
}
|
}
|
||||||
@@ -140,94 +130,6 @@ impl Context{
|
|||||||
self.0.post(url,body).await.map_err(Error::Reqwest)?
|
self.0.post(url,body).await.map_err(Error::Reqwest)?
|
||||||
).await.map_err(Error::Response)?;
|
).await.map_err(Error::Response)?;
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
pub async fn delete_script_policy(&self,config:GetScriptPolicyRequest)->Result<(),Error>{
|
|
||||||
let url_raw=format!("{}/script-policy/{}",self.0.base_url,config.ScriptPolicyID.0);
|
|
||||||
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
|
||||||
|
|
||||||
response_ok(
|
|
||||||
self.0.delete(url).await.map_err(Error::Reqwest)?
|
|
||||||
).await.map_err(Error::Response)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
pub async fn get_submissions(&self,config:GetSubmissionsRequest<'_>)->Result<SubmissionsResponse,Error>{
|
|
||||||
let url_raw=format!("{}/submissions",self.0.base_url);
|
|
||||||
let mut url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
|
||||||
|
|
||||||
{
|
|
||||||
let mut query_pairs=url.query_pairs_mut();
|
|
||||||
query_pairs.append_pair("Page",config.Page.to_string().as_str());
|
|
||||||
query_pairs.append_pair("Limit",config.Limit.to_string().as_str());
|
|
||||||
if let Some(sort)=config.Sort{
|
|
||||||
query_pairs.append_pair("Sort",(sort as u8).to_string().as_str());
|
|
||||||
}
|
|
||||||
if let Some(display_name)=config.DisplayName{
|
|
||||||
query_pairs.append_pair("DisplayName",display_name);
|
|
||||||
}
|
|
||||||
if let Some(creator)=config.Creator{
|
|
||||||
query_pairs.append_pair("Creator",creator);
|
|
||||||
}
|
|
||||||
if let Some(game_id)=config.GameID{
|
|
||||||
query_pairs.append_pair("GameID",(game_id as u8).to_string().as_str());
|
|
||||||
}
|
|
||||||
if let Some(submitter)=config.Submitter{
|
|
||||||
query_pairs.append_pair("Submitter",submitter.to_string().as_str());
|
|
||||||
}
|
|
||||||
if let Some(asset_id)=config.AssetID{
|
|
||||||
query_pairs.append_pair("AssetID",asset_id.to_string().as_str());
|
|
||||||
}
|
|
||||||
if let Some(uploaded_asset_id)=config.UploadedAssetID{
|
|
||||||
query_pairs.append_pair("UploadedAssetID",uploaded_asset_id.to_string().as_str());
|
|
||||||
}
|
|
||||||
if let Some(status_id)=config.StatusID{
|
|
||||||
query_pairs.append_pair("StatusID",(status_id as u8).to_string().as_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
response_ok(
|
|
||||||
self.0.get(url).await.map_err(Error::Reqwest)?
|
|
||||||
).await.map_err(Error::Response)?
|
|
||||||
.json().await.map_err(Error::ReqwestJson)
|
|
||||||
}
|
|
||||||
pub async fn get_maps(&self,config:GetMapsRequest<'_>)->Result<Vec<MapResponse>,Error>{
|
|
||||||
let url_raw=format!("{}/maps",self.0.base_url);
|
|
||||||
let mut url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
|
||||||
|
|
||||||
{
|
|
||||||
let mut query_pairs=url.query_pairs_mut();
|
|
||||||
query_pairs.append_pair("Page",config.Page.to_string().as_str());
|
|
||||||
query_pairs.append_pair("Limit",config.Limit.to_string().as_str());
|
|
||||||
if let Some(sort)=config.Sort{
|
|
||||||
query_pairs.append_pair("Sort",(sort as u8).to_string().as_str());
|
|
||||||
}
|
|
||||||
if let Some(display_name)=config.DisplayName{
|
|
||||||
query_pairs.append_pair("DisplayName",display_name);
|
|
||||||
}
|
|
||||||
if let Some(creator)=config.Creator{
|
|
||||||
query_pairs.append_pair("Creator",creator);
|
|
||||||
}
|
|
||||||
if let Some(game_id)=config.GameID{
|
|
||||||
query_pairs.append_pair("GameID",(game_id as u8).to_string().as_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
response_ok(
|
|
||||||
self.0.get(url).await.map_err(Error::Reqwest)?
|
|
||||||
).await.map_err(Error::Response)?
|
|
||||||
.json().await.map_err(Error::ReqwestJson)
|
|
||||||
}
|
|
||||||
pub async fn release_submissions(&self,config:ReleaseRequest<'_>)->Result<(),Error>{
|
|
||||||
let url_raw=format!("{}/release-submissions",self.0.base_url);
|
|
||||||
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
|
||||||
|
|
||||||
let body=serde_json::to_string(config.schedule).map_err(Error::JSON)?;
|
|
||||||
|
|
||||||
response_ok(
|
|
||||||
self.0.post(url,body).await.map_err(Error::Reqwest)?
|
|
||||||
).await.map_err(Error::Response)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
219
validation/api/src/internal.rs
Normal file
219
validation/api/src/internal.rs
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
use crate::types::*;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Context(crate::context::Context);
|
||||||
|
|
||||||
|
// conditionally include specified query pairs
|
||||||
|
macro_rules! query_pairs{
|
||||||
|
($url:expr,)=>{
|
||||||
|
$url
|
||||||
|
};
|
||||||
|
($url:expr,$(($param:expr,$value:expr))+)=>{
|
||||||
|
{
|
||||||
|
let mut url=$url;
|
||||||
|
url.query_pairs_mut()
|
||||||
|
$(.append_pair($param,$value))*;
|
||||||
|
url
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// there are lots of action endpoints and they all follow the same pattern
|
||||||
|
macro_rules! action{
|
||||||
|
($system:expr,$fname:ident,$config:ident,$config_type:ident,$action:expr,$config_submission_id:expr,$(($param:expr,$value:expr))*)=>{
|
||||||
|
pub async fn $fname(&self,$config:$config_type)->Result<(),Error>{
|
||||||
|
let url_raw=format!(concat!("{}/",$system,"/{}/",$action),self.0.base_url,$config_submission_id);
|
||||||
|
let url=query_pairs!(reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?,$(($param,$value))*);
|
||||||
|
|
||||||
|
response_ok(
|
||||||
|
self.0.post_empty_body(url).await.map_err(Error::Reqwest)?
|
||||||
|
).await.map_err(Error::Response)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
impl Context{
|
||||||
|
pub fn new(base_url:String)->reqwest::Result<Self>{
|
||||||
|
Ok(Self(crate::context::Context::new(base_url,None)?))
|
||||||
|
}
|
||||||
|
pub async fn get_script(&self,config:GetScriptRequest)->Result<ScriptResponse,Error>{
|
||||||
|
let url_raw=format!("{}/scripts/{}",self.0.base_url,config.ScriptID.0);
|
||||||
|
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
||||||
|
|
||||||
|
response_ok(
|
||||||
|
self.0.get(url).await.map_err(Error::Reqwest)?
|
||||||
|
).await.map_err(Error::Response)?
|
||||||
|
.json().await.map_err(Error::ReqwestJson)
|
||||||
|
}
|
||||||
|
pub async fn get_scripts<'a>(&self,config:GetScriptsRequest<'a>)->Result<Vec<ScriptResponse>,Error>{
|
||||||
|
let url_raw=format!("{}/scripts",self.0.base_url);
|
||||||
|
let mut url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut query_pairs=url.query_pairs_mut();
|
||||||
|
query_pairs.append_pair("Page",config.Page.to_string().as_str());
|
||||||
|
query_pairs.append_pair("Limit",config.Limit.to_string().as_str());
|
||||||
|
if let Some(name)=config.Name{
|
||||||
|
query_pairs.append_pair("Name",name);
|
||||||
|
}
|
||||||
|
if let Some(hash)=config.Hash{
|
||||||
|
query_pairs.append_pair("Hash",hash);
|
||||||
|
}
|
||||||
|
if let Some(source)=config.Source{
|
||||||
|
query_pairs.append_pair("Source",source);
|
||||||
|
}
|
||||||
|
if let Some(resource_type)=config.ResourceType{
|
||||||
|
query_pairs.append_pair("ResourceType",(resource_type as i32).to_string().as_str());
|
||||||
|
}
|
||||||
|
if let Some(resource_id)=config.ResourceID{
|
||||||
|
query_pairs.append_pair("ResourceID",resource_id.to_string().as_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
response_ok(
|
||||||
|
self.0.get(url).await.map_err(Error::Reqwest)?
|
||||||
|
).await.map_err(Error::Response)?
|
||||||
|
.json().await.map_err(Error::ReqwestJson)
|
||||||
|
}
|
||||||
|
pub async fn get_script_from_hash<'a>(&self,config:HashRequest<'a>)->Result<Option<ScriptResponse>,SingleItemError>{
|
||||||
|
let scripts=self.get_scripts(GetScriptsRequest{
|
||||||
|
Page:1,
|
||||||
|
Limit:2,
|
||||||
|
Hash:Some(config.hash),
|
||||||
|
Name:None,
|
||||||
|
Source:None,
|
||||||
|
ResourceType:None,
|
||||||
|
ResourceID:None,
|
||||||
|
}).await.map_err(SingleItemError::Other)?;
|
||||||
|
if 1<scripts.len(){
|
||||||
|
return Err(SingleItemError::DuplicateItems);
|
||||||
|
}
|
||||||
|
Ok(scripts.into_iter().next())
|
||||||
|
}
|
||||||
|
pub async fn create_script<'a>(&self,config:CreateScriptRequest<'a>)->Result<ScriptIDResponse,Error>{
|
||||||
|
let url_raw=format!("{}/scripts",self.0.base_url);
|
||||||
|
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
||||||
|
|
||||||
|
let body=serde_json::to_string(&config).map_err(Error::JSON)?;
|
||||||
|
|
||||||
|
response_ok(
|
||||||
|
self.0.post(url,body).await.map_err(Error::Reqwest)?
|
||||||
|
).await.map_err(Error::Response)?
|
||||||
|
.json().await.map_err(Error::ReqwestJson)
|
||||||
|
}
|
||||||
|
pub async fn get_script_policies<'a>(&self,config:GetScriptPoliciesRequest<'a>)->Result<Vec<ScriptPolicyResponse>,Error>{
|
||||||
|
let url_raw=format!("{}/script-policy",self.0.base_url);
|
||||||
|
let mut url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut query_pairs=url.query_pairs_mut();
|
||||||
|
query_pairs.append_pair("Page",config.Page.to_string().as_str());
|
||||||
|
query_pairs.append_pair("Limit",config.Limit.to_string().as_str());
|
||||||
|
if let Some(hash)=config.FromScriptHash{
|
||||||
|
query_pairs.append_pair("FromScriptHash",hash);
|
||||||
|
}
|
||||||
|
if let Some(script_id)=config.ToScriptID{
|
||||||
|
query_pairs.append_pair("ToScriptID",script_id.0.to_string().as_str());
|
||||||
|
}
|
||||||
|
if let Some(policy)=config.Policy{
|
||||||
|
query_pairs.append_pair("Policy",(policy as i32).to_string().as_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
response_ok(
|
||||||
|
self.0.get(url).await.map_err(Error::Reqwest)?
|
||||||
|
).await.map_err(Error::Response)?
|
||||||
|
.json().await.map_err(Error::ReqwestJson)
|
||||||
|
}
|
||||||
|
pub async fn get_script_policy_from_hash<'a>(&self,config:HashRequest<'a>)->Result<Option<ScriptPolicyResponse>,SingleItemError>{
|
||||||
|
let policies=self.get_script_policies(GetScriptPoliciesRequest{
|
||||||
|
Page:1,
|
||||||
|
Limit:2,
|
||||||
|
FromScriptHash:Some(config.hash),
|
||||||
|
ToScriptID:None,
|
||||||
|
Policy:None,
|
||||||
|
}).await.map_err(SingleItemError::Other)?;
|
||||||
|
if 1<policies.len(){
|
||||||
|
return Err(SingleItemError::DuplicateItems);
|
||||||
|
}
|
||||||
|
Ok(policies.into_iter().next())
|
||||||
|
}
|
||||||
|
pub async fn create_script_policy(&self,config:CreateScriptPolicyRequest)->Result<ScriptPolicyIDResponse,Error>{
|
||||||
|
let url_raw=format!("{}/script-policy",self.0.base_url);
|
||||||
|
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
||||||
|
|
||||||
|
let body=serde_json::to_string(&config).map_err(Error::JSON)?;
|
||||||
|
|
||||||
|
response_ok(
|
||||||
|
self.0.post(url,body).await.map_err(Error::Reqwest)?
|
||||||
|
).await.map_err(Error::Response)?
|
||||||
|
.json().await.map_err(Error::ReqwestJson)
|
||||||
|
}
|
||||||
|
pub async fn create_submission<'a>(&self,config:CreateSubmissionRequest<'a>)->Result<SubmissionIDResponse,Error>{
|
||||||
|
let url_raw=format!("{}/submissions",self.0.base_url);
|
||||||
|
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
||||||
|
|
||||||
|
let body=serde_json::to_string(&config).map_err(Error::JSON)?;
|
||||||
|
|
||||||
|
response_ok(
|
||||||
|
self.0.post(url,body).await.map_err(Error::Reqwest)?
|
||||||
|
).await.map_err(Error::Response)?
|
||||||
|
.json().await.map_err(Error::ReqwestJson)
|
||||||
|
}
|
||||||
|
// simple submission endpoints
|
||||||
|
action!("submissions",action_submission_request_changes,config,ActionSubmissionRequestChangesRequest,"status/validator-request-changes",config.SubmissionID,
|
||||||
|
("ErrorMessage",config.ErrorMessage.as_str())
|
||||||
|
);
|
||||||
|
action!("submissions",action_submission_submitted,config,ActionSubmissionSubmittedRequest,"status/validator-submitted",config.SubmissionID,
|
||||||
|
("ModelVersion",config.ModelVersion.to_string().as_str())
|
||||||
|
("DisplayName",config.DisplayName.as_str())
|
||||||
|
("Creator",config.Creator.as_str())
|
||||||
|
("GameID",config.GameID.to_string().as_str())
|
||||||
|
);
|
||||||
|
action!("submissions",action_submission_validated,config,SubmissionID,"status/validator-validated",config.0,);
|
||||||
|
action!("submissions",update_submission_validated_model,config,UpdateSubmissionModelRequest,"validated-model",config.SubmissionID,
|
||||||
|
("ValidatedModelID",config.ModelID.to_string().as_str())
|
||||||
|
("ValidatedModelVersion",config.ModelVersion.to_string().as_str())
|
||||||
|
);
|
||||||
|
action!("submissions",action_submission_uploaded,config,ActionSubmissionUploadedRequest,"status/validator-uploaded",config.SubmissionID,
|
||||||
|
("UploadedAssetID",config.UploadedAssetID.to_string().as_str())
|
||||||
|
);
|
||||||
|
action!("submissions",action_submission_accepted,config,ActionSubmissionAcceptedRequest,"status/validator-failed",config.SubmissionID,
|
||||||
|
("ErrorMessage",config.ErrorMessage.as_str())
|
||||||
|
);
|
||||||
|
pub async fn create_mapfix<'a>(&self,config:CreateMapfixRequest<'a>)->Result<MapfixIDResponse,Error>{
|
||||||
|
let url_raw=format!("{}/mapfixes",self.0.base_url);
|
||||||
|
let url=reqwest::Url::parse(url_raw.as_str()).map_err(Error::Parse)?;
|
||||||
|
|
||||||
|
let body=serde_json::to_string(&config).map_err(Error::JSON)?;
|
||||||
|
|
||||||
|
response_ok(
|
||||||
|
self.0.post(url,body).await.map_err(Error::Reqwest)?
|
||||||
|
).await.map_err(Error::Response)?
|
||||||
|
.json().await.map_err(Error::ReqwestJson)
|
||||||
|
}
|
||||||
|
// simple mapfixes endpoints
|
||||||
|
action!("mapfixes",action_mapfix_request_changes,config,ActionMapfixRequestChangesRequest,"status/validator-request-changes",config.MapfixID,
|
||||||
|
("ErrorMessage",config.ErrorMessage.as_str())
|
||||||
|
);
|
||||||
|
action!("mapfixes",action_mapfix_submitted,config,ActionMapfixSubmittedRequest,"status/validator-submitted",config.MapfixID,
|
||||||
|
("ModelVersion",config.ModelVersion.to_string().as_str())
|
||||||
|
("DisplayName",config.DisplayName.as_str())
|
||||||
|
("Creator",config.Creator.as_str())
|
||||||
|
("GameID",config.GameID.to_string().as_str())
|
||||||
|
);
|
||||||
|
action!("mapfixes",action_mapfix_validated,config,MapfixID,"status/validator-validated",config.0,);
|
||||||
|
action!("mapfixes",update_mapfix_validated_model,config,UpdateMapfixModelRequest,"validated-model",config.MapfixID,
|
||||||
|
("ValidatedModelID",config.ModelID.to_string().as_str())
|
||||||
|
("ValidatedModelVersion",config.ModelVersion.to_string().as_str())
|
||||||
|
);
|
||||||
|
action!("mapfixes",action_mapfix_uploaded,config,ActionMapfixUploadedRequest,"status/validator-uploaded",config.MapfixID,);
|
||||||
|
action!("mapfixes",action_mapfix_accepted,config,ActionMapfixAcceptedRequest,"status/validator-failed",config.MapfixID,
|
||||||
|
("ErrorMessage",config.ErrorMessage.as_str())
|
||||||
|
);
|
||||||
|
// simple operation endpoint
|
||||||
|
action!("operations",action_operation_failed,config,ActionOperationFailedRequest,"status/operation-failed",config.OperationID,
|
||||||
|
("StatusMessage",config.StatusMessage.as_str())
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -2,6 +2,11 @@ mod context;
|
|||||||
pub use context::Cookie;
|
pub use context::Cookie;
|
||||||
|
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
|
#[cfg(feature="internal")]
|
||||||
|
pub mod internal;
|
||||||
|
|
||||||
|
#[cfg(feature="external")]
|
||||||
pub mod external;
|
pub mod external;
|
||||||
|
|
||||||
//lazy reexports
|
//lazy reexports
|
||||||
|
|||||||
@@ -14,25 +14,21 @@ impl std::fmt::Display for Error{
|
|||||||
impl std::error::Error for Error{}
|
impl std::error::Error for Error{}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum SingleItemError<Items>{
|
pub enum SingleItemError{
|
||||||
DuplicateItems(Items),
|
DuplicateItems,
|
||||||
Other(Error),
|
Other(Error),
|
||||||
}
|
}
|
||||||
impl<Items> std::fmt::Display for SingleItemError<Items>
|
impl std::fmt::Display for SingleItemError{
|
||||||
where
|
|
||||||
Items:std::fmt::Debug
|
|
||||||
{
|
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
write!(f,"{self:?}")
|
write!(f,"{self:?}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<Items> std::error::Error for SingleItemError<Items> where Items:std::fmt::Debug{}
|
impl std::error::Error for SingleItemError{}
|
||||||
pub type ScriptSingleItemError=SingleItemError<Vec<ScriptID>>;
|
|
||||||
pub type ScriptPolicySingleItemError=SingleItemError<Vec<ScriptPolicyID>>;
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct UrlAndBody{
|
pub struct StatusCodeWithUrlAndBody{
|
||||||
|
pub status_code:reqwest::StatusCode,
|
||||||
pub url:url::Url,
|
pub url:url::Url,
|
||||||
pub body:String,
|
pub body:String,
|
||||||
}
|
}
|
||||||
@@ -40,10 +36,7 @@ pub struct UrlAndBody{
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ResponseError{
|
pub enum ResponseError{
|
||||||
Reqwest(reqwest::Error),
|
Reqwest(reqwest::Error),
|
||||||
Details{
|
StatusCodeWithUrlAndBody(StatusCodeWithUrlAndBody),
|
||||||
status_code:reqwest::StatusCode,
|
|
||||||
url_and_body:Box<UrlAndBody>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for ResponseError{
|
impl std::fmt::Display for ResponseError{
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
@@ -60,30 +53,23 @@ pub async fn response_ok(response:reqwest::Response)->Result<reqwest::Response,R
|
|||||||
let url=response.url().to_owned();
|
let url=response.url().to_owned();
|
||||||
let bytes=response.bytes().await.map_err(ResponseError::Reqwest)?;
|
let bytes=response.bytes().await.map_err(ResponseError::Reqwest)?;
|
||||||
let body=String::from_utf8_lossy(&bytes).to_string();
|
let body=String::from_utf8_lossy(&bytes).to_string();
|
||||||
Err(ResponseError::Details{
|
Err(ResponseError::StatusCodeWithUrlAndBody(StatusCodeWithUrlAndBody{
|
||||||
status_code,
|
status_code,
|
||||||
url_and_body:Box::new(UrlAndBody{url,body})
|
url,
|
||||||
})
|
body,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone,Copy,Debug,Hash,Eq,PartialEq,Ord,PartialOrd,serde_repr::Serialize_repr,serde_repr::Deserialize_repr)]
|
|
||||||
#[repr(u8)]
|
|
||||||
pub enum GameID{
|
|
||||||
Bhop=1,
|
|
||||||
Surf=2,
|
|
||||||
KreedzClimb=3,
|
|
||||||
FlyTrials=5,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
#[derive(Clone,Debug,serde::Serialize)]
|
#[derive(Clone,Debug,serde::Serialize)]
|
||||||
pub struct CreateMapfixRequest<'a>{
|
pub struct CreateMapfixRequest<'a>{
|
||||||
pub OperationID:OperationID,
|
pub OperationID:i32,
|
||||||
pub AssetOwner:i64,
|
pub AssetOwner:i64,
|
||||||
pub DisplayName:&'a str,
|
pub DisplayName:&'a str,
|
||||||
pub Creator:&'a str,
|
pub Creator:&'a str,
|
||||||
pub GameID:GameID,
|
pub GameID:i32,
|
||||||
pub AssetID:u64,
|
pub AssetID:u64,
|
||||||
pub AssetVersion:u64,
|
pub AssetVersion:u64,
|
||||||
pub TargetAssetID:u64,
|
pub TargetAssetID:u64,
|
||||||
@@ -98,11 +84,11 @@ pub struct MapfixIDResponse{
|
|||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
#[derive(Clone,Debug,serde::Serialize)]
|
#[derive(Clone,Debug,serde::Serialize)]
|
||||||
pub struct CreateSubmissionRequest<'a>{
|
pub struct CreateSubmissionRequest<'a>{
|
||||||
pub OperationID:OperationID,
|
pub OperationID:i32,
|
||||||
pub AssetOwner:i64,
|
pub AssetOwner:i64,
|
||||||
pub DisplayName:&'a str,
|
pub DisplayName:&'a str,
|
||||||
pub Creator:&'a str,
|
pub Creator:&'a str,
|
||||||
pub GameID:GameID,
|
pub GameID:i32,
|
||||||
pub AssetID:u64,
|
pub AssetID:u64,
|
||||||
pub AssetVersion:u64,
|
pub AssetVersion:u64,
|
||||||
pub Status:u32,
|
pub Status:u32,
|
||||||
@@ -114,9 +100,9 @@ pub struct SubmissionIDResponse{
|
|||||||
pub SubmissionID:SubmissionID,
|
pub SubmissionID:SubmissionID,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone,Copy,Debug,Hash,Eq,PartialEq,serde::Serialize,serde::Deserialize)]
|
#[derive(Clone,Copy,Debug,PartialEq,Eq,serde::Serialize,serde::Deserialize)]
|
||||||
pub struct ScriptID(pub(crate)i64);
|
pub struct ScriptID(pub(crate)i64);
|
||||||
#[derive(Clone,Copy,Debug,Hash,Eq,PartialEq,serde::Serialize,serde::Deserialize)]
|
#[derive(Clone,Copy,Debug,serde::Serialize,serde::Deserialize)]
|
||||||
pub struct ScriptPolicyID(pub(crate)i64);
|
pub struct ScriptPolicyID(pub(crate)i64);
|
||||||
|
|
||||||
#[derive(Clone,Copy,Debug,PartialEq,Eq,serde_repr::Serialize_repr,serde_repr::Deserialize_repr)]
|
#[derive(Clone,Copy,Debug,PartialEq,Eq,serde_repr::Serialize_repr,serde_repr::Deserialize_repr)]
|
||||||
@@ -145,7 +131,7 @@ pub struct GetScriptsRequest<'a>{
|
|||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
pub ResourceType:Option<ResourceType>,
|
pub ResourceType:Option<ResourceType>,
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
pub ResourceID:Option<ResourceID>,
|
pub ResourceID:Option<i64>,
|
||||||
}
|
}
|
||||||
#[derive(Clone,Copy,Debug)]
|
#[derive(Clone,Copy,Debug)]
|
||||||
pub struct HashRequest<'a>{
|
pub struct HashRequest<'a>{
|
||||||
@@ -159,7 +145,7 @@ pub struct ScriptResponse{
|
|||||||
pub Hash:String,
|
pub Hash:String,
|
||||||
pub Source:String,
|
pub Source:String,
|
||||||
pub ResourceType:ResourceType,
|
pub ResourceType:ResourceType,
|
||||||
pub ResourceID:ResourceID,
|
pub ResourceID:i64,
|
||||||
}
|
}
|
||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
#[derive(Clone,Debug,serde::Serialize)]
|
#[derive(Clone,Debug,serde::Serialize)]
|
||||||
@@ -168,7 +154,7 @@ pub struct CreateScriptRequest<'a>{
|
|||||||
pub Source:&'a str,
|
pub Source:&'a str,
|
||||||
pub ResourceType:ResourceType,
|
pub ResourceType:ResourceType,
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
pub ResourceID:Option<ResourceID>,
|
pub ResourceID:Option<i64>,
|
||||||
}
|
}
|
||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
#[derive(Clone,Debug,serde::Deserialize)]
|
#[derive(Clone,Debug,serde::Deserialize)]
|
||||||
@@ -186,10 +172,6 @@ pub enum Policy{
|
|||||||
Replace=4,
|
Replace=4,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
|
||||||
pub struct GetScriptPolicyRequest{
|
|
||||||
pub ScriptPolicyID:ScriptPolicyID,
|
|
||||||
}
|
|
||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
#[derive(Clone,Debug,serde::Serialize)]
|
#[derive(Clone,Debug,serde::Serialize)]
|
||||||
pub struct GetScriptPoliciesRequest<'a>{
|
pub struct GetScriptPoliciesRequest<'a>{
|
||||||
@@ -238,160 +220,49 @@ pub struct UpdateScriptPolicyRequest{
|
|||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
#[derive(Clone,Debug)]
|
#[derive(Clone,Debug)]
|
||||||
pub struct UpdateSubmissionModelRequest{
|
pub struct UpdateSubmissionModelRequest{
|
||||||
pub SubmissionID:SubmissionID,
|
pub SubmissionID:i64,
|
||||||
pub ModelID:u64,
|
pub ModelID:u64,
|
||||||
pub ModelVersion:u64,
|
pub ModelVersion:u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone,Debug)]
|
|
||||||
pub enum Sort{
|
|
||||||
Disabled=0,
|
|
||||||
DisplayNameAscending=1,
|
|
||||||
DisplayNameDescending=2,
|
|
||||||
DateAscending=3,
|
|
||||||
DateDescending=4,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone,Debug,serde_repr::Deserialize_repr)]
|
|
||||||
#[repr(u8)]
|
|
||||||
pub enum SubmissionStatus{
|
|
||||||
// Phase: Creation
|
|
||||||
UnderConstruction=0,
|
|
||||||
ChangesRequested=1,
|
|
||||||
|
|
||||||
// Phase: Review
|
|
||||||
Submitting=2,
|
|
||||||
Submitted=3,
|
|
||||||
|
|
||||||
// Phase: Testing
|
|
||||||
AcceptedUnvalidated=4, // pending script review, can re-trigger validation
|
|
||||||
Validating=5,
|
|
||||||
Validated=6,
|
|
||||||
Uploading=7,
|
|
||||||
Uploaded=8, // uploaded to the group, but pending release
|
|
||||||
|
|
||||||
// Phase: Final SubmissionStatus
|
|
||||||
Rejected=9,
|
|
||||||
Released=10,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
|
||||||
#[derive(Clone,Debug)]
|
|
||||||
pub struct GetSubmissionsRequest<'a>{
|
|
||||||
pub Page:u32,
|
|
||||||
pub Limit:u32,
|
|
||||||
pub Sort:Option<Sort>,
|
|
||||||
pub DisplayName:Option<&'a str>,
|
|
||||||
pub Creator:Option<&'a str>,
|
|
||||||
pub GameID:Option<GameID>,
|
|
||||||
pub Submitter:Option<u64>,
|
|
||||||
pub AssetID:Option<u64>,
|
|
||||||
pub UploadedAssetID:Option<u64>,
|
|
||||||
pub StatusID:Option<SubmissionStatus>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
|
||||||
#[derive(Clone,Debug,serde::Deserialize)]
|
|
||||||
pub struct SubmissionResponse{
|
|
||||||
pub ID:SubmissionID,
|
|
||||||
pub DisplayName:String,
|
|
||||||
pub Creator:String,
|
|
||||||
pub GameID:GameID,
|
|
||||||
pub CreatedAt:i64,
|
|
||||||
pub UpdatedAt:i64,
|
|
||||||
pub Submitter:u64,
|
|
||||||
pub AssetID:u64,
|
|
||||||
pub AssetVersion:u64,
|
|
||||||
pub UploadedAssetID:u64,
|
|
||||||
pub StatusID:SubmissionStatus,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
|
||||||
#[derive(Clone,Debug,serde::Deserialize)]
|
|
||||||
pub struct SubmissionsResponse{
|
|
||||||
pub Total:u64,
|
|
||||||
pub Submissions:Vec<SubmissionResponse>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
|
||||||
#[derive(Clone,Debug)]
|
|
||||||
pub struct GetMapsRequest<'a>{
|
|
||||||
pub Page:u32,
|
|
||||||
pub Limit:u32,
|
|
||||||
pub Sort:Option<Sort>,
|
|
||||||
pub DisplayName:Option<&'a str>,
|
|
||||||
pub Creator:Option<&'a str>,
|
|
||||||
pub GameID:Option<GameID>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
|
||||||
#[derive(Clone,Debug,serde::Deserialize)]
|
|
||||||
pub struct MapResponse{
|
|
||||||
pub ID:i64,
|
|
||||||
pub DisplayName:String,
|
|
||||||
pub Creator:String,
|
|
||||||
pub GameID:GameID,
|
|
||||||
pub Date:i64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
|
||||||
#[derive(Clone,Debug,serde::Serialize)]
|
|
||||||
pub struct Check{
|
|
||||||
pub Name:&'static str,
|
|
||||||
pub Summary:String,
|
|
||||||
pub Passed:bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
#[derive(Clone,Debug)]
|
#[derive(Clone,Debug)]
|
||||||
pub struct ActionSubmissionSubmittedRequest{
|
pub struct ActionSubmissionSubmittedRequest{
|
||||||
pub SubmissionID:SubmissionID,
|
pub SubmissionID:i64,
|
||||||
pub ModelVersion:u64,
|
pub ModelVersion:u64,
|
||||||
pub DisplayName:String,
|
pub DisplayName:String,
|
||||||
pub Creator:String,
|
pub Creator:String,
|
||||||
pub GameID:GameID,
|
pub GameID:u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
#[derive(Clone,Debug)]
|
#[derive(Clone,Debug)]
|
||||||
pub struct ActionSubmissionRequestChangesRequest{
|
pub struct ActionSubmissionRequestChangesRequest{
|
||||||
pub SubmissionID:SubmissionID,
|
pub SubmissionID:i64,
|
||||||
|
pub ErrorMessage:String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
#[derive(Clone,Debug)]
|
#[derive(Clone,Debug)]
|
||||||
pub struct ActionSubmissionUploadedRequest{
|
pub struct ActionSubmissionUploadedRequest{
|
||||||
pub SubmissionID:SubmissionID,
|
pub SubmissionID:i64,
|
||||||
pub UploadedAssetID:u64,
|
pub UploadedAssetID:u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
#[derive(Clone,Debug)]
|
#[derive(Clone,Debug)]
|
||||||
pub struct ActionSubmissionAcceptedRequest{
|
pub struct ActionSubmissionAcceptedRequest{
|
||||||
pub SubmissionID:SubmissionID,
|
pub SubmissionID:i64,
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
|
||||||
#[derive(Clone,Debug)]
|
|
||||||
pub struct CreateSubmissionAuditErrorRequest{
|
|
||||||
pub SubmissionID:SubmissionID,
|
|
||||||
pub ErrorMessage:String,
|
pub ErrorMessage:String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
#[derive(Clone,Copy,Debug,serde::Deserialize)]
|
||||||
#[derive(Clone,Debug)]
|
pub struct SubmissionID(pub i64);
|
||||||
pub struct CreateSubmissionAuditCheckListRequest<'a>{
|
|
||||||
pub SubmissionID:SubmissionID,
|
|
||||||
pub CheckList:&'a [Check],
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone,Copy,Debug,Hash,Eq,PartialEq,serde::Serialize,serde::Deserialize)]
|
|
||||||
pub struct SubmissionID(pub(crate)i64);
|
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
#[derive(Clone,Debug)]
|
#[derive(Clone,Debug)]
|
||||||
pub struct UpdateMapfixModelRequest{
|
pub struct UpdateMapfixModelRequest{
|
||||||
pub MapfixID:MapfixID,
|
pub MapfixID:i64,
|
||||||
pub ModelID:u64,
|
pub ModelID:u64,
|
||||||
pub ModelVersion:u64,
|
pub ModelVersion:u64,
|
||||||
}
|
}
|
||||||
@@ -399,82 +270,39 @@ pub struct UpdateMapfixModelRequest{
|
|||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
#[derive(Clone,Debug)]
|
#[derive(Clone,Debug)]
|
||||||
pub struct ActionMapfixSubmittedRequest{
|
pub struct ActionMapfixSubmittedRequest{
|
||||||
pub MapfixID:MapfixID,
|
pub MapfixID:i64,
|
||||||
pub ModelVersion:u64,
|
pub ModelVersion:u64,
|
||||||
pub DisplayName:String,
|
pub DisplayName:String,
|
||||||
pub Creator:String,
|
pub Creator:String,
|
||||||
pub GameID:GameID,
|
pub GameID:u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
#[derive(Clone,Debug)]
|
#[derive(Clone,Debug)]
|
||||||
pub struct ActionMapfixRequestChangesRequest{
|
pub struct ActionMapfixRequestChangesRequest{
|
||||||
pub MapfixID:MapfixID,
|
pub MapfixID:i64,
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
|
||||||
#[derive(Clone,Debug)]
|
|
||||||
pub struct ActionMapfixUploadedRequest{
|
|
||||||
pub MapfixID:MapfixID,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
|
||||||
#[derive(Clone,Debug)]
|
|
||||||
pub struct ActionMapfixAcceptedRequest{
|
|
||||||
pub MapfixID:MapfixID,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
|
||||||
#[derive(Clone,Debug)]
|
|
||||||
pub struct CreateMapfixAuditErrorRequest{
|
|
||||||
pub MapfixID:MapfixID,
|
|
||||||
pub ErrorMessage:String,
|
pub ErrorMessage:String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
#[derive(Clone,Debug)]
|
#[derive(Clone,Debug)]
|
||||||
pub struct CreateMapfixAuditCheckListRequest<'a>{
|
pub struct ActionMapfixUploadedRequest{
|
||||||
pub MapfixID:MapfixID,
|
pub MapfixID:i64,
|
||||||
pub CheckList:&'a [Check],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone,Copy,Debug,Hash,Eq,PartialEq,serde::Serialize,serde::Deserialize)]
|
#[allow(nonstandard_style)]
|
||||||
pub struct MapfixID(pub(crate)i64);
|
#[derive(Clone,Debug)]
|
||||||
|
pub struct ActionMapfixAcceptedRequest{
|
||||||
|
pub MapfixID:i64,
|
||||||
|
pub ErrorMessage:String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone,Copy,Debug,serde::Deserialize)]
|
||||||
|
pub struct MapfixID(pub i64);
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
#[derive(Clone,Debug)]
|
#[derive(Clone,Debug)]
|
||||||
pub struct ActionOperationFailedRequest{
|
pub struct ActionOperationFailedRequest{
|
||||||
pub OperationID:OperationID,
|
pub OperationID:i32,
|
||||||
pub StatusMessage:String,
|
pub StatusMessage:String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone,Copy,Debug,Hash,Eq,PartialEq,serde::Serialize,serde::Deserialize)]
|
|
||||||
pub struct OperationID(pub(crate)i64);
|
|
||||||
|
|
||||||
#[derive(Clone,Copy,Debug,Hash,Eq,PartialEq,serde::Serialize,serde::Deserialize)]
|
|
||||||
pub struct ResourceID(pub(crate)i64);
|
|
||||||
|
|
||||||
#[derive(Clone,Copy,Debug)]
|
|
||||||
pub enum Resource{
|
|
||||||
Submission(SubmissionID),
|
|
||||||
Mapfix(MapfixID),
|
|
||||||
}
|
|
||||||
impl Resource{
|
|
||||||
pub fn split(self)->(ResourceType,ResourceID){
|
|
||||||
match self{
|
|
||||||
Resource::Mapfix(MapfixID(mapfix_id))=>(ResourceType::Mapfix,ResourceID(mapfix_id)),
|
|
||||||
Resource::Submission(SubmissionID(submission_id))=>(ResourceType::Submission,ResourceID(submission_id)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(nonstandard_style)]
|
|
||||||
#[derive(Clone,Debug,serde::Serialize)]
|
|
||||||
pub struct ReleaseInfo{
|
|
||||||
pub SubmissionID:SubmissionID,
|
|
||||||
pub Date:chrono::DateTime<chrono::Utc>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ReleaseRequest<'a>{
|
|
||||||
pub schedule:&'a [ReleaseInfo],
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
use std::collections::{HashSet,HashMap};
|
use std::collections::{HashSet,HashMap};
|
||||||
use crate::download::download_asset_version;
|
use crate::download::download_asset_version;
|
||||||
use crate::rbx_util::{get_mapinfo,get_root_instance,read_dom,ReadDomError,GameID,ParseGameIDError,MapInfo,GetRootInstanceError,StringValueError};
|
use crate::rbx_util::{class_is_a,get_mapinfo,get_root_instance,read_dom,ReadDomError,GameID,ParseGameIDError,MapInfo,GetRootInstanceError,StringValueError};
|
||||||
|
|
||||||
use heck::{ToSnakeCase,ToTitleCase};
|
use heck::{ToSnakeCase,ToTitleCase};
|
||||||
use rbx_dom_weak::Instance;
|
|
||||||
use rust_grpc::validator::Check;
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -14,8 +12,6 @@ pub enum Error{
|
|||||||
Download(crate::download::Error),
|
Download(crate::download::Error),
|
||||||
ModelFileDecode(ReadDomError),
|
ModelFileDecode(ReadDomError),
|
||||||
GetRootInstance(GetRootInstanceError),
|
GetRootInstance(GetRootInstanceError),
|
||||||
IntoMapInfoOwned(IntoMapInfoOwnedError),
|
|
||||||
ToJsonValue(serde_json::Error),
|
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for Error{
|
impl std::fmt::Display for Error{
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
@@ -26,15 +22,13 @@ impl std::error::Error for Error{}
|
|||||||
|
|
||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
pub struct CheckRequest{
|
pub struct CheckRequest{
|
||||||
ModelID:u64,
|
pub ModelID:u64,
|
||||||
SkipChecks:bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<crate::nats_types::CheckMapfixRequest> for CheckRequest{
|
impl From<crate::nats_types::CheckMapfixRequest> for CheckRequest{
|
||||||
fn from(value:crate::nats_types::CheckMapfixRequest)->Self{
|
fn from(value:crate::nats_types::CheckMapfixRequest)->Self{
|
||||||
Self{
|
Self{
|
||||||
ModelID:value.ModelID,
|
ModelID:value.ModelID,
|
||||||
SkipChecks:value.SkipChecks,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,7 +36,6 @@ impl From<crate::nats_types::CheckSubmissionRequest> for CheckRequest{
|
|||||||
fn from(value:crate::nats_types::CheckSubmissionRequest)->Self{
|
fn from(value:crate::nats_types::CheckSubmissionRequest)->Self{
|
||||||
Self{
|
Self{
|
||||||
ModelID:value.ModelID,
|
ModelID:value.ModelID,
|
||||||
SkipChecks:value.SkipChecks,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,166 +47,98 @@ impl ModeID{
|
|||||||
const BONUS:Self=Self(1);
|
const BONUS:Self=Self(1);
|
||||||
}
|
}
|
||||||
enum Zone{
|
enum Zone{
|
||||||
Start,
|
Start(ModeID),
|
||||||
Finish,
|
Finish(ModeID),
|
||||||
Anticheat,
|
Anticheat(ModeID),
|
||||||
}
|
|
||||||
struct ModeElement{
|
|
||||||
zone:Zone,
|
|
||||||
mode_id:ModeID,
|
|
||||||
}
|
}
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub enum IDParseError{
|
pub enum IDParseError{
|
||||||
NoCaptures,
|
NoCaptures,
|
||||||
ParseInt(core::num::ParseIntError),
|
ParseInt(core::num::ParseIntError)
|
||||||
}
|
}
|
||||||
// Parse a Zone from a part name
|
impl std::str::FromStr for Zone{
|
||||||
impl std::str::FromStr for ModeElement{
|
|
||||||
type Err=IDParseError;
|
type Err=IDParseError;
|
||||||
fn from_str(s:&str)->Result<Self,Self::Err>{
|
fn from_str(s:&str)->Result<Self,Self::Err>{
|
||||||
match s{
|
match s{
|
||||||
"MapStart"=>Ok(Self{zone:Zone::Start,mode_id:ModeID::MAIN}),
|
"MapStart"=>Ok(Self::Start(ModeID::MAIN)),
|
||||||
"MapFinish"=>Ok(Self{zone:Zone::Finish,mode_id:ModeID::MAIN}),
|
"MapFinish"=>Ok(Self::Finish(ModeID::MAIN)),
|
||||||
"MapAnticheat"=>Ok(Self{zone:Zone::Anticheat,mode_id:ModeID::MAIN}),
|
"MapAnticheat"=>Ok(Self::Anticheat(ModeID::MAIN)),
|
||||||
"BonusStart"=>Ok(Self{zone:Zone::Start,mode_id:ModeID::BONUS}),
|
"BonusStart"=>Ok(Self::Start(ModeID::BONUS)),
|
||||||
"BonusFinish"=>Ok(Self{zone:Zone::Finish,mode_id:ModeID::BONUS}),
|
"BonusFinish"=>Ok(Self::Finish(ModeID::BONUS)),
|
||||||
"BonusAnticheat"=>Ok(Self{zone:Zone::Anticheat,mode_id:ModeID::BONUS}),
|
"BonusAnticheat"=>Ok(Self::Anticheat(ModeID::BONUS)),
|
||||||
other=>{
|
other=>{
|
||||||
let everything_pattern=lazy_regex::lazy_regex!(r"^Bonus(\d+)Start$|^BonusStart(\d+)$|^Bonus(\d+)Finish$|^BonusFinish(\d+)$|^Bonus(\d+)Anticheat$|^BonusAnticheat(\d+)$");
|
let bonus_start_pattern=lazy_regex::lazy_regex!(r"^Bonus(\d+)Start$|^BonusStart(\d+)$");
|
||||||
if let Some(captures)=everything_pattern.captures(other){
|
if let Some(captures)=bonus_start_pattern.captures(other){
|
||||||
if let Some(mode_id)=captures.get(1).or(captures.get(2)){
|
return Ok(Self::Start(ModeID(captures[1].parse().map_err(IDParseError::ParseInt)?)));
|
||||||
return Ok(Self{
|
}
|
||||||
zone:Zone::Start,
|
let bonus_finish_pattern=lazy_regex::lazy_regex!(r"^Bonus(\d+)Finish$|^BonusFinish(\d+)$");
|
||||||
mode_id:ModeID(mode_id.as_str().parse().map_err(IDParseError::ParseInt)?),
|
if let Some(captures)=bonus_finish_pattern.captures(other){
|
||||||
});
|
return Ok(Self::Finish(ModeID(captures[1].parse().map_err(IDParseError::ParseInt)?)));
|
||||||
}
|
}
|
||||||
if let Some(mode_id)=captures.get(3).or(captures.get(4)){
|
let bonus_finish_pattern=lazy_regex::lazy_regex!(r"^Bonus(\d+)Anticheat$|^BonusAnticheat(\d+)$");
|
||||||
return Ok(Self{
|
if let Some(captures)=bonus_finish_pattern.captures(other){
|
||||||
zone:Zone::Finish,
|
return Ok(Self::Anticheat(ModeID(captures[1].parse().map_err(IDParseError::ParseInt)?)));
|
||||||
mode_id:ModeID(mode_id.as_str().parse().map_err(IDParseError::ParseInt)?),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if let Some(mode_id)=captures.get(5).or(captures.get(6)){
|
|
||||||
return Ok(Self{
|
|
||||||
zone:Zone::Anticheat,
|
|
||||||
mode_id:ModeID(mode_id.as_str().parse().map_err(IDParseError::ParseInt)?),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(IDParseError::NoCaptures)
|
Err(IDParseError::NoCaptures)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for ModeElement{
|
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
|
||||||
match self{
|
|
||||||
ModeElement{zone:Zone::Start,mode_id:ModeID::MAIN}=>write!(f,"MapStart"),
|
|
||||||
ModeElement{zone:Zone::Start,mode_id:ModeID::BONUS}=>write!(f,"BonusStart"),
|
|
||||||
ModeElement{zone:Zone::Start,mode_id:ModeID(mode_id)}=>write!(f,"Bonus{mode_id}Start"),
|
|
||||||
ModeElement{zone:Zone::Finish,mode_id:ModeID::MAIN}=>write!(f,"MapFinish"),
|
|
||||||
ModeElement{zone:Zone::Finish,mode_id:ModeID::BONUS}=>write!(f,"BonusFinish"),
|
|
||||||
ModeElement{zone:Zone::Finish,mode_id:ModeID(mode_id)}=>write!(f,"Bonus{mode_id}Finish"),
|
|
||||||
ModeElement{zone:Zone::Anticheat,mode_id:ModeID::MAIN}=>write!(f,"MapAnticheat"),
|
|
||||||
ModeElement{zone:Zone::Anticheat,mode_id:ModeID::BONUS}=>write!(f,"BonusAnticheat"),
|
|
||||||
ModeElement{zone:Zone::Anticheat,mode_id:ModeID(mode_id)}=>write!(f,"Bonus{mode_id}Anticheat"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone,Copy,Debug,Hash,Eq,PartialEq)]
|
#[derive(Clone,Copy,Debug,Hash,Eq,PartialEq)]
|
||||||
struct StageID(u64);
|
struct SpawnID(u64);
|
||||||
impl StageID{
|
impl SpawnID{
|
||||||
const FIRST:Self=Self(1);
|
const FIRST:Self=Self(1);
|
||||||
}
|
}
|
||||||
enum StageElementBehaviour{
|
enum SpawnTeleport{
|
||||||
Teleport,
|
Teleport(SpawnID),
|
||||||
Spawn,
|
Spawn(SpawnID),
|
||||||
}
|
}
|
||||||
struct StageElement{
|
impl std::str::FromStr for SpawnTeleport{
|
||||||
stage_id:StageID,
|
|
||||||
behaviour:StageElementBehaviour,
|
|
||||||
}
|
|
||||||
// Parse a SpawnTeleport from a part name
|
|
||||||
impl std::str::FromStr for StageElement{
|
|
||||||
type Err=IDParseError;
|
type Err=IDParseError;
|
||||||
fn from_str(s:&str)->Result<Self,Self::Err>{
|
fn from_str(s:&str)->Result<Self,Self::Err>{
|
||||||
// Trigger ForceTrigger Teleport ForceTeleport SpawnAt ForceSpawnAt
|
// Trigger ForceTrigger Teleport ForceTeleport SpawnAt ForceSpawnAt
|
||||||
let bonus_start_pattern=lazy_regex::lazy_regex!(r"^(?:Force)?(Teleport|SpawnAt|Trigger)(\d+)$");
|
let bonus_start_pattern=lazy_regex::lazy_regex!(r"^(?:Force)?(Teleport|SpawnAt|Trigger)(\d+)$");
|
||||||
if let Some(captures)=bonus_start_pattern.captures(s){
|
if let Some(captures)=bonus_start_pattern.captures(s){
|
||||||
return Ok(StageElement{
|
return Ok(Self::Teleport(SpawnID(captures[1].parse().map_err(IDParseError::ParseInt)?)));
|
||||||
behaviour:StageElementBehaviour::Teleport,
|
|
||||||
stage_id:StageID(captures[1].parse().map_err(IDParseError::ParseInt)?),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// Spawn
|
// Spawn
|
||||||
let bonus_finish_pattern=lazy_regex::lazy_regex!(r"^Spawn(\d+)$");
|
let bonus_finish_pattern=lazy_regex::lazy_regex!(r"^Spawn(\d+)$");
|
||||||
if let Some(captures)=bonus_finish_pattern.captures(s){
|
if let Some(captures)=bonus_finish_pattern.captures(s){
|
||||||
return Ok(StageElement{
|
return Ok(Self::Spawn(SpawnID(captures[1].parse().map_err(IDParseError::ParseInt)?)));
|
||||||
behaviour:StageElementBehaviour::Spawn,
|
|
||||||
stage_id:StageID(captures[1].parse().map_err(IDParseError::ParseInt)?),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Err(IDParseError::NoCaptures)
|
Err(IDParseError::NoCaptures)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for StageElement{
|
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
|
||||||
match self{
|
|
||||||
StageElement{behaviour:StageElementBehaviour::Spawn,stage_id:StageID(stage_id)}=>write!(f,"Spawn{stage_id}"),
|
|
||||||
StageElement{behaviour:StageElementBehaviour::Teleport,stage_id:StageID(stage_id)}=>write!(f,"Teleport{stage_id}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone,Copy,Debug,Hash,Eq,PartialEq)]
|
#[derive(Clone,Copy,Debug,Hash,Eq,PartialEq)]
|
||||||
struct WormholeID(u64);
|
struct WormholeID(u64);
|
||||||
enum WormholeBehaviour{
|
enum Wormhole{
|
||||||
In,
|
In(WormholeID),
|
||||||
Out,
|
Out(WormholeID),
|
||||||
}
|
}
|
||||||
struct WormholeElement{
|
impl std::str::FromStr for Wormhole{
|
||||||
behaviour:WormholeBehaviour,
|
|
||||||
wormhole_id:WormholeID,
|
|
||||||
}
|
|
||||||
// Parse a Wormhole from a part name
|
|
||||||
impl std::str::FromStr for WormholeElement{
|
|
||||||
type Err=IDParseError;
|
type Err=IDParseError;
|
||||||
fn from_str(s:&str)->Result<Self,Self::Err>{
|
fn from_str(s:&str)->Result<Self,Self::Err>{
|
||||||
let bonus_start_pattern=lazy_regex::lazy_regex!(r"^WormholeIn(\d+)$");
|
let bonus_start_pattern=lazy_regex::lazy_regex!(r"^WormholeIn(\d+)$");
|
||||||
if let Some(captures)=bonus_start_pattern.captures(s){
|
if let Some(captures)=bonus_start_pattern.captures(s){
|
||||||
return Ok(Self{
|
return Ok(Self::In(WormholeID(captures[1].parse().map_err(IDParseError::ParseInt)?)));
|
||||||
behaviour:WormholeBehaviour::In,
|
|
||||||
wormhole_id:WormholeID(captures[1].parse().map_err(IDParseError::ParseInt)?),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
let bonus_finish_pattern=lazy_regex::lazy_regex!(r"^WormholeOut(\d+)$");
|
let bonus_finish_pattern=lazy_regex::lazy_regex!(r"^WormholeOut(\d+)$");
|
||||||
if let Some(captures)=bonus_finish_pattern.captures(s){
|
if let Some(captures)=bonus_finish_pattern.captures(s){
|
||||||
return Ok(Self{
|
return Ok(Self::Out(WormholeID(captures[1].parse().map_err(IDParseError::ParseInt)?)));
|
||||||
behaviour:WormholeBehaviour::Out,
|
|
||||||
wormhole_id:WormholeID(captures[1].parse().map_err(IDParseError::ParseInt)?),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
Err(IDParseError::NoCaptures)
|
Err(IDParseError::NoCaptures)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for WormholeElement{
|
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
|
||||||
match self{
|
|
||||||
WormholeElement{behaviour:WormholeBehaviour::In,wormhole_id:WormholeID(wormhole_id)}=>write!(f,"WormholeIn{wormhole_id}"),
|
|
||||||
WormholeElement{behaviour:WormholeBehaviour::Out,wormhole_id:WormholeID(wormhole_id)}=>write!(f,"WormholeOut{wormhole_id}"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Count various map elements
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Counts<'a>{
|
struct Counts<'a>{
|
||||||
mode_start_counts:HashMap<ModeID,Vec<&'a Instance>>,
|
mode_start_counts:HashMap<ModeID,Vec<&'a str>>,
|
||||||
mode_finish_counts:HashMap<ModeID,Vec<&'a Instance>>,
|
mode_finish_counts:HashMap<ModeID,Vec<&'a str>>,
|
||||||
mode_anticheat_counts:HashMap<ModeID,Vec<&'a Instance>>,
|
mode_anticheat_counts:HashMap<ModeID,Vec<&'a str>>,
|
||||||
teleport_counts:HashMap<StageID,Vec<&'a Instance>>,
|
teleport_counts:HashMap<SpawnID,Vec<&'a str>>,
|
||||||
spawn_counts:HashMap<StageID,u64>,
|
spawn_counts:HashMap<SpawnID,u64>,
|
||||||
wormhole_in_counts:HashMap<WormholeID,u64>,
|
wormhole_in_counts:HashMap<WormholeID,u64>,
|
||||||
wormhole_out_counts:HashMap<WormholeID,u64>,
|
wormhole_out_counts:HashMap<WormholeID,u64>,
|
||||||
}
|
}
|
||||||
@@ -223,50 +148,35 @@ pub struct ModelInfo<'a>{
|
|||||||
model_name:&'a str,
|
model_name:&'a str,
|
||||||
map_info:MapInfo<'a>,
|
map_info:MapInfo<'a>,
|
||||||
counts:Counts<'a>,
|
counts:Counts<'a>,
|
||||||
unanchored_parts:Vec<&'a Instance>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_model_info<'a>(dom:&'a rbx_dom_weak::WeakDom,model_instance:&'a rbx_dom_weak::Instance)->ModelInfo<'a>{
|
pub fn get_model_info<'a>(dom:&'a rbx_dom_weak::WeakDom,model_instance:&'a rbx_dom_weak::Instance)->ModelInfo<'a>{
|
||||||
// extract model info
|
// extract model info
|
||||||
let map_info=get_mapinfo(dom,model_instance);
|
let map_info=get_mapinfo(&dom,model_instance);
|
||||||
|
|
||||||
// count objects (default count is 0)
|
// count objects (default count is 0)
|
||||||
let mut counts=Counts::default();
|
let mut counts=Counts::default();
|
||||||
|
for instance in dom.descendants_of(model_instance.referent()){
|
||||||
// locate unanchored parts
|
if class_is_a(instance.class.as_str(),"BasePart"){
|
||||||
let mut unanchored_parts=Vec::new();
|
// Zones
|
||||||
let anchored_ustr=rbx_dom_weak::ustr("Anchored");
|
match instance.name.parse(){
|
||||||
|
Ok(Zone::Start(mode_id))=>counts.mode_start_counts.entry(mode_id).or_default().push(instance.name.as_str()),
|
||||||
let db=rbx_reflection_database::get();
|
Ok(Zone::Finish(mode_id))=>counts.mode_finish_counts.entry(mode_id).or_default().push(instance.name.as_str()),
|
||||||
let base_part=&db.classes["BasePart"];
|
Ok(Zone::Anticheat(mode_id))=>counts.mode_anticheat_counts.entry(mode_id).or_default().push(instance.name.as_str()),
|
||||||
let base_parts=dom.descendants_of(model_instance.referent()).filter(|&instance|
|
Err(_)=>(),
|
||||||
db.classes.get(instance.class.as_str()).is_some_and(|class|
|
}
|
||||||
db.has_superclass(class,base_part)
|
// Spawns & Teleports
|
||||||
)
|
match instance.name.parse(){
|
||||||
);
|
Ok(SpawnTeleport::Teleport(spawn_id))=>counts.teleport_counts.entry(spawn_id).or_default().push(instance.name.as_str()),
|
||||||
for instance in base_parts{
|
Ok(SpawnTeleport::Spawn(spawn_id))=>*counts.spawn_counts.entry(spawn_id).or_insert(0)+=1,
|
||||||
// Zones
|
Err(_)=>(),
|
||||||
match instance.name.parse(){
|
}
|
||||||
Ok(ModeElement{zone:Zone::Start,mode_id})=>counts.mode_start_counts.entry(mode_id).or_default().push(instance),
|
// Wormholes
|
||||||
Ok(ModeElement{zone:Zone::Finish,mode_id})=>counts.mode_finish_counts.entry(mode_id).or_default().push(instance),
|
match instance.name.parse(){
|
||||||
Ok(ModeElement{zone:Zone::Anticheat,mode_id})=>counts.mode_anticheat_counts.entry(mode_id).or_default().push(instance),
|
Ok(Wormhole::In(wormhole_id))=>*counts.wormhole_in_counts.entry(wormhole_id).or_insert(0)+=1,
|
||||||
Err(_)=>(),
|
Ok(Wormhole::Out(wormhole_id))=>*counts.wormhole_out_counts.entry(wormhole_id).or_insert(0)+=1,
|
||||||
}
|
Err(_)=>(),
|
||||||
// Spawns & Teleports
|
}
|
||||||
match instance.name.parse(){
|
|
||||||
Ok(StageElement{behaviour:StageElementBehaviour::Teleport,stage_id})=>counts.teleport_counts.entry(stage_id).or_default().push(instance),
|
|
||||||
Ok(StageElement{behaviour:StageElementBehaviour::Spawn,stage_id})=>*counts.spawn_counts.entry(stage_id).or_insert(0)+=1,
|
|
||||||
Err(_)=>(),
|
|
||||||
}
|
|
||||||
// Wormholes
|
|
||||||
match instance.name.parse(){
|
|
||||||
Ok(WormholeElement{behaviour:WormholeBehaviour::In,wormhole_id})=>*counts.wormhole_in_counts.entry(wormhole_id).or_insert(0)+=1,
|
|
||||||
Ok(WormholeElement{behaviour:WormholeBehaviour::Out,wormhole_id})=>*counts.wormhole_out_counts.entry(wormhole_id).or_insert(0)+=1,
|
|
||||||
Err(_)=>(),
|
|
||||||
}
|
|
||||||
// Unanchored parts
|
|
||||||
if let Some(rbx_dom_weak::types::Variant::Bool(false))=instance.properties.get(&anchored_ustr){
|
|
||||||
unanchored_parts.push(instance);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +185,6 @@ pub fn get_model_info<'a>(dom:&'a rbx_dom_weak::WeakDom,model_instance:&'a rbx_d
|
|||||||
model_name:model_instance.name.as_str(),
|
model_name:model_instance.name.as_str(),
|
||||||
map_info,
|
map_info,
|
||||||
counts,
|
counts,
|
||||||
unanchored_parts,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +198,6 @@ impl<'a,Str> StringCheckContext<'a,Str>
|
|||||||
where
|
where
|
||||||
&'a str:PartialEq<Str>,
|
&'a str:PartialEq<Str>,
|
||||||
{
|
{
|
||||||
/// Compute the StringCheck, passing through the provided value on success.
|
|
||||||
fn check<T>(self,value:T)->StringCheck<'a,T,Str>{
|
fn check<T>(self,value:T)->StringCheck<'a,T,Str>{
|
||||||
if self.observed==self.expected{
|
if self.observed==self.expected{
|
||||||
StringCheck(Ok(value))
|
StringCheck(Ok(value))
|
||||||
@@ -298,7 +206,7 @@ impl<'a,Str> StringCheckContext<'a,Str>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<Str:std::fmt::Display> std::fmt::Display for StringCheckContext<'_,Str>{
|
impl<'a,Str:std::fmt::Display> std::fmt::Display for StringCheckContext<'a,Str>{
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
write!(f,"expected: {}, observed: {}",self.expected,self.observed)
|
write!(f,"expected: {}, observed: {}",self.expected,self.observed)
|
||||||
}
|
}
|
||||||
@@ -319,7 +227,6 @@ fn check_empty(value:&str)->Result<&str,StringEmpty>{
|
|||||||
pub struct DuplicateCheckContext<ID,T>(HashMap<ID,T>);
|
pub struct DuplicateCheckContext<ID,T>(HashMap<ID,T>);
|
||||||
pub struct DuplicateCheck<ID,T>(Result<(),DuplicateCheckContext<ID,T>>);
|
pub struct DuplicateCheck<ID,T>(Result<(),DuplicateCheckContext<ID,T>>);
|
||||||
impl<ID,T> DuplicateCheckContext<ID,T>{
|
impl<ID,T> DuplicateCheckContext<ID,T>{
|
||||||
/// Compute the DuplicateCheck using the contents predicate.
|
|
||||||
fn check(self,f:impl Fn(&T)->bool)->DuplicateCheck<ID,T>{
|
fn check(self,f:impl Fn(&T)->bool)->DuplicateCheck<ID,T>{
|
||||||
let Self(mut set)=self;
|
let Self(mut set)=self;
|
||||||
// remove correct entries
|
// remove correct entries
|
||||||
@@ -333,11 +240,10 @@ impl<ID,T> DuplicateCheckContext<ID,T>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that there are no items which do not have a matching item in a reference set
|
// check that there is at least one matching item for each item in a reference set, and no extra items
|
||||||
pub struct SetDifferenceCheckContextAllowNone<ID,T>{
|
pub struct SetDifferenceCheckContextAllowNone<ID,T>{
|
||||||
extra:HashMap<ID,T>,
|
extra:HashMap<ID,T>,
|
||||||
}
|
}
|
||||||
// Check that there is at least one matching item for each item in a reference set, and no extra items
|
|
||||||
pub struct SetDifferenceCheckContextAtLeastOne<ID,T>{
|
pub struct SetDifferenceCheckContextAtLeastOne<ID,T>{
|
||||||
extra:HashMap<ID,T>,
|
extra:HashMap<ID,T>,
|
||||||
missing:HashSet<ID>,
|
missing:HashSet<ID>,
|
||||||
@@ -351,10 +257,9 @@ impl<ID,T> SetDifferenceCheckContextAllowNone<ID,T>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<ID:Eq+std::hash::Hash,T> SetDifferenceCheckContextAllowNone<ID,T>{
|
impl<ID:Eq+std::hash::Hash,T> SetDifferenceCheckContextAllowNone<ID,T>{
|
||||||
/// Compute the SetDifferenceCheck result for the specified reference set.
|
|
||||||
fn check<U>(mut self,reference_set:&HashMap<ID,U>)->SetDifferenceCheck<Self>{
|
fn check<U>(mut self,reference_set:&HashMap<ID,U>)->SetDifferenceCheck<Self>{
|
||||||
// remove correct entries
|
// remove correct entries
|
||||||
for id in reference_set.keys(){
|
for (id,_) in reference_set{
|
||||||
self.extra.remove(id);
|
self.extra.remove(id);
|
||||||
}
|
}
|
||||||
// if any entries remain, they are incorrect
|
// if any entries remain, they are incorrect
|
||||||
@@ -374,10 +279,9 @@ impl<ID,T> SetDifferenceCheckContextAtLeastOne<ID,T>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<ID:Copy+Eq+std::hash::Hash,T> SetDifferenceCheckContextAtLeastOne<ID,T>{
|
impl<ID:Copy+Eq+std::hash::Hash,T> SetDifferenceCheckContextAtLeastOne<ID,T>{
|
||||||
/// Compute the SetDifferenceCheck result for the specified reference set.
|
|
||||||
fn check<U>(mut self,reference_set:&HashMap<ID,U>)->SetDifferenceCheck<Self>{
|
fn check<U>(mut self,reference_set:&HashMap<ID,U>)->SetDifferenceCheck<Self>{
|
||||||
// remove correct entries
|
// remove correct entries
|
||||||
for id in reference_set.keys(){
|
for (id,_) in reference_set{
|
||||||
if self.extra.remove(id).is_none(){
|
if self.extra.remove(id).is_none(){
|
||||||
// the set did not contain a required item. This is a fail
|
// the set did not contain a required item. This is a fail
|
||||||
self.missing.insert(*id);
|
self.missing.insert(*id);
|
||||||
@@ -392,36 +296,14 @@ impl<ID:Copy+Eq+std::hash::Hash,T> SetDifferenceCheckContextAtLeastOne<ID,T>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Info lifted out of a fully compliant map
|
|
||||||
pub struct MapInfoOwned{
|
pub struct MapInfoOwned{
|
||||||
pub display_name:String,
|
pub display_name:String,
|
||||||
pub creator:String,
|
pub creator:String,
|
||||||
pub game_id:GameID,
|
pub game_id:GameID,
|
||||||
}
|
}
|
||||||
#[allow(dead_code)]
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum IntoMapInfoOwnedError{
|
|
||||||
DisplayName(StringValueError),
|
|
||||||
Creator(StringValueError),
|
|
||||||
GameID(ParseGameIDError),
|
|
||||||
}
|
|
||||||
impl TryFrom<MapInfo<'_>> for MapInfoOwned{
|
|
||||||
type Error=IntoMapInfoOwnedError;
|
|
||||||
fn try_from(value:MapInfo<'_>)->Result<Self,Self::Error>{
|
|
||||||
Ok(Self{
|
|
||||||
display_name:value.display_name.map_err(IntoMapInfoOwnedError::DisplayName)?.to_owned(),
|
|
||||||
creator:value.creator.map_err(IntoMapInfoOwnedError::Creator)?.to_owned(),
|
|
||||||
game_id:value.game_id.map_err(IntoMapInfoOwnedError::GameID)?,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Named dummy types for readability
|
// crazy!
|
||||||
struct Exists;
|
pub struct MapCheck<'a>{
|
||||||
struct Absent;
|
|
||||||
|
|
||||||
/// The result of every map check.
|
|
||||||
struct MapCheck<'a>{
|
|
||||||
// === METADATA CHECKS ===
|
// === METADATA CHECKS ===
|
||||||
// The root must be of class Model
|
// The root must be of class Model
|
||||||
model_class:StringCheck<'a,(),&'static str>,
|
model_class:StringCheck<'a,(),&'static str>,
|
||||||
@@ -439,27 +321,24 @@ struct MapCheck<'a>{
|
|||||||
|
|
||||||
// === MODE CHECKS ===
|
// === MODE CHECKS ===
|
||||||
// MapStart must exist
|
// MapStart must exist
|
||||||
mapstart:Result<Exists,Absent>,
|
mapstart:Result<(),()>,
|
||||||
// No duplicate map starts (including bonuses)
|
// No duplicate map starts (including bonuses)
|
||||||
mode_start_counts:DuplicateCheck<ModeID,Vec<&'a Instance>>,
|
mode_start_counts:DuplicateCheck<ModeID,Vec<&'a str>>,
|
||||||
// At least one finish zone for each start zone, and no finishes with no start
|
// At least one finish zone for each start zone, and no finishes with no start
|
||||||
mode_finish_counts:SetDifferenceCheck<SetDifferenceCheckContextAtLeastOne<ModeID,Vec<&'a Instance>>>,
|
mode_finish_counts:SetDifferenceCheck<SetDifferenceCheckContextAtLeastOne<ModeID,Vec<&'a str>>>,
|
||||||
// Check for dangling MapAnticheat zones (no associated MapStart)
|
// Check for dangling MapAnticheat zones (no associated MapStart)
|
||||||
mode_anticheat_counts:SetDifferenceCheck<SetDifferenceCheckContextAllowNone<ModeID,Vec<&'a Instance>>>,
|
mode_anticheat_counts:SetDifferenceCheck<SetDifferenceCheckContextAllowNone<ModeID,Vec<&'a str>>>,
|
||||||
// Spawn1 must exist
|
// Spawn1 must exist
|
||||||
spawn1:Result<Exists,Absent>,
|
spawn1:Result<(),()>,
|
||||||
// Check for dangling Teleport# (no associated Spawn#)
|
// Check for dangling Teleport# (no associated Spawn#)
|
||||||
teleport_counts:SetDifferenceCheck<SetDifferenceCheckContextAllowNone<StageID,Vec<&'a Instance>>>,
|
teleport_counts:SetDifferenceCheck<SetDifferenceCheckContextAllowNone<SpawnID,Vec<&'a str>>>,
|
||||||
// No duplicate Spawn#
|
// No duplicate Spawn#
|
||||||
spawn_counts:DuplicateCheck<StageID,u64>,
|
spawn_counts:DuplicateCheck<SpawnID,u64>,
|
||||||
// Check for dangling WormholeIn# (no associated WormholeOut#)
|
// Check for dangling WormholeIn# (no associated WormholeOut#)
|
||||||
wormhole_in_counts:SetDifferenceCheck<SetDifferenceCheckContextAtLeastOne<WormholeID,u64>>,
|
wormhole_in_counts:SetDifferenceCheck<SetDifferenceCheckContextAtLeastOne<WormholeID,u64>>,
|
||||||
// No duplicate WormholeOut# (duplicate WormholeIn# ok)
|
// No duplicate WormholeOut# (duplicate WormholeIn# ok)
|
||||||
// No dangling WormholeOut#
|
// No dangling WormholeOut#
|
||||||
wormhole_out_counts:DuplicateCheck<WormholeID,u64>,
|
wormhole_out_counts:DuplicateCheck<WormholeID,u64>,
|
||||||
|
|
||||||
// === GENERAL CHECKS ===
|
|
||||||
unanchored_parts:Result<(),Vec<&'a Instance>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ModelInfo<'a>{
|
impl<'a> ModelInfo<'a>{
|
||||||
@@ -491,17 +370,17 @@ impl<'a> ModelInfo<'a>{
|
|||||||
let game_id=self.map_info.game_id;
|
let game_id=self.map_info.game_id;
|
||||||
|
|
||||||
// MapStart must exist
|
// MapStart must exist
|
||||||
let mapstart=if self.counts.mode_start_counts.contains_key(&ModeID::MAIN){
|
let mapstart=if self.counts.mode_start_counts.get(&ModeID::MAIN).is_some(){
|
||||||
Ok(Exists)
|
Ok(())
|
||||||
}else{
|
}else{
|
||||||
Err(Absent)
|
Err(())
|
||||||
};
|
};
|
||||||
|
|
||||||
// Spawn1 must exist
|
// Spawn1 must exist
|
||||||
let spawn1=if self.counts.spawn_counts.contains_key(&StageID::FIRST){
|
let spawn1=if self.counts.spawn_counts.get(&SpawnID::FIRST).is_some(){
|
||||||
Ok(Exists)
|
Ok(())
|
||||||
}else{
|
}else{
|
||||||
Err(Absent)
|
Err(())
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check that at least one finish zone exists for each start zone.
|
// Check that at least one finish zone exists for each start zone.
|
||||||
@@ -533,13 +412,6 @@ impl<'a> ModelInfo<'a>{
|
|||||||
// There must be exactly one of any perticular wormhole out id in the map.
|
// There must be exactly one of any perticular wormhole out id in the map.
|
||||||
let wormhole_out_counts=DuplicateCheckContext(self.counts.wormhole_out_counts).check(|&c|1<c);
|
let wormhole_out_counts=DuplicateCheckContext(self.counts.wormhole_out_counts).check(|&c|1<c);
|
||||||
|
|
||||||
// There must not be any unanchored parts
|
|
||||||
let unanchored_parts=if self.unanchored_parts.is_empty(){
|
|
||||||
Ok(())
|
|
||||||
}else{
|
|
||||||
Err(self.unanchored_parts)
|
|
||||||
};
|
|
||||||
|
|
||||||
MapCheck{
|
MapCheck{
|
||||||
model_class,
|
model_class,
|
||||||
model_name,
|
model_name,
|
||||||
@@ -555,13 +427,12 @@ impl<'a> ModelInfo<'a>{
|
|||||||
spawn_counts,
|
spawn_counts,
|
||||||
wormhole_in_counts,
|
wormhole_in_counts,
|
||||||
wormhole_out_counts,
|
wormhole_out_counts,
|
||||||
unanchored_parts,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MapCheck<'_>{
|
impl<'a> MapCheck<'a>{
|
||||||
fn result(self)->Result<MapInfoOwned,Result<MapCheckList,serde_json::Error>>{
|
fn pass(self)->Result<MapInfoOwned,Self>{
|
||||||
match self{
|
match self{
|
||||||
MapCheck{
|
MapCheck{
|
||||||
model_class:StringCheck(Ok(())),
|
model_class:StringCheck(Ok(())),
|
||||||
@@ -569,16 +440,15 @@ impl MapCheck<'_>{
|
|||||||
display_name:Ok(Ok(StringCheck(Ok(display_name)))),
|
display_name:Ok(Ok(StringCheck(Ok(display_name)))),
|
||||||
creator:Ok(Ok(creator)),
|
creator:Ok(Ok(creator)),
|
||||||
game_id:Ok(game_id),
|
game_id:Ok(game_id),
|
||||||
mapstart:Ok(Exists),
|
mapstart:Ok(()),
|
||||||
mode_start_counts:DuplicateCheck(Ok(())),
|
mode_start_counts:DuplicateCheck(Ok(())),
|
||||||
mode_finish_counts:SetDifferenceCheck(Ok(())),
|
mode_finish_counts:SetDifferenceCheck(Ok(())),
|
||||||
mode_anticheat_counts:SetDifferenceCheck(Ok(())),
|
mode_anticheat_counts:SetDifferenceCheck(Ok(())),
|
||||||
spawn1:Ok(Exists),
|
spawn1:Ok(()),
|
||||||
teleport_counts:SetDifferenceCheck(Ok(())),
|
teleport_counts:SetDifferenceCheck(Ok(())),
|
||||||
spawn_counts:DuplicateCheck(Ok(())),
|
spawn_counts:DuplicateCheck(Ok(())),
|
||||||
wormhole_in_counts:SetDifferenceCheck(Ok(())),
|
wormhole_in_counts:SetDifferenceCheck(Ok(())),
|
||||||
wormhole_out_counts:DuplicateCheck(Ok(())),
|
wormhole_out_counts:DuplicateCheck(Ok(())),
|
||||||
unanchored_parts:Ok(()),
|
|
||||||
}=>{
|
}=>{
|
||||||
Ok(MapInfoOwned{
|
Ok(MapInfoOwned{
|
||||||
display_name:display_name.to_owned(),
|
display_name:display_name.to_owned(),
|
||||||
@@ -586,267 +456,157 @@ impl MapCheck<'_>{
|
|||||||
game_id,
|
game_id,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
other=>Err(other.itemize()),
|
other=>Err(other),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Separated<F>{
|
fn write_comma_separated<T>(
|
||||||
f:F,
|
f:&mut std::fmt::Formatter<'_>,
|
||||||
separator:&'static str,
|
mut it:impl Iterator<Item=T>,
|
||||||
}
|
custom_write:impl Fn(&mut std::fmt::Formatter<'_>,T)->std::fmt::Result
|
||||||
impl<F> Separated<F>{
|
)->std::fmt::Result{
|
||||||
fn new(separator:&'static str,f:F)->Self{
|
if let Some(t)=it.next(){
|
||||||
Self{separator,f}
|
custom_write(f,t)?;
|
||||||
|
for t in it{
|
||||||
|
write!(f,", ")?;
|
||||||
|
custom_write(f,t)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
impl<F,I,D> std::fmt::Display for Separated<F>
|
|
||||||
where
|
macro_rules! write_zone{
|
||||||
D:std::fmt::Display,
|
($f:expr,$mode:expr,$zone:expr)=>{
|
||||||
I:IntoIterator<Item=D>,
|
match $mode{
|
||||||
F:Fn()->I,
|
ModeID(0)=>write!($f,concat!("Map",$zone)),
|
||||||
{
|
ModeID(1)=>write!($f,concat!("Bonus",$zone)),
|
||||||
|
ModeID(other)=>write!($f,concat!("Bonus{}",$zone),other),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
impl<'a> std::fmt::Display for MapCheck<'a>{
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
let mut it=(self.f)().into_iter();
|
if let StringCheck(Err(context))=&self.model_class{
|
||||||
if let Some(first)=it.next(){
|
writeln!(f,"Invalid model class: {context}")?;
|
||||||
write!(f,"{first}")?;
|
}
|
||||||
for item in it{
|
if let StringCheck(Err(context))=&self.model_name{
|
||||||
write!(f,"{}{item}",self.separator)?;
|
writeln!(f,"Model name must have snake_case: {context}")?;
|
||||||
|
}
|
||||||
|
match &self.display_name{
|
||||||
|
Ok(Ok(StringCheck(Ok(_))))=>(),
|
||||||
|
Ok(Ok(StringCheck(Err(context))))=>writeln!(f,"DisplayName must have Title Case: {context}")?,
|
||||||
|
Ok(Err(context))=>writeln!(f,"Invalid DisplayName: {context}")?,
|
||||||
|
Err(StringValueError::ObjectNotFound)=>writeln!(f,"Missing DisplayName StringValue")?,
|
||||||
|
Err(StringValueError::ValueNotSet)=>writeln!(f,"DisplayName Value not set")?,
|
||||||
|
Err(StringValueError::NonStringValue)=>writeln!(f,"DisplayName Value is not a String")?,
|
||||||
|
}
|
||||||
|
match &self.creator{
|
||||||
|
Ok(Ok(_))=>(),
|
||||||
|
Ok(Err(context))=>writeln!(f,"Invalid Creator: {context}")?,
|
||||||
|
Err(StringValueError::ObjectNotFound)=>writeln!(f,"Missing Creator StringValue")?,
|
||||||
|
Err(StringValueError::ValueNotSet)=>writeln!(f,"Creator Value not set")?,
|
||||||
|
Err(StringValueError::NonStringValue)=>writeln!(f,"Creator Value is not a String")?,
|
||||||
|
}
|
||||||
|
if let Err(_parse_game_id_error)=&self.game_id{
|
||||||
|
writeln!(f,"Model name must be prefixed with bhop_ surf_ or flytrials_")?;
|
||||||
|
}
|
||||||
|
if let Err(())=&self.mapstart{
|
||||||
|
writeln!(f,"Model has no MapStart")?;
|
||||||
|
}
|
||||||
|
if let DuplicateCheck(Err(DuplicateCheckContext(context)))=&self.mode_start_counts{
|
||||||
|
write!(f,"Duplicate start zones: ")?;
|
||||||
|
write_comma_separated(f,context.iter(),|f,(mode_id,names)|{
|
||||||
|
write_zone!(f,mode_id,"Start")?;
|
||||||
|
write!(f," ({} duplicates)",names.len())?;
|
||||||
|
Ok(())
|
||||||
|
})?;
|
||||||
|
writeln!(f,"")?;
|
||||||
|
}
|
||||||
|
if let SetDifferenceCheck(Err(context))=&self.mode_finish_counts{
|
||||||
|
if !context.extra.is_empty(){
|
||||||
|
let plural=if context.extra.len()==1{"zone"}else{"zones"};
|
||||||
|
write!(f,"No matching start zone for finish {plural}: ")?;
|
||||||
|
write_comma_separated(f,context.extra.iter(),|f,(mode_id,_names)|
|
||||||
|
write_zone!(f,mode_id,"Finish")
|
||||||
|
)?;
|
||||||
|
writeln!(f,"")?;
|
||||||
}
|
}
|
||||||
|
if !context.missing.is_empty(){
|
||||||
|
let plural=if context.missing.len()==1{"zone"}else{"zones"};
|
||||||
|
write!(f,"Missing finish {plural}: ")?;
|
||||||
|
write_comma_separated(f,context.missing.iter(),|f,mode_id|
|
||||||
|
write_zone!(f,mode_id,"Finish")
|
||||||
|
)?;
|
||||||
|
writeln!(f,"")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let SetDifferenceCheck(Err(context))=&self.mode_anticheat_counts{
|
||||||
|
if !context.extra.is_empty(){
|
||||||
|
let plural=if context.extra.len()==1{"zone"}else{"zones"};
|
||||||
|
write!(f,"No matching start zone for anticheat {plural}: ")?;
|
||||||
|
write_comma_separated(f,context.extra.iter(),|f,(mode_id,_names)|
|
||||||
|
write_zone!(f,mode_id,"Anticheat")
|
||||||
|
)?;
|
||||||
|
writeln!(f,"")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Err(())=&self.spawn1{
|
||||||
|
writeln!(f,"Model has no Spawn1")?;
|
||||||
|
}
|
||||||
|
if let SetDifferenceCheck(Err(context))=&self.teleport_counts{
|
||||||
|
for (_,names) in &context.extra{
|
||||||
|
let plural=if names.len()==1{"object"}else{"objects"};
|
||||||
|
write!(f,"No matching Spawn for {plural}: ")?;
|
||||||
|
write_comma_separated(f,names.iter(),|f,&name|{
|
||||||
|
write!(f,"{name}")
|
||||||
|
})?;
|
||||||
|
writeln!(f,"")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let DuplicateCheck(Err(DuplicateCheckContext(context)))=&self.spawn_counts{
|
||||||
|
write!(f,"Duplicate Spawn: ")?;
|
||||||
|
write_comma_separated(f,context.iter(),|f,(SpawnID(spawn_id),count)|
|
||||||
|
write!(f,"Spawn{spawn_id} ({count} duplicates)")
|
||||||
|
)?;
|
||||||
|
writeln!(f,"")?;
|
||||||
|
}
|
||||||
|
if let SetDifferenceCheck(Err(context))=&self.wormhole_in_counts{
|
||||||
|
if !context.extra.is_empty(){
|
||||||
|
write!(f,"WormholeIn with no matching WormholeOut: ")?;
|
||||||
|
write_comma_separated(f,context.extra.iter(),|f,(WormholeID(wormhole_id),_count)|
|
||||||
|
write!(f,"WormholeIn{wormhole_id}")
|
||||||
|
)?;
|
||||||
|
writeln!(f,"")?;
|
||||||
|
}
|
||||||
|
if !context.missing.is_empty(){
|
||||||
|
// This counts WormholeIn objects, but
|
||||||
|
// flipped logic is easier to understand
|
||||||
|
write!(f,"WormholeOut with no matching WormholeIn: ")?;
|
||||||
|
write_comma_separated(f,context.missing.iter(),|f,WormholeID(wormhole_id)|
|
||||||
|
write!(f,"WormholeOut{wormhole_id}")
|
||||||
|
)?;
|
||||||
|
writeln!(f,"")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let DuplicateCheck(Err(DuplicateCheckContext(context)))=&self.wormhole_out_counts{
|
||||||
|
write!(f,"Duplicate WormholeOut: ")?;
|
||||||
|
write_comma_separated(f,context.iter(),|f,(WormholeID(wormhole_id),count)|
|
||||||
|
write!(f,"WormholeOut{wormhole_id} ({count} duplicates)")
|
||||||
|
)?;
|
||||||
|
writeln!(f,"")?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Duplicates<D>{
|
pub struct CheckReportAndVersion{
|
||||||
display:D,
|
pub status:Result<MapInfoOwned,String>,
|
||||||
duplicates:usize,
|
|
||||||
}
|
|
||||||
impl<D> Duplicates<D>{
|
|
||||||
fn new(display:D,duplicates:usize)->Self{
|
|
||||||
Self{
|
|
||||||
display,
|
|
||||||
duplicates,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<D:std::fmt::Display> std::fmt::Display for Duplicates<D>{
|
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
|
||||||
write!(f,"{} ({} duplicates)",self.display,self.duplicates)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
macro_rules! passed{
|
|
||||||
($name:literal)=>{
|
|
||||||
Check{
|
|
||||||
name:$name.to_owned(),
|
|
||||||
summary:String::new(),
|
|
||||||
passed:true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
macro_rules! summary{
|
|
||||||
($name:literal,$summary:expr)=>{
|
|
||||||
Check{
|
|
||||||
name:$name.to_owned(),
|
|
||||||
summary:$summary,
|
|
||||||
passed:false,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
macro_rules! summary_format{
|
|
||||||
($name:literal,$fmt:literal)=>{
|
|
||||||
Check{
|
|
||||||
name:$name.to_owned(),
|
|
||||||
summary:format!($fmt),
|
|
||||||
passed:false,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate an error message for each observed issue separated by newlines.
|
|
||||||
// This defines MapCheck.to_string() which is used in MapCheck.result()
|
|
||||||
impl MapCheck<'_>{
|
|
||||||
fn itemize(&self)->Result<MapCheckList,serde_json::Error>{
|
|
||||||
let model_class=match &self.model_class{
|
|
||||||
StringCheck(Ok(()))=>passed!("ModelClass"),
|
|
||||||
StringCheck(Err(context))=>summary_format!("ModelClass","Invalid model class: {context}"),
|
|
||||||
};
|
|
||||||
let model_name=match &self.model_name{
|
|
||||||
StringCheck(Ok(()))=>passed!("ModelName"),
|
|
||||||
StringCheck(Err(context))=>summary_format!("ModelName","Model name must have snake_case: {context}"),
|
|
||||||
};
|
|
||||||
let display_name=match &self.display_name{
|
|
||||||
Ok(Ok(StringCheck(Ok(_))))=>passed!("DisplayName"),
|
|
||||||
Ok(Ok(StringCheck(Err(context))))=>summary_format!("DisplayName","DisplayName must have Title Case: {context}"),
|
|
||||||
Ok(Err(context))=>summary_format!("DisplayName","Invalid DisplayName: {context}"),
|
|
||||||
Err(StringValueError::ObjectNotFound)=>summary!("DisplayName","Missing DisplayName StringValue".to_owned()),
|
|
||||||
Err(StringValueError::ValueNotSet)=>summary!("DisplayName","DisplayName Value not set".to_owned()),
|
|
||||||
Err(StringValueError::NonStringValue)=>summary!("DisplayName","DisplayName Value is not a String".to_owned()),
|
|
||||||
};
|
|
||||||
let creator=match &self.creator{
|
|
||||||
Ok(Ok(_))=>passed!("Creator"),
|
|
||||||
Ok(Err(context))=>summary_format!("Creator","Invalid Creator: {context}"),
|
|
||||||
Err(StringValueError::ObjectNotFound)=>summary!("Creator","Missing Creator StringValue".to_owned()),
|
|
||||||
Err(StringValueError::ValueNotSet)=>summary!("Creator","Creator Value not set".to_owned()),
|
|
||||||
Err(StringValueError::NonStringValue)=>summary!("Creator","Creator Value is not a String".to_owned()),
|
|
||||||
};
|
|
||||||
let game_id=match &self.game_id{
|
|
||||||
Ok(_)=>passed!("GameID"),
|
|
||||||
Err(ParseGameIDError)=>summary!("GameID","Model name must be prefixed with bhop_ surf_ or flytrials_".to_owned()),
|
|
||||||
};
|
|
||||||
let mapstart=match &self.mapstart{
|
|
||||||
Ok(Exists)=>passed!("MapStart"),
|
|
||||||
Err(Absent)=>summary_format!("MapStart","Model has no MapStart"),
|
|
||||||
};
|
|
||||||
let duplicate_start=match &self.mode_start_counts{
|
|
||||||
DuplicateCheck(Ok(()))=>passed!("DuplicateStart"),
|
|
||||||
DuplicateCheck(Err(DuplicateCheckContext(context)))=>{
|
|
||||||
let context=Separated::new(", ",||context.iter().map(|(&mode_id,instances)|
|
|
||||||
Duplicates::new(ModeElement{zone:Zone::Start,mode_id},instances.len())
|
|
||||||
));
|
|
||||||
summary_format!("DuplicateStart","Duplicate start zones: {context}")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let (extra_finish,missing_finish)=match &self.mode_finish_counts{
|
|
||||||
SetDifferenceCheck(Ok(()))=>(passed!("DanglingFinish"),passed!("MissingFinish")),
|
|
||||||
SetDifferenceCheck(Err(context))=>(
|
|
||||||
if context.extra.is_empty(){
|
|
||||||
passed!("DanglingFinish")
|
|
||||||
}else{
|
|
||||||
let plural=if context.extra.len()==1{"zone"}else{"zones"};
|
|
||||||
let context=Separated::new(", ",||context.extra.iter().map(|(&mode_id,_instances)|
|
|
||||||
ModeElement{zone:Zone::Finish,mode_id}
|
|
||||||
));
|
|
||||||
summary_format!("DanglingFinish","No matching start zone for finish {plural}: {context}")
|
|
||||||
},
|
|
||||||
if context.missing.is_empty(){
|
|
||||||
passed!("MissingFinish")
|
|
||||||
}else{
|
|
||||||
let plural=if context.missing.len()==1{"zone"}else{"zones"};
|
|
||||||
let context=Separated::new(", ",||context.missing.iter().map(|&mode_id|
|
|
||||||
ModeElement{zone:Zone::Finish,mode_id}
|
|
||||||
));
|
|
||||||
summary_format!("MissingFinish","Missing finish {plural}: {context}")
|
|
||||||
}
|
|
||||||
),
|
|
||||||
};
|
|
||||||
let dangling_anticheat=match &self.mode_anticheat_counts{
|
|
||||||
SetDifferenceCheck(Ok(()))=>passed!("DanglingAnticheat"),
|
|
||||||
SetDifferenceCheck(Err(context))=>{
|
|
||||||
if context.extra.is_empty(){
|
|
||||||
passed!("DanglingAnticheat")
|
|
||||||
}else{
|
|
||||||
let plural=if context.extra.len()==1{"zone"}else{"zones"};
|
|
||||||
let context=Separated::new(", ",||context.extra.iter().map(|(&mode_id,_instances)|
|
|
||||||
ModeElement{zone:Zone::Anticheat,mode_id}
|
|
||||||
));
|
|
||||||
summary_format!("DanglingAnticheat","No matching start zone for anticheat {plural}: {context}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let spawn1=match &self.spawn1{
|
|
||||||
Ok(Exists)=>passed!("Spawn1"),
|
|
||||||
Err(Absent)=>summary_format!("Spawn1","Model has no Spawn1"),
|
|
||||||
};
|
|
||||||
let dangling_teleport=match &self.teleport_counts{
|
|
||||||
SetDifferenceCheck(Ok(()))=>passed!("DanglingTeleport"),
|
|
||||||
SetDifferenceCheck(Err(context))=>{
|
|
||||||
let unique_names:HashSet<_>=context.extra.values().flat_map(|instances|
|
|
||||||
instances.iter().map(|instance|instance.name.as_str())
|
|
||||||
).collect();
|
|
||||||
let plural=if unique_names.len()==1{"object"}else{"objects"};
|
|
||||||
let context=Separated::new(", ",||&unique_names);
|
|
||||||
summary_format!("DanglingTeleport","No matching Spawn for {plural}: {context}")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let duplicate_spawns=match &self.spawn_counts{
|
|
||||||
DuplicateCheck(Ok(()))=>passed!("DuplicateSpawn"),
|
|
||||||
DuplicateCheck(Err(DuplicateCheckContext(context)))=>{
|
|
||||||
let context=Separated::new(", ",||context.iter().map(|(&stage_id,&instances)|
|
|
||||||
Duplicates::new(StageElement{behaviour:StageElementBehaviour::Spawn,stage_id},instances as usize)
|
|
||||||
));
|
|
||||||
summary_format!("DuplicateSpawn","Duplicate Spawn: {context}")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let (extra_wormhole_in,missing_wormhole_in)=match &self.wormhole_in_counts{
|
|
||||||
SetDifferenceCheck(Ok(()))=>(passed!("ExtraWormholeIn"),passed!("MissingWormholeIn")),
|
|
||||||
SetDifferenceCheck(Err(context))=>(
|
|
||||||
if context.extra.is_empty(){
|
|
||||||
passed!("ExtraWormholeIn")
|
|
||||||
}else{
|
|
||||||
let context=Separated::new(", ",||context.extra.iter().map(|(&wormhole_id,_instances)|
|
|
||||||
WormholeElement{behaviour:WormholeBehaviour::In,wormhole_id}
|
|
||||||
));
|
|
||||||
summary_format!("ExtraWormholeIn","WormholeIn with no matching WormholeOut: {context}")
|
|
||||||
},
|
|
||||||
if context.missing.is_empty(){
|
|
||||||
passed!("MissingWormholeIn")
|
|
||||||
}else{
|
|
||||||
// This counts WormholeIn objects, but
|
|
||||||
// flipped logic is easier to understand
|
|
||||||
let context=Separated::new(", ",||context.missing.iter().map(|&wormhole_id|
|
|
||||||
WormholeElement{behaviour:WormholeBehaviour::Out,wormhole_id}
|
|
||||||
));
|
|
||||||
summary_format!("MissingWormholeIn","WormholeOut with no matching WormholeIn: {context}")
|
|
||||||
}
|
|
||||||
)
|
|
||||||
};
|
|
||||||
let duplicate_wormhole_out=match &self.wormhole_out_counts{
|
|
||||||
DuplicateCheck(Ok(()))=>passed!("DuplicateWormholeOut"),
|
|
||||||
DuplicateCheck(Err(DuplicateCheckContext(context)))=>{
|
|
||||||
let context=Separated::new(", ",||context.iter().map(|(&wormhole_id,&instances)|
|
|
||||||
Duplicates::new(WormholeElement{behaviour:WormholeBehaviour::Out,wormhole_id},instances as usize)
|
|
||||||
));
|
|
||||||
summary_format!("DuplicateWormholeOut","Duplicate WormholeOut: {context}")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let unanchored_parts=match &self.unanchored_parts{
|
|
||||||
Ok(())=>passed!("UnanchoredParts"),
|
|
||||||
Err(unanchored_parts)=>{
|
|
||||||
let count=unanchored_parts.len();
|
|
||||||
let plural=if count==1{"part"}else{"parts"};
|
|
||||||
let context=Separated::new(", ",||unanchored_parts.iter().map(|&instance|
|
|
||||||
instance.name.as_str()
|
|
||||||
).take(20));
|
|
||||||
summary_format!("UnanchoredParts","{count} unanchored {plural}: {context}")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Ok(MapCheckList{checks:vec![
|
|
||||||
model_class,
|
|
||||||
model_name,
|
|
||||||
display_name,
|
|
||||||
creator,
|
|
||||||
game_id,
|
|
||||||
mapstart,
|
|
||||||
duplicate_start,
|
|
||||||
extra_finish,
|
|
||||||
missing_finish,
|
|
||||||
dangling_anticheat,
|
|
||||||
spawn1,
|
|
||||||
dangling_teleport,
|
|
||||||
duplicate_spawns,
|
|
||||||
extra_wormhole_in,
|
|
||||||
missing_wormhole_in,
|
|
||||||
duplicate_wormhole_out,
|
|
||||||
unanchored_parts,
|
|
||||||
]})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(serde::Serialize)]
|
|
||||||
pub struct MapCheckList{
|
|
||||||
pub checks:Vec<Check>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct CheckListAndVersion{
|
|
||||||
pub status:Result<MapInfoOwned,MapCheckList>,
|
|
||||||
pub version:u64,
|
pub version:u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::message_handler::MessageHandler{
|
impl crate::message_handler::MessageHandler{
|
||||||
pub async fn check_inner(&self,check_info:CheckRequest)->Result<CheckListAndVersion,Error>{
|
pub async fn check_inner(&self,check_info:CheckRequest)->Result<CheckReportAndVersion,Error>{
|
||||||
// discover asset creator and latest version
|
// discover asset creator and latest version
|
||||||
let info=self.cloud_context.get_asset_info(
|
let info=self.cloud_context.get_asset_info(
|
||||||
rbx_asset::cloud::GetAssetLatestRequest{asset_id:check_info.ModelID}
|
rbx_asset::cloud::GetAssetLatestRequest{asset_id:check_info.ModelID}
|
||||||
@@ -871,17 +631,6 @@ impl crate::message_handler::MessageHandler{
|
|||||||
// extract the root instance
|
// extract the root instance
|
||||||
let model_instance=get_root_instance(&dom).map_err(Error::GetRootInstance)?;
|
let model_instance=get_root_instance(&dom).map_err(Error::GetRootInstance)?;
|
||||||
|
|
||||||
// skip checks
|
|
||||||
if check_info.SkipChecks{
|
|
||||||
// extract required fields
|
|
||||||
let map_info=get_mapinfo(&dom,model_instance);
|
|
||||||
let map_info_owned=map_info.try_into().map_err(Error::IntoMapInfoOwned)?;
|
|
||||||
let status=Ok(map_info_owned);
|
|
||||||
|
|
||||||
// return early
|
|
||||||
return Ok(CheckListAndVersion{status,version});
|
|
||||||
}
|
|
||||||
|
|
||||||
// extract information from the model
|
// extract information from the model
|
||||||
let model_info=get_model_info(&dom,model_instance);
|
let model_info=get_model_info(&dom,model_instance);
|
||||||
|
|
||||||
@@ -889,12 +638,8 @@ impl crate::message_handler::MessageHandler{
|
|||||||
let map_check=model_info.check();
|
let map_check=model_info.check();
|
||||||
|
|
||||||
// check the report, generate an error message if it fails the check
|
// check the report, generate an error message if it fails the check
|
||||||
let status=match map_check.result(){
|
let status=map_check.pass().map_err(|e|e.to_string());
|
||||||
Ok(map_info)=>Ok(map_info),
|
|
||||||
Err(Ok(check_list))=>Err(check_list),
|
|
||||||
Err(Err(e))=>return Err(Error::ToJsonValue(e)),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(CheckListAndVersion{status,version})
|
Ok(CheckReportAndVersion{status,version})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use crate::check::CheckListAndVersion;
|
use crate::check::CheckReportAndVersion;
|
||||||
use crate::nats_types::CheckMapfixRequest;
|
use crate::nats_types::CheckMapfixRequest;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error{
|
pub enum Error{
|
||||||
Check(crate::check::Error),
|
Check(crate::check::Error),
|
||||||
ApiActionMapfixCheck(tonic::Status),
|
ApiActionMapfixCheck(submissions_api::Error),
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for Error{
|
impl std::fmt::Display for Error{
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
@@ -21,49 +21,32 @@ impl crate::message_handler::MessageHandler{
|
|||||||
|
|
||||||
// update the mapfix depending on the result
|
// update the mapfix depending on the result
|
||||||
match check_result{
|
match check_result{
|
||||||
Ok(CheckListAndVersion{status:Ok(map_info),version})=>{
|
Ok(CheckReportAndVersion{status:Ok(map_info),version})=>self.api.action_mapfix_submitted(
|
||||||
self.mapfixes.set_status_submitted(
|
submissions_api::types::ActionMapfixSubmittedRequest{
|
||||||
rust_grpc::validator::SubmittedRequest{
|
MapfixID:mapfix_id,
|
||||||
id:mapfix_id,
|
ModelVersion:version,
|
||||||
model_version:version,
|
DisplayName:map_info.display_name,
|
||||||
display_name:map_info.display_name,
|
Creator:map_info.creator,
|
||||||
creator:map_info.creator,
|
GameID:map_info.game_id as u32,
|
||||||
game_id:map_info.game_id as u32,
|
}
|
||||||
}
|
).await.map_err(Error::ApiActionMapfixCheck)?,
|
||||||
).await.map_err(Error::ApiActionMapfixCheck)?;
|
|
||||||
|
|
||||||
// Do not proceed to request changes
|
|
||||||
return Ok(());
|
|
||||||
},
|
|
||||||
// update the mapfix model status to request changes
|
// update the mapfix model status to request changes
|
||||||
Ok(CheckListAndVersion{status:Err(check_list),..})=>{
|
Ok(CheckReportAndVersion{status:Err(report),..})=>self.api.action_mapfix_request_changes(
|
||||||
self.mapfixes.create_audit_checklist(
|
submissions_api::types::ActionMapfixRequestChangesRequest{
|
||||||
rust_grpc::validator::AuditChecklistRequest{
|
MapfixID:mapfix_id,
|
||||||
id:mapfix_id,
|
ErrorMessage:report,
|
||||||
check_list:check_list.checks,
|
}
|
||||||
}
|
).await.map_err(Error::ApiActionMapfixCheck)?,
|
||||||
).await.map_err(Error::ApiActionMapfixCheck)?;
|
// TODO: report the error
|
||||||
},
|
|
||||||
// update the mapfix model status to request changes
|
// update the mapfix model status to request changes
|
||||||
Err(e)=>{
|
Err(e)=>self.api.action_mapfix_request_changes(
|
||||||
// log error
|
submissions_api::types::ActionMapfixRequestChangesRequest{
|
||||||
println!("[check_mapfix] Error: {e}");
|
MapfixID:mapfix_id,
|
||||||
|
ErrorMessage:e.to_string(),
|
||||||
self.mapfixes.create_audit_error(
|
}
|
||||||
rust_grpc::validator::AuditErrorRequest{
|
).await.map_err(Error::ApiActionMapfixCheck)?,
|
||||||
id:mapfix_id,
|
|
||||||
error_message:e.to_string(),
|
|
||||||
}
|
|
||||||
).await.map_err(Error::ApiActionMapfixCheck)?;
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.mapfixes.set_status_request_changes(
|
|
||||||
rust_grpc::validator::MapfixId{
|
|
||||||
id:mapfix_id,
|
|
||||||
}
|
|
||||||
).await.map_err(Error::ApiActionMapfixCheck)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use crate::check::CheckListAndVersion;
|
use crate::check::CheckReportAndVersion;
|
||||||
use crate::nats_types::CheckSubmissionRequest;
|
use crate::nats_types::CheckSubmissionRequest;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error{
|
pub enum Error{
|
||||||
Check(crate::check::Error),
|
Check(crate::check::Error),
|
||||||
ApiActionSubmissionCheck(tonic::Status),
|
ApiActionSubmissionCheck(submissions_api::Error),
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for Error{
|
impl std::fmt::Display for Error{
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
@@ -22,49 +22,32 @@ impl crate::message_handler::MessageHandler{
|
|||||||
// update the submission depending on the result
|
// update the submission depending on the result
|
||||||
match check_result{
|
match check_result{
|
||||||
// update the submission model status to submitted
|
// update the submission model status to submitted
|
||||||
Ok(CheckListAndVersion{status:Ok(map_info),version})=>{
|
Ok(CheckReportAndVersion{status:Ok(map_info),version})=>self.api.action_submission_submitted(
|
||||||
self.submissions.set_status_submitted(
|
submissions_api::types::ActionSubmissionSubmittedRequest{
|
||||||
rust_grpc::validator::SubmittedRequest{
|
SubmissionID:submission_id,
|
||||||
id:submission_id,
|
ModelVersion:version,
|
||||||
model_version:version,
|
DisplayName:map_info.display_name,
|
||||||
display_name:map_info.display_name,
|
Creator:map_info.creator,
|
||||||
creator:map_info.creator,
|
GameID:map_info.game_id as u32,
|
||||||
game_id:map_info.game_id as u32,
|
|
||||||
}
|
|
||||||
).await.map_err(Error::ApiActionSubmissionCheck)?;
|
|
||||||
|
|
||||||
// Do not proceed to request changes
|
|
||||||
return Ok(());
|
|
||||||
},
|
|
||||||
// update the submission model status to request changes
|
|
||||||
Ok(CheckListAndVersion{status:Err(check_list),..})=>{
|
|
||||||
self.submissions.create_audit_checklist(
|
|
||||||
rust_grpc::validator::AuditChecklistRequest{
|
|
||||||
id:submission_id,
|
|
||||||
check_list:check_list.checks,
|
|
||||||
}
|
}
|
||||||
).await.map_err(Error::ApiActionSubmissionCheck)?;
|
).await.map_err(Error::ApiActionSubmissionCheck)?,
|
||||||
},
|
|
||||||
// update the submission model status to request changes
|
// update the submission model status to request changes
|
||||||
Err(e)=>{
|
Ok(CheckReportAndVersion{status:Err(report),..})=>self.api.action_submission_request_changes(
|
||||||
// log error
|
submissions_api::types::ActionSubmissionRequestChangesRequest{
|
||||||
println!("[check_submission] Error: {e}");
|
SubmissionID:submission_id,
|
||||||
|
ErrorMessage:report,
|
||||||
self.submissions.create_audit_error(
|
}
|
||||||
rust_grpc::validator::AuditErrorRequest{
|
).await.map_err(Error::ApiActionSubmissionCheck)?,
|
||||||
id:submission_id,
|
// TODO: report the error
|
||||||
error_message:e.to_string(),
|
// update the submission model status to request changes
|
||||||
}
|
Err(e)=>self.api.action_submission_request_changes(
|
||||||
).await.map_err(Error::ApiActionSubmissionCheck)?;
|
submissions_api::types::ActionSubmissionRequestChangesRequest{
|
||||||
},
|
SubmissionID:submission_id,
|
||||||
|
ErrorMessage:e.to_string(),
|
||||||
|
}
|
||||||
|
).await.map_err(Error::ApiActionSubmissionCheck)?,
|
||||||
}
|
}
|
||||||
|
|
||||||
self.submissions.set_status_request_changes(
|
|
||||||
rust_grpc::validator::SubmissionId{
|
|
||||||
id:submission_id,
|
|
||||||
}
|
|
||||||
).await.map_err(Error::ApiActionSubmissionCheck)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use crate::create::CreateRequest;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error{
|
pub enum Error{
|
||||||
Create(crate::create::Error),
|
Create(crate::create::Error),
|
||||||
ApiActionMapfixCreate(tonic::Status),
|
ApiActionMapfixCreate(submissions_api::Error),
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for Error{
|
impl std::fmt::Display for Error{
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
@@ -22,33 +22,30 @@ impl crate::message_handler::MessageHandler{
|
|||||||
}).await.map_err(Error::Create)?;
|
}).await.map_err(Error::Create)?;
|
||||||
|
|
||||||
// call create on api
|
// call create on api
|
||||||
self.mapfixes.create(rust_grpc::validator::MapfixCreate{
|
self.api.create_mapfix(submissions_api::types::CreateMapfixRequest{
|
||||||
operation_id:create_info.OperationID,
|
OperationID:create_info.OperationID,
|
||||||
asset_owner:create_request.AssetOwner,
|
AssetOwner:create_request.AssetOwner as i64,
|
||||||
display_name:create_request.DisplayName.unwrap_or_default(),
|
DisplayName:create_request.DisplayName.as_deref().unwrap_or_default(),
|
||||||
creator:create_request.Creator.unwrap_or_default(),
|
Creator:create_request.Creator.as_deref().unwrap_or_default(),
|
||||||
// not great TODO: make this great
|
// not great TODO: make this great
|
||||||
game_id:create_request.GameID.unwrap_or(crate::rbx_util::GameID::Bhop) as u32,
|
GameID:create_request.GameID.unwrap_or(crate::rbx_util::GameID::Bhop) as i32,
|
||||||
asset_id:create_info.ModelID,
|
AssetID:create_info.ModelID,
|
||||||
asset_version:create_request.AssetVersion,
|
AssetVersion:create_request.AssetVersion,
|
||||||
target_asset_id:create_info.TargetAssetID,
|
TargetAssetID:create_info.TargetAssetID,
|
||||||
description:create_info.Description,
|
Description:create_info.Description.as_str(),
|
||||||
}).await.map_err(Error::ApiActionMapfixCreate)?;
|
}).await.map_err(Error::ApiActionMapfixCreate)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub async fn create_mapfix(&self,create_info:CreateMapfixRequest)->Result<(),tonic::Status>{
|
pub async fn create_mapfix(&self,create_info:CreateMapfixRequest)->Result<(),submissions_api::Error>{
|
||||||
let operation_id=create_info.OperationID;
|
let operation_id=create_info.OperationID;
|
||||||
|
|
||||||
let create_result=self.create_mapfix_inner(create_info).await;
|
let create_result=self.create_mapfix_inner(create_info).await;
|
||||||
|
|
||||||
if let Err(e)=create_result{
|
if let Err(e)=create_result{
|
||||||
// log error
|
self.api.action_operation_failed(submissions_api::types::ActionOperationFailedRequest{
|
||||||
println!("[create_mapfix] Error: {e}");
|
OperationID:operation_id,
|
||||||
|
StatusMessage:e.to_string(),
|
||||||
self.operations.fail(rust_grpc::validator::OperationFailRequest{
|
|
||||||
operation_id,
|
|
||||||
status_message:e.to_string(),
|
|
||||||
}).await?;
|
}).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use crate::rbx_util::GameID;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error{
|
pub enum Error{
|
||||||
Create(crate::create::Error),
|
Create(crate::create::Error),
|
||||||
ApiActionSubmissionCreate(tonic::Status),
|
ApiActionSubmissionCreate(submissions_api::Error),
|
||||||
}
|
}
|
||||||
impl std::fmt::Display for Error{
|
impl std::fmt::Display for Error{
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
@@ -23,46 +23,43 @@ impl crate::message_handler::MessageHandler{
|
|||||||
|
|
||||||
// grab values from submission form, otherwise try to fill blanks from map data
|
// grab values from submission form, otherwise try to fill blanks from map data
|
||||||
let display_name=if create_info.DisplayName.is_empty(){
|
let display_name=if create_info.DisplayName.is_empty(){
|
||||||
create_request.DisplayName.unwrap_or_default()
|
create_request.DisplayName.as_deref().unwrap_or_default()
|
||||||
}else{
|
}else{
|
||||||
create_info.DisplayName
|
create_info.DisplayName.as_str()
|
||||||
};
|
};
|
||||||
|
|
||||||
let creator=if create_info.Creator.is_empty(){
|
let creator=if create_info.Creator.is_empty(){
|
||||||
create_request.Creator.unwrap_or_default()
|
create_request.Creator.as_deref().unwrap_or_default()
|
||||||
}else{
|
}else{
|
||||||
create_info.Creator
|
create_info.Creator.as_str()
|
||||||
};
|
};
|
||||||
|
|
||||||
let game_id=create_info.GameID.try_into().ok().or(create_request.GameID).unwrap_or(GameID::Bhop);
|
let game_id=create_info.GameID.try_into().ok().or(create_request.GameID).unwrap_or(GameID::Bhop);
|
||||||
|
|
||||||
// call create on api
|
// call create on api
|
||||||
self.submissions.create(rust_grpc::validator::SubmissionCreate{
|
self.api.create_submission(submissions_api::types::CreateSubmissionRequest{
|
||||||
operation_id:create_info.OperationID,
|
OperationID:create_info.OperationID,
|
||||||
asset_owner:create_request.AssetOwner,
|
AssetOwner:create_request.AssetOwner as i64,
|
||||||
display_name:display_name,
|
DisplayName:display_name,
|
||||||
creator:creator,
|
Creator:creator,
|
||||||
game_id:game_id as u32,
|
GameID:game_id as i32,
|
||||||
asset_id:create_info.ModelID,
|
AssetID:create_info.ModelID,
|
||||||
asset_version:create_request.AssetVersion,
|
AssetVersion:create_request.AssetVersion,
|
||||||
status:create_info.Status,
|
Status:create_info.Status,
|
||||||
roles:create_info.Roles,
|
Roles:create_info.Roles,
|
||||||
}).await.map_err(Error::ApiActionSubmissionCreate)?;
|
}).await.map_err(Error::ApiActionSubmissionCreate)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub async fn create_submission(&self,create_info:CreateSubmissionRequest)->Result<(),tonic::Status>{
|
pub async fn create_submission(&self,create_info:CreateSubmissionRequest)->Result<(),submissions_api::Error>{
|
||||||
let operation_id=create_info.OperationID;
|
let operation_id=create_info.OperationID;
|
||||||
|
|
||||||
let create_result=self.create_submission_inner(create_info).await;
|
let create_result=self.create_submission_inner(create_info).await;
|
||||||
|
|
||||||
if let Err(e)=create_result{
|
if let Err(e)=create_result{
|
||||||
// log error
|
self.api.action_operation_failed(submissions_api::types::ActionOperationFailedRequest{
|
||||||
println!("[create_submission] Error: {e}");
|
OperationID:operation_id,
|
||||||
|
StatusMessage:e.to_string(),
|
||||||
self.operations.fail(rust_grpc::validator::OperationFailRequest{
|
|
||||||
operation_id:operation_id,
|
|
||||||
status_message:e.to_string(),
|
|
||||||
}).await?;
|
}).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
use rust_grpc::validator::{ScriptId,ScriptPolicyId};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
#[expect(dead_code)]
|
|
||||||
pub enum SingleItemError<Items>{
|
|
||||||
DuplicateItems(Items),
|
|
||||||
Other(tonic::Status),
|
|
||||||
}
|
|
||||||
impl<Items> std::fmt::Display for SingleItemError<Items>
|
|
||||||
where
|
|
||||||
Items:std::fmt::Debug
|
|
||||||
{
|
|
||||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
|
||||||
write!(f,"{self:?}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl<Items> std::error::Error for SingleItemError<Items> where Items:std::fmt::Debug{}
|
|
||||||
pub type ScriptSingleItemError=SingleItemError<Vec<ScriptId>>;
|
|
||||||
pub type ScriptPolicySingleItemError=SingleItemError<Vec<ScriptPolicyId>>;
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
use crate::endpoint;
|
|
||||||
use rust_grpc::validator::*;
|
|
||||||
pub type ValidatorMapfixesServiceClient=rust_grpc::validator::validator_mapfix_service_client::ValidatorMapfixServiceClient<tonic::transport::channel::Channel>;
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Service{
|
|
||||||
client:ValidatorMapfixesServiceClient,
|
|
||||||
}
|
|
||||||
impl Service{
|
|
||||||
pub fn new(
|
|
||||||
client:ValidatorMapfixesServiceClient,
|
|
||||||
)->Self{
|
|
||||||
Self{client}
|
|
||||||
}
|
|
||||||
endpoint!(create,MapfixCreate,MapfixId);
|
|
||||||
endpoint!(create_audit_error,AuditErrorRequest,NullResponse);
|
|
||||||
endpoint!(create_audit_checklist,AuditChecklistRequest,NullResponse);
|
|
||||||
endpoint!(set_validated_model,ValidatedModelRequest,NullResponse);
|
|
||||||
endpoint!(set_status_submitted,SubmittedRequest,NullResponse);
|
|
||||||
endpoint!(set_status_request_changes,MapfixId,NullResponse);
|
|
||||||
endpoint!(set_status_validated,MapfixId,NullResponse);
|
|
||||||
endpoint!(set_status_failed,MapfixId,NullResponse);
|
|
||||||
endpoint!(set_status_uploaded,MapfixId,NullResponse);
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
|
|
||||||
pub mod error;
|
|
||||||
|
|
||||||
pub mod mapfixes;
|
|
||||||
pub mod operations;
|
|
||||||
pub mod scripts;
|
|
||||||
pub mod script_policy;
|
|
||||||
pub mod submissions;
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! endpoint{
|
|
||||||
($fn:ident,$in:ident,$out:ident)=>{
|
|
||||||
pub async fn $fn(&self,request:$in)->Result<$out,tonic::Status>{
|
|
||||||
Ok(self.client.clone().$fn(request).await?.into_inner())
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
use crate::endpoint;
|
|
||||||
use rust_grpc::validator::*;
|
|
||||||
pub type ValidatorOperationsServiceClient=rust_grpc::validator::validator_operation_service_client::ValidatorOperationServiceClient<tonic::transport::channel::Channel>;
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Service{
|
|
||||||
client:ValidatorOperationsServiceClient,
|
|
||||||
}
|
|
||||||
impl Service{
|
|
||||||
pub fn new(
|
|
||||||
client:ValidatorOperationsServiceClient,
|
|
||||||
)->Self{
|
|
||||||
Self{client}
|
|
||||||
}
|
|
||||||
endpoint!(fail,OperationFailRequest,NullResponse);
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
use crate::endpoint;
|
|
||||||
use crate::grpc::error::ScriptPolicySingleItemError;
|
|
||||||
use rust_grpc::validator::*;
|
|
||||||
pub type ValidatorScriptPolicyServiceClient=rust_grpc::validator::validator_script_policy_service_client::ValidatorScriptPolicyServiceClient<tonic::transport::channel::Channel>;
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Service{
|
|
||||||
client:ValidatorScriptPolicyServiceClient,
|
|
||||||
}
|
|
||||||
impl Service{
|
|
||||||
pub fn new(
|
|
||||||
client:ValidatorScriptPolicyServiceClient,
|
|
||||||
)->Self{
|
|
||||||
Self{client}
|
|
||||||
}
|
|
||||||
endpoint!(create,ScriptPolicyCreate,ScriptPolicyId);
|
|
||||||
endpoint!(list,ScriptPolicyListRequest,ScriptPolicyListResponse);
|
|
||||||
pub async fn get_from_hash(&self,hash:u64)->Result<Option<ScriptPolicy>,ScriptPolicySingleItemError>{
|
|
||||||
let policies=self.list(ScriptPolicyListRequest{
|
|
||||||
filter:Some(ScriptPolicyFilter{
|
|
||||||
from_script_hash:Some(hash),
|
|
||||||
to_script_id:None,
|
|
||||||
policy:None,
|
|
||||||
}),
|
|
||||||
page:Some(Pagination{
|
|
||||||
number:1,
|
|
||||||
size:2,
|
|
||||||
}),
|
|
||||||
}).await.map_err(ScriptPolicySingleItemError::Other)?;
|
|
||||||
if 1<policies.script_policies.len(){
|
|
||||||
return Err(ScriptPolicySingleItemError::DuplicateItems(policies.script_policies.into_iter().map(|item|ScriptPolicyId{id:item.id}).collect()));
|
|
||||||
}
|
|
||||||
Ok(policies.script_policies.into_iter().next())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user