Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jenkinsci
sub-group
Jenkins Cli
提交
711c22ac
J
Jenkins Cli
项目概览
jenkinsci
/
sub-group
/
Jenkins Cli
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
Jenkins Cli
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
711c22ac
编写于
7月 02, 2019
作者:
LinuxSuRen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add user edit cmd
上级
1e4f543a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
191 addition
and
9 deletion
+191
-9
app/cmd/user.go
app/cmd/user.go
+3
-9
app/cmd/user_edit.go
app/cmd/user_edit.go
+56
-0
app/cmd/user_token.go
app/cmd/user_token.go
+54
-0
client/user.go
client/user.go
+78
-0
未找到文件。
app/cmd/user.go
浏览文件 @
711c22ac
...
...
@@ -32,15 +32,9 @@ var userCmd = &cobra.Command{
jclient
.
Proxy
=
jenkins
.
Proxy
jclient
.
ProxyAuth
=
jenkins
.
ProxyAuth
var
tokenName
string
if
len
(
args
)
>
0
{
tokenName
=
args
[
0
]
}
if
status
,
err
:=
jclient
.
Create
(
tokenName
);
err
==
nil
{
var
data
[]
byte
if
data
,
err
=
userOption
.
Output
(
status
);
err
==
nil
{
fmt
.
Printf
(
"%s
\n
"
,
string
(
data
))
if
status
,
err
:=
jclient
.
Get
();
err
==
nil
{
if
data
,
err
:=
userOption
.
Output
(
status
);
err
==
nil
{
fmt
.
Println
(
string
(
data
))
}
else
{
log
.
Fatal
(
err
)
}
...
...
app/cmd/user_edit.go
0 → 100644
浏览文件 @
711c22ac
package
cmd
import
(
"log"
"github.com/AlecAivazis/survey"
"github.com/linuxsuren/jenkins-cli/client"
"github.com/spf13/cobra"
)
type
UserEditOption
struct
{
Description
bool
}
var
userEditOption
UserEditOption
func
init
()
{
userCmd
.
AddCommand
(
userEditCmd
)
userEditCmd
.
Flags
()
.
BoolVarP
(
&
userEditOption
.
Description
,
"desc"
,
"d"
,
false
,
"Edit the description"
)
}
var
userEditCmd
=
&
cobra
.
Command
{
Use
:
"edit"
,
Short
:
"Edit the user of your Jenkins"
,
Long
:
`Edit the user of your Jenkins`
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
jenkins
:=
getCurrentJenkins
()
jclient
:=
&
client
.
UserClient
{}
jclient
.
URL
=
jenkins
.
URL
jclient
.
UserName
=
jenkins
.
UserName
jclient
.
Token
=
jenkins
.
Token
jclient
.
Proxy
=
jenkins
.
Proxy
jclient
.
ProxyAuth
=
jenkins
.
ProxyAuth
if
status
,
err
:=
jclient
.
Get
();
err
==
nil
{
description
:=
status
.
Description
prompt
:=
&
survey
.
Editor
{
Message
:
"Edit your pipeline script"
,
FileName
:
"*.sh"
,
Default
:
description
,
AppendDefault
:
true
,
}
if
err
=
survey
.
AskOne
(
prompt
,
&
description
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
else
{
if
err
=
jclient
.
EditDesc
(
description
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
}
else
{
log
.
Fatal
(
err
)
}
},
}
app/cmd/user_token.go
0 → 100644
浏览文件 @
711c22ac
package
cmd
import
(
"fmt"
"log"
"github.com/linuxsuren/jenkins-cli/client"
"github.com/spf13/cobra"
)
type
UserTokenOption
struct
{
Generate
bool
Name
string
}
var
userTokenOption
UserTokenOption
func
init
()
{
userCmd
.
AddCommand
(
userTokenCmd
)
userTokenCmd
.
Flags
()
.
BoolVarP
(
&
userTokenOption
.
Generate
,
"generate"
,
"g"
,
false
,
"Generate the token"
)
userTokenCmd
.
Flags
()
.
StringVarP
(
&
userTokenOption
.
Name
,
"name"
,
"n"
,
""
,
"Name of the token"
)
}
var
userTokenCmd
=
&
cobra
.
Command
{
Use
:
"token"
,
Short
:
"Token the user of your Jenkins"
,
Long
:
`Token the user of your Jenkins`
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
!
userTokenOption
.
Generate
{
cmd
.
Help
()
return
}
jenkins
:=
getCurrentJenkins
()
jclient
:=
&
client
.
UserClient
{}
jclient
.
URL
=
jenkins
.
URL
jclient
.
UserName
=
jenkins
.
UserName
jclient
.
Token
=
jenkins
.
Token
jclient
.
Proxy
=
jenkins
.
Proxy
jclient
.
ProxyAuth
=
jenkins
.
ProxyAuth
tokenName
:=
userTokenOption
.
Name
if
status
,
err
:=
jclient
.
Create
(
tokenName
);
err
==
nil
{
var
data
[]
byte
if
data
,
err
=
userOption
.
Output
(
status
);
err
==
nil
{
fmt
.
Printf
(
"%s
\n
"
,
string
(
data
))
}
else
{
log
.
Fatal
(
err
)
}
}
else
{
log
.
Fatal
(
err
)
}
},
}
client/user.go
浏览文件 @
711c22ac
...
...
@@ -27,6 +27,77 @@ type TokenData struct {
TokenValue
string
}
func
(
q
*
UserClient
)
Get
()
(
status
*
User
,
err
error
)
{
api
:=
fmt
.
Sprintf
(
"%s/user/%s/api/json"
,
q
.
URL
,
q
.
UserName
)
var
(
req
*
http
.
Request
response
*
http
.
Response
)
req
,
err
=
http
.
NewRequest
(
"GET"
,
api
,
nil
)
if
err
==
nil
{
q
.
AuthHandle
(
req
)
}
else
{
return
}
client
:=
q
.
GetClient
()
if
response
,
err
=
client
.
Do
(
req
);
err
==
nil
{
code
:=
response
.
StatusCode
var
data
[]
byte
data
,
err
=
ioutil
.
ReadAll
(
response
.
Body
)
if
code
==
200
{
if
err
==
nil
{
status
=
&
User
{}
err
=
json
.
Unmarshal
(
data
,
status
)
}
}
else
{
log
.
Fatal
(
string
(
data
))
}
}
else
{
log
.
Fatal
(
err
)
}
return
}
func
(
q
*
UserClient
)
EditDesc
(
description
string
)
(
err
error
)
{
api
:=
fmt
.
Sprintf
(
"%s/user/%s/submitDescription"
,
q
.
URL
,
q
.
UserName
)
var
(
req
*
http
.
Request
response
*
http
.
Response
)
formData
:=
url
.
Values
{}
formData
.
Add
(
"description"
,
description
)
payload
:=
strings
.
NewReader
(
formData
.
Encode
())
req
,
err
=
http
.
NewRequest
(
"POST"
,
api
,
payload
)
if
err
==
nil
{
q
.
AuthHandle
(
req
)
}
else
{
return
}
req
.
Header
.
Set
(
"Content-Type"
,
"application/x-www-form-urlencoded"
)
if
err
=
q
.
CrumbHandle
(
req
);
err
!=
nil
{
log
.
Fatal
(
err
)
}
client
:=
q
.
GetClient
()
if
response
,
err
=
client
.
Do
(
req
);
err
==
nil
{
code
:=
response
.
StatusCode
var
data
[]
byte
data
,
err
=
ioutil
.
ReadAll
(
response
.
Body
)
if
code
==
200
{
}
else
{
log
.
Fatal
(
string
(
data
))
}
}
else
{
log
.
Fatal
(
err
)
}
return
}
func
(
q
*
UserClient
)
Create
(
newTokenName
string
)
(
status
*
Token
,
err
error
)
{
if
newTokenName
==
""
{
newTokenName
=
fmt
.
Sprintf
(
"jcli-%s"
,
randomdata
.
SillyName
())
...
...
@@ -72,3 +143,10 @@ func (q *UserClient) Create(newTokenName string) (status *Token, err error) {
}
return
}
type
User
struct
{
AbsoluteUrl
string
Description
string
FullName
string
ID
string
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录