Commit 02df78db authored by Fabio Pitino's avatar Fabio Pitino Committed by Grzegorz Bizon

Move HasVariable concern to CI namespace

HasVariable concern is only used by CI variable classes
parent 521663ea
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Ci module Ci
class GroupVariable < ApplicationRecord class GroupVariable < ApplicationRecord
extend Gitlab::Ci::Model extend Gitlab::Ci::Model
include HasVariable include Ci::HasVariable
include Presentable include Presentable
include Maskable include Maskable
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Ci module Ci
class JobVariable < ApplicationRecord class JobVariable < ApplicationRecord
extend Gitlab::Ci::Model extend Gitlab::Ci::Model
include NewHasVariable include Ci::NewHasVariable
include BulkInsertSafe include BulkInsertSafe
belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Ci module Ci
class PipelineScheduleVariable < ApplicationRecord class PipelineScheduleVariable < ApplicationRecord
extend Gitlab::Ci::Model extend Gitlab::Ci::Model
include HasVariable include Ci::HasVariable
belongs_to :pipeline_schedule belongs_to :pipeline_schedule
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Ci module Ci
class PipelineVariable < ApplicationRecord class PipelineVariable < ApplicationRecord
extend Gitlab::Ci::Model extend Gitlab::Ci::Model
include HasVariable include Ci::HasVariable
belongs_to :pipeline belongs_to :pipeline
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Ci module Ci
class Variable < ApplicationRecord class Variable < ApplicationRecord
extend Gitlab::Ci::Model extend Gitlab::Ci::Model
include HasVariable include Ci::HasVariable
include Presentable include Presentable
include Maskable include Maskable
prepend HasEnvironmentScope 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 ...@@ -37,7 +37,7 @@ module Gitlab
case resource case resource
when Hash when Hash
self.new(resource.symbolize_keys) self.new(resource.symbolize_keys)
when ::HasVariable when ::Ci::HasVariable
self.new(resource.to_runner_variable) self.new(resource.to_runner_variable)
when self when self
resource.dup resource.dup
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe HasVariable do describe Ci::HasVariable do
subject { build(:ci_variable) } subject { build(:ci_variable) }
it { is_expected.to validate_presence_of(:key) } it { is_expected.to validate_presence_of(:key) }
......
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_examples 'CI variable' do 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 describe "variable type" do
it 'defines variable types' 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