Kaynağa Gözat

add get components endpoint

Alexander Belanger 4 yıl önce
ebeveyn
işleme
0d4ae2feeb

+ 45 - 0
api/server/handlers/release/get_components.go

@@ -0,0 +1,45 @@
+package release
+
+import (
+	"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"
+	"github.com/porter-dev/porter/api/types"
+	"github.com/porter-dev/porter/internal/helm/grapher"
+	"helm.sh/helm/v3/pkg/release"
+)
+
+type GetComponentsHandler struct {
+	handlers.PorterHandlerReadWriter
+	authz.KubernetesAgentGetter
+}
+
+func NewGetComponentsHandler(
+	config *config.Config,
+	writer shared.ResultWriter,
+) *GetComponentsHandler {
+	return &GetComponentsHandler{
+		PorterHandlerReadWriter: handlers.NewDefaultPorterHandler(config, nil, writer),
+		KubernetesAgentGetter:   authz.NewOutOfClusterAgentGetter(config),
+	}
+}
+
+func (c *GetComponentsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+	helmRelease, _ := r.Context().Value(types.ReleaseScope).(*release.Release)
+
+	yamlArr := grapher.ImportMultiDocYAML([]byte(helmRelease.Manifest))
+	objects := grapher.ParseObjs(yamlArr, helmRelease.Namespace)
+
+	parsed := grapher.ParsedObjs{
+		Objects: objects,
+	}
+
+	parsed.GetControlRel()
+	parsed.GetLabelRel()
+	parsed.GetSpecRel()
+
+	c.WriteResult(w, r, parsed)
+}

+ 30 - 0
api/server/router/release.go

@@ -112,6 +112,36 @@ func getReleaseRoutes(
 		Router:   r,
 	})
 
+	// GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/{version}/components -> release.NewGetComponentsHandler
+	getComponentsEndpoint := factory.NewAPIEndpoint(
+		&types.APIRequestMetadata{
+			Verb:   types.APIVerbGet,
+			Method: types.HTTPVerbGet,
+			Path: &types.Path{
+				Parent:       basePath,
+				RelativePath: relPath + "/components",
+			},
+			Scopes: []types.PermissionScope{
+				types.UserScope,
+				types.ProjectScope,
+				types.ClusterScope,
+				types.NamespaceScope,
+				types.ReleaseScope,
+			},
+		},
+	)
+
+	getComponentsHandler := release.NewGetComponentsHandler(
+		config,
+		factory.GetResultWriter(),
+	)
+
+	routes = append(routes, &Route{
+		Endpoint: getComponentsEndpoint,
+		Handler:  getComponentsHandler,
+		Router:   r,
+	})
+
 	// GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases/{name}/history -> release.NewGetHistoryHandler
 	getHistoryEndpoint := factory.NewAPIEndpoint(
 		&types.APIRequestMetadata{

+ 2 - 3
dashboard/src/main/home/cluster-dashboard/expanded-chart/ExpandedChart.tsx

@@ -203,13 +203,12 @@ const ExpandedChart: React.FC<Props> = (props) => {
       const res = await api.getChartComponents(
         "<token>",
         {
-          namespace: currentChart.namespace,
-          cluster_id: currentCluster.id,
-          storage: StorageType.Secret,
         },
         {
           id: currentProject.id,
           name: currentChart.name,
+          namespace: currentChart.namespace,
+          cluster_id: currentCluster.id,
           revision: currentChart.version,
         }
       );

+ 5 - 6
dashboard/src/shared/api.tsx

@@ -431,13 +431,12 @@ const getCharts = baseApi<
 
 const getChartComponents = baseApi<
   {
-    namespace: string;
-    cluster_id: number;
-    storage: StorageType;
   },
-  { id: number; name: string; revision: number }
+  { id: number; cluster_id: number; namespace: string; name: string; revision: number }
 >("GET", (pathParams) => {
-  return `/api/projects/${pathParams.id}/releases/${pathParams.name}/${pathParams.revision}/components`;
+  let { id, cluster_id, namespace, name, revision } = pathParams
+
+  return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/${revision}/components`
 });
 
 const getChartControllers = baseApi<
@@ -733,7 +732,7 @@ const getRevisions = baseApi<
   { id: number; cluster_id: number; namespace: string; name: string }
 >("GET", (pathParams) => {
   console.log("PATH PARAMS", pathParams)
-  
+
   let { id, cluster_id, namespace, name } = pathParams
 
   return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/history`

+ 1 - 1
docs/developing/backend-refactor-status.md

@@ -133,7 +133,7 @@
 | <li>- [ ] `GET /api/projects/{project_id}/releases/{name}/webhook_token`                                                    |             |                 |             |                  |
 | <li>- [ ] `POST /api/projects/{project_id}/releases/{name}/webhook_token`                                                   |             |                 |             |                  |
 | <li>- [x] `GET /api/projects/{project_id}/releases/{name}/{revision}`                                                       |             |                 |             |                  |
-| <li>- [ ] `GET /api/projects/{project_id}/releases/{name}/{revision}/components`                                            |             |                 |             |                  |
+| <li>- [X] `GET /api/projects/{project_id}/releases/{name}/{revision}/components`                                            | AB          |                 |             |                  |
 | <li>- [X] `GET /api/projects/{project_id}/releases/{name}/{revision}/controllers`                                           | AB          | yes             |             |                  |
 | <li>- [ ] `GET /api/projects/{project_id}/releases/{name}/{revision}/pods/all`                                              |             |                 |             |                  |
 | <li>- [ ] `GET /api/projects/{project_id}/roles`                                                                            |             |                 |             |                  |