Admiralty controller able to handle the setup of an admiralty connection between two peers

This commit is contained in:
pb
2025-03-13 16:39:50 +01:00
parent 150d6591be
commit 7b43fa19ff
3 changed files with 23 additions and 8 deletions

View File

@@ -260,7 +260,7 @@ func(c *AdmiraltyController) GetKubeSecret() {
// @Description Creat a secret from a Kubeconfig that will be associated to an Admiralty Target
// @Param execution path string true "execution id of the workflow"
// @Param kubeconfig body controllers.Kubeconfig true "Kubeconfig to use when creating secret"
// @Param kubeconfig body controllers.RemoteKubeconfig true "Kubeconfig to use when creating secret"
// @Success 201
// @router /secret/:execution [post]
func (c *AdmiraltyController) CreateKubeSecret() {
@@ -310,10 +310,8 @@ func (c *AdmiraltyController) CreateKubeSecret() {
// @name GetAdmiraltyNodes
// @description Allows user to test if an admiralty connection has already been established : Target and valid Secret set up on the local host and Source set up on remote host
// @Param execution path string true "execution id of the workflow"
// @Success 200
// @Success 203
// @router /node/:execution [get]
func (c *AdmiraltyController) GetNodeReady(){
var secret v1.Secret
@@ -380,7 +378,9 @@ func (c *AdmiraltyController) GetNodeReady(){
token, err := retrieveTokenFromKonfig(editedKubeconfig)
if err != nil {
fmt.Println("Error while trying to retrieve token for kubeconfing")
fmt.Println(err)
HandleControllerErrors(c.Controller,500,&err,nil)
}
// Decode token
@@ -407,14 +407,19 @@ func (c *AdmiraltyController) GetNodeReady(){
func retrieveTokenFromKonfig(editedKubeconfig map[string]interface{}) (string,error) {
var kubeUsers []KubeUser
b, err := json.Marshal(editedKubeconfig["users"])
b, err := yaml.Marshal(editedKubeconfig["users"])
if err != nil {
fmt.Println()
fmt.Println("Error while retrieving the users attribute from the Kubeconfig")
fmt.Println(err)
return "", err
}
err = yaml.Unmarshal(b,&kubeUsers)
if err != nil {
fmt.Println("Error while unmarshalling users attribute from kubeconfig")
fmt.Println(err)
return "", nil
}
fmt.Println(kubeUsers)
token := kubeUsers[0].User.Token
return token, nil