Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Admin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
osuny
Admin
Commits
0de17159
Commit
0de17159
authored
2 years ago
by
pabois
Browse files
Options
Downloads
Patches
Plain Diff
tout cassé
parent
c653b572
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/services/active_storage_key_converter.rb
+0
-19
0 additions, 19 deletions
app/services/active_storage_key_converter.rb
db/migrate/20230106132654_migrate_to_rails7_sha256_signature.rb
+48
-0
48 additions, 0 deletions
...rate/20230106132654_migrate_to_rails7_sha256_signature.rb
with
48 additions
and
19 deletions
app/services/active_storage_key_converter.rb
deleted
100644 → 0
+
0
−
19
View file @
c653b572
class
ActiveStorageKeyConverter
def
self
.
convert
(
legacy_signed_id
)
# Try to find blob with the un-modified legacy_signed_id
blob
=
ActiveStorage
::
Blob
.
find_signed!
(
legacy_signed_id
)
legacy_signed_id
rescue
ActiveSupport
::
MessageVerifier
::
InvalidSignature
#
key_generator
=
ActiveSupport
::
KeyGenerator
.
new
(
Rails
.
application
.
secrets
.
secret_key_base
,
iterations:
1000
,
hash_digest_class:
OpenSSL
::
Digest
::
SHA1
)
key_generator
=
ActiveSupport
::
CachingKeyGenerator
.
new
(
key_generator
)
secret
=
key_generator
.
generate_key
(
"ActiveStorage"
)
verifier
=
ActiveSupport
::
MessageVerifier
.
new
(
secret
)
ActiveStorage
::
Blob
.
find_by_id
(
verifier
.
verify
(
legacy_signed_id
,
purpose: :blob_id
)).
try
(
:signed_id
)
end
end
This diff is collapsed.
Click to expand it.
app/services/blocks_migration
.rb
→
db/migrate/20230106132654_migrate_to_rails7_sha256_signature
.rb
+
48
−
0
View file @
0de17159
class
BlocksMigration
def
self
.
cleanup
class
MigrateToRails7Sha256Signature
<
ActiveRecord
::
Migration
[
7.0
]
def
up
Communication
::
Block
.
all
.
find_each
{
|
block
|
self
.
crawl
(
block
.
data
)
crawl
(
block
.
data
)
block
.
save
}
end
protected
def
self
.
crawl
(
enumerable
)
def
crawl
(
enumerable
)
case
enumerable
when
Array
enumerable
.
each
do
|
item
|
...
...
@@ -19,7 +18,7 @@ class BlocksMigration
enumerable
.
keys
.
each
do
|
key
|
if
key
==
"signed_id"
# Convert value
enumerable
[
key
]
=
ActiveStorageKeyConverter
.
convert
(
enumerable
[
key
])
if
key
==
"signed_id"
enumerable
[
key
]
=
convert
(
enumerable
[
key
])
if
key
==
"signed_id"
elsif
[
Array
,
Hash
].
include?
(
enumerable
[
key
].
class
)
crawl
(
enumerable
[
key
])
end
...
...
@@ -27,4 +26,23 @@ class BlocksMigration
end
end
end
\ No newline at end of file
def
convert
(
legacy_signed_id
)
begin
# Try to find blob with the un-modified legacy_signed_id
blob
=
ActiveStorage
::
Blob
.
find_signed!
(
legacy_signed_id
)
legacy_signed_id
rescue
ActiveSupport
::
MessageVerifier
::
InvalidSignature
#
key_generator
=
ActiveSupport
::
KeyGenerator
.
new
(
Rails
.
application
.
secrets
.
secret_key_base
,
iterations:
1000
,
hash_digest_class:
OpenSSL
::
Digest
::
SHA1
)
key_generator
=
ActiveSupport
::
CachingKeyGenerator
.
new
(
key_generator
)
secret
=
key_generator
.
generate_key
(
"ActiveStorage"
)
verifier
=
ActiveSupport
::
MessageVerifier
.
new
(
secret
)
ActiveStorage
::
Blob
.
find_by_id
(
verifier
.
verify
(
legacy_signed_id
,
purpose: :blob_id
)).
try
(
:signed_id
)
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment