From c4c87f54ab509439a8411be82a8774eeee5c530a Mon Sep 17 00:00:00 2001 From: Thierry Joyal Date: Thu, 16 Jan 2020 10:52:41 -0500 Subject: [PATCH] Add dashboard read_only option (#135) --- lib/dogapi/facade.rb | 8 ++++---- lib/dogapi/v1/dash.rb | 10 ++++++---- spec/integration/dash_spec.rb | 4 +++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/dogapi/facade.rb b/lib/dogapi/facade.rb index bdfb8aa7..19a96387 100644 --- a/lib/dogapi/facade.rb +++ b/lib/dogapi/facade.rb @@ -320,13 +320,13 @@ def detach_tags(host_id, source=nil) # # Create a dashboard. - def create_dashboard(title, description, graphs, template_variables=nil) - @dash_service.create_dashboard(title, description, graphs, template_variables) + def create_dashboard(title, description, graphs, template_variables = nil, read_only = false) + @dash_service.create_dashboard(title, description, graphs, template_variables, read_only) end # Update a dashboard. - def update_dashboard(dash_id, title, description, graphs, template_variables=nil) - @dash_service.update_dashboard(dash_id, title, description, graphs, template_variables) + def update_dashboard(dash_id, title, description, graphs, template_variables = nil, read_only = false) + @dash_service.update_dashboard(dash_id, title, description, graphs, template_variables, read_only) end # Fetch the given dashboard. diff --git a/lib/dogapi/v1/dash.rb b/lib/dogapi/v1/dash.rb index 89cf8018..ef9a9390 100644 --- a/lib/dogapi/v1/dash.rb +++ b/lib/dogapi/v1/dash.rb @@ -11,23 +11,25 @@ class DashService < Dogapi::APIService API_VERSION = 'v1' - def create_dashboard(title, description, graphs, template_variables = nil) + def create_dashboard(title, description, graphs, template_variables = nil, read_only = false) body = { :title => title, :description => description, :graphs => graphs, - :template_variables => (template_variables or []) + :template_variables => (template_variables or []), + :read_only => read_only } request(Net::HTTP::Post, "/api/#{API_VERSION}/dash", nil, body, true) end - def update_dashboard(dash_id, title, description, graphs, template_variables=nil) + def update_dashboard(dash_id, title, description, graphs, template_variables = nil, read_only = false) body = { :title => title, :description => description, :graphs => graphs, - :template_variables => (template_variables or []) + :template_variables => (template_variables or []), + :read_only => read_only } request(Net::HTTP::Put, "/api/#{API_VERSION}/dash/#{dash_id}", nil, body, true) diff --git a/spec/integration/dash_spec.rb b/spec/integration/dash_spec.rb index 96dd7957..c2800c47 100644 --- a/spec/integration/dash_spec.rb +++ b/spec/integration/dash_spec.rb @@ -23,12 +23,14 @@ 'prefix' => 'host', 'default' => 'host:my-host' }].freeze + READ_ONLY = false DASH_BODY = { title: TITLE, description: DESCRIPTION, graphs: GRAPHS, - template_variables: TEMPLATE_VARIABLES + template_variables: TEMPLATE_VARIABLES, + read_only: READ_ONLY }.freeze DASH_ARGS = DASH_BODY.values