Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
33786425
Commit
33786425
authored
Nov 09, 2016
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Grapify runners API
parent
c392b0cc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
55 deletions
+66
-55
lib/api/runners.rb
lib/api/runners.rb
+64
-53
spec/requests/api/runners_spec.rb
spec/requests/api/runners_spec.rb
+2
-2
No files found.
lib/api/runners.rb
View file @
33786425
module
API
module
API
# Runners API
class
Runners
<
Grape
::
API
class
Runners
<
Grape
::
API
before
{
authenticate!
}
before
{
authenticate!
}
resource
:runners
do
resource
:runners
do
# Get runners available for user
desc
'Get runners available for user'
do
#
success
Entities
::
Runner
# Example Request:
end
# GET /runners
params
do
optional
:scope
,
type:
String
,
values:
%w[active paused online]
,
desc:
'The scope of specific runners to show'
end
get
do
get
do
runners
=
filter_runners
(
current_user
.
ci_authorized_runners
,
params
[
:scope
],
without:
[
'specific'
,
'shared'
])
runners
=
filter_runners
(
current_user
.
ci_authorized_runners
,
params
[
:scope
],
without:
[
'specific'
,
'shared'
])
present
paginate
(
runners
),
with:
Entities
::
Runner
present
paginate
(
runners
),
with:
Entities
::
Runner
end
end
# Get all runners - shared and specific
desc
'Get all runners - shared and specific'
do
#
success
Entities
::
Runner
# Example Request:
end
# GET /runners/all
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
get
'all'
do
authenticated_as_admin!
authenticated_as_admin!
runners
=
filter_runners
(
Ci
::
Runner
.
all
,
params
[
:scope
])
runners
=
filter_runners
(
Ci
::
Runner
.
all
,
params
[
:scope
])
present
paginate
(
runners
),
with:
Entities
::
Runner
present
paginate
(
runners
),
with:
Entities
::
Runner
end
end
# Get runner's details
desc
"Get runner's details"
do
#
success
Entities
::
RunnerDetails
# Parameters:
end
# id (required) - The ID of ther runner
params
do
# Example Request:
requires
:id
,
type:
Integer
,
desc:
'The ID of the runner'
# GET /runners/:i
d
en
d
get
':id'
do
get
':id'
do
runner
=
get_runner
(
params
[
:id
])
runner
=
get_runner
(
params
[
:id
])
authenticate_show_runner!
(
runner
)
authenticate_show_runner!
(
runner
)
...
@@ -36,33 +41,37 @@ module API
...
@@ -36,33 +41,37 @@ module API
present
runner
,
with:
Entities
::
RunnerDetails
,
current_user:
current_user
present
runner
,
with:
Entities
::
RunnerDetails
,
current_user:
current_user
end
end
# Update runner's details
desc
"Update runner's details"
do
#
success
Entities
::
RunnerDetails
# Parameters:
end
# id (required) - The ID of ther runner
params
do
# description (optional) - Runner's description
requires
:id
,
type:
Integer
,
desc:
'The ID of the runner'
# active (optional) - Runner's status
optional
:description
,
type:
String
,
desc:
'The description of the runner'
# tag_list (optional) - Array of tags for runner
optional
:active
,
type:
Boolean
,
desc:
'The state of a runner'
# Example Request:
optional
:tag_list
,
type:
Array
[
String
],
desc:
'The list of tags for a runner'
# PUT /runners/:id
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
put
':id'
do
runner
=
get_runner
(
params
[
:id
]
)
runner
=
get_runner
(
params
.
delete
(
:id
)
)
authenticate_update_runner!
(
runner
)
authenticate_update_runner!
(
runner
)
attrs
=
attributes_for_keys
[
:description
,
:active
,
:tag_list
,
:run_untagged
,
:locked
]
runner_params
=
declared
(
params
,
include_missing:
false
)
if
runner
.
update
(
attrs
)
if
runner
.
update
(
runner_params
)
present
runner
,
with:
Entities
::
RunnerDetails
,
current_user:
current_user
present
runner
,
with:
Entities
::
RunnerDetails
,
current_user:
current_user
else
else
render_validation_error!
(
runner
)
render_validation_error!
(
runner
)
end
end
end
end
# Remove runner
desc
'Remove a runner'
do
#
success
Entities
::
Runner
# Parameters:
end
# id (required) - The ID of ther runner
params
do
# Example Request:
requires
:id
,
type:
Integer
,
desc:
'The ID of the runner'
# DELETE /runners/:i
d
en
d
delete
':id'
do
delete
':id'
do
runner
=
get_runner
(
params
[
:id
])
runner
=
get_runner
(
params
[
:id
])
authenticate_delete_runner!
(
runner
)
authenticate_delete_runner!
(
runner
)
...
@@ -72,28 +81,31 @@ module API
...
@@ -72,28 +81,31 @@ module API
end
end
end
end
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
resource
:projects
do
resource
:projects
do
before
{
authorize_admin_project
}
before
{
authorize_admin_project
}
# Get runners available for project
desc
'Get runners available for project'
do
#
success
Entities
::
Runner
# Example Request:
end
# GET /projects/:id/runners
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
get
':id/runners'
do
runners
=
filter_runners
(
Ci
::
Runner
.
owned_or_shared
(
user_project
.
id
),
params
[
:scope
])
runners
=
filter_runners
(
Ci
::
Runner
.
owned_or_shared
(
user_project
.
id
),
params
[
:scope
])
present
paginate
(
runners
),
with:
Entities
::
Runner
present
paginate
(
runners
),
with:
Entities
::
Runner
end
end
# Enable runner for project
desc
'Enable a runner for a project'
do
#
success
Entities
::
Runner
# Parameters:
end
# id (required) - The ID of the project
params
do
# runner_id (required) - The ID of the runner
requires
:runner_id
,
type:
Integer
,
desc:
'The ID of the runner'
# Example Request:
end
# POST /projects/:id/runners/:runner_id
post
':id/runners'
do
post
':id/runners'
do
required_attributes!
[
:runner_id
]
runner
=
get_runner
(
params
[
:runner_id
])
runner
=
get_runner
(
params
[
:runner_id
])
authenticate_enable_runner!
(
runner
)
authenticate_enable_runner!
(
runner
)
...
@@ -106,13 +118,12 @@ module API
...
@@ -106,13 +118,12 @@ module API
end
end
end
end
# Disable project's runner
desc
"Disable project's runner"
do
#
success
Entities
::
Runner
# Parameters:
end
# id (required) - The ID of the project
params
do
# runner_id (required) - The ID of the runner
requires
:runner_id
,
type:
Integer
,
desc:
'The ID of the runner'
# Example Request:
end
# DELETE /projects/:id/runners/:runner_id
delete
':id/runners/:runner_id'
do
delete
':id/runners/:runner_id'
do
runner_project
=
user_project
.
runner_projects
.
find_by
(
runner_id:
params
[
:runner_id
])
runner_project
=
user_project
.
runner_projects
.
find_by
(
runner_id:
params
[
:runner_id
])
not_found!
(
'Runner'
)
unless
runner_project
not_found!
(
'Runner'
)
unless
runner_project
...
...
spec/requests/api/runners_spec.rb
View file @
33786425
...
@@ -226,7 +226,7 @@ describe API::Runners, api: true do
...
@@ -226,7 +226,7 @@ describe API::Runners, api: true do
context
'authorized user'
do
context
'authorized user'
do
context
'when runner is shared'
do
context
'when runner is shared'
do
it
'does not update runner'
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
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
@@ -234,7 +234,7 @@ describe API::Runners, api: true do
...
@@ -234,7 +234,7 @@ describe API::Runners, api: true do
context
'when runner is not shared'
do
context
'when runner is not shared'
do
it
'does not update runner without access to it'
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
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment