Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/integrations/field.rb')
-rw-r--r--app/models/integrations/field.rb27
1 files changed, 22 insertions, 5 deletions
diff --git a/app/models/integrations/field.rb b/app/models/integrations/field.rb
index cbda418755b..53c8f5f623e 100644
--- a/app/models/integrations/field.rb
+++ b/app/models/integrations/field.rb
@@ -4,14 +4,16 @@ module Integrations
class Field
SECRET_NAME = %r/token|key|password|passphrase|secret/.freeze
+ BOOLEAN_ATTRIBUTES = %i[required api_only exposes_secrets].freeze
+
ATTRIBUTES = %i[
- section type placeholder required choices value checkbox_label
+ section type placeholder choices value checkbox_label
title help
non_empty_password_help
non_empty_password_title
- api_only
- exposes_secrets
- ].freeze
+ ].concat(BOOLEAN_ATTRIBUTES).freeze
+
+ TYPES = %w[text textarea password checkbox select].freeze
attr_reader :name, :integration_class
@@ -22,6 +24,13 @@ module Integrations
attributes[:type] = SECRET_NAME.match?(@name) ? 'password' : type
attributes[:api_only] = api_only
@attributes = attributes.freeze
+
+ invalid_attributes = attributes.keys - ATTRIBUTES
+ if invalid_attributes.present?
+ raise ArgumentError, "Invalid attributes #{invalid_attributes.inspect}"
+ elsif !TYPES.include?(self[:type])
+ raise ArgumentError, "Invalid type #{self[:type].inspect}"
+ end
end
def [](key)
@@ -34,11 +43,19 @@ module Integrations
end
def secret?
- @attributes[:type] == 'password'
+ self[:type] == 'password'
end
ATTRIBUTES.each do |name|
define_method(name) { self[name] }
end
+
+ BOOLEAN_ATTRIBUTES.each do |name|
+ define_method("#{name}?") { !!self[name] }
+ end
+
+ TYPES.each do |type|
+ define_method("#{type}?") { self[:type] == type }
+ end
end
end