Skip to content

Commit

Permalink
Change organization in datasource_by_name
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Lukowski committed Jul 11, 2024
1 parent 35644b2 commit 7f89da9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/puppet/provider/grafana_datasource/grafana.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def fetch_organization
end

def datasource_by_name
change_organization
response = send_request('GET', format('%s/datasources/name/%s', resource[:grafana_api_path], ERB::Util.url_encode(resource[:name])))
return nil if response.code == '404'

Expand Down Expand Up @@ -149,12 +150,15 @@ def secure_json_data
{}
end

def change_organization
response = send_request 'POST', format('%s/user/using/%s', resource[:grafana_api_path], fetch_organization[:id])
raise format('Failed to switch to org %s (HTTP response: %s/%s)', fetch_organization[:id], response.code, response.body) unless response.code == '200'
end

def flush
return if resource['ensure'] == :absent

# change organizations
response = send_request 'POST', format('%s/user/using/%s', resource[:grafana_api_path], fetch_organization[:id])
raise format('Failed to switch to org %s (HTTP response: %s/%s)', fetch_organization[:id], response.code, response.body) unless response.code == '200'
change_organization

# Build the `data` to POST/PUT by first creating a hash with some defaults which will be used if we're _creating_ a datasource
data = {
Expand Down

0 comments on commit 7f89da9

Please sign in to comment.