MCPcopy
hub / github.com/kubewall/kubewall / PostBearer

Method PostBearer

backend/handlers/app/config.go:72–108  ·  view source on GitHub ↗
(c echo.Context)

Source from the content-addressed store, hash-verified

70}
71
72func (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
110func (h *AppConfigHandler) PostCertificate(c echo.Context) error {
111 serverIP := strings.TrimSpace(c.FormValue("serverIP"))

Callers

nothing calls this directly

Calls 8

generateBearerConfigFunction · 0.85
homeDirFunction · 0.85
writeKubeconfigToFileFunction · 0.85
validateKubeconfigFileFunction · 0.85
ConfigExistsMethod · 0.80
SaveKubeConfigMethod · 0.80
validateConfigNameFunction · 0.70
ConfigMethod · 0.65

Tested by

no test coverage detected