Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Jenkins 中文社区
jenkins-cli
提交
6b6c15f1
J
jenkins-cli
项目概览
Jenkins 中文社区
/
jenkins-cli
通知
49
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins-cli
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
6b6c15f1
编写于
2月 15, 2020
作者:
LinuxSuRen
提交者:
GitHub
2月 15, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #325 from LinuxSuRen/fix/credentials
Fix that cannot create credentials
上级
98c10918
8a117d51
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
24 addition
and
11 deletion
+24
-11
app/cmd/credential_create.go
app/cmd/credential_create.go
+9
-4
app/cmd/credential_create_test.go
app/cmd/credential_create_test.go
+6
-2
client/common.go
client/common.go
+3
-3
client/credentials.go
client/credentials.go
+3
-1
client/credentials_test.go
client/credentials_test.go
+3
-1
未找到文件。
app/cmd/credential_create.go
浏览文件 @
6b6c15f1
...
...
@@ -20,7 +20,8 @@ type CredentialCreateOption struct {
Secret
string
Type
string
Scope
string
Type
string
RoundTripper
http
.
RoundTripper
}
...
...
@@ -33,11 +34,13 @@ func init() {
i18n
.
T
(
"The store name of Jenkins credentials"
))
credentialCreateCmd
.
Flags
()
.
StringVarP
(
&
credentialCreateOption
.
Type
,
"type"
,
""
,
"basic"
,
i18n
.
T
(
"The type of Jenkins credentials which could be: basic, secret"
))
credentialCreateCmd
.
Flags
()
.
StringVarP
(
&
credentialCreateOption
.
ID
,
"id"
,
""
,
""
,
credentialCreateCmd
.
Flags
()
.
StringVarP
(
&
credentialCreateOption
.
Scope
,
"scope"
,
""
,
"GLOBAL"
,
i18n
.
T
(
"The scope of Jenkins credentials which might be GLOBAL or SYSTEM"
))
credentialCreateCmd
.
Flags
()
.
StringVarP
(
&
credentialCreateOption
.
ID
,
"credential-id"
,
""
,
""
,
i18n
.
T
(
"The ID of Jenkins credentials"
))
credentialCreateCmd
.
Flags
()
.
StringVarP
(
&
credentialCreateOption
.
Username
,
"username"
,
""
,
""
,
credentialCreateCmd
.
Flags
()
.
StringVarP
(
&
credentialCreateOption
.
Username
,
"
credential-
username"
,
""
,
""
,
i18n
.
T
(
"The Username of Jenkins credentials"
))
credentialCreateCmd
.
Flags
()
.
StringVarP
(
&
credentialCreateOption
.
Password
,
"password"
,
""
,
""
,
credentialCreateCmd
.
Flags
()
.
StringVarP
(
&
credentialCreateOption
.
Password
,
"
credential-
password"
,
""
,
""
,
i18n
.
T
(
"The Password of Jenkins credentials"
))
credentialCreateCmd
.
Flags
()
.
StringVarP
(
&
credentialCreateOption
.
Description
,
"desc"
,
""
,
""
,
i18n
.
T
(
"The Description of Jenkins credentials"
))
...
...
@@ -74,6 +77,7 @@ var credentialCreateCmd = &cobra.Command{
Username
:
credentialCreateOption
.
Username
,
Password
:
credentialCreateOption
.
Password
,
Credential
:
client
.
Credential
{
Scope
:
credentialCreateOption
.
Scope
,
ID
:
credentialCreateOption
.
ID
,
Description
:
credentialCreateOption
.
Description
,
},
...
...
@@ -82,6 +86,7 @@ var credentialCreateCmd = &cobra.Command{
err
=
jClient
.
CreateSecret
(
credentialCreateOption
.
Store
,
client
.
StringCredentials
{
Secret
:
credentialCreateOption
.
Secret
,
Credential
:
client
.
Credential
{
Scope
:
credentialCreateOption
.
Scope
,
ID
:
credentialCreateOption
.
ID
,
Description
:
credentialCreateOption
.
Description
,
},
...
...
app/cmd/credential_create_test.go
浏览文件 @
6b6c15f1
...
...
@@ -70,7 +70,9 @@ var _ = Describe("credential create command", func() {
})
It
(
"should success with user name and password"
,
func
()
{
credential
:=
client
.
UsernamePasswordCredential
{}
credential
:=
client
.
UsernamePasswordCredential
{
Credential
:
client
.
Credential
{
Scope
:
"GLOBAL"
},
}
client
.
PrepareForCreateUsernamePasswordCredential
(
roundTripper
,
"http://localhost:8080/jenkins"
,
"admin"
,
"111e3a2f0231198855dceaff96f20540a9"
,
store
,
credential
)
...
...
@@ -81,7 +83,9 @@ var _ = Describe("credential create command", func() {
})
It
(
"should success with secret"
,
func
()
{
credential
:=
client
.
StringCredentials
{}
credential
:=
client
.
StringCredentials
{
Credential
:
client
.
Credential
{
Scope
:
"GLOBAL"
},
}
client
.
PrepareForCreateSecretCredential
(
roundTripper
,
"http://localhost:8080/jenkins"
,
"admin"
,
"111e3a2f0231198855dceaff96f20540a9"
,
store
,
credential
)
...
...
client/common.go
浏览文件 @
6b6c15f1
...
...
@@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"go.uber.org/zap"
"io"
"io/ioutil"
"log"
...
...
@@ -162,9 +163,8 @@ func (j *JenkinsCore) ErrorHandle(statusCode int, data []byte) (err error) {
}
else
{
err
=
fmt
.
Errorf
(
"unexpected status code: %d"
,
statusCode
)
}
if
j
.
Debug
{
ioutil
.
WriteFile
(
"debug.html"
,
data
,
0664
)
}
logger
.
Debug
(
"get response"
,
zap
.
String
(
"data"
,
string
(
data
)))
return
}
...
...
client/credentials.go
浏览文件 @
6b6c15f1
...
...
@@ -3,6 +3,7 @@ package client
import
(
"encoding/json"
"fmt"
"go.uber.org/zap"
"net/url"
"strings"
...
...
@@ -32,6 +33,8 @@ func (c *CredentialsManager) Delete(store, id string) (err error) {
func
(
c
*
CredentialsManager
)
Create
(
store
,
credential
string
)
(
err
error
)
{
api
:=
fmt
.
Sprintf
(
"/credentials/store/%s/domain/_/createCredentials"
,
store
)
logger
.
Debug
(
"create credential"
,
zap
.
String
(
"api"
,
api
),
zap
.
String
(
"payload"
,
credential
))
formData
:=
url
.
Values
{}
formData
.
Add
(
"json"
,
fmt
.
Sprintf
(
`{"credentials": %s}`
,
credential
))
payload
:=
strings
.
NewReader
(
formData
.
Encode
())
...
...
@@ -55,7 +58,6 @@ func (c *CredentialsManager) CreateUsernamePassword(store string, cred UsernameP
func
(
c
*
CredentialsManager
)
CreateSecret
(
store
string
,
cred
StringCredentials
)
(
err
error
)
{
var
payload
[]
byte
cred
.
Class
=
"org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl"
cred
.
Scope
=
"GLOBAL"
if
payload
,
err
=
json
.
Marshal
(
cred
);
err
==
nil
{
err
=
c
.
Create
(
store
,
string
(
payload
))
}
...
...
client/credentials_test.go
浏览文件 @
6b6c15f1
...
...
@@ -68,7 +68,9 @@ var _ = Describe("job test", func() {
Context
(
"CreateSecret"
,
func
()
{
It
(
"should success"
,
func
()
{
cred
:=
client
.
StringCredentials
{}
cred
:=
client
.
StringCredentials
{
Credential
:
client
.
Credential
{
Scope
:
"GLOBAL"
},
}
client
.
PrepareForCreateSecretCredential
(
roundTripper
,
credentialsManager
.
URL
,
""
,
""
,
store
,
cred
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录