diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ci/group_variable.rb | 4 | ||||
-rw-r--r-- | app/models/ci/job_variable.rb | 2 | ||||
-rw-r--r-- | app/models/ci/pipeline_schedule_variable.rb | 2 | ||||
-rw-r--r-- | app/models/ci/pipeline_variable.rb | 2 | ||||
-rw-r--r-- | app/models/ci/variable.rb | 4 | ||||
-rw-r--r-- | app/models/concerns/ci/has_variable.rb | 36 | ||||
-rw-r--r-- | app/models/concerns/ci/maskable.rb | 25 | ||||
-rw-r--r-- | app/models/concerns/ci/new_has_variable.rb | 16 | ||||
-rw-r--r-- | app/models/concerns/has_variable.rb | 34 | ||||
-rw-r--r-- | app/models/concerns/maskable.rb | 23 | ||||
-rw-r--r-- | app/models/concerns/new_has_variable.rb | 14 | ||||
-rw-r--r-- | app/models/jira_import_data.rb | 31 | ||||
-rw-r--r-- | app/models/project.rb | 14 |
13 files changed, 123 insertions, 84 deletions
diff --git a/app/models/ci/group_variable.rb b/app/models/ci/group_variable.rb index 0e50265c7ba..1e1dd68ee6c 100644 --- a/app/models/ci/group_variable.rb +++ b/app/models/ci/group_variable.rb @@ -3,9 +3,9 @@ module Ci class GroupVariable < ApplicationRecord extend Gitlab::Ci::Model - include HasVariable + include Ci::HasVariable include Presentable - include Maskable + include Ci::Maskable belongs_to :group, class_name: "::Group" diff --git a/app/models/ci/job_variable.rb b/app/models/ci/job_variable.rb index f2968c037c7..7eea8a37150 100644 --- a/app/models/ci/job_variable.rb +++ b/app/models/ci/job_variable.rb @@ -3,7 +3,7 @@ module Ci class JobVariable < ApplicationRecord extend Gitlab::Ci::Model - include NewHasVariable + include Ci::NewHasVariable include BulkInsertSafe belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id diff --git a/app/models/ci/pipeline_schedule_variable.rb b/app/models/ci/pipeline_schedule_variable.rb index be6e5e76c31..adef9911ae1 100644 --- a/app/models/ci/pipeline_schedule_variable.rb +++ b/app/models/ci/pipeline_schedule_variable.rb @@ -3,7 +3,7 @@ module Ci class PipelineScheduleVariable < ApplicationRecord extend Gitlab::Ci::Model - include HasVariable + include Ci::HasVariable belongs_to :pipeline_schedule diff --git a/app/models/ci/pipeline_variable.rb b/app/models/ci/pipeline_variable.rb index 51a6272e1ff..84ca4833cd7 100644 --- a/app/models/ci/pipeline_variable.rb +++ b/app/models/ci/pipeline_variable.rb @@ -3,7 +3,7 @@ module Ci class PipelineVariable < ApplicationRecord extend Gitlab::Ci::Model - include HasVariable + include Ci::HasVariable belongs_to :pipeline diff --git a/app/models/ci/variable.rb b/app/models/ci/variable.rb index 760872d3e6b..08d39595c61 100644 --- a/app/models/ci/variable.rb +++ b/app/models/ci/variable.rb @@ -3,9 +3,9 @@ module Ci class Variable < ApplicationRecord extend Gitlab::Ci::Model - include HasVariable + include Ci::HasVariable include Presentable - include Maskable + include Ci::Maskable prepend HasEnvironmentScope belongs_to :project diff --git a/app/models/concerns/ci/has_variable.rb b/app/models/concerns/ci/has_variable.rb new file mode 100644 index 00000000000..9bf2b409080 --- /dev/null +++ b/app/models/concerns/ci/has_variable.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Ci + module HasVariable + extend ActiveSupport::Concern + + included do + enum variable_type: { + env_var: 1, + file: 2 + } + + validates :key, + presence: true, + length: { maximum: 255 }, + format: { with: /\A[a-zA-Z0-9_]+\z/, + message: "can contain only letters, digits and '_'." } + + scope :order_key_asc, -> { reorder(key: :asc) } + + attr_encrypted :value, + mode: :per_attribute_iv_and_salt, + insecure_mode: true, + key: Settings.attr_encrypted_db_key_base, + algorithm: 'aes-256-cbc' + + def key=(new_key) + super(new_key.to_s.strip) + end + end + + def to_runner_variable + { key: key, value: value, public: false, file: file? } + end + end +end diff --git a/app/models/concerns/ci/maskable.rb b/app/models/concerns/ci/maskable.rb new file mode 100644 index 00000000000..15bc48bf964 --- /dev/null +++ b/app/models/concerns/ci/maskable.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module Ci + module Maskable + extend ActiveSupport::Concern + + # * Single line + # * No escape characters + # * No variables + # * No spaces + # * Minimal length of 8 characters + # * Characters must be from the Base64 alphabet (RFC4648) with the addition of @ and : + # * Absolutely no fun is allowed + REGEX = /\A[a-zA-Z0-9_+=\/@:-]{8,}\z/.freeze + + included do + validates :masked, inclusion: { in: [true, false] } + validates :value, format: { with: REGEX }, if: :masked? + end + + def to_runner_variable + super.merge(masked: masked?) + end + end +end diff --git a/app/models/concerns/ci/new_has_variable.rb b/app/models/concerns/ci/new_has_variable.rb new file mode 100644 index 00000000000..546d243e5de --- /dev/null +++ b/app/models/concerns/ci/new_has_variable.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Ci + module NewHasVariable + extend ActiveSupport::Concern + include Ci::HasVariable + + included do + attr_encrypted :value, + mode: :per_attribute_iv, + algorithm: 'aes-256-gcm', + key: Settings.attr_encrypted_db_key_base_32, + insecure_mode: false + end + end +end diff --git a/app/models/concerns/has_variable.rb b/app/models/concerns/has_variable.rb deleted file mode 100644 index b4e99569071..00000000000 --- a/app/models/concerns/has_variable.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true - -module HasVariable - extend ActiveSupport::Concern - - included do - enum variable_type: { - env_var: 1, - file: 2 - } - - validates :key, - presence: true, - length: { maximum: 255 }, - format: { with: /\A[a-zA-Z0-9_]+\z/, - message: "can contain only letters, digits and '_'." } - - scope :order_key_asc, -> { reorder(key: :asc) } - - attr_encrypted :value, - mode: :per_attribute_iv_and_salt, - insecure_mode: true, - key: Settings.attr_encrypted_db_key_base, - algorithm: 'aes-256-cbc' - - def key=(new_key) - super(new_key.to_s.strip) - end - end - - def to_runner_variable - { key: key, value: value, public: false, file: file? } - end -end diff --git a/app/models/concerns/maskable.rb b/app/models/concerns/maskable.rb deleted file mode 100644 index d70e47bc4ff..00000000000 --- a/app/models/concerns/maskable.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -module Maskable - extend ActiveSupport::Concern - - # * Single line - # * No escape characters - # * No variables - # * No spaces - # * Minimal length of 8 characters - # * Characters must be from the Base64 alphabet (RFC4648) with the addition of @ and : - # * Absolutely no fun is allowed - REGEX = /\A[a-zA-Z0-9_+=\/@:-]{8,}\z/.freeze - - included do - validates :masked, inclusion: { in: [true, false] } - validates :value, format: { with: REGEX }, if: :masked? - end - - def to_runner_variable - super.merge(masked: masked?) - end -end diff --git a/app/models/concerns/new_has_variable.rb b/app/models/concerns/new_has_variable.rb deleted file mode 100644 index 429bf496872..00000000000 --- a/app/models/concerns/new_has_variable.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -module NewHasVariable - extend ActiveSupport::Concern - include HasVariable - - included do - attr_encrypted :value, - mode: :per_attribute_iv, - algorithm: 'aes-256-gcm', - key: Settings.attr_encrypted_db_key_base_32, - insecure_mode: false - end -end diff --git a/app/models/jira_import_data.rb b/app/models/jira_import_data.rb index 3f882deb24d..63be190aa0d 100644 --- a/app/models/jira_import_data.rb +++ b/app/models/jira_import_data.rb @@ -3,17 +3,40 @@ class JiraImportData < ProjectImportData JiraProjectDetails = Struct.new(:key, :scheduled_at, :scheduled_by) + FORCE_IMPORT_KEY = 'force-import' + def projects return [] unless data - projects = data.dig('jira', 'projects').map do |p| + projects = data.dig('jira', 'projects')&.map do |p| JiraProjectDetails.new(p['key'], p['scheduled_at'], p['scheduled_by']) end - projects.sort_by { |jp| jp.scheduled_at } + + projects&.sort_by { |jp| jp.scheduled_at } || [] end def <<(project) - self.data ||= { jira: { projects: [] } } - self.data['jira']['projects'] << project.to_h.deep_stringify_keys! + self.data ||= { 'jira' => { 'projects' => [] } } + self.data['jira'] ||= { 'projects' => [] } + self.data['jira']['projects'] = [] if data['jira']['projects'].blank? || !data['jira']['projects'].is_a?(Array) + + self.data['jira']['projects'] << project.to_h + self.data.deep_stringify_keys! + end + + def force_import! + self.data ||= {} + self.data.deep_merge!({ 'jira' => { FORCE_IMPORT_KEY => true } }) + self.data.deep_stringify_keys! + end + + def force_import? + !!data&.dig('jira', FORCE_IMPORT_KEY) && !projects.blank? + end + + def finish_import! + return if data&.dig('jira', FORCE_IMPORT_KEY).nil? + + data['jira'].delete(FORCE_IMPORT_KEY) end end diff --git a/app/models/project.rb b/app/models/project.rb index 4892c5310ec..7e006e734c5 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -868,6 +868,8 @@ class Project < ApplicationRecord elsif gitlab_project_import? # Do not retry on Import/Export until https://gitlab.com/gitlab-org/gitlab-foss/issues/26189 is solved. RepositoryImportWorker.set(retry: false).perform_async(self.id) + elsif jira_import? + Gitlab::JiraImport::Stage::StartImportWorker.perform_async(self.id) else RepositoryImportWorker.perform_async(self.id) end @@ -900,7 +902,7 @@ class Project < ApplicationRecord # This method is overridden in EE::Project model def remove_import_data - import_data&.destroy + import_data&.destroy unless jira_import? end def ci_config_path=(value) @@ -947,7 +949,7 @@ class Project < ApplicationRecord end def import? - external_import? || forked? || gitlab_project_import? || bare_repository_import? + external_import? || forked? || gitlab_project_import? || jira_import? || bare_repository_import? end def external_import? @@ -962,6 +964,14 @@ class Project < ApplicationRecord import_type == 'bare_repository' end + def jira_import? + import_type == 'jira' && Feature.enabled?(:jira_issue_import, self) + end + + def jira_force_import? + jira_import? && import_data&.becomes(JiraImportData)&.force_import? + end + def gitlab_project_import? import_type == 'gitlab_project' end |