Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
33786425
提交
33786425
编辑于
8 years ago
作者:
Robert Schilling
浏览文件
操作
下载
补丁
差异文件
Grapify runners API
上级
c392b0cc
No related branches found
No related tags found
无相关合并请求
变更
2
隐藏空白变更内容
行内
左右并排
显示
2 个更改的文件
lib/api/runners.rb
+64
-53
64 个添加, 53 个删除
lib/api/runners.rb
spec/requests/api/runners_spec.rb
+2
-2
2 个添加, 2 个删除
spec/requests/api/runners_spec.rb
有
66 个添加
和
55 个删除
lib/api/runners.rb
+
64
−
53
浏览文件 @
33786425
module
API
# Runners API
class
Runners
<
Grape
::
API
before
{
authenticate!
}
resource
:runners
do
# Get runners available for user
#
# Example Request:
# GET /runners
desc
'Get runners available for user'
do
success
Entities
::
Runner
end
params
do
optional
:scope
,
type:
String
,
values:
%w[active paused online]
,
desc:
'The scope of specific runners to show'
end
get
do
runners
=
filter_runners
(
current_user
.
ci_authorized_runners
,
params
[
:scope
],
without:
[
'specific'
,
'shared'
])
present
paginate
(
runners
),
with:
Entities
::
Runner
end
# Get all runners - shared and specific
#
# Example Request:
# GET /runners/all
desc
'Get all runners - shared and specific'
do
success
Entities
::
Runner
end
params
do
optional
:scope
,
type:
String
,
values:
%w[active paused online specific shared]
,
desc:
'The scope of specific runners to show'
end
get
'all'
do
authenticated_as_admin!
runners
=
filter_runners
(
Ci
::
Runner
.
all
,
params
[
:scope
])
present
paginate
(
runners
),
with:
Entities
::
Runner
end
#
Get runner's details
#
# Parameters:
# id (required) - The ID of ther runner
# Example Request:
# GET /runners/:i
d
desc
"
Get runner's details
"
do
success
Entities
::
RunnerDetails
end
params
do
requires
:id
,
type:
Integer
,
desc:
'The ID of the runner'
en
d
get
':id'
do
runner
=
get_runner
(
params
[
:id
])
authenticate_show_runner!
(
runner
)
...
...
@@ -36,33 +41,37 @@ class Runners < Grape::API
present
runner
,
with:
Entities
::
RunnerDetails
,
current_user:
current_user
end
# Update runner's details
#
# Parameters:
# id (required) - The ID of ther runner
# description (optional) - Runner's description
# active (optional) - Runner's status
# tag_list (optional) - Array of tags for runner
# Example Request:
# PUT /runners/:id
desc
"Update runner's details"
do
success
Entities
::
RunnerDetails
end
params
do
requires
:id
,
type:
Integer
,
desc:
'The ID of the runner'
optional
:description
,
type:
String
,
desc:
'The description of the runner'
optional
:active
,
type:
Boolean
,
desc:
'The state of a runner'
optional
:tag_list
,
type:
Array
[
String
],
desc:
'The list of tags for a runner'
optional
:run_untagged
,
type:
Boolean
,
desc:
'Flag indicating the runner can execute untagged jobs'
optional
:locked
,
type:
Boolean
,
desc:
'Flag indicating the runner is locked'
at_least_one_of
:description
,
:active
,
:tag_list
,
:run_untagged
,
:locked
end
put
':id'
do
runner
=
get_runner
(
params
[
:id
]
)
runner
=
get_runner
(
params
.
delete
(
:id
)
)
authenticate_update_runner!
(
runner
)
attrs
=
attributes_for_keys
[
:description
,
:active
,
:tag_list
,
:run_untagged
,
:locked
]
if
runner
.
update
(
attrs
)
runner_params
=
declared
(
params
,
include_missing:
false
)
if
runner
.
update
(
runner_params
)
present
runner
,
with:
Entities
::
RunnerDetails
,
current_user:
current_user
else
render_validation_error!
(
runner
)
end
end
#
Remove runner
#
# Parameters:
# id (required) - The ID of ther runner
# Example Request:
# DELETE /runners/:i
d
desc
'
Remove
a
runner
'
do
success
Entities
::
Runner
end
params
do
requires
:id
,
type:
Integer
,
desc:
'The ID of the runner'
en
d
delete
':id'
do
runner
=
get_runner
(
params
[
:id
])
authenticate_delete_runner!
(
runner
)
...
...
@@ -72,28 +81,31 @@ class Runners < Grape::API
end
end
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
resource
:projects
do
before
{
authorize_admin_project
}
# Get runners available for project
#
# Example Request:
# GET /projects/:id/runners
desc
'Get runners available for project'
do
success
Entities
::
Runner
end
params
do
optional
:scope
,
type:
String
,
values:
%w[active paused online specific shared]
,
desc:
'The scope of specific runners to show'
end
get
':id/runners'
do
runners
=
filter_runners
(
Ci
::
Runner
.
owned_or_shared
(
user_project
.
id
),
params
[
:scope
])
present
paginate
(
runners
),
with:
Entities
::
Runner
end
# Enable runner for project
#
# Parameters:
# id (required) - The ID of the project
# runner_id (required) - The ID of the runner
# Example Request:
# POST /projects/:id/runners/:runner_id
desc
'Enable a runner for a project'
do
success
Entities
::
Runner
end
params
do
requires
:runner_id
,
type:
Integer
,
desc:
'The ID of the runner'
end
post
':id/runners'
do
required_attributes!
[
:runner_id
]
runner
=
get_runner
(
params
[
:runner_id
])
authenticate_enable_runner!
(
runner
)
...
...
@@ -106,13 +118,12 @@ class Runners < Grape::API
end
end
# Disable project's runner
#
# Parameters:
# id (required) - The ID of the project
# runner_id (required) - The ID of the runner
# Example Request:
# DELETE /projects/:id/runners/:runner_id
desc
"Disable project's runner"
do
success
Entities
::
Runner
end
params
do
requires
:runner_id
,
type:
Integer
,
desc:
'The ID of the runner'
end
delete
':id/runners/:runner_id'
do
runner_project
=
user_project
.
runner_projects
.
find_by
(
runner_id:
params
[
:runner_id
])
not_found!
(
'Runner'
)
unless
runner_project
...
...
此差异已折叠。
点击以展开。
spec/requests/api/runners_spec.rb
+
2
−
2
浏览文件 @
33786425
...
...
@@ -226,7 +226,7 @@ def update_runner(id, user, args)
context
'authorized user'
do
context
'when runner is shared'
do
it
'does not update runner'
do
put
api
(
"/runners/
#{
shared_runner
.
id
}
"
,
user
)
put
api
(
"/runners/
#{
shared_runner
.
id
}
"
,
user
)
,
description:
'test'
expect
(
response
).
to
have_http_status
(
403
)
end
...
...
@@ -234,7 +234,7 @@ def update_runner(id, user, args)
context
'when runner is not shared'
do
it
'does not update runner without access to it'
do
put
api
(
"/runners/
#{
specific_runner
.
id
}
"
,
user2
)
put
api
(
"/runners/
#{
specific_runner
.
id
}
"
,
user2
)
,
description:
'test'
expect
(
response
).
to
have_http_status
(
403
)
end
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录