Justin Rhee há 3 anos atrás
pai
commit
69b153b800

+ 0 - 30
api/server/handlers/porter_app/get.go

@@ -1,30 +0,0 @@
-package porter_app
-
-import (
-	"net/http"
-
-	"github.com/porter-dev/porter/api/server/handlers"
-	"github.com/porter-dev/porter/api/server/shared"
-	"github.com/porter-dev/porter/api/server/shared/config"
-	"github.com/porter-dev/porter/api/types"
-	"github.com/porter-dev/porter/internal/models"
-)
-
-type PorterAppGetHandler struct {
-	handlers.PorterHandlerWriter
-}
-
-func NewPorterAppGetHandler(
-	config *config.Config,
-	writer shared.ResultWriter,
-) *PorterAppGetHandler {
-	return &PorterAppGetHandler{
-		PorterHandlerWriter: handlers.NewDefaultPorterHandler(config, nil, writer),
-	}
-}
-
-func (p *PorterAppGetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-	proj, _ := r.Context().Value(types.ProjectScope).(*models.Project)
-
-	p.WriteResult(w, r, proj.ToProjectType())
-}

+ 9 - 6
api/server/handlers/porter_app/create.go → api/server/handlers/stacks/create_porter_app.go

@@ -1,8 +1,10 @@
-package porter_app
+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/config"
@@ -10,6 +12,7 @@ import (
 
 type CreatePorterAppHandler struct {
 	handlers.PorterHandlerReadWriter
+	authz.KubernetesAgentGetter
 }
 
 func NewCreatePorterAppHandler(
@@ -19,14 +22,14 @@ func NewCreatePorterAppHandler(
 ) *CreatePorterAppHandler {
 	return &CreatePorterAppHandler{
 		PorterHandlerReadWriter: handlers.NewDefaultPorterHandler(config, decoderValidator, writer),
+		KubernetesAgentGetter:   authz.NewOutOfClusterAgentGetter(config),
 	}
 }
 
 func (c *CreatePorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-	// read the project from context
-	// proj, _ := r.Context().Value(types.ProjectScope).(*models.Project)
+	// ctx := r.Context()
+	// cluster, _ := ctx.Value(types.ClusterScope).(*models.Cluster)
+	fmt.Println("congrats on making it!")
 
-	// request := &types.ProjectAppRequest{}
-
-	c.WriteResult(w, r, 1)
+	w.WriteHeader(http.StatusCreated)
 }

+ 0 - 114
api/server/router/porter_app.go

@@ -1,114 +0,0 @@
-package router
-
-import (
-	"github.com/go-chi/chi"
-	"github.com/porter-dev/porter/api/server/handlers/porter_app"
-	"github.com/porter-dev/porter/api/server/shared"
-	"github.com/porter-dev/porter/api/server/shared/config"
-	"github.com/porter-dev/porter/api/server/shared/router"
-	"github.com/porter-dev/porter/api/types"
-)
-
-func NewPorterAppScopedRegisterer(children ...*router.Registerer) *router.Registerer {
-	return &router.Registerer{
-		GetRoutes: GetPorterAppScopedRoutes,
-		Children:  children,
-	}
-}
-
-func GetPorterAppScopedRoutes(
-	r chi.Router,
-	config *config.Config,
-	basePath *types.Path,
-	factory shared.APIEndpointFactory,
-	children ...*router.Registerer,
-) []*router.Route {
-	routes, porterAppPath := getPorterAppRoutes(r, config, basePath, factory)
-
-	if len(children) > 0 {
-		r.Route(porterAppPath.RelativePath, func(r chi.Router) {
-			for _, child := range children {
-				childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
-
-				routes = append(routes, childRoutes...)
-			}
-		})
-	}
-
-	return routes
-}
-
-func getPorterAppRoutes(
-	r chi.Router,
-	config *config.Config,
-	basePath *types.Path,
-	factory shared.APIEndpointFactory,
-) ([]*router.Route, *types.Path) {
-	relPath := "/porter_apps/{name}"
-
-	newPath := &types.Path{
-		Parent:       basePath,
-		RelativePath: relPath,
-	}
-
-	routes := make([]*router.Route, 0)
-
-	// GET /api/projects/{project_id}/clusters/{cluster_id}/porter_apps/{name} -> porter_app.NewPorterAppGetHandler
-	getEndpoint := factory.NewAPIEndpoint(
-		&types.APIRequestMetadata{
-			Verb:   types.APIVerbGet,
-			Method: types.HTTPVerbGet,
-			Path: &types.Path{
-				Parent:       basePath,
-				RelativePath: relPath,
-			},
-			Scopes: []types.PermissionScope{
-				types.UserScope,
-				types.ProjectScope,
-				types.ClusterScope,
-			},
-		},
-	)
-
-	getHandler := porter_app.NewPorterAppGetHandler(
-		config,
-		factory.GetResultWriter(),
-	)
-
-	routes = append(routes, &router.Route{
-		Endpoint: getEndpoint,
-		Handler:  getHandler,
-		Router:   r,
-	})
-
-	// POST /api/projects/{project_id}/clusters/{cluster_id}/porter_apps -> porter_app.NewCreatePorterAppHandler
-	createPorterAppEndpoint := factory.NewAPIEndpoint(
-		&types.APIRequestMetadata{
-			Verb:   types.APIVerbCreate,
-			Method: types.HTTPVerbPost,
-			Path: &types.Path{
-				Parent:       basePath,
-				RelativePath: relPath,
-			},
-			Scopes: []types.PermissionScope{
-				types.UserScope,
-				types.ProjectScope,
-				types.ClusterScope,
-			},
-		},
-	)
-
-	createPorterAppHandler := porter_app.NewCreatePorterAppHandler(
-		config,
-		factory.GetDecoderValidator(),
-		factory.GetResultWriter(),
-	)
-
-	routes = append(routes, &router.Route{
-		Endpoint: createPorterAppEndpoint,
-		Handler:  createPorterAppHandler,
-		Router:   r,
-	})
-
-	return routes, newPath
-}

+ 0 - 2
api/server/router/router.go

@@ -27,7 +27,6 @@ func NewAPIRouter(config *config.Config) *chi.Mux {
 	baseRegisterer := NewBaseRegisterer()
 	oauthCallbackRegisterer := NewOAuthCallbackRegisterer()
 
-	porterAppRegisterer := NewPorterAppScopedRegisterer()
 	releaseRegisterer := NewReleaseScopedRegisterer()
 	namespaceRegisterer := NewNamespaceScopedRegisterer(releaseRegisterer)
 	clusterIntegrationRegisterer := NewClusterIntegrationScopedRegisterer()
@@ -43,7 +42,6 @@ func NewAPIRouter(config *config.Config) *chi.Mux {
 	slackIntegrationRegisterer := NewSlackIntegrationScopedRegisterer()
 	projRegisterer := NewProjectScopedRegisterer(
 		clusterRegisterer,
-		porterAppRegisterer,
 		registryRegisterer,
 		helmRepoRegisterer,
 		inviteRegisterer,

+ 29 - 0
api/server/router/stack.go

@@ -53,6 +53,35 @@ func getStackRoutes(
 
 	var routes []*router.Route
 
+	// POST /api/projects/{project_id}/clusters/{cluster_id}/stacks/update_config -> stacks.NewCreateStackHandler
+	createPorterAppEndpoint := factory.NewAPIEndpoint(
+		&types.APIRequestMetadata{
+			Verb:   types.APIVerbCreate,
+			Method: types.HTTPVerbPost,
+			Path: &types.Path{
+				Parent:       basePath,
+				RelativePath: relPath + "/update_config",
+			},
+			Scopes: []types.PermissionScope{
+				types.UserScope,
+				types.ProjectScope,
+				types.ClusterScope,
+			},
+		},
+	)
+
+	createPorterAppHandler := stacks.NewCreatePorterAppHandler(
+		config,
+		factory.GetDecoderValidator(),
+		factory.GetResultWriter(),
+	)
+
+	routes = append(routes, &router.Route{
+		Endpoint: createPorterAppEndpoint,
+		Handler:  createPorterAppHandler,
+		Router:   r,
+	})
+
 	// POST /api/projects/{project_id}/clusters/{cluster_id}/stacks -> stacks.NewCreateStackHandler
 	createEndpoint := factory.NewAPIEndpoint(
 		&types.APIRequestMetadata{

+ 3 - 2
dashboard/src/components/porter/VerticalSteps.tsx

@@ -16,7 +16,7 @@ const VerticalSteps: React.FC<Props> = ({
     <StyledVerticalSteps>
       {steps.map((step, i) => {
         return (
-          <StepWrapper>
+          <StepWrapper isLast={i === steps.length - 1}>
             {
               (i !== steps.length - 1) && (
                 <Line isActive={i + 1 <= currentStep} />
@@ -83,10 +83,11 @@ const OpacityWrapper = styled.div<{
 `;
 
 const StepWrapper = styled.div<{
+  isLast: boolean;
 }>`
   padding-left: 30px;
   position: relative;
-  margin-bottom: 35px;
+  margin-bottom: ${props => props.isLast ? "" : "35px"};
 `;
 
 const StyledVerticalSteps = styled.div<{

+ 16 - 0
dashboard/src/main/home/app-dashboard/AppDashboard.tsx

@@ -167,6 +167,22 @@ const AppDashboard: React.FC<Props> = ({
           })}
         </List>
       )}
+      <Button 
+        onClick={async () => {
+          try {
+            const res = await api.createPorterApp("<token>", { name: "cool" }, {
+              project_id: currentProject.id,
+              cluster_id: currentCluster.id,
+            });
+            console.log(res.data);
+          }
+          catch (err) {
+            console.log(err);
+          }
+        }}
+      >
+        Diplo
+      </Button>
       <Spacer y={5} />
     </StyledAppDashboard>
   );

+ 2 - 2
dashboard/src/main/home/app-dashboard/new-app-flow/NewAppFlow.tsx

@@ -226,10 +226,10 @@ const NewAppFlow: React.FC<Props> = ({ ...props }) => {
                   setValue={(e) => {}}
                 />
               </>,
+              <Button onClick={() => setShowGHAModal(true)}>Deploy app</Button>
             ]}
           />
-          <Spacer y={1} />
-          <Button onClick={() => setShowGHAModal(true)}>DEPLYOY</Button>
+          <Spacer y={3} />
         </StyledConfigureTemplate>
       </Div>
       {showGHAModal && (

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

@@ -164,6 +164,19 @@ const createEmailVerification = baseApi<{}, {}>("POST", (pathParams) => {
   return `/api/email/verify/initiate`;
 });
 
+const createPorterApp = baseApi<
+  {
+    name: string;
+  },
+  {
+    project_id: number;
+    cluster_id: number;
+  }
+>("POST", (pathParams) => {
+  let { project_id, cluster_id } = pathParams;
+  return `/api/projects/${project_id}/clusters/${cluster_id}/stacks/update_config`;
+});
+
 const createEnvironment = baseApi<
   {
     name: string;
@@ -2443,6 +2456,7 @@ export default {
   createPasswordResetVerify,
   createPasswordResetFinalize,
   createProject,
+  createPorterApp,
   createConfigMap,
   deleteCluster,
   deleteConfigMap,