debian-mirror-gitlab/app/services/metrics/dashboard/transient_embed_service.rb

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

47 lines
1.2 KiB
Ruby
Raw Normal View History

2020-04-22 19:07:51 +05:30
# frozen_string_literal: true
# Acts as a pass-through to allow embeddable dashboards to be
# generated based on external data, but still processed with the
# required attributes that allow the FE to render them appropriately.
#
# Use Gitlab::Metrics::Dashboard::Finder to retrive dashboards.
module Metrics
module Dashboard
class TransientEmbedService < ::Metrics::Dashboard::BaseEmbedService
extend ::Gitlab::Utils::Override
class << self
def valid_params?(params)
[
embedded?(params[:embedded]),
params[:embed_json]
].all?
end
end
private
override :get_raw_dashboard
def get_raw_dashboard
2020-05-24 23:13:21 +05:30
Gitlab::Json.parse(params[:embed_json])
rescue JSON::ParserError => e
invalid_embed_json!(e.message)
2020-04-22 19:07:51 +05:30
end
override :sequence
def sequence
2020-07-28 23:09:34 +05:30
[STAGES::MetricEndpointInserter]
2020-04-22 19:07:51 +05:30
end
override :identifiers
def identifiers
Digest::SHA256.hexdigest(params[:embed_json])
end
2020-05-24 23:13:21 +05:30
def invalid_embed_json!(message)
2021-06-08 01:23:25 +05:30
raise DashboardProcessingError, _("Parsing error for param :embed_json. %{message}") % { message: message }
2020-05-24 23:13:21 +05:30
end
2020-04-22 19:07:51 +05:30
end
end
end