Remove test parameters in swagger comments
This commit is contained in:
parent
7eac712e01
commit
b35f1c5ff3
@ -77,9 +77,10 @@ func (c *AdmiraltyController) GetAllTargets() {
|
|||||||
serv, err := infrastructure.NewService()
|
serv, err := infrastructure.NewService()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// change code to 500
|
// change code to 500
|
||||||
c.Ctx.Output.SetStatus(500)
|
HandleControllerErrors(c.Controller,500,&err,nil)
|
||||||
c.ServeJSON()
|
// c.Ctx.Output.SetStatus(500)
|
||||||
c.Data["json"] = map[string]string{"error": err.Error()}
|
// c.ServeJSON()
|
||||||
|
// c.Data["json"] = map[string]string{"error": err.Error()}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,9 +119,7 @@ func (c *AdmiraltyController) GetOneTarget() {
|
|||||||
|
|
||||||
// @Title CreateSource
|
// @Title CreateSource
|
||||||
// @Description Create an Admiralty Source on remote cluster
|
// @Description Create an Admiralty Source on remote cluster
|
||||||
// @Param dc_id path string true "which dc to contact"
|
|
||||||
// @Param execution path string true "execution id of the workflow"
|
// @Param execution path string true "execution id of the workflow"
|
||||||
// @Param kubeconfigInfo body controllers.KubeInfo true "url and serviceAccount to use with the source formatted as json object"
|
|
||||||
// @Success 200
|
// @Success 200
|
||||||
// @router /source/:id [post]
|
// @router /source/:id [post]
|
||||||
func (c *AdmiraltyController) CreateSource() {
|
func (c *AdmiraltyController) CreateSource() {
|
||||||
@ -140,15 +139,9 @@ func (c *AdmiraltyController) CreateSource() {
|
|||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
fmt.Println("Key : ", data.KubeKey)
|
fmt.Println("Key : ", data.KubeKey)
|
||||||
|
|
||||||
dc_id := c.Ctx.Input.Param(":dc_id")
|
|
||||||
execution := c.Ctx.Input.Param(":execution")
|
execution := c.Ctx.Input.Param(":execution")
|
||||||
_ = dc_id
|
serv, err := infrastructure.NewKubernetesService()
|
||||||
serv, err := infrastructure.NewRemoteKubernetesService(
|
|
||||||
*data.Url,
|
|
||||||
*data.KubeCA,
|
|
||||||
*data.KubeCert,
|
|
||||||
*data.KubeKey,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// change code to 500
|
// change code to 500
|
||||||
c.Ctx.Output.SetStatus(500)
|
c.Ctx.Output.SetStatus(500)
|
||||||
@ -177,15 +170,14 @@ func (c *AdmiraltyController) CreateSource() {
|
|||||||
|
|
||||||
// @Title CreateAdmiraltyTarget
|
// @Title CreateAdmiraltyTarget
|
||||||
// @Description Create an Admiralty Target in the namespace associated to the executionID
|
// @Description Create an Admiralty Target in the namespace associated to the executionID
|
||||||
// @Param dc_id path string true "which dc to contact"
|
|
||||||
// @Param execution path string true "execution id of the workflow"
|
// @Param execution path string true "execution id of the workflow"
|
||||||
// @Success 201
|
// @Success 201
|
||||||
// @router /target/:id [post]
|
// @router /target/:id [post]
|
||||||
func (c *AdmiraltyController) CreateAdmiraltyTarget(){
|
func (c *AdmiraltyController) CreateAdmiraltyTarget(){
|
||||||
var data map[string]interface{}
|
var data map[string]interface{}
|
||||||
dc_id := c.Ctx.Input.Param(":dc_id")
|
|
||||||
execution := c.Ctx.Input.Param(":execution")
|
execution := c.Ctx.Input.Param(":execution")
|
||||||
_ = dc_id
|
|
||||||
|
|
||||||
serv, err := infrastructure.NewService()
|
serv, err := infrastructure.NewService()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -229,15 +221,14 @@ func (c *AdmiraltyController) CreateAdmiraltyTarget(){
|
|||||||
|
|
||||||
// @Title GetKubeSecret
|
// @Title GetKubeSecret
|
||||||
// @Description Retrieve the secret created from a Kubeconfig that will be associated to an Admiralty Target
|
// @Description Retrieve the secret created from a Kubeconfig that will be associated to an Admiralty Target
|
||||||
// @Param dc_id path string true "which dc to contact"
|
|
||||||
// @Param execution path string true "execution id of the workflow"
|
// @Param execution path string true "execution id of the workflow"
|
||||||
// @Success 200
|
// @Success 200
|
||||||
// @router /secret/:id [get]
|
// @router /secret/:id [get]
|
||||||
func(c *AdmiraltyController) GetKubeSecret() {
|
func(c *AdmiraltyController) GetKubeSecret() {
|
||||||
var data map[string]interface{}
|
var data map[string]interface{}
|
||||||
dc_id := c.Ctx.Input.Param(":dc_id")
|
|
||||||
execution := c.Ctx.Input.Param(":execution")
|
execution := c.Ctx.Input.Param(":execution")
|
||||||
_ = dc_id
|
|
||||||
|
|
||||||
serv, err := infrastructure.NewService()
|
serv, err := infrastructure.NewService()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -278,7 +269,7 @@ func(c *AdmiraltyController) GetKubeSecret() {
|
|||||||
|
|
||||||
// @Title CreateKubeSecret
|
// @Title CreateKubeSecret
|
||||||
// @Description Creat a secret from a Kubeconfig that will be associated to an Admiralty Target
|
// @Description Creat a secret from a Kubeconfig that will be associated to an Admiralty Target
|
||||||
// @Param dc_id path string true "which dc to contact"
|
|
||||||
// @Param execution path string true "execution id of the workflow"
|
// @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.Kubeconfig true "Kubeconfig to use when creating secret"
|
||||||
// @Success 200
|
// @Success 200
|
||||||
@ -299,9 +290,9 @@ func (c *AdmiraltyController) CreateKubeSecret() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_id := c.Ctx.Input.Param(":dc_id")
|
|
||||||
execution := c.Ctx.Input.Param(":execution")
|
execution := c.Ctx.Input.Param(":execution")
|
||||||
_ = dc_id
|
|
||||||
|
|
||||||
serv, err := infrastructure.NewService()
|
serv, err := infrastructure.NewService()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -329,16 +320,16 @@ func (c *AdmiraltyController) CreateKubeSecret() {
|
|||||||
|
|
||||||
// @name GetAdmiraltyNodes
|
// @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
|
// @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 dc_id path string true "which dc to contact"
|
|
||||||
// @Param execution path string true "execution id of the workflow"
|
// @Param execution path string true "execution id of the workflow"
|
||||||
// @Success 200
|
// @Success 200
|
||||||
// @Success 203
|
// @Success 203
|
||||||
// @router /node/:id [get]
|
// @router /node/:id [get]
|
||||||
func (c *AdmiraltyController) GetNodeReady(){
|
func (c *AdmiraltyController) GetNodeReady(){
|
||||||
var secret v1.Secret
|
var secret v1.Secret
|
||||||
dc_id := c.Ctx.Input.Param(":dc_id")
|
|
||||||
execution := c.Ctx.Input.Param(":execution")
|
execution := c.Ctx.Input.Param(":execution")
|
||||||
_ = dc_id
|
|
||||||
|
|
||||||
serv, err := infrastructure.NewService()
|
serv, err := infrastructure.NewService()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -384,7 +375,6 @@ func (c *AdmiraltyController) GetNodeReady(){
|
|||||||
|
|
||||||
// Extract JWT token RS265 encoded
|
// Extract JWT token RS265 encoded
|
||||||
var editedKubeconfig map[string]interface{}
|
var editedKubeconfig map[string]interface{}
|
||||||
var kubeUsers []KubeUser
|
|
||||||
json.Unmarshal(resp,&secret)
|
json.Unmarshal(resp,&secret)
|
||||||
byteEditedKubeconfig := secret.Data["config"]
|
byteEditedKubeconfig := secret.Data["config"]
|
||||||
err = yaml.Unmarshal(byteEditedKubeconfig,&editedKubeconfig)
|
err = yaml.Unmarshal(byteEditedKubeconfig,&editedKubeconfig)
|
||||||
@ -397,25 +387,26 @@ func (c *AdmiraltyController) GetNodeReady(){
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
b, err := json.Marshal(editedKubeconfig["users"])
|
|
||||||
err = yaml.Unmarshal(b,&kubeUsers)
|
token, err := retrieveTokenFromKonfig(editedKubeconfig)
|
||||||
token := kubeUsers[0].User.Token
|
if err != nil {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Decode token
|
// Decode token
|
||||||
t, _, err := new(jwt.Parser).ParseUnverified(token, jwt.MapClaims{})
|
isExpired, err := isTokenExpired(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("couldn't decode token")
|
fmt.Println("Error veryfing token's expiration")
|
||||||
c.Data["json"] = false
|
c.Ctx.Output.SetStatus(500)
|
||||||
|
c.Data["json"] = err
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
expiration, err := t.Claims.GetExpirationTime()
|
if *isExpired {
|
||||||
fmt.Println("Expiration date : " + expiration.UTC().Format("2006-01-02T15:04:05"))
|
|
||||||
|
|
||||||
if expiration.Add(1 * time.Hour).Unix() < time.Now().Unix() {
|
|
||||||
c.Data["json"] = map[string]string{
|
c.Data["json"] = map[string]string{
|
||||||
"token" : "token in the secret is expired and must be regenerated",
|
"token" : "token in the secret is expired and must be regenerated",
|
||||||
}
|
}
|
||||||
|
c.Ctx.Output.SetStatus(410)
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,16 +415,50 @@ func (c *AdmiraltyController) GetNodeReady(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func retrieveTokenFromKonfig(editedKubeconfig map[string]interface{}) (string,error) {
|
||||||
|
var kubeUsers []KubeUser
|
||||||
|
b, err := json.Marshal(editedKubeconfig["users"])
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
err = yaml.Unmarshal(b,&kubeUsers)
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
}
|
||||||
|
token := kubeUsers[0].User.Token
|
||||||
|
|
||||||
|
return token, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func isTokenExpired(token string) (*bool, error){
|
||||||
|
t, _, err := new(jwt.Parser).ParseUnverified(token, jwt.MapClaims{})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("couldn't decode token")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
expiration, err := t.Claims.GetExpirationTime()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error while checking token's expiration time")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fmt.Println("Expiration date : " + expiration.UTC().Format("2006-01-02T15:04:05"))
|
||||||
|
|
||||||
|
expired := expiration.Unix() < time.Now().Unix()
|
||||||
|
|
||||||
|
return &expired, nil
|
||||||
|
}
|
||||||
|
|
||||||
// @name Get Admiralty Kubeconfig
|
// @name Get Admiralty Kubeconfig
|
||||||
// @description Retrieve a kubeconfig from the host with the token to authenticate as the SA from the namespace identified with execution id
|
// @description Retrieve a kubeconfig from the host with the token to authenticate as the SA from the namespace identified with execution id
|
||||||
// @Param dc_id path string true "which dc to contact"
|
|
||||||
// @Param execution path string true "execution id of the workflow"
|
// @Param execution path string true "execution id of the workflow"
|
||||||
// @Success 200
|
// @Success 200
|
||||||
// @router /kubeconfig/:id [get]
|
// @router /kubeconfig/:id [get]
|
||||||
func (c *AdmiraltyController) GetAdmiraltyKubeconfig() {
|
func (c *AdmiraltyController) GetAdmiraltyKubeconfig() {
|
||||||
dc_id := c.Ctx.Input.Param(":dc_id")
|
|
||||||
execution := c.Ctx.Input.Param(":execution")
|
execution := c.Ctx.Input.Param(":execution")
|
||||||
_ = dc_id
|
|
||||||
|
|
||||||
serv, err := infrastructure.NewService()
|
serv, err := infrastructure.NewService()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -478,13 +503,12 @@ func (c *AdmiraltyController) GetAdmiraltyKubeconfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func NewHostKubeWithToken(token string) (*models.KubeConfigValue, error){
|
func NewHostKubeWithToken(token string) (*models.KubeConfigValue, error){
|
||||||
if len(token) == 0 {
|
if len(token) == 0 {
|
||||||
return nil, fmt.Errorf("You didn't provide a token to be inserted in the Kubeconfig")
|
return nil, fmt.Errorf("you didn't provide a token to be inserted in the Kubeconfig")
|
||||||
}
|
}
|
||||||
|
|
||||||
encodedCA := base64.StdEncoding.EncodeToString([]byte(conf.GetConfig().KubeCA))
|
encodedCA := base64.StdEncoding.EncodeToString([]byte(conf.GetConfig().KubeCA))
|
||||||
|
Loading…
Reference in New Issue
Block a user