debian-mirror-gitlab/lib/gitlab/metrics/dashboard/validator.rb

29 lines
1 KiB
Ruby
Raw Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
module Gitlab
module Metrics
module Dashboard
module Validator
2020-11-24 15:15:51 +05:30
DASHBOARD_SCHEMA_PATH = Rails.root.join(*%w[lib gitlab metrics dashboard validator schemas dashboard.json]).freeze
2020-10-24 23:57:45 +05:30
class << self
def validate(content, schema_path = DASHBOARD_SCHEMA_PATH, dashboard_path: nil, project: nil)
2020-11-24 15:15:51 +05:30
errors(content, schema_path, dashboard_path: dashboard_path, project: project).empty?
2020-10-24 23:57:45 +05:30
end
def validate!(content, schema_path = DASHBOARD_SCHEMA_PATH, dashboard_path: nil, project: nil)
2020-11-24 15:15:51 +05:30
errors = errors(content, schema_path, dashboard_path: dashboard_path, project: project)
2020-10-24 23:57:45 +05:30
errors.empty? || raise(errors.first)
end
2020-11-24 15:15:51 +05:30
def errors(content, schema_path = DASHBOARD_SCHEMA_PATH, dashboard_path: nil, project: nil)
Validator::Client
.new(content, schema_path, dashboard_path: dashboard_path, project: project)
.execute
2020-10-24 23:57:45 +05:30
end
end
end
end
end
end