2022-03-09 13:08:16 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Integrations
|
|
|
|
class Field
|
2022-04-04 14:08:38 -04:00
|
|
|
SECRET_NAME = %r/token|key|password|passphrase|secret/.freeze
|
2022-03-09 13:08:16 -05:00
|
|
|
|
|
|
|
ATTRIBUTES = %i[
|
|
|
|
section type placeholder required choices value checkbox_label
|
|
|
|
title help
|
|
|
|
non_empty_password_help
|
|
|
|
non_empty_password_title
|
|
|
|
api_only
|
2022-04-22 08:08:38 -04:00
|
|
|
exposes_secrets
|
2022-03-09 13:08:16 -05:00
|
|
|
].freeze
|
|
|
|
|
|
|
|
attr_reader :name
|
|
|
|
|
|
|
|
def initialize(name:, type: 'text', api_only: false, **attributes)
|
|
|
|
@name = name.to_s.freeze
|
|
|
|
|
2022-04-04 14:08:38 -04:00
|
|
|
attributes[:type] = SECRET_NAME.match?(@name) ? 'password' : type
|
2022-03-09 13:08:16 -05:00
|
|
|
attributes[:api_only] = api_only
|
|
|
|
@attributes = attributes.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def [](key)
|
|
|
|
return name if key == :name
|
|
|
|
|
|
|
|
value = @attributes[key]
|
|
|
|
return value.call if value.respond_to?(:call)
|
|
|
|
|
|
|
|
value
|
|
|
|
end
|
|
|
|
|
2022-04-04 14:08:38 -04:00
|
|
|
def secret?
|
2022-03-09 13:08:16 -05:00
|
|
|
@attributes[:type] == 'password'
|
|
|
|
end
|
|
|
|
|
|
|
|
ATTRIBUTES.each do |name|
|
|
|
|
define_method(name) { self[name] }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|