4
4
"net/http"
5
5
6
6
v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1"
7
+ "kusionstack.io/kusion/pkg/domain/constant"
7
8
)
8
9
9
10
// CreateWorkspaceRequest represents the create request structure for
@@ -33,9 +34,9 @@ type UpdateWorkspaceRequest struct {
33
34
// Labels are custom labels associated with the workspace.
34
35
Labels map [string ]string `json:"labels"`
35
36
// Owners is a list of owners for the workspace.
36
- Owners []string `json:"owners" binding:"required" `
37
+ Owners []string `json:"owners"`
37
38
// BackendID is the configuration backend id associated with the workspace.
38
- BackendID uint `json:"backendID" binding:"required" `
39
+ BackendID uint `json:"backendID"`
39
40
}
40
41
41
42
type WorkspaceCredentials struct {
@@ -53,6 +54,34 @@ type WorkspaceConfigs struct {
53
54
* v1.Workspace `yaml:",inline" json:",inline"`
54
55
}
55
56
57
+ func (payload * CreateWorkspaceRequest ) Validate () error {
58
+ if payload .Name == "" {
59
+ return constant .ErrEmptyWorkspaceName
60
+ }
61
+
62
+ if validName (payload .Name ) {
63
+ return constant .ErrInvalidWorkspaceName
64
+ }
65
+
66
+ if payload .BackendID == 0 {
67
+ return constant .ErrEmptyBackendID
68
+ }
69
+
70
+ if len (payload .Owners ) == 0 {
71
+ return constant .ErrEmptyOwners
72
+ }
73
+
74
+ return nil
75
+ }
76
+
77
+ func (payload * UpdateWorkspaceRequest ) Validate () error {
78
+ if payload .Name != "" && validName (payload .Name ) {
79
+ return constant .ErrInvalidWorkspaceName
80
+ }
81
+
82
+ return nil
83
+ }
84
+
56
85
func (payload * CreateWorkspaceRequest ) Decode (r * http.Request ) error {
57
86
return decode (r , payload )
58
87
}
0 commit comments