| ... | @@ -8,11 +8,13 @@ class GrafanaIntegration < ApplicationRecord |
... | @@ -8,11 +8,13 @@ class GrafanaIntegration < ApplicationRecord |
|
|
algorithm: 'aes-256-gcm',
|
|
algorithm: 'aes-256-gcm',
|
|
|
key: Settings.attr_encrypted_db_key_base_32
|
|
key: Settings.attr_encrypted_db_key_base_32
|
|
|
|
|
|
|
|
|
before_validation :check_token_changes
|
|
|
|
|
|
|
validates :grafana_url,
|
|
validates :grafana_url,
|
|
|
length: { maximum: 1024 },
|
|
length: { maximum: 1024 },
|
|
|
addressable_url: { enforce_sanitization: true, ascii_only: true }
|
|
addressable_url: { enforce_sanitization: true, ascii_only: true }
|
|
|
|
|
|
|
|
validates :token, :project, presence: true
|
|
validates :encrypted_token, :project, presence: true
|
|
|
|
|
|
|
|
validates :enabled, inclusion: { in: [true, false] }
|
|
validates :enabled, inclusion: { in: [true, false] }
|
|
|
|
|
|
| ... | @@ -23,4 +25,28 @@ class GrafanaIntegration < ApplicationRecord |
... | @@ -23,4 +25,28 @@ class GrafanaIntegration < ApplicationRecord |
|
|
|
|
|
|
|
@client ||= ::Grafana::Client.new(api_url: grafana_url.chomp('/'), token: token)
|
|
@client ||= ::Grafana::Client.new(api_url: grafana_url.chomp('/'), token: token)
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
def masked_token
|
|
|
|
mask(encrypted_token)
|
|
|
|
end
|
|
|
|
|
|
|
|
def masked_token_was
|
|
|
|
mask(encrypted_token_was)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def token
|
|
|
|
decrypt(:token, encrypted_token)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_token_changes
|
|
|
|
return unless [encrypted_token_was, masked_token_was].include?(token)
|
|
|
|
|
|
|
|
clear_attribute_changes [:token, :encrypted_token, :encrypted_token_iv]
|
|
|
|
end
|
|
|
|
|
|
|
|
def mask(token)
|
|
|
|
token&.squish&.gsub(/./, '*')
|
|
|
|
end
|
|
|
end |
|
end |