2020-04-07 20:09:30 -04:00
|
|
|
# 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-04-30 14:09:38 -04:00
|
|
|
Gitlab::Json.parse(params[:embed_json])
|
2020-04-24 11:09:37 -04:00
|
|
|
rescue JSON::ParserError => e
|
|
|
|
invalid_embed_json!(e.message)
|
2020-04-07 20:09:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
override :sequence
|
|
|
|
def sequence
|
2020-06-18 11:08:45 -04:00
|
|
|
[STAGES::MetricEndpointInserter]
|
2020-04-07 20:09:30 -04:00
|
|
|
end
|
2020-04-21 11:21:10 -04:00
|
|
|
|
|
|
|
override :identifiers
|
|
|
|
def identifiers
|
|
|
|
Digest::SHA256.hexdigest(params[:embed_json])
|
|
|
|
end
|
2020-04-24 11:09:37 -04:00
|
|
|
|
|
|
|
def invalid_embed_json!(message)
|
2021-05-04 11:10:36 -04:00
|
|
|
raise DashboardProcessingError, _("Parsing error for param :embed_json. %{message}") % { message: message }
|
2020-04-24 11:09:37 -04:00
|
|
|
end
|
2020-04-07 20:09:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|