2022-09-21 04:49:42 +00:00
|
|
|
package kubernetes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2022-10-17 21:46:27 +00:00
|
|
|
"strconv"
|
2022-09-21 04:49:42 +00:00
|
|
|
|
2023-09-01 22:27:02 +00:00
|
|
|
httperror "github.com/portainer/portainer/pkg/libhttp/error"
|
|
|
|
"github.com/portainer/portainer/pkg/libhttp/request"
|
|
|
|
"github.com/portainer/portainer/pkg/libhttp/response"
|
2022-09-21 04:49:42 +00:00
|
|
|
)
|
|
|
|
|
2023-05-09 04:42:26 +00:00
|
|
|
func (handler *Handler) getKubernetesConfigMapsAndSecrets(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
2022-10-17 21:46:27 +00:00
|
|
|
endpointID, err := request.RetrieveNumericRouteVariableValue(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return httperror.BadRequest(
|
|
|
|
"Invalid environment identifier route variable",
|
|
|
|
err,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
cli, ok := handler.KubernetesClientFactory.GetProxyKubeClient(
|
|
|
|
strconv.Itoa(endpointID), r.Header.Get("Authorization"),
|
|
|
|
)
|
|
|
|
if !ok {
|
|
|
|
return httperror.InternalServerError(
|
|
|
|
"Failed to lookup KubeClient",
|
|
|
|
nil,
|
|
|
|
)
|
|
|
|
}
|
2022-09-21 04:49:42 +00:00
|
|
|
|
|
|
|
namespace, err := request.RetrieveRouteVariableValue(r, "namespace")
|
|
|
|
if err != nil {
|
2022-09-26 19:43:24 +00:00
|
|
|
return httperror.BadRequest(
|
|
|
|
"Invalid namespace identifier route variable",
|
|
|
|
err,
|
|
|
|
)
|
2022-09-21 04:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
configmaps, err := cli.GetConfigMapsAndSecrets(namespace)
|
|
|
|
if err != nil {
|
2022-09-26 19:43:24 +00:00
|
|
|
return httperror.InternalServerError(
|
2022-10-17 21:46:27 +00:00
|
|
|
"Unable to retrieve configmaps and secrets",
|
2022-09-26 19:43:24 +00:00
|
|
|
err,
|
|
|
|
)
|
2022-09-21 04:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return response.JSON(w, configmaps)
|
|
|
|
}
|