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
1143411a
Commit
1143411a
authored
Nov 23, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce Sidekiq signature of scheduled tokens migration
parent
627b4833
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
10 deletions
+23
-10
db/post_migrate/20181121111200_schedule_runners_token_encryption.rb
...grate/20181121111200_schedule_runners_token_encryption.rb
+1
-1
lib/gitlab/background_migration/encrypt_runners_tokens.rb
lib/gitlab/background_migration/encrypt_runners_tokens.rb
+9
-1
spec/lib/gitlab/background_migration/encrypt_runners_tokens_spec.rb
...itlab/background_migration/encrypt_runners_tokens_spec.rb
+6
-8
spec/migrations/schedule_runners_token_encryption_spec.rb
spec/migrations/schedule_runners_token_encryption_spec.rb
+7
-0
No files found.
db/post_migrate/20181121111200_schedule_runners_token_encryption.rb
View file @
1143411a
...
@@ -24,7 +24,7 @@ class ScheduleRunnersTokenEncryption < ActiveRecord::Migration
...
@@ -24,7 +24,7 @@ class ScheduleRunnersTokenEncryption < ActiveRecord::Migration
relation
.
each_batch
(
of:
RANGE_SIZE
)
do
|
relation
|
relation
.
each_batch
(
of:
RANGE_SIZE
)
do
|
relation
|
range
=
relation
.
pluck
(
'MIN(id)'
,
'MAX(id)'
).
first
range
=
relation
.
pluck
(
'MIN(id)'
,
'MAX(id)'
).
first
args
=
[
model
,
model
.
encrypted_attributes
.
keys
,
*
range
]
args
=
[
model
.
name
.
demodulize
.
downcase
,
*
range
]
BackgroundMigrationWorker
.
perform_in
(
delay
,
MIGRATION
,
args
)
BackgroundMigrationWorker
.
perform_in
(
delay
,
MIGRATION
,
args
)
end
end
...
...
lib/gitlab/background_migration/encrypt_runners_tokens.rb
View file @
1143411a
...
@@ -15,6 +15,14 @@ module Gitlab
...
@@ -15,6 +15,14 @@ module Gitlab
#
#
# https://gitlab.com/gitlab-org/gitlab-ce/issues/54328
# https://gitlab.com/gitlab-org/gitlab-ce/issues/54328
#
#
class
EncryptRunnersTokens
<
EncryptColumns
;
end
class
EncryptRunnersTokens
<
EncryptColumns
def
perform
(
model
,
from
,
to
)
resource
=
"::Gitlab::BackgroundMigration::Models::EncryptColumns::
#{
model
.
to_s
.
capitalize
}
"
model
=
resource
.
constantize
attributes
=
model
.
encrypted_attributes
.
keys
super
(
model
,
attributes
,
from
,
to
)
end
end
end
end
end
end
spec/lib/gitlab/background_migration/encrypt_runners_tokens_spec.rb
View file @
1143411a
...
@@ -12,7 +12,7 @@ describe Gitlab::BackgroundMigration::EncryptRunnersTokens, :migration, schema:
...
@@ -12,7 +12,7 @@ describe Gitlab::BackgroundMigration::EncryptRunnersTokens, :migration, schema:
end
end
it
'migrates runners registration tokens'
do
it
'migrates runners registration tokens'
do
migrate!
(
:settings
,
:runners_registration_token
,
1
,
1
)
migrate!
(
:settings
,
1
,
1
)
encrypted_token
=
settings
.
first
.
runners_registration_token_encrypted
encrypted_token
=
settings
.
first
.
runners_registration_token_encrypted
decrypted_token
=
::
Gitlab
::
CryptoHelper
.
aes256_gcm_decrypt
(
encrypted_token
)
decrypted_token
=
::
Gitlab
::
CryptoHelper
.
aes256_gcm_decrypt
(
encrypted_token
)
...
@@ -30,7 +30,7 @@ describe Gitlab::BackgroundMigration::EncryptRunnersTokens, :migration, schema:
...
@@ -30,7 +30,7 @@ describe Gitlab::BackgroundMigration::EncryptRunnersTokens, :migration, schema:
end
end
it
'migrates runners registration tokens'
do
it
'migrates runners registration tokens'
do
migrate!
(
:namespace
,
:runners_token
,
11
,
22
)
migrate!
(
:namespace
,
11
,
22
)
expect
(
namespaces
.
all
.
reload
).
to
all
(
expect
(
namespaces
.
all
.
reload
).
to
all
(
have_attributes
(
runners_token:
nil
,
runners_token_encrypted:
be_a
(
String
))
have_attributes
(
runners_token:
nil
,
runners_token_encrypted:
be_a
(
String
))
...
@@ -47,7 +47,7 @@ describe Gitlab::BackgroundMigration::EncryptRunnersTokens, :migration, schema:
...
@@ -47,7 +47,7 @@ describe Gitlab::BackgroundMigration::EncryptRunnersTokens, :migration, schema:
end
end
it
'migrates runners registration tokens'
do
it
'migrates runners registration tokens'
do
migrate!
(
:project
,
:runners_token
,
111
,
116
)
migrate!
(
:project
,
111
,
116
)
expect
(
projects
.
all
.
reload
).
to
all
(
expect
(
projects
.
all
.
reload
).
to
all
(
have_attributes
(
runners_token:
nil
,
runners_token_encrypted:
be_a
(
String
))
have_attributes
(
runners_token:
nil
,
runners_token_encrypted:
be_a
(
String
))
...
@@ -63,7 +63,7 @@ describe Gitlab::BackgroundMigration::EncryptRunnersTokens, :migration, schema:
...
@@ -63,7 +63,7 @@ describe Gitlab::BackgroundMigration::EncryptRunnersTokens, :migration, schema:
end
end
it
'migrates runners communication tokens'
do
it
'migrates runners communication tokens'
do
migrate!
(
:runner
,
:token
,
201
,
203
)
migrate!
(
:runner
,
201
,
203
)
expect
(
runners
.
all
.
reload
).
to
all
(
expect
(
runners
.
all
.
reload
).
to
all
(
have_attributes
(
token:
nil
,
token_encrypted:
be_a
(
String
))
have_attributes
(
token:
nil
,
token_encrypted:
be_a
(
String
))
...
@@ -71,9 +71,7 @@ describe Gitlab::BackgroundMigration::EncryptRunnersTokens, :migration, schema:
...
@@ -71,9 +71,7 @@ describe Gitlab::BackgroundMigration::EncryptRunnersTokens, :migration, schema:
end
end
end
end
def
migrate!
(
model
,
attribute
,
from
,
to
)
def
migrate!
(
model
,
from
,
to
)
model
=
"::Gitlab::BackgroundMigration::Models::EncryptColumns::
#{
model
.
to_s
.
capitalize
}
"
subject
.
perform
(
model
,
from
,
to
)
subject
.
perform
(
model
,
[
attribute
],
from
,
to
)
end
end
end
end
spec/migrations/schedule_runners_token_encryption_spec.rb
View file @
1143411a
...
@@ -24,6 +24,13 @@ describe ScheduleRunnersTokenEncryption, :migration do
...
@@ -24,6 +24,13 @@ describe ScheduleRunnersTokenEncryption, :migration do
Timecop
.
freeze
do
Timecop
.
freeze
do
migrate!
migrate!
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_delayed_migration
(
2
.
minutes
,
'settings'
,
1
,
1
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_delayed_migration
(
2
.
minutes
,
'namespace'
,
11
,
11
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_delayed_migration
(
4
.
minutes
,
'namespace'
,
12
,
12
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_delayed_migration
(
2
.
minutes
,
'project'
,
111
,
111
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_delayed_migration
(
4
.
minutes
,
'project'
,
114
,
114
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_delayed_migration
(
2
.
minutes
,
'runner'
,
201
,
201
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_delayed_migration
(
4
.
minutes
,
'runner'
,
202
,
202
)
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
7
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
7
end
end
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