Skip to content

Commit

Permalink
Add dashboard read_only option (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjoyal authored and gzussa committed Jan 16, 2020
1 parent bf4cfc4 commit c4c87f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions lib/dogapi/facade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions lib/dogapi/v1/dash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion spec/integration/dash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c4c87f5

Please sign in to comment.