Skip to content

Commit 8b39102

Browse files
authored
chore: add API POST request validation (#1371)
1 parent 1597bf9 commit 8b39102

31 files changed

Lines changed: 467 additions & 157 deletions

api/openapispec/docs.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3753,18 +3753,18 @@ const docTemplate = `{
37533753
"constant.SourceProviderType": {
37543754
"type": "string",
37553755
"enum": [
3756+
"git",
37563757
"git",
37573758
"github",
37583759
"oci",
3759-
"local",
3760-
"git"
3760+
"local"
37613761
],
37623762
"x-enum-varnames": [
3763+
"DefaultSourceType",
37633764
"SourceProviderTypeGit",
37643765
"SourceProviderTypeGithub",
37653766
"SourceProviderTypeOCI",
3766-
"SourceProviderTypeLocal",
3767-
"DefaultSourceType"
3767+
"SourceProviderTypeLocal"
37683768
]
37693769
},
37703770
"constant.StackState": {
@@ -4919,6 +4919,7 @@ const docTemplate = `{
49194919
"request.CreateBackendRequest": {
49204920
"type": "object",
49214921
"required": [
4922+
"backendConfig",
49224923
"name"
49234924
],
49244925
"properties": {
@@ -4975,6 +4976,7 @@ const docTemplate = `{
49754976
"request.CreateOrganizationRequest": {
49764977
"type": "object",
49774978
"required": [
4979+
"name",
49784980
"owners"
49794981
],
49804982
"properties": {
@@ -5005,7 +5007,8 @@ const docTemplate = `{
50055007
"request.CreateProjectRequest": {
50065008
"type": "object",
50075009
"required": [
5008-
"domain"
5010+
"name",
5011+
"path"
50095012
],
50105013
"properties": {
50115014
"description": {
@@ -5188,8 +5191,7 @@ const docTemplate = `{
51885191
"request.UpdateBackendRequest": {
51895192
"type": "object",
51905193
"required": [
5191-
"id",
5192-
"name"
5194+
"id"
51935195
],
51945196
"properties": {
51955197
"backendConfig": {
@@ -5248,8 +5250,7 @@ const docTemplate = `{
52485250
"request.UpdateOrganizationRequest": {
52495251
"type": "object",
52505252
"required": [
5251-
"id",
5252-
"owners"
5253+
"id"
52535254
],
52545255
"properties": {
52555256
"description": {
@@ -5283,7 +5284,6 @@ const docTemplate = `{
52835284
"request.UpdateProjectRequest": {
52845285
"type": "object",
52855286
"required": [
5286-
"domain",
52875287
"id"
52885288
],
52895289
"properties": {
@@ -5334,10 +5334,7 @@ const docTemplate = `{
53345334
"request.UpdateSourceRequest": {
53355335
"type": "object",
53365336
"required": [
5337-
"id",
5338-
"name",
5339-
"remote",
5340-
"sourceProvider"
5337+
"id"
53415338
],
53425339
"properties": {
53435340
"description": {
@@ -5379,8 +5376,7 @@ const docTemplate = `{
53795376
"request.UpdateStackRequest": {
53805377
"type": "object",
53815378
"required": [
5382-
"id",
5383-
"name"
5379+
"id"
53845380
],
53855381
"properties": {
53865382
"description": {

api/openapispec/swagger.json

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3742,18 +3742,18 @@
37423742
"constant.SourceProviderType": {
37433743
"type": "string",
37443744
"enum": [
3745+
"git",
37453746
"git",
37463747
"github",
37473748
"oci",
3748-
"local",
3749-
"git"
3749+
"local"
37503750
],
37513751
"x-enum-varnames": [
3752+
"DefaultSourceType",
37523753
"SourceProviderTypeGit",
37533754
"SourceProviderTypeGithub",
37543755
"SourceProviderTypeOCI",
3755-
"SourceProviderTypeLocal",
3756-
"DefaultSourceType"
3756+
"SourceProviderTypeLocal"
37573757
]
37583758
},
37593759
"constant.StackState": {
@@ -4908,6 +4908,7 @@
49084908
"request.CreateBackendRequest": {
49094909
"type": "object",
49104910
"required": [
4911+
"backendConfig",
49114912
"name"
49124913
],
49134914
"properties": {
@@ -4964,6 +4965,7 @@
49644965
"request.CreateOrganizationRequest": {
49654966
"type": "object",
49664967
"required": [
4968+
"name",
49674969
"owners"
49684970
],
49694971
"properties": {
@@ -4994,7 +4996,8 @@
49944996
"request.CreateProjectRequest": {
49954997
"type": "object",
49964998
"required": [
4997-
"domain"
4999+
"name",
5000+
"path"
49985001
],
49995002
"properties": {
50005003
"description": {
@@ -5177,8 +5180,7 @@
51775180
"request.UpdateBackendRequest": {
51785181
"type": "object",
51795182
"required": [
5180-
"id",
5181-
"name"
5183+
"id"
51825184
],
51835185
"properties": {
51845186
"backendConfig": {
@@ -5237,8 +5239,7 @@
52375239
"request.UpdateOrganizationRequest": {
52385240
"type": "object",
52395241
"required": [
5240-
"id",
5241-
"owners"
5242+
"id"
52425243
],
52435244
"properties": {
52445245
"description": {
@@ -5272,7 +5273,6 @@
52725273
"request.UpdateProjectRequest": {
52735274
"type": "object",
52745275
"required": [
5275-
"domain",
52765276
"id"
52775277
],
52785278
"properties": {
@@ -5323,10 +5323,7 @@
53235323
"request.UpdateSourceRequest": {
53245324
"type": "object",
53255325
"required": [
5326-
"id",
5327-
"name",
5328-
"remote",
5329-
"sourceProvider"
5326+
"id"
53305327
],
53315328
"properties": {
53325329
"description": {
@@ -5368,8 +5365,7 @@
53685365
"request.UpdateStackRequest": {
53695366
"type": "object",
53705367
"required": [
5371-
"id",
5372-
"name"
5368+
"id"
53735369
],
53745370
"properties": {
53755371
"description": {

api/openapispec/swagger.yaml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ definitions:
3030
constant.SourceProviderType:
3131
enum:
3232
- git
33+
- git
3334
- github
3435
- oci
3536
- local
36-
- git
3737
type: string
3838
x-enum-varnames:
39+
- DefaultSourceType
3940
- SourceProviderTypeGit
4041
- SourceProviderTypeGithub
4142
- SourceProviderTypeOCI
4243
- SourceProviderTypeLocal
43-
- DefaultSourceType
4444
constant.StackState:
4545
enum:
4646
- UnSynced
@@ -864,6 +864,7 @@ definitions:
864864
description: Name is the name of the backend.
865865
type: string
866866
required:
867+
- backendConfig
867868
- name
868869
type: object
869870
request.CreateModuleRequest:
@@ -908,6 +909,7 @@ definitions:
908909
type: string
909910
type: array
910911
required:
912+
- name
911913
- owners
912914
type: object
913915
request.CreateProjectRequest:
@@ -942,7 +944,8 @@ definitions:
942944
description: SourceID is the configuration source id associated with the project.
943945
type: integer
944946
required:
945-
- domain
947+
- name
948+
- path
946949
type: object
947950
request.CreateSourceRequest:
948951
properties:
@@ -1060,7 +1063,6 @@ definitions:
10601063
type: string
10611064
required:
10621065
- id
1063-
- name
10641066
type: object
10651067
request.UpdateModuleRequest:
10661068
properties:
@@ -1107,7 +1109,6 @@ definitions:
11071109
type: array
11081110
required:
11091111
- id
1110-
- owners
11111112
type: object
11121113
request.UpdateProjectRequest:
11131114
properties:
@@ -1144,7 +1145,6 @@ definitions:
11441145
description: SourceID is the configuration source id associated with the project.
11451146
type: integer
11461147
required:
1147-
- domain
11481148
- id
11491149
type: object
11501150
request.UpdateSourceRequest:
@@ -1176,9 +1176,6 @@ definitions:
11761176
type: string
11771177
required:
11781178
- id
1179-
- name
1180-
- remote
1181-
- sourceProvider
11821179
type: object
11831180
request.UpdateStackRequest:
11841181
properties:
@@ -1218,7 +1215,6 @@ definitions:
12181215
type: string
12191216
required:
12201217
- id
1221-
- name
12221218
type: object
12231219
request.UpdateWorkspaceRequest:
12241220
properties:

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,15 @@ require (
105105
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
106106
github.com/containers/ocicrypt v1.2.0 // indirect
107107
github.com/containers/storage v1.56.0 // indirect
108+
github.com/creack/pty v1.1.20 // indirect
108109
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
109110
github.com/distribution/reference v0.6.0 // indirect
110111
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
111112
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
112113
github.com/goccy/go-json v0.10.3 // indirect
113114
github.com/hashicorp/go-hclog v1.6.3 // indirect
114115
github.com/hashicorp/go-plugin v1.6.1 // indirect
116+
github.com/hashicorp/golang-lru v1.0.2 // indirect
115117
github.com/kubescape/go-git-url v0.0.30 // indirect
116118
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
117119
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
@@ -325,9 +327,9 @@ require (
325327
go.opentelemetry.io/otel v1.31.0 // indirect
326328
go.opentelemetry.io/otel/metric v1.31.0 // indirect
327329
go.opentelemetry.io/otel/trace v1.31.0 // indirect
328-
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
330+
go.starlark.net v0.0.0-20231101134539-556fd59b42f6 // indirect
329331
go.uber.org/multierr v1.11.0 // indirect
330-
golang.org/x/arch v0.4.0 // indirect
332+
golang.org/x/arch v0.11.0 // indirect
331333
golang.org/x/crypto v0.29.0
332334
golang.org/x/mod v0.22.0 // indirect
333335
golang.org/x/net v0.31.0 // indirect

go.sum

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ github.com/containers/storage v1.56.0/go.mod h1:c6WKowcAlED/DkWGNuL9bvGYqIWCVy7i
438438
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
439439
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
440440
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
441-
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
442-
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
441+
github.com/creack/pty v1.1.20 h1:VIPb/a2s17qNeQgDnkfZC35RScx+blkKF8GV68n80J4=
442+
github.com/creack/pty v1.1.20/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
443443
github.com/cyphar/filepath-securejoin v0.3.4 h1:VBWugsJh2ZxJmLFSM06/0qzQyiQX2Qs0ViKrUAcqdZ8=
444444
github.com/cyphar/filepath-securejoin v0.3.4/go.mod h1:8s/MCNJREmFK0H02MF6Ihv1nakJe4L/w3WZLHNkvlYM=
445445
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -773,8 +773,8 @@ github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKe
773773
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
774774
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
775775
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
776-
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
777-
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
776+
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
777+
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
778778
github.com/hashicorp/hc-install v0.6.2 h1:V1k+Vraqz4olgZ9UzKiAcbman9i9scg9GgSt/U3mw/M=
779779
github.com/hashicorp/hc-install v0.6.2/go.mod h1:2JBpd+NCFKiHiu/yYCGaPyPHhZLxXTpz8oreHa/a3Ps=
780780
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
@@ -1162,16 +1162,16 @@ go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC
11621162
go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys=
11631163
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A=
11641164
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
1165-
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca h1:VdD38733bfYv5tUZwEIskMM93VanwNIi5bIKnDrJdEY=
1166-
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds=
1165+
go.starlark.net v0.0.0-20231101134539-556fd59b42f6 h1:+eC0F/k4aBLC4szgOcjd7bDTEnpxADJyWJE0yowgM3E=
1166+
go.starlark.net v0.0.0-20231101134539-556fd59b42f6/go.mod h1:LcLNIzVOMp4oV+uusnpk+VU+SzXaJakUuBjoCSWH5dM=
11671167
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
11681168
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
11691169
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
11701170
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
11711171
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
11721172
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
1173-
golang.org/x/arch v0.4.0 h1:A8WCeEWhLwPBKNbFi5Wv5UTCBx5zzubnXDlMOFAzFMc=
1174-
golang.org/x/arch v0.4.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
1173+
golang.org/x/arch v0.11.0 h1:KXV8WWKCXm6tRpLirl2szsO5j/oOODwZf4hATmGVNs4=
1174+
golang.org/x/arch v0.11.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
11751175
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
11761176
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
11771177
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@@ -1436,7 +1436,6 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn
14361436
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
14371437
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
14381438
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
1439-
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
14401439
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
14411440
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
14421441
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=

pkg/domain/constant/backend.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package constant
2+
3+
import "errors"
4+
5+
var (
6+
ErrInvalidBackendName = errors.New("backend name can only have alphanumeric characters and underscores with [a-zA-Z0-9_]")
7+
ErrEmptyBackendType = errors.New("backend type is required")
8+
ErrInvalidBackendType = errors.New("backend type is should be one of the following: [local, oss, s3, google]")
9+
)

pkg/domain/constant/global.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package constant
22

3-
import "time"
3+
import (
4+
"errors"
5+
"time"
6+
)
47

58
// These constants represent the possible states of a stack.
69
const (
@@ -25,3 +28,8 @@ const (
2528
CommonPageDefault = 1
2629
CommonPageSizeDefault = 10
2730
)
31+
32+
var (
33+
ErrEmptyURL = errors.New("URL is empty")
34+
ErrInvalidURL = errors.New("invalid URL")
35+
)

0 commit comments

Comments
 (0)