Skip to content

Commit

Permalink
feat: add workspace config apis for kusion server
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-hm19 committed Nov 14, 2024
1 parent 210ef29 commit e4c61cb
Show file tree
Hide file tree
Showing 15 changed files with 3,351 additions and 487 deletions.
1,037 changes: 953 additions & 84 deletions api/openapispec/docs.go

Large diffs are not rendered by default.

1,037 changes: 953 additions & 84 deletions api/openapispec/swagger.json

Large diffs are not rendered by default.

625 changes: 615 additions & 10 deletions api/openapispec/swagger.yaml

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion pkg/domain/request/workspace_request.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package request

import "net/http"
import (
"net/http"

v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1"
)

// CreateWorkspaceRequest represents the create request structure for
// workspace.
Expand Down Expand Up @@ -45,6 +49,10 @@ type WorkspaceCredentials struct {
AwsRegion string `json:"awsRegion,omitempty"`
}

type WorkspaceConfigs struct {
*v1.Workspace `yaml:",inline" json:",inline"`
}

func (payload *CreateWorkspaceRequest) Decode(r *http.Request) error {
return decode(r, payload)
}
Expand All @@ -56,3 +64,7 @@ func (payload *UpdateWorkspaceRequest) Decode(r *http.Request) error {
func (payload *WorkspaceCredentials) Decode(r *http.Request) error {
return decode(r, payload)
}

func (payload *WorkspaceConfigs) Decode(r *http.Request) error {
return decode(r, payload)
}
4 changes: 2 additions & 2 deletions pkg/server/handler/module/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (h *Handler) DeleteModule() http.HandlerFunc {
// @Failure 429 {object} error "Too Many Requests"
// @Failure 404 {object} error "Not Found"
// @Failure 500 {object} error "Internal Server Error"
// @Router /api/v1/modules/{name} [put]
// @Router /api/v1/modules/{name} [put]
func (h *Handler) UpdateModule() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// Getting stuff from context.
Expand Down Expand Up @@ -125,7 +125,7 @@ func (h *Handler) UpdateModule() http.HandlerFunc {
// @Failure 429 {object} error "Too Many Requests"
// @Failure 404 {object} error "Not Found"
// @Failure 500 {object} error "Internal Server Error"
// @Router /api/v1/modules/{name} [get]
// @Router /api/v1/modules/{name} [get]
func (h *Handler) GetModule() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// Getting stuff from context.
Expand Down
142 changes: 71 additions & 71 deletions pkg/server/handler/stack/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ import (
stackmanager "kusionstack.io/kusion/pkg/server/manager/stack"
)

// @Id previewStack
// @Summary Preview stack
// @Description Preview stack information by stack ID
// @Tags stack
// @Produce json
// @Param stack_id path int true "Stack ID"
// @Param importedResources body request.StackImportRequest false "The resources to import during the stack preview"
// @Param workspace query string true "The target workspace to preview the spec in."
// @Param importResources query bool false "Import existing resources during the stack preview"
// @Param output query string false "Output format. Choices are: json, default. Default to default output format in Kusion."
// @Param detail query bool false "Show detailed output"
// @Param specID query string false "The Spec ID to use for the preview. Default to the last one generated."
// @Param force query bool false "Force the preview even when the stack is locked"
// @Success 200 {object} models.Changes "Success"
// @Failure 400 {object} error "Bad Request"
// @Failure 401 {object} error "Unauthorized"
// @Failure 429 {object} error "Too Many Requests"
// @Failure 404 {object} error "Not Found"
// @Failure 500 {object} error "Internal Server Error"
// @Router /api/v1/stacks/{stack_id}/preview [post]
// @Id previewStack

Check failure on line 17 in pkg/server/handler/stack/execute.go

View workflow job for this annotation

GitHub Actions / Golang Lint

File is not `gofumpt`-ed (gofumpt)
// @Summary Preview stack
// @Description Preview stack information by stack ID
// @Tags stack
// @Produce json
// @Param stack_id path int true "Stack ID"
// @Param importedResources body request.StackImportRequest false "The resources to import during the stack preview"
// @Param workspace query string true "The target workspace to preview the spec in."
// @Param importResources query bool false "Import existing resources during the stack preview"
// @Param output query string false "Output format. Choices are: json, default. Default to default output format in Kusion."
// @Param detail query bool false "Show detailed output"
// @Param specID query string false "The Spec ID to use for the preview. Default to the last one generated."
// @Param force query bool false "Force the preview even when the stack is locked"
// @Success 200 {object} models.Changes "Success"
// @Failure 400 {object} error "Bad Request"
// @Failure 401 {object} error "Unauthorized"
// @Failure 429 {object} error "Too Many Requests"
// @Failure 404 {object} error "Not Found"
// @Failure 500 {object} error "Internal Server Error"
// @Router /api/v1/stacks/{stack_id}/preview [post]
func (h *Handler) PreviewStack() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// Getting stuff from context
Expand Down Expand Up @@ -73,22 +73,22 @@ func (h *Handler) PreviewStack() http.HandlerFunc {
}
}

// @Id generateStack
// @Summary Generate stack
// @Description Generate stack information by stack ID
// @Tags stack
// @Produce json
// @Param stack_id path int true "Stack ID"
// @Param workspace query string true "The target workspace to preview the spec in."
// @Param format query string false "The format to generate the spec in. Choices are: spec. Default to spec."
// @Param force query bool false "Force the generate even when the stack is locked"
// @Success 200 {object} v1.Spec "Success"
// @Failure 400 {object} error "Bad Request"
// @Failure 401 {object} error "Unauthorized"
// @Failure 429 {object} error "Too Many Requests"
// @Failure 404 {object} error "Not Found"
// @Failure 500 {object} error "Internal Server Error"
// @Router /api/v1/stacks/{stack_id}/generate [post]
// @Id generateStack

Check failure on line 76 in pkg/server/handler/stack/execute.go

View workflow job for this annotation

GitHub Actions / Golang Lint

File is not `gofumpt`-ed (gofumpt)
// @Summary Generate stack
// @Description Generate stack information by stack ID
// @Tags stack
// @Produce json
// @Param stack_id path int true "Stack ID"
// @Param workspace query string true "The target workspace to preview the spec in."
// @Param format query string false "The format to generate the spec in. Choices are: spec. Default to spec."
// @Param force query bool false "Force the generate even when the stack is locked"
// @Success 200 {object} v1.Spec "Success"
// @Failure 400 {object} error "Bad Request"
// @Failure 401 {object} error "Unauthorized"
// @Failure 429 {object} error "Too Many Requests"
// @Failure 404 {object} error "Not Found"
// @Failure 500 {object} error "Internal Server Error"
// @Router /api/v1/stacks/{stack_id}/generate [post]
func (h *Handler) GenerateStack() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// Getting stuff from context
Expand All @@ -111,25 +111,25 @@ func (h *Handler) GenerateStack() http.HandlerFunc {
}
}

// @Id applyStack
// @Summary Apply stack
// @Description Apply stack information by stack ID
// @Tags stack
// @Produce json
// @Param stack_id path int true "Stack ID"
// @Param importedResources body request.StackImportRequest false "The resources to import during the stack preview"
// @Param workspace query string true "The target workspace to preview the spec in."
// @Param importResources query bool false "Import existing resources during the stack preview"
// @Param specID query string false "The Spec ID to use for the apply. Will generate a new spec if omitted."
// @Param force query bool false "Force the apply even when the stack is locked. May cause concurrency issues!!!"
// @Param dryrun query bool false "Apply in dry-run mode"
// @Success 200 {object} string "Success"
// @Failure 400 {object} error "Bad Request"
// @Failure 401 {object} error "Unauthorized"
// @Failure 429 {object} error "Too Many Requests"
// @Failure 404 {object} error "Not Found"
// @Failure 500 {object} error "Internal Server Error"
// @Router /api/v1/stacks/{stack_id}/apply [post]
// @Id applyStack

Check failure on line 114 in pkg/server/handler/stack/execute.go

View workflow job for this annotation

GitHub Actions / Golang Lint

File is not `gofumpt`-ed (gofumpt)
// @Summary Apply stack
// @Description Apply stack information by stack ID
// @Tags stack
// @Produce json
// @Param stack_id path int true "Stack ID"
// @Param importedResources body request.StackImportRequest false "The resources to import during the stack preview"
// @Param workspace query string true "The target workspace to preview the spec in."
// @Param importResources query bool false "Import existing resources during the stack preview"
// @Param specID query string false "The Spec ID to use for the apply. Will generate a new spec if omitted."
// @Param force query bool false "Force the apply even when the stack is locked. May cause concurrency issues!!!"
// @Param dryrun query bool false "Apply in dry-run mode"
// @Success 200 {object} string "Success"
// @Failure 400 {object} error "Bad Request"
// @Failure 401 {object} error "Unauthorized"
// @Failure 429 {object} error "Too Many Requests"
// @Failure 404 {object} error "Not Found"
// @Failure 500 {object} error "Internal Server Error"
// @Router /api/v1/stacks/{stack_id}/apply [post]
func (h *Handler) ApplyStack() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// Getting stuff from context
Expand Down Expand Up @@ -178,22 +178,22 @@ func (h *Handler) ApplyStack() http.HandlerFunc {
}
}

