Jelajahi Sumber

Replaced update stack name with update stack

jnfrati 3 tahun lalu
induk
melakukan
0c8394dea3

+ 6 - 6
api/server/handlers/stack/update_stack_name.go → api/server/handlers/stack/update_stack.go

@@ -12,25 +12,25 @@ import (
 	"github.com/porter-dev/porter/internal/models"
 )
 
-type StackUpdateStackName struct {
+type StackUpdateStack struct {
 	handlers.PorterHandlerReadWriter
 }
 
-func NewStackUpdateStackNameHandler(
+func NewStackUpdateStackHandler(
 	config *config.Config,
 	reader shared.RequestDecoderValidator,
 	writer shared.ResultWriter,
-) *StackUpdateStackName {
-	return &StackUpdateStackName{
+) *StackUpdateStack {
+	return &StackUpdateStack{
 		PorterHandlerReadWriter: handlers.NewDefaultPorterHandler(config, reader, writer),
 	}
 }
 
-func (p *StackUpdateStackName) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+func (p *StackUpdateStack) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 	proj, _ := r.Context().Value(types.ProjectScope).(*models.Project)
 	stack, _ := r.Context().Value(types.StackScope).(*models.Stack)
 
-	req := &types.UpdateStackNameRequest{}
+	req := &types.UpdateStackRequest{}
 
 	if ok := p.DecodeAndValidate(w, r, req); !ok {
 		return

+ 10 - 11
api/server/router/v1/stack.go

@@ -820,10 +820,11 @@ func getV1StackRoutes(
 		Router:   r,
 	})
 
-	// PATCH /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/update_name -> stack.NewStackAddApplicationHandler
-	// swagger:operation PATCH /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id}/update_name addApplication
+	// PATCH /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id} -> stack.NewStackUpdateStackHandler
+	// swagger:operation PATCH /api/v1/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/stacks/{stack_id} updateStack
 	//
-	// Adds an application to an existing stack
+	// Updates a stack.
+	// Currently only the stack name can be updated.
 	//
 	// ---
 	// produces:
@@ -837,15 +838,13 @@ func getV1StackRoutes(
 	//   - name: namespace
 	//   - name: stack_id
 	//   - in: body
-	//     name: AddApplicationToStack
-	//     description: The application to add
+	//     name: UpdateStack
+	//     description: The stack to update
 	//     schema:
-	//       $ref: '#/definitions/CreateStackAppResourceRequest'
+	//       $ref: '#/definitions/UpdateStackRequest'
 	// responses:
 	//   '200':
-	//     description: Successfully added the application to the stack
-	//   '400':
-	//     description: Stack does not have any revisions
+	//     description: Successfully updated the stack
 	//   '403':
 	//     description: Forbidden
 	updateStackNameEndpoint := factory.NewAPIEndpoint(
@@ -854,7 +853,7 @@ func getV1StackRoutes(
 			Method: types.HTTPVerbPatch,
 			Path: &types.Path{
 				Parent:       basePath,
-				RelativePath: relPath + "/{stack_id}/update_name",
+				RelativePath: relPath + "/{stack_id}",
 			},
 			Scopes: []types.PermissionScope{
 				types.UserScope,
@@ -866,7 +865,7 @@ func getV1StackRoutes(
 		},
 	)
 
-	updateStackNameHandler := stack.NewStackUpdateStackNameHandler(
+	updateStackNameHandler := stack.NewStackUpdateStackHandler(
 		config,
 		factory.GetDecoderValidator(),
 		factory.GetResultWriter(),

+ 1 - 1
api/types/stacks.go

@@ -63,7 +63,7 @@ type CreateStackAppResourceRequest struct {
 	SourceConfigName string `json:"source_config_name" form:"required"`
 }
 
-type UpdateStackNameRequest struct {
+type UpdateStackRequest struct {
 	Name string `json:"name" form:"required"`
 }
 

+ 1 - 1
dashboard/src/main/home/cluster-dashboard/stacks/ExpandedStack/components/Settings.tsx

@@ -40,7 +40,7 @@ const Settings = ({
   const handleStackNameChange = async () => {
     setButtonStatus("loading");
     try {
-      await api.updateStackName(
+      await api.updateStack(
         "<token>",
         {
           name: stackName,

+ 3 - 3
dashboard/src/shared/api.tsx

@@ -2145,7 +2145,7 @@ const removeStackEnvGroup = baseApi<
     `/api/v1/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/stacks/${stack_id}/remove_env_group/${env_group_name}`
 );
 
-const updateStackName = baseApi<
+const updateStack = baseApi<
   {
     name: string;
   },
@@ -2158,7 +2158,7 @@ const updateStackName = baseApi<
 >(
   "PATCH",
   ({ project_id, cluster_id, namespace, stack_id }) =>
-    `/api/v1/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/stacks/${stack_id}/update_name`
+    `/api/v1/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/stacks/${stack_id}`
 );
 
 const getGithubStatus = baseApi<{}, {}>("GET", ({}) => `/api/status/github`);
@@ -2362,7 +2362,7 @@ export default {
   removeStackAppResource,
   addStackEnvGroup,
   removeStackEnvGroup,
-  updateStackName,
+  updateStack,
 
   // STATUS
   getGithubStatus,