Anukul Sangwan 4 лет назад
Родитель
Сommit
0b75cef926

+ 48 - 0
api/server/handlers/namespace/list_configmaps.go

@@ -0,0 +1,48 @@
+package namespace
+
+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/apierrors"
+	"github.com/porter-dev/porter/api/server/shared/config"
+	"github.com/porter-dev/porter/api/types"
+	"github.com/porter-dev/porter/internal/models"
+)
+
+type ListConfigMapsHandler struct {
+	handlers.PorterHandlerWriter
+	authz.KubernetesAgentGetter
+}
+
+func NewListConfigMapsHandler(
+	config *config.Config,
+	writer shared.ResultWriter,
+) *ListConfigMapsHandler {
+	return &ListConfigMapsHandler{
+		PorterHandlerWriter:   handlers.NewDefaultPorterHandler(config, nil, writer),
+		KubernetesAgentGetter: authz.NewOutOfClusterAgentGetter(config),
+	}
+}
+
+func (c *ListConfigMapsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+	namespace := r.Context().Value(types.NamespaceScope).(string)
+	cluster, _ := r.Context().Value(types.ClusterScope).(*models.Cluster)
+
+	agent, err := c.GetAgent(r, cluster)
+
+	if err != nil {
+		c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
+		return
+	}
+
+	configMaps, err := agent.ListConfigMaps(namespace)
+
+	var res = types.ListConfigMapsResponse{
+		ConfigMapList: configMaps,
+	}
+
+	c.WriteResult(w, r, res)
+}

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

@@ -83,6 +83,35 @@ func getNamespaceRoutes(
 		Router:   r,
 	})
 
+	// GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/configmap/list -> namespace.NewListConfigMapsHandler
+	listConfigMapsEndpoint := factory.NewAPIEndpoint(
+		&types.APIRequestMetadata{
+			Verb:   types.APIVerbGet,
+			Method: types.HTTPVerbGet,
+			Path: &types.Path{
+				Parent:       basePath,
+				RelativePath: relPath + "/configmap/list",
+			},
+			Scopes: []types.PermissionScope{
+				types.UserScope,
+				types.ProjectScope,
+				types.ClusterScope,
+				types.NamespaceScope,
+			},
+		},
+	)
+
+	listConfigMapsHandler := namespace.NewListConfigMapsHandler(
+		config,
+		factory.GetResultWriter(),
+	)
+
+	routes = append(routes, &Route{
+		Endpoint: listConfigMapsEndpoint,
+		Handler:  listConfigMapsHandler,
+		Router:   r,
+	})
+
 	// GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases -> namespace.NewListReleasesHandler
 	listReleasesEndpoint := factory.NewAPIEndpoint(
 		&types.APIRequestMetadata{

+ 4 - 0
api/types/namespace.go

@@ -62,3 +62,7 @@ type GetConfigMapRequest struct {
 type GetConfigMapResponse struct {
 	*v1.ConfigMap
 }
+
+type ListConfigMapsResponse struct {
+	*v1.ConfigMapList
+}

+ 2 - 3
dashboard/src/main/home/cluster-dashboard/env-groups/EnvGroupList.tsx

@@ -38,12 +38,11 @@ export default class EnvGroupList extends Component<PropsType, StateType> {
     api
       .listConfigMaps(
         "<token>",
+        {},
         {
+          id: this.context.currentProject.id,
           namespace: this.props.namespace,
           cluster_id: this.props.currentCluster.id,
-        },
-        {
-          id: this.context.currentProject.id,
         }
       )
       .then((res) => {

+ 6 - 4
dashboard/src/main/home/modals/LoadEnvGroupModal.tsx

@@ -9,7 +9,10 @@ import { Context } from "shared/Context";
 import Loading from "components/Loading";
 import SaveButton from "components/SaveButton";
 import { KeyValue } from "components/form-components/KeyValueArray";
-import { EnvGroupData, formattedEnvironmentValue } from "../cluster-dashboard/env-groups/EnvGroup";
+import {
+  EnvGroupData,
+  formattedEnvironmentValue,
+} from "../cluster-dashboard/env-groups/EnvGroup";
 
 type PropsType = {
   namespace: string;
@@ -45,12 +48,11 @@ export default class LoadEnvGroupModal extends Component<PropsType, StateType> {
     api
       .listConfigMaps(
         "<token>",
+        {},
         {
+          id: this.context.currentProject.id,
           namespace: this.props.namespace,
           cluster_id: this.props.clusterId || this.context.currentCluster.id,
-        },
-        {
-          id: this.context.currentProject.id,
         }
       )
       .then((res) => {

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

@@ -876,13 +876,14 @@ const upgradeChartValues = baseApi<
 });
 
 const listConfigMaps = baseApi<
+  {},
   {
+    id: number;
     namespace: string;
     cluster_id: number;
-  },
-  { id: number }
+  }
 >("GET", (pathParams) => {
-  return `/api/projects/${pathParams.id}/k8s/configmap/list`;
+  return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/list`;
 });
 
 const getConfigMap = baseApi<

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

@@ -80,7 +80,7 @@
 | <li>- [x] `GET /api/projects/{project_id}/k8s/configmap`                                                                    |             | yes             |             | yes              |
 | <li>- [ ] `POST /api/projects/{project_id}/k8s/configmap/create`                                                            |             |                 |             |                  |
 | <li>- [ ] `DELETE /api/projects/{project_id}/k8s/configmap/delete`                                                          |             |                 |             |                  |
-| <li>- [ ] `GET /api/projects/{project_id}/k8s/configmap/list`                                                               |             |                 |             |                  |
+| <li>- [x] `GET /api/projects/{project_id}/k8s/configmap/list`                                                               |             | yes             |             | yes              |
 | <li>- [ ] `POST /api/projects/{project_id}/k8s/configmap/rename`                                                            |             |                 |             |                  |
 | <li>- [ ] `POST /api/projects/{project_id}/k8s/configmap/update`                                                            |             |                 |             |                  |
 | <li>- [ ] `GET /api/projects/{project_id}/k8s/helm_releases`                                                                |             |                 |             |                  |