Commit 0f036967 authored by Fabio Pitino's avatar Fabio Pitino

Move Maskable concern to Ci namespace

The concern is only used by CI variables
parent 93fa7a0e
...@@ -45,6 +45,6 @@ module CiVariablesHelper ...@@ -45,6 +45,6 @@ module CiVariablesHelper
end end
def ci_variable_maskable_regex def ci_variable_maskable_regex
Maskable::REGEX.inspect.sub('\\A', '^').sub('\\z', '$').sub(/^\//, '').sub(/\/[a-z]*$/, '').gsub('\/', '/') Ci::Maskable::REGEX.inspect.sub('\\A', '^').sub('\\z', '$').sub(/^\//, '').sub(/\/[a-z]*$/, '').gsub('\/', '/')
end end
end end
...@@ -5,7 +5,7 @@ module Ci ...@@ -5,7 +5,7 @@ module Ci
extend Gitlab::Ci::Model extend Gitlab::Ci::Model
include HasVariable include HasVariable
include Presentable include Presentable
include Maskable include Ci::Maskable
belongs_to :group, class_name: "::Group" belongs_to :group, class_name: "::Group"
......
...@@ -5,7 +5,7 @@ module Ci ...@@ -5,7 +5,7 @@ module Ci
extend Gitlab::Ci::Model extend Gitlab::Ci::Model
include HasVariable include HasVariable
include Presentable include Presentable
include Maskable include Ci::Maskable
prepend HasEnvironmentScope prepend HasEnvironmentScope
belongs_to :project belongs_to :project
......
# 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
# 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
...@@ -8,7 +8,7 @@ describe Ci::GroupVariable do ...@@ -8,7 +8,7 @@ describe Ci::GroupVariable do
it_behaves_like "CI variable" it_behaves_like "CI variable"
it { is_expected.to include_module(Presentable) } it { is_expected.to include_module(Presentable) }
it { is_expected.to include_module(Maskable) } it { is_expected.to include_module(Ci::Maskable) }
it { is_expected.to validate_uniqueness_of(:key).scoped_to(:group_id).with_message(/\(\w+\) has already been taken/) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:group_id).with_message(/\(\w+\) has already been taken/) }
describe '.unprotected' do describe '.unprotected' do
......
...@@ -9,7 +9,7 @@ describe Ci::Variable do ...@@ -9,7 +9,7 @@ describe Ci::Variable do
describe 'validations' do describe 'validations' do
it { is_expected.to include_module(Presentable) } it { is_expected.to include_module(Presentable) }
it { is_expected.to include_module(Maskable) } it { is_expected.to include_module(Ci::Maskable) }
it { is_expected.to include_module(HasEnvironmentScope) } it { is_expected.to include_module(HasEnvironmentScope) }
it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id, :environment_scope).with_message(/\(\w+\) has already been taken/) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:project_id, :environment_scope).with_message(/\(\w+\) has already been taken/) }
end end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
describe Maskable do describe Ci::Maskable do
let(:variable) { build(:ci_variable) } let(:variable) { build(:ci_variable) }
describe 'masked value validations' do describe 'masked value validations' do
...@@ -34,7 +34,7 @@ describe Maskable do ...@@ -34,7 +34,7 @@ describe Maskable do
end end
describe 'REGEX' do describe 'REGEX' do
subject { Maskable::REGEX } subject { Ci::Maskable::REGEX }
it 'does not match strings shorter than 8 letters' do it 'does not match strings shorter than 8 letters' do
expect(subject.match?('hello')).to eq(false) expect(subject.match?('hello')).to eq(false)
......
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