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
Tatuya Kamada
gitlab-ce
Commits
e2e43a11
Commit
e2e43a11
authored
Dec 10, 2015
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use new runners registration token to register CI runners
parent
219afbad
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
7 deletions
+12
-7
config/initializers/4_ci_app.rb
config/initializers/4_ci_app.rb
+0
-2
lib/ci/api/helpers.rb
lib/ci/api/helpers.rb
+5
-1
lib/ci/api/runners.rb
lib/ci/api/runners.rb
+1
-1
spec/requests/ci/api/runners_spec.rb
spec/requests/ci/api/runners_spec.rb
+6
-3
No files found.
config/initializers/4_ci_app.rb
View file @
e2e43a11
module
GitlabCi
module
GitlabCi
VERSION
=
Gitlab
::
VERSION
VERSION
=
Gitlab
::
VERSION
REVISION
=
Gitlab
::
REVISION
REVISION
=
Gitlab
::
REVISION
REGISTRATION_TOKEN
=
SecureRandom
.
hex
(
10
)
def
self
.
config
def
self
.
config
Settings
Settings
...
...
lib/ci/api/helpers.rb
View file @
e2e43a11
...
@@ -6,7 +6,7 @@ module Ci
...
@@ -6,7 +6,7 @@ module Ci
UPDATE_RUNNER_EVERY
=
60
UPDATE_RUNNER_EVERY
=
60
def
authenticate_runners!
def
authenticate_runners!
forbidden!
unless
params
[
:token
]
==
GitlabCi
::
REGISTRATION_TOKEN
forbidden!
unless
runner_registration_token_valid?
end
end
def
authenticate_runner!
def
authenticate_runner!
...
@@ -22,6 +22,10 @@ module Ci
...
@@ -22,6 +22,10 @@ module Ci
forbidden!
unless
token
&&
build
.
valid_token?
(
token
)
forbidden!
unless
token
&&
build
.
valid_token?
(
token
)
end
end
def
runner_registration_token_valid?
params
[
:token
]
==
current_application_settings
.
runners_registration_token
end
def
update_runner_last_contact
def
update_runner_last_contact
# Use a random threshold to prevent beating DB updates
# Use a random threshold to prevent beating DB updates
contacted_at_max_age
=
UPDATE_RUNNER_EVERY
+
Random
.
rand
(
UPDATE_RUNNER_EVERY
)
contacted_at_max_age
=
UPDATE_RUNNER_EVERY
+
Random
.
rand
(
UPDATE_RUNNER_EVERY
)
...
...
lib/ci/api/runners.rb
View file @
e2e43a11
...
@@ -40,7 +40,7 @@ module Ci
...
@@ -40,7 +40,7 @@ module Ci
required_attributes!
[
:token
]
required_attributes!
[
:token
]
runner
=
runner
=
if
params
[
:token
]
==
GitlabCi
::
REGISTRATION_TOKEN
if
runner_registration_token_valid?
# Create shared runner. Requires admin access
# Create shared runner. Requires admin access
Ci
::
Runner
.
create
(
Ci
::
Runner
.
create
(
description:
params
[
:description
],
description:
params
[
:description
],
...
...
spec/requests/ci/api/runners_spec.rb
View file @
e2e43a11
...
@@ -4,8 +4,11 @@ describe Ci::API::API do
...
@@ -4,8 +4,11 @@ describe Ci::API::API do
include
ApiHelpers
include
ApiHelpers
include
StubGitlabCalls
include
StubGitlabCalls
let
(
:registration_token
)
{
'abcdefg123456'
}
before
do
before
do
stub_gitlab_calls
stub_gitlab_calls
stub_application_setting
(
runners_registration_token:
registration_token
)
end
end
describe
"GET /runners"
do
describe
"GET /runners"
do
...
@@ -33,20 +36,20 @@ describe Ci::API::API do
...
@@ -33,20 +36,20 @@ describe Ci::API::API do
describe
"POST /runners/register"
do
describe
"POST /runners/register"
do
describe
"should create a runner if token provided"
do
describe
"should create a runner if token provided"
do
before
{
post
ci_api
(
"/runners/register"
),
token:
GitlabCi
::
REGISTRATION_TOKEN
}
before
{
post
ci_api
(
"/runners/register"
),
token:
registration_token
}
it
{
expect
(
response
.
status
).
to
eq
(
201
)
}
it
{
expect
(
response
.
status
).
to
eq
(
201
)
}
end
end
describe
"should create a runner with description"
do
describe
"should create a runner with description"
do
before
{
post
ci_api
(
"/runners/register"
),
token:
GitlabCi
::
REGISTRATION_TOKEN
,
description:
"server.hostname"
}
before
{
post
ci_api
(
"/runners/register"
),
token:
registration_token
,
description:
"server.hostname"
}
it
{
expect
(
response
.
status
).
to
eq
(
201
)
}
it
{
expect
(
response
.
status
).
to
eq
(
201
)
}
it
{
expect
(
Ci
::
Runner
.
first
.
description
).
to
eq
(
"server.hostname"
)
}
it
{
expect
(
Ci
::
Runner
.
first
.
description
).
to
eq
(
"server.hostname"
)
}
end
end
describe
"should create a runner with tags"
do
describe
"should create a runner with tags"
do
before
{
post
ci_api
(
"/runners/register"
),
token:
GitlabCi
::
REGISTRATION_TOKEN
,
tag_list:
"tag1, tag2"
}
before
{
post
ci_api
(
"/runners/register"
),
token:
registration_token
,
tag_list:
"tag1, tag2"
}
it
{
expect
(
response
.
status
).
to
eq
(
201
)
}
it
{
expect
(
response
.
status
).
to
eq
(
201
)
}
it
{
expect
(
Ci
::
Runner
.
first
.
tag_list
.
sort
).
to
eq
([
"tag1"
,
"tag2"
])
}
it
{
expect
(
Ci
::
Runner
.
first
.
tag_list
.
sort
).
to
eq
([
"tag1"
,
"tag2"
])
}
...
...
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