2016-09-29 09:46:39 +05:30
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module Node
|
|
|
|
##
|
|
|
|
# Entry that represents an environment.
|
|
|
|
#
|
|
|
|
class Environment < Entry
|
|
|
|
include Validatable
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
ALLOWED_KEYS = %i[name url action on_stop]
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
validations do
|
|
|
|
validate do
|
|
|
|
unless hash? || string?
|
|
|
|
errors.add(:config, 'should be a hash or a string')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
validates :name, presence: true
|
|
|
|
validates :name,
|
|
|
|
type: {
|
|
|
|
with: String,
|
|
|
|
message: Gitlab::Regex.environment_name_regex_message }
|
|
|
|
|
|
|
|
validates :name,
|
|
|
|
format: {
|
|
|
|
with: Gitlab::Regex.environment_name_regex,
|
|
|
|
message: Gitlab::Regex.environment_name_regex_message }
|
|
|
|
|
|
|
|
with_options if: :hash? do
|
|
|
|
validates :config, allowed_keys: ALLOWED_KEYS
|
|
|
|
|
|
|
|
validates :url,
|
|
|
|
length: { maximum: 255 },
|
|
|
|
addressable_url: true,
|
|
|
|
allow_nil: true
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
validates :action,
|
|
|
|
inclusion: { in: %w[start stop], message: 'should be start or stop' },
|
|
|
|
allow_nil: true
|
|
|
|
|
|
|
|
validates :on_stop, type: String, allow_nil: true
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def hash?
|
|
|
|
@config.is_a?(Hash)
|
|
|
|
end
|
|
|
|
|
|
|
|
def string?
|
|
|
|
@config.is_a?(String)
|
|
|
|
end
|
|
|
|
|
|
|
|
def name
|
|
|
|
value[:name]
|
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
|
|
|
value[:url]
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
def action
|
|
|
|
value[:action] || 'start'
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_stop
|
|
|
|
value[:on_stop]
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
def value
|
|
|
|
case @config
|
2016-11-03 12:29:30 +05:30
|
|
|
when String then { name: @config, action: 'start' }
|
2016-09-29 09:46:39 +05:30
|
|
|
when Hash then @config
|
|
|
|
else {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|