Explorar el Código

implement get stack endpoint

Justin Rhee hace 3 años
padre
commit
15e955772a

+ 45 - 0
api/server/handlers/stacks/get_porter_app.go

@@ -0,0 +1,45 @@
+package stacks
+
+import (
+	"fmt"
+	"net/http"
+
+	"github.com/porter-dev/porter/api/server/authz"
+	"github.com/porter-dev/porter/api/server/handlers"
+	"github.com/porter-dev/porter/api/server/shared"
+	"github.com/porter-dev/porter/api/server/shared/apierrors"
+	"github.com/porter-dev/porter/api/server/shared/config"
+	"github.com/porter-dev/porter/api/server/shared/requestutils"
+	"github.com/porter-dev/porter/api/types"
+	"github.com/porter-dev/porter/internal/models"
+)
+
+type GetPorterAppHandler struct {
+	handlers.PorterHandlerReadWriter
+	authz.KubernetesAgentGetter
+}
+
+func NewGetPorterAppHandler(
+	config *config.Config,
+	writer shared.ResultWriter,
+) *GetPorterAppHandler {
+	return &GetPorterAppHandler{
+		PorterHandlerReadWriter: handlers.NewDefaultPorterHandler(config, nil, writer),
+	}
+}
+
+func (c *GetPorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+	ctx := r.Context()
+	cluster, _ := ctx.Value(types.ClusterScope).(*models.Cluster)
+	name, _ := requestutils.GetURLParamString(r, types.URLParamReleaseName)
+
+	app, err := c.Repo().PorterApp().ReadPorterApp(cluster.ID, name)
+	if err != nil {
+		c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
+		return
+	}
+
+	fmt.Println("got here", app)
+
+	c.WriteResult(w, r, app.ToPorterAppType())
+}

+ 8 - 9
api/server/router/stack.go

@@ -55,14 +55,14 @@ func getStackRoutes(
 
 	var routes []*router.Route
 
-	// POST /api/projects/{project_id}/clusters/{cluster_id}/stacks/update_config -> stacks.NewCreateStackHandler
-	createPorterAppEndpoint := factory.NewAPIEndpoint(
+	// GET /api/projects/{project_id}/clusters/{cluster_id}/stacks/{name} -> stacks.NewPorterAppGetHandler
+	getPorterAppEndpoint := factory.NewAPIEndpoint(
 		&types.APIRequestMetadata{
-			Verb:   types.APIVerbCreate,
-			Method: types.HTTPVerbPost,
+			Verb:   types.APIVerbGet,
+			Method: types.HTTPVerbGet,
 			Path: &types.Path{
 				Parent:       basePath,
-				RelativePath: relPath + "/update_config",
+				RelativePath: relPath + "/{name}",
 			},
 			Scopes: []types.PermissionScope{
 				types.UserScope,
@@ -72,15 +72,14 @@ func getStackRoutes(
 		},
 	)
 
-	createPorterAppHandler := stacks.NewCreatePorterAppHandler(
+	getPorterAppHandler := stacks.NewGetPorterAppHandler(
 		config,
-		factory.GetDecoderValidator(),
 		factory.GetResultWriter(),
 	)
 
 	routes = append(routes, &router.Route{
-		Endpoint: createPorterAppEndpoint,
-		Handler:  createPorterAppHandler,
+		Endpoint: getPorterAppEndpoint,
+		Handler:  getPorterAppHandler,
 		Router:   r,
 	})
 

+ 13 - 0
dashboard/src/shared/api.tsx

@@ -164,6 +164,18 @@ const createEmailVerification = baseApi<{}, {}>("POST", (pathParams) => {
   return `/api/email/verify/initiate`;
 });
 
+const getPorterApp = baseApi<
+  {},
+  {
+    project_id: number;
+    cluster_id: number;
+    name: string;
+  }
+>("GET", (pathParams) => {
+  let { project_id, cluster_id, name } = pathParams;
+  return `/api/projects/${project_id}/clusters/${cluster_id}/stacks/${name}`;
+});
+
 const createPorterApp = baseApi<
   {
     name: string;
@@ -2529,6 +2541,7 @@ export default {
   createPasswordResetVerify,
   createPasswordResetFinalize,
   createProject,
+  getPorterApp,
   createPorterApp,
   updatePorterStack,
   createConfigMap,