diff --git a/pkg/apis/devops/v1alpha2/register.go b/pkg/apis/devops/v1alpha2/register.go index c1c1897c4..5b4535b8f 100644 --- a/pkg/apis/devops/v1alpha2/register.go +++ b/pkg/apis/devops/v1alpha2/register.go @@ -721,7 +721,7 @@ func addWebService(c *restful.Container) error { Param(webservice.QueryParameter("limit", "limit count"). Required(false). DataFormat("limit=%d")). - Returns(http.StatusOK, RespOK,[]devops.NodeSteps{}). + Returns(http.StatusOK, RespOK, []devops.NodeSteps{}). Writes([]devops.NodeSteps{})) // match /pipeline-model-converter/toJenkinsfile @@ -784,7 +784,7 @@ func addWebService(c *restful.Container) error { Param(webservice.QueryParameter("limit", "limit count"). Required(true). DataFormat("limit=%d")). - Returns(http.StatusOK, RespOK,[]devops.NodesDetail{}). + Returns(http.StatusOK, RespOK, []devops.NodesDetail{}). Writes(devops.NodesDetail{})) // out of scm get all steps in nodes. @@ -799,7 +799,7 @@ func addWebService(c *restful.Container) error { Param(webservice.QueryParameter("limit", "limit count"). Required(true). DataFormat("limit=%d")). - Returns(http.StatusOK, RespOK,[]devops.NodesDetail{}). + Returns(http.StatusOK, RespOK, []devops.NodesDetail{}). Writes(devops.NodesDetail{})) c.Add(webservice) diff --git a/pkg/models/devops/project_credential.go b/pkg/models/devops/project_credential.go index a8d33bad8..dd08a4dab 100644 --- a/pkg/models/devops/project_credential.go +++ b/pkg/models/devops/project_credential.go @@ -53,30 +53,23 @@ type JenkinsCredential struct { } type UsernamePasswordCredential struct { - Id string `json:"id"` - Username string `json:"username,omitempty"` - Password string `json:"password,omitempty"` - Description string `json:"description,omitempty"` + Username string `json:"username,omitempty"` + Password string `json:"password,omitempty"` } type SshCredential struct { - Id string `json:"id"` - Username string `json:"username,omitempty"` - Passphrase string `json:"passphrase,omitempty"` - PrivateKey string `json:"private_key,omitempty" mapstructure:"private_key"` - Description string `json:"description,omitempty"` + Username string `json:"username,omitempty"` + Passphrase string `json:"passphrase,omitempty"` + PrivateKey string `json:"private_key,omitempty" mapstructure:"private_key"` } type SecretTextCredential struct { - Id string `json:"id"` Secret string `json:"secret,omitempty"` Description string `json:"description,omitempty"` } type KubeconfigCredential struct { - Id string `json:"id"` - Content string `json:"content,omitempty"` - Description string `json:"description,omitempty"` + Content string `json:"content,omitempty"` } const ( diff --git a/pkg/models/devops/project_credential_handler.go b/pkg/models/devops/project_credential_handler.go index 4fdf38cbe..f70d2e660 100644 --- a/pkg/models/devops/project_credential_handler.go +++ b/pkg/models/devops/project_credential_handler.go @@ -32,23 +32,23 @@ import ( func CreateProjectCredential(projectId, username string, credentialRequest *JenkinsCredential) (string, error) { jenkinsClient := admin_jenkins.Client() + err := checkJenkinsCredentialExists(projectId, credentialRequest.Domain, credentialRequest.Id) + if err != nil { + glog.Errorf("%+v", err) + return "", err + } switch credentialRequest.Type { case CredentialTypeUsernamePassword: - err := checkJenkinsCredentialExists(projectId, credentialRequest.Domain, credentialRequest.UsernamePasswordCredential.Id) - if err != nil { - glog.Errorf("%+v", err) - return "", err - } if credentialRequest.UsernamePasswordCredential == nil { err := fmt.Errorf("usename_password should not be nil") glog.Error(err) return "", restful.NewError(http.StatusBadRequest, err.Error()) } credentialId, err := jenkinsClient.CreateUsernamePasswordCredentialInFolder(credentialRequest.Domain, - credentialRequest.UsernamePasswordCredential.Id, + credentialRequest.Id, credentialRequest.UsernamePasswordCredential.Username, credentialRequest.UsernamePasswordCredential.Password, - credentialRequest.UsernamePasswordCredential.Description, + credentialRequest.Description, projectId) if err != nil { glog.Errorf("%+v", err) @@ -61,22 +61,17 @@ func CreateProjectCredential(projectId, username string, credentialRequest *Jenk } return *credentialId, nil case CredentialTypeSsh: - err := checkJenkinsCredentialExists(projectId, credentialRequest.Domain, credentialRequest.SshCredential.Id) - if err != nil { - glog.Errorf("%+v", err) - return "", err - } if credentialRequest.SshCredential == nil { err := fmt.Errorf("ssh should not be nil") glog.Error(err) return "", restful.NewError(http.StatusBadRequest, err.Error()) } credentialId, err := jenkinsClient.CreateSshCredentialInFolder(credentialRequest.Domain, - credentialRequest.SshCredential.Id, + credentialRequest.Id, credentialRequest.SshCredential.Username, credentialRequest.SshCredential.Passphrase, credentialRequest.SshCredential.PrivateKey, - credentialRequest.SshCredential.Description, + credentialRequest.Description, projectId) if err != nil { glog.Errorf("%+v", err) @@ -90,11 +85,6 @@ func CreateProjectCredential(projectId, username string, credentialRequest *Jenk } return *credentialId, nil case CredentialTypeSecretText: - err := checkJenkinsCredentialExists(projectId, credentialRequest.Domain, credentialRequest.SecretTextCredential.Id) - if err != nil { - glog.Errorf("%+v", err) - return "", err - } if credentialRequest.SecretTextCredential == nil { err := fmt.Errorf("secret_text should not be nil") glog.Error(err) @@ -102,9 +92,9 @@ func CreateProjectCredential(projectId, username string, credentialRequest *Jenk } credentialId, err := jenkinsClient.CreateSecretTextCredentialInFolder(credentialRequest.Domain, - credentialRequest.SecretTextCredential.Id, + credentialRequest.Id, credentialRequest.SecretTextCredential.Secret, - credentialRequest.SecretTextCredential.Description, + credentialRequest.Description, projectId) if err != nil { glog.Errorf("%+v", err) @@ -118,20 +108,15 @@ func CreateProjectCredential(projectId, username string, credentialRequest *Jenk } return *credentialId, nil case CredentialTypeKubeConfig: - err := checkJenkinsCredentialExists(projectId, credentialRequest.Domain, credentialRequest.KubeconfigCredential.Id) - if err != nil { - glog.Errorf("%+v", err) - return "", err - } if credentialRequest.KubeconfigCredential == nil { err := fmt.Errorf("kubeconfig should not be nil") glog.Error(err) return "", restful.NewError(http.StatusBadRequest, err.Error()) } credentialId, err := jenkinsClient.CreateKubeconfigCredentialInFolder(credentialRequest.Domain, - credentialRequest.KubeconfigCredential.Id, + credentialRequest.Id, credentialRequest.KubeconfigCredential.Content, - credentialRequest.KubeconfigCredential.Description, + credentialRequest.Description, projectId) if err != nil { glog.Errorf("%+v", err) @@ -173,7 +158,7 @@ func UpdateProjectCredential(projectId, credentialId string, credentialRequest * credentialId, credentialRequest.UsernamePasswordCredential.Username, credentialRequest.UsernamePasswordCredential.Password, - credentialRequest.UsernamePasswordCredential.Description, + credentialRequest.Description, projectId) if err != nil { glog.Errorf("%+v", err) @@ -192,7 +177,7 @@ func UpdateProjectCredential(projectId, credentialId string, credentialRequest * credentialRequest.SshCredential.Username, credentialRequest.SshCredential.Passphrase, credentialRequest.SshCredential.PrivateKey, - credentialRequest.SshCredential.Description, + credentialRequest.Description, projectId) if err != nil { glog.Errorf("%+v", err) @@ -225,7 +210,7 @@ func UpdateProjectCredential(projectId, credentialId string, credentialRequest * credentialId, err := jenkinsClient.UpdateKubeconfigCredentialInFolder(credentialRequest.Domain, credentialId, credentialRequest.KubeconfigCredential.Content, - credentialRequest.KubeconfigCredential.Description, + credentialRequest.Description, projectId) if err != nil { glog.Errorf("%+v", err) @@ -321,11 +306,11 @@ func GetProjectCredential(projectId, credentialId, domain, getContent string) (* doc.Find("input[name*=id][type=text]").Each(func(i int, selection *goquery.Selection) { value, _ := selection.Attr("value") - content.Id = value + response.Id = value }) doc.Find("input[name*=description]").Each(func(i int, selection *goquery.Selection) { value, _ := selection.Attr("value") - content.Description = value + response.Description = value }) response.KubeconfigCredential = content case CredentialTypeUsernamePassword: @@ -337,11 +322,11 @@ func GetProjectCredential(projectId, credentialId, domain, getContent string) (* doc.Find("input[name*=id][type=text]").Each(func(i int, selection *goquery.Selection) { value, _ := selection.Attr("value") - content.Id = value + response.Id = value }) doc.Find("input[name*=description]").Each(func(i int, selection *goquery.Selection) { value, _ := selection.Attr("value") - content.Description = value + response.Description = value }) response.UsernamePasswordCredential = content case CredentialTypeSsh: @@ -353,11 +338,11 @@ func GetProjectCredential(projectId, credentialId, domain, getContent string) (* doc.Find("input[name*=id][type=text]").Each(func(i int, selection *goquery.Selection) { value, _ := selection.Attr("value") - content.Id = value + response.Id = value }) doc.Find("input[name*=description]").Each(func(i int, selection *goquery.Selection) { value, _ := selection.Attr("value") - content.Description = value + response.Description = value }) doc.Find("textarea[name*=privateKey]").Each(func(i int, selection *goquery.Selection) { value := selection.Text()