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:
-rw-r--r--app/models/project.rb1
-rw-r--r--app/models/project_import_data.rb3
-rw-r--r--db/migrate/20160302151724_add_import_credentials_to_project_import_data.rb6
-rw-r--r--db/migrate/20160302151724_add_import_credentials_to_projects.rb6
-rw-r--r--db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb36
5 files changed, 37 insertions, 15 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 36b11366f3f..6f5d592755a 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -91,7 +91,6 @@ class Project < ActiveRecord::Base
attr_accessor :new_default_branch
attr_accessor :old_path_with_namespace
- attr_encrypted :import_credentials, key: Gitlab::Application.secrets.db_key_base
# Relations
belongs_to :creator, foreign_key: 'creator_id', class_name: 'User'
diff --git a/app/models/project_import_data.rb b/app/models/project_import_data.rb
index cd3319f077e..2900b86d643 100644
--- a/app/models/project_import_data.rb
+++ b/app/models/project_import_data.rb
@@ -12,7 +12,8 @@ require 'file_size_validator'
class ProjectImportData < ActiveRecord::Base
belongs_to :project
-
+ attr_encrypted :credentials, key: Gitlab::Application.secrets.db_key_base
+
serialize :data, JSON
validates :project, presence: true
diff --git a/db/migrate/20160302151724_add_import_credentials_to_project_import_data.rb b/db/migrate/20160302151724_add_import_credentials_to_project_import_data.rb
new file mode 100644
index 00000000000..ff3d8b466dc
--- /dev/null
+++ b/db/migrate/20160302151724_add_import_credentials_to_project_import_data.rb
@@ -0,0 +1,6 @@
+class AddImportCredentialsToProjectImportData < ActiveRecord::Migration
+ def change
+ add_column :project_import_data, :encrypted_credentials, :text
+ add_column :project_import_data, :encrypted_credentials_iv, :text
+ end
+end
diff --git a/db/migrate/20160302151724_add_import_credentials_to_projects.rb b/db/migrate/20160302151724_add_import_credentials_to_projects.rb
deleted file mode 100644
index 3cfe2bbd50a..00000000000
--- a/db/migrate/20160302151724_add_import_credentials_to_projects.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-class AddImportCredentialsToProjects < ActiveRecord::Migration
- def change
- add_column :projects, :encrypted_import_credentials, :text
- add_column :projects, :encrypted_import_credentials_iv, :text
- end
-end
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 3f1b65aff14..dda7648fb87 100644
--- a/db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb
+++ b/db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb
@@ -1,16 +1,38 @@
class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration
+
+ class ImportUrlSanitizer
+ def initialize(url)
+ @url = url
+ end
+
+ def sanitized_url
+ @sanitized_url ||= @url[regex_extractor, 1] + @url[regex_extractor, 3]
+ end
+
+ def credentials
+ @credentials ||= @url[regex_extractor, 2]
+ end
+
+ private
+
+ # Regex matches 1 <first part of URL>, 2 <token or to be encrypted stuff>,
+ # 3 <last part of URL>
+ def regex_extractor
+ /(.*\/\/)(.*)(\@.*)/
+ end
+ end
+
def up
projects_with_wrong_import_url.each do |project|
- project.update_columns(import_url: nil) # TODO Check really nil?
- # TODO: migrate current credentials to import_credentials?
- # TODO: Notify user ?
+ sanitizer = ImportUrlSanitizer.new(project.import_urls)
+ project.update_columns(import_url: sanitizer.sanitized_url)
+ if project.import_data
+ project.import_data.update_columns(credentials: sanitizer.credentials)
+ end
end
end
- private
-
-
- def projects_with_dot_atom
+ 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 from projects p WHERE p.import_url LIKE '%//%:%@%' or p.import_url like '#{"_"*40}@github.com%'")
end