Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-03-21 17:11:05 +0300
committerJames Lopez <james@jameslopez.es>2016-03-21 17:11:05 +0300
commit030b13944534be505dc97667ce2094ed6c588f12 (patch)
tree048c815816d461423f4eeb28ceb08efd1d7ebfa0 /db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb
parent8d7d9c8daa61d58a17fea648771a1bb6c9341304 (diff)
more refactoring
Diffstat (limited to 'db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb')
-rw-r--r--db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb23
1 files changed, 10 insertions, 13 deletions
diff --git a/db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb b/db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb
index f98ec925ac4..fd718ef3974 100644
--- a/db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb
+++ b/db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb
@@ -1,3 +1,6 @@
+# Loops through old importer projects that kept a token/password in the import URL
+# and encrypts the credentials into a separate field in project#import_data
+# #down method not supported
class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration
class FakeProjectImportData
@@ -7,24 +10,18 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration
end
def up
- projects_with_wrong_import_url.find_in_batches do |project_batch|
- project_batch.each do |project|
- sanitizer = Gitlab::ImportUrlSanitizer.new(project["import_url"])
+ projects_with_wrong_import_url do |project|
+ import_url = Gitlab::ImportUrl.new(project["import_url"])
- ActiveRecord::Base.transaction do
- execute("UPDATE projects SET import_url = '#{quote(sanitizer.sanitized_url)}' WHERE id = #{project['id']}")
- fake_import_data = FakeProjectImportData.new
- fake_import_data.credentials = sanitizer.credentials
- execute("UPDATE project_import_data SET encrypted_credentials = '#{quote(fake_import_data.encrypted_credentials)}' WHERE project_id = #{project['id']}")
- end
+ ActiveRecord::Base.transaction do
+ execute("UPDATE projects SET import_url = '#{quote(import_url.sanitized_url)}' WHERE id = #{project['id']}")
+ fake_import_data = FakeProjectImportData.new
+ fake_import_data.credentials = import_url.credentials
+ execute("UPDATE project_import_data SET encrypted_credentials = '#{quote(fake_import_data.encrypted_credentials)}' WHERE project_id = #{project['id']}")
end
end
end
- def down
-
- end
-
def projects_with_wrong_import_url
# TODO Check live with #operations for possible false positives. Also, consider regex? But may have issues MySQL/PSQL
select_all("SELECT p.id, p.import_url FROM projects p WHERE p.import_url IS NOT NULL AND (p.import_url LIKE '%//%:%@%' OR p.import_url LIKE '#{"_"*40}@github.com%')")