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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
364791c9
Commit
364791c9
authored
Mar 08, 2019
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update TokenAuthenticatable so methods can be overridden
parent
6b0d4933
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
8 deletions
+19
-8
app/models/application_setting.rb
app/models/application_setting.rb
+6
-2
app/models/concerns/token_authenticatable.rb
app/models/concerns/token_authenticatable.rb
+13
-6
No files found.
app/models/application_setting.rb
View file @
364791c9
...
@@ -7,11 +7,15 @@ class ApplicationSetting < ActiveRecord::Base
...
@@ -7,11 +7,15 @@ class ApplicationSetting < ActiveRecord::Base
include
IgnorableColumn
include
IgnorableColumn
include
ChronicDurationAttribute
include
ChronicDurationAttribute
include
ApplicationSettingImplementation
add_authentication_token_field
:runners_registration_token
,
encrypted:
->
{
Feature
.
enabled?
(
:application_settings_tokens_optional_encryption
)
?
:optional
:
:required
}
add_authentication_token_field
:runners_registration_token
,
encrypted:
->
{
Feature
.
enabled?
(
:application_settings_tokens_optional_encryption
)
?
:optional
:
:required
}
add_authentication_token_field
:health_check_access_token
add_authentication_token_field
:health_check_access_token
# Include here so it can override methods from
# `add_authentication_token_field`
# We don't prepend for now because otherwise we'll need to
# fix a lot of tests using allow_any_instance_of
include
ApplicationSettingImplementation
serialize
:restricted_visibility_levels
# rubocop:disable Cop/ActiveRecordSerialize
serialize
:restricted_visibility_levels
# rubocop:disable Cop/ActiveRecordSerialize
serialize
:import_sources
# rubocop:disable Cop/ActiveRecordSerialize
serialize
:import_sources
# rubocop:disable Cop/ActiveRecordSerialize
serialize
:disabled_oauth_sign_in_sources
,
Array
# rubocop:disable Cop/ActiveRecordSerialize
serialize
:disabled_oauth_sign_in_sources
,
Array
# rubocop:disable Cop/ActiveRecordSerialize
...
...
app/models/concerns/token_authenticatable.rb
View file @
364791c9
...
@@ -26,34 +26,41 @@ module TokenAuthenticatable
...
@@ -26,34 +26,41 @@ module TokenAuthenticatable
end
end
end
end
define_method
(
token_field
)
do
mod
=
token_authenticatable_module
mod
.
define_method
(
token_field
)
do
strategy
.
get_token
(
self
)
strategy
.
get_token
(
self
)
end
end
define_method
(
"set_
#{
token_field
}
"
)
do
|
token
|
mod
.
define_method
(
"set_
#{
token_field
}
"
)
do
|
token
|
strategy
.
set_token
(
self
,
token
)
strategy
.
set_token
(
self
,
token
)
end
end
define_method
(
"ensure_
#{
token_field
}
"
)
do
mod
.
define_method
(
"ensure_
#{
token_field
}
"
)
do
strategy
.
ensure_token
(
self
)
strategy
.
ensure_token
(
self
)
end
end
# Returns a token, but only saves when the database is in read & write mode
# Returns a token, but only saves when the database is in read & write mode
define_method
(
"ensure_
#{
token_field
}
!"
)
do
mod
.
define_method
(
"ensure_
#{
token_field
}
!"
)
do
strategy
.
ensure_token!
(
self
)
strategy
.
ensure_token!
(
self
)
end
end
# Resets the token, but only saves when the database is in read & write mode
# Resets the token, but only saves when the database is in read & write mode
define_method
(
"reset_
#{
token_field
}
!"
)
do
mod
.
define_method
(
"reset_
#{
token_field
}
!"
)
do
strategy
.
reset_token!
(
self
)
strategy
.
reset_token!
(
self
)
end
end
define_method
(
"
#{
token_field
}
_matches?"
)
do
|
other_token
|
mod
.
define_method
(
"
#{
token_field
}
_matches?"
)
do
|
other_token
|
token
=
read_attribute
(
token_field
)
token
=
read_attribute
(
token_field
)
token
.
present?
&&
ActiveSupport
::
SecurityUtils
.
variable_size_secure_compare
(
other_token
,
token
)
token
.
present?
&&
ActiveSupport
::
SecurityUtils
.
variable_size_secure_compare
(
other_token
,
token
)
end
end
end
end
def
token_authenticatable_module
@token_authenticatable_module
||=
const_set
(
:TokenAuthenticatable
,
Module
.
new
).
tap
(
&
method
(
:include
))
end
def
token_authenticatable_fields
def
token_authenticatable_fields
@token_authenticatable_fields
||=
[]
@token_authenticatable_fields
||=
[]
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