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
d2dd8ca7
Commit
d2dd8ca7
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
2301ccee
Changes
2
Hide 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 @
d2dd8ca7
...
...
@@ -7,11 +7,15 @@ class ApplicationSetting < ActiveRecord::Base
include
IgnorableColumn
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
: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
:import_sources
# rubocop:disable Cop/ActiveRecordSerialize
serialize
:disabled_oauth_sign_in_sources
,
Array
# rubocop:disable Cop/ActiveRecordSerialize
...
...
app/models/concerns/token_authenticatable.rb
View file @
d2dd8ca7
...
...
@@ -26,34 +26,41 @@ module TokenAuthenticatable
end
end
define_method
(
token_field
)
do
mod
=
token_authenticatable_module
mod
.
define_method
(
token_field
)
do
strategy
.
get_token
(
self
)
end
define_method
(
"set_
#{
token_field
}
"
)
do
|
token
|
mod
.
define_method
(
"set_
#{
token_field
}
"
)
do
|
token
|
strategy
.
set_token
(
self
,
token
)
end
define_method
(
"ensure_
#{
token_field
}
"
)
do
mod
.
define_method
(
"ensure_
#{
token_field
}
"
)
do
strategy
.
ensure_token
(
self
)
end
# 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
)
end
# 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
)
end
define_method
(
"
#{
token_field
}
_matches?"
)
do
|
other_token
|
mod
.
define_method
(
"
#{
token_field
}
_matches?"
)
do
|
other_token
|
token
=
read_attribute
(
token_field
)
token
.
present?
&&
ActiveSupport
::
SecurityUtils
.
variable_size_secure_compare
(
other_token
,
token
)
end
end
def
token_authenticatable_module
@token_authenticatable_module
||=
const_set
(
:TokenAuthenticatable
,
Module
.
new
).
tap
(
&
method
(
:include
))
end
def
token_authenticatable_fields
@token_authenticatable_fields
||=
[]
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