2019-10-03 17:07:29 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class GrafanaIntegration < ApplicationRecord
|
|
|
|
belongs_to :project
|
|
|
|
|
|
|
|
attr_encrypted :token,
|
|
|
|
mode: :per_attribute_iv,
|
|
|
|
algorithm: 'aes-256-gcm',
|
|
|
|
key: Settings.attr_encrypted_db_key_base_32
|
|
|
|
|
|
|
|
validates :grafana_url,
|
|
|
|
length: { maximum: 1024 },
|
|
|
|
addressable_url: { enforce_sanitization: true, ascii_only: true }
|
|
|
|
|
|
|
|
validates :token, :project, presence: true
|
2019-10-10 08:06:19 -04:00
|
|
|
|
2019-11-01 14:06:00 -04:00
|
|
|
validates :enabled, inclusion: { in: [true, false] }
|
|
|
|
|
2019-10-10 08:06:19 -04:00
|
|
|
def client
|
2019-11-01 14:06:00 -04:00
|
|
|
return unless enabled?
|
|
|
|
|
2019-10-10 08:06:19 -04:00
|
|
|
@client ||= ::Grafana::Client.new(api_url: grafana_url.chomp('/'), token: token)
|
|
|
|
end
|
2019-10-03 17:07:29 -04:00
|
|
|
end
|