(c echo.Context)
| 70 | } |
| 71 | |
| 72 | func (h *AppConfigHandler) PostBearer(c echo.Context) error { |
| 73 | serverIP := strings.TrimSpace(c.FormValue("serverIP")) |
| 74 | name := strings.TrimSpace(c.FormValue("name")) |
| 75 | token := strings.TrimSpace(c.FormValue("token")) |
| 76 | configName := strings.TrimSpace(c.FormValue("configName")) |
| 77 | |
| 78 | if serverIP == "" || name == "" || token == "" { |
| 79 | return echo.NewHTTPError(http.StatusBadRequest, "missing required fields: serverIP, name, or token") |
| 80 | } |
| 81 | |
| 82 | // Validate config name |
| 83 | if err := validateConfigName(configName); err != nil { |
| 84 | return echo.NewHTTPError(http.StatusBadRequest, err.Error()) |
| 85 | } |
| 86 | |
| 87 | // Normalize to lowercase |
| 88 | configName = strings.ToLower(strings.TrimSpace(configName)) |
| 89 | |
| 90 | // Check for duplicates |
| 91 | if h.container.Config().ConfigExists(configName) { |
| 92 | return echo.NewHTTPError(http.StatusConflict, fmt.Sprintf("config '%s' already exists", configName)) |
| 93 | } |
| 94 | |
| 95 | kubeconfig := generateBearerConfig(serverIP, name, token) |
| 96 | path := filepath.Join(homeDir(), config.AppConfigDir, config.AppKubeConfigDir, configName) |
| 97 | |
| 98 | if err := writeKubeconfigToFile(path, kubeconfig); err != nil { |
| 99 | return err |
| 100 | } |
| 101 | if err := validateKubeconfigFile(path); err != nil { |
| 102 | defer os.Remove(path) |
| 103 | return echo.NewHTTPError(http.StatusBadRequest, "invalid kubeconfig").SetInternal(err) |
| 104 | } |
| 105 | |
| 106 | h.container.Config().SaveKubeConfig(configName) |
| 107 | return c.JSON(http.StatusOK, echo.Map{"success": true, "configId": configName}) |
| 108 | } |
| 109 | |
| 110 | func (h *AppConfigHandler) PostCertificate(c echo.Context) error { |
| 111 | serverIP := strings.TrimSpace(c.FormValue("serverIP")) |
nothing calls this directly
no test coverage detected