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
b5a5fdf0
Commit
b5a5fdf0
authored
Feb 22, 2018
by
Dylan Griffith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Persist runner IP address on contact (#43489)
parent
0be4a77d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
11 deletions
+45
-11
app/models/ci/runner.rb
app/models/ci/runner.rb
+2
-2
db/migrate/20180222043024_add_ip_address_to_runner.rb
db/migrate/20180222043024_add_ip_address_to_runner.rb
+9
-0
db/schema.rb
db/schema.rb
+2
-1
lib/api/helpers/runner.rb
lib/api/helpers/runner.rb
+12
-6
lib/api/runner.rb
lib/api/runner.rb
+2
-2
spec/requests/api/runner_spec.rb
spec/requests/api/runner_spec.rb
+18
-0
No files found.
app/models/ci/runner.rb
View file @
b5a5fdf0
...
@@ -49,7 +49,7 @@ module Ci
...
@@ -49,7 +49,7 @@ module Ci
ref_protected:
1
ref_protected:
1
}
}
cached_attr_reader
:version
,
:revision
,
:platform
,
:architecture
,
:contacted_at
cached_attr_reader
:version
,
:revision
,
:platform
,
:architecture
,
:contacted_at
,
:ip_address
# Searches for runners matching the given query.
# Searches for runners matching the given query.
#
#
...
@@ -157,7 +157,7 @@ module Ci
...
@@ -157,7 +157,7 @@ module Ci
end
end
def
update_cached_info
(
values
)
def
update_cached_info
(
values
)
values
=
values
&
.
slice
(
:version
,
:revision
,
:platform
,
:architecture
)
||
{}
values
=
values
&
.
slice
(
:version
,
:revision
,
:platform
,
:architecture
,
:ip_address
)
||
{}
values
[
:contacted_at
]
=
Time
.
now
values
[
:contacted_at
]
=
Time
.
now
cache_attributes
(
values
)
cache_attributes
(
values
)
...
...
db/migrate/20180222043024_add_ip_address_to_runner.rb
0 → 100644
View file @
b5a5fdf0
class
AddIpAddressToRunner
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
change
add_column
:ci_runners
,
:ip_address
,
:string
end
end
db/schema.rb
View file @
b5a5fdf0
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
201802
16121030
)
do
ActiveRecord
::
Schema
.
define
(
version:
201802
22043024
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
@@ -437,6 +437,7 @@ ActiveRecord::Schema.define(version: 20180216121030) do
...
@@ -437,6 +437,7 @@ ActiveRecord::Schema.define(version: 20180216121030) do
t
.
boolean
"run_untagged"
,
default:
true
,
null:
false
t
.
boolean
"run_untagged"
,
default:
true
,
null:
false
t
.
boolean
"locked"
,
default:
false
,
null:
false
t
.
boolean
"locked"
,
default:
false
,
null:
false
t
.
integer
"access_level"
,
default:
0
,
null:
false
t
.
integer
"access_level"
,
default:
0
,
null:
false
t
.
string
"ip_address"
end
end
add_index
"ci_runners"
,
[
"contacted_at"
],
name:
"index_ci_runners_on_contacted_at"
,
using: :btree
add_index
"ci_runners"
,
[
"contacted_at"
],
name:
"index_ci_runners_on_contacted_at"
,
using: :btree
...
...
lib/api/helpers/runner.rb
View file @
b5a5fdf0
...
@@ -9,16 +9,22 @@ module API
...
@@ -9,16 +9,22 @@ module API
Gitlab
::
CurrentSettings
.
runners_registration_token
)
Gitlab
::
CurrentSettings
.
runners_registration_token
)
end
end
def
get_runner_version_from_params
def
authenticate_runner!
return
unless
params
[
'info'
].
present?
forbidden!
unless
current_runner
attributes_for_keys
(
%w(name version revision platform architecture)
,
params
[
'info'
])
current_runner
.
update_cached_info
(
get_runner_details_from_request
)
end
end
def
authenticate_runner!
def
get_runner_details_from_request
forbidden!
unless
current_runner
return
get_runner_ip
unless
params
[
'info'
].
present?
attributes_for_keys
(
%w(name version revision platform architecture)
,
params
[
'info'
])
.
merge
(
get_runner_ip
)
end
current_runner
.
update_cached_info
(
get_runner_version_from_params
)
def
get_runner_ip
{
ip_address:
request
.
ip
}
end
end
def
current_runner
def
current_runner
...
...
lib/api/runner.rb
View file @
b5a5fdf0
...
@@ -16,7 +16,8 @@ module API
...
@@ -16,7 +16,8 @@ module API
optional
:tag_list
,
type:
Array
[
String
],
desc:
%q(List of Runner's tags)
optional
:tag_list
,
type:
Array
[
String
],
desc:
%q(List of Runner's tags)
end
end
post
'/'
do
post
'/'
do
attributes
=
attributes_for_keys
[
:description
,
:locked
,
:run_untagged
,
:tag_list
]
attributes
=
attributes_for_keys
([
:description
,
:locked
,
:run_untagged
,
:tag_list
])
.
merge
(
get_runner_details_from_request
)
runner
=
runner
=
if
runner_registration_token_valid?
if
runner_registration_token_valid?
...
@@ -30,7 +31,6 @@ module API
...
@@ -30,7 +31,6 @@ module API
return
forbidden!
unless
runner
return
forbidden!
unless
runner
if
runner
.
id
if
runner
.
id
runner
.
update
(
get_runner_version_from_params
)
present
runner
,
with:
Entities
::
RunnerRegistrationDetails
present
runner
,
with:
Entities
::
RunnerRegistrationDetails
else
else
not_found!
not_found!
...
...
spec/requests/api/runner_spec.rb
View file @
b5a5fdf0
...
@@ -122,6 +122,15 @@ describe API::Runner do
...
@@ -122,6 +122,15 @@ describe API::Runner do
end
end
end
end
end
end
it
"sets the runner's ip_address"
do
post
api
(
'/runners'
),
{
token:
registration_token
},
{
'REMOTE_ADDR'
=>
'123.111.123.111'
}
expect
(
response
).
to
have_gitlab_http_status
201
expect
(
Ci
::
Runner
.
first
.
ip_address
).
to
eq
(
'123.111.123.111'
)
end
end
end
describe
'DELETE /api/v4/runners'
do
describe
'DELETE /api/v4/runners'
do
...
@@ -422,6 +431,15 @@ describe API::Runner do
...
@@ -422,6 +431,15 @@ describe API::Runner do
end
end
end
end
it
"sets the runner's ip_address"
do
post
api
(
'/jobs/request'
),
{
token:
runner
.
token
},
{
'User-Agent'
=>
user_agent
,
'REMOTE_ADDR'
=>
'123.222.123.222'
}
expect
(
response
).
to
have_gitlab_http_status
201
expect
(
runner
.
reload
.
ip_address
).
to
eq
(
'123.222.123.222'
)
end
context
'when concurrently updating a job'
do
context
'when concurrently updating a job'
do
before
do
before
do
expect_any_instance_of
(
Ci
::
Build
).
to
receive
(
:run!
)
expect_any_instance_of
(
Ci
::
Build
).
to
receive
(
:run!
)
...
...
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