debian-mirror-gitlab/app/models/integrations/field.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1 KiB
Ruby
Raw Normal View History

2022-05-07 20:08:51 +05:30
# frozen_string_literal: true
module Integrations
class Field
2022-06-21 17:19:12 +05:30
SECRET_NAME = %r/token|key|password|passphrase|secret/.freeze
2022-05-07 20:08:51 +05:30
ATTRIBUTES = %i[
section type placeholder required choices value checkbox_label
title help
non_empty_password_help
non_empty_password_title
api_only
2022-07-16 23:28:13 +05:30
exposes_secrets
2022-05-07 20:08:51 +05:30
].freeze
2022-07-23 23:45:48 +05:30
attr_reader :name, :integration_class
2022-05-07 20:08:51 +05:30
2022-07-23 23:45:48 +05:30
def initialize(name:, integration_class:, type: 'text', api_only: false, **attributes)
2022-05-07 20:08:51 +05:30
@name = name.to_s.freeze
2022-07-23 23:45:48 +05:30
@integration_class = integration_class
2022-05-07 20:08:51 +05:30
2022-06-21 17:19:12 +05:30
attributes[:type] = SECRET_NAME.match?(@name) ? 'password' : type
2022-05-07 20:08:51 +05:30
attributes[:api_only] = api_only
@attributes = attributes.freeze
end
def [](key)
return name if key == :name
value = @attributes[key]
2022-07-23 23:45:48 +05:30
return integration_class.class_exec(&value) if value.respond_to?(:call)
2022-05-07 20:08:51 +05:30
value
end
2022-06-21 17:19:12 +05:30
def secret?
2022-05-07 20:08:51 +05:30
@attributes[:type] == 'password'
end
ATTRIBUTES.each do |name|
define_method(name) { self[name] }
end
end
end