Changed the return of the /kubeconfig to encoded kubeconfig

This commit is contained in:
pb
2025-02-28 17:57:13 +01:00
parent f75499d827
commit ba3afc69be
2 changed files with 19 additions and 5 deletions

View File

@@ -12,8 +12,8 @@ import (
beego "github.com/beego/beego/v2/server/web"
jwt "github.com/golang-jwt/jwt/v5"
"gopkg.in/yaml.v2"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/yaml"
)
type KubeInfo struct {
@@ -462,7 +462,19 @@ func (c *AdmiraltyController) GetAdmiraltyKubeconfig() {
return
}
c.Data["json"] = kubeconfig
b, err := yaml.Marshal(kubeconfig)
if err != nil {
fmt.Println("Error while marshalling kubeconfig")
c.Ctx.Output.SetStatus(500)
c.Data["json"] = map[string]string{"error": err.Error()}
c.ServeJSON()
}
encodedKubeconfig := base64.StdEncoding.EncodeToString(b)
c.Data["json"] = map[string]string{
"data": encodedKubeconfig,
}
c.ServeJSON()
return
}