Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
7bf044a7
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
7bf044a7
编写于
5月 10, 2019
作者:
R
runzexia
提交者:
GitHub
5月 10, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #401 from runzexia/refactor-credential-create
refactor credential api
上级
d27c5b96
002b54a1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
73 deletion
+26
-73
pkg/apis/devops/v1alpha2/register.go
pkg/apis/devops/v1alpha2/register.go
+3
-3
pkg/models/devops/project_credential.go
pkg/models/devops/project_credential.go
+6
-13
pkg/models/devops/project_credential_handler.go
pkg/models/devops/project_credential_handler.go
+17
-57
未找到文件。
pkg/apis/devops/v1alpha2/register.go
浏览文件 @
7bf044a7
...
...
@@ -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
)
...
...
pkg/models/devops/project_credential.go
浏览文件 @
7bf044a7
...
...
@@ -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
(
...
...
pkg/models/devops/project_credential_handler.go
浏览文件 @
7bf044a7
...
...
@@ -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
)
...
...
@@ -318,15 +303,6 @@ func GetProjectCredential(projectId, credentialId, domain, getContent string) (*
value
:=
selection
.
Text
()
content
.
Content
=
value
})
doc
.
Find
(
"input[name*=id][type=text]"
)
.
Each
(
func
(
i
int
,
selection
*
goquery
.
Selection
)
{
value
,
_
:=
selection
.
Attr
(
"value"
)
content
.
Id
=
value
})
doc
.
Find
(
"input[name*=description]"
)
.
Each
(
func
(
i
int
,
selection
*
goquery
.
Selection
)
{
value
,
_
:=
selection
.
Attr
(
"value"
)
content
.
Description
=
value
})
response
.
KubeconfigCredential
=
content
case
CredentialTypeUsernamePassword
:
content
:=
&
UsernamePasswordCredential
{}
...
...
@@ -335,14 +311,6 @@ func GetProjectCredential(projectId, credentialId, domain, getContent string) (*
content
.
Username
=
value
})
doc
.
Find
(
"input[name*=id][type=text]"
)
.
Each
(
func
(
i
int
,
selection
*
goquery
.
Selection
)
{
value
,
_
:=
selection
.
Attr
(
"value"
)
content
.
Id
=
value
})
doc
.
Find
(
"input[name*=description]"
)
.
Each
(
func
(
i
int
,
selection
*
goquery
.
Selection
)
{
value
,
_
:=
selection
.
Attr
(
"value"
)
content
.
Description
=
value
})
response
.
UsernamePasswordCredential
=
content
case
CredentialTypeSsh
:
content
:=
&
SshCredential
{}
...
...
@@ -350,15 +318,7 @@ func GetProjectCredential(projectId, credentialId, domain, getContent string) (*
value
,
_
:=
selection
.
Attr
(
"value"
)
content
.
Username
=
value
})
doc
.
Find
(
"input[name*=id][type=text]"
)
.
Each
(
func
(
i
int
,
selection
*
goquery
.
Selection
)
{
value
,
_
:=
selection
.
Attr
(
"value"
)
content
.
Id
=
value
})
doc
.
Find
(
"input[name*=description]"
)
.
Each
(
func
(
i
int
,
selection
*
goquery
.
Selection
)
{
value
,
_
:=
selection
.
Attr
(
"value"
)
content
.
Description
=
value
})
doc
.
Find
(
"textarea[name*=privateKey]"
)
.
Each
(
func
(
i
int
,
selection
*
goquery
.
Selection
)
{
value
:=
selection
.
Text
()
content
.
PrivateKey
=
value
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录