// @Id destroyStack
// @Summary Destroy stack
// @Description Destroy stack information by stack ID
// @Tags stack
// @Produce json
// @Param stack_id path int true "Stack ID"
// @Param workspace query string true "The target workspace to preview the spec in."
// @Param force query bool false "Force the destroy even when the stack is locked. May cause concurrency issues!!!"
// @Param dryrun query bool false "Destroy in dry-run mode"
// @Success 200 {object} string "Success"
// @Failure 400 {object} error "Bad Request"
// @Failure 401 {object} error "Unauthorized"
// @Failure 429 {object} error "Too Many Requests"
// @Failure 404 {object} error "Not Found"
// @Failure 500 {object} error "Internal Server Error"
// @Router /api/v1/stacks/{stack_id}/destroy [post]
// @Id destroyStack
// @Summary Destroy stack
// @Description Destroy stack information by stack ID
// @Tags stack
// @Produce json
// @Param stack_id path int true "Stack ID"
// @Param workspace query string true "The target workspace to preview the spec in."
// @Param force query bool false "Force the destroy even when the stack is locked. May cause concurrency issues!!!"
// @Param dryrun query bool false "Destroy in dry-run mode"
// @Success 200 {object} string "Success"
// @Failure 400 {object} error "Bad Request"
// @Failure 401 {object} error "Unauthorized"
// @Failure 429 {object} error "Too Many Requests"
// @Failure 404 {object} error "Not Found"
// @Failure 500 {object} error "Internal Server Error"
// @Router /api/v1/stacks/{stack_id}/destroy [post]
func (h *Handler) DestroyStack() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// Getting stuff from context
Expand Down
Loading

0 comments on commit e4c61cb

Please sign in to comment.