Commit 61d48edf authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'move-has-variable-concern-to-ci-namespace' into 'master'

Move HasVariable and NewHasVariable concerns to CI namespace

See merge request gitlab-org/gitlab!27306
parents 482586a4 02df78db
......@@ -3,7 +3,7 @@
module Ci
class GroupVariable < ApplicationRecord
extend Gitlab::Ci::Model
include HasVariable
include Ci::HasVariable
include Presentable
include Maskable
......
......@@ -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
......
......@@ -3,7 +3,7 @@
module Ci
class PipelineScheduleVariable < ApplicationRecord
extend Gitlab::Ci::Model
include HasVariable
include Ci::HasVariable
belongs_to :pipeline_schedule
......
......@@ -3,7 +3,7 @@
module Ci
class PipelineVariable < ApplicationRecord
extend Gitlab::Ci::Model
include HasVariable
include Ci::HasVariable
belongs_to :pipeline
......
......@@ -3,7 +3,7 @@
module Ci
class Variable < ApplicationRecord
extend Gitlab::Ci::Model
include HasVariable
include Ci::HasVariable
include Presentable
include Maskable
prepend HasEnvironmentScope
......
# 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
# 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
# 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
# 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
......@@ -37,7 +37,7 @@ module Gitlab
case resource
when Hash
self.new(resource.symbolize_keys)
when ::HasVariable
when ::Ci::HasVariable
self.new(resource.to_runner_variable)
when self
resource.dup
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe HasVariable do
describe Ci::HasVariable do
subject { build(:ci_variable) }
it { is_expected.to validate_presence_of(:key) }
......
# frozen_string_literal: true
RSpec.shared_examples 'CI variable' do
it { is_expected.to include_module(HasVariable) }
it { is_expected.to include_module(Ci::HasVariable) }
describe "variable type" do
it 'defines variable types' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment