Skip to content

Commit

Permalink
Fix voxpupuli#104 - User password set on each puppet run
Browse files Browse the repository at this point in the history
  • Loading branch information
TuningYourCode authored and alexjfisher committed Apr 21, 2020
1 parent fa9fc7b commit f3e62cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/puppet/provider/grafana_user/grafana.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def theme=(value)
end

def password
user[:password]
nil
end

def password=(value)
Expand Down Expand Up @@ -126,6 +126,24 @@ def save_user
self.user = nil
end

def check_password
uri = URI.parse format('%s://%s:%d%s/dashboards/home', grafana_scheme, grafana_host, grafana_port, resource[:grafana_api_path])
request = Net::HTTP::Get.new(uri.to_s)
request.content_type = 'application/json'
request.basic_auth resource[:name], resource[:password]
response = Net::HTTP.start(grafana_host, grafana_port,
use_ssl: grafana_scheme == 'https',
verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
http.request(request)
end

if response.code == '200'
true
else
false
end
end

def delete_user
response = send_request('DELETE', format('%s/admin/users/%s', resource[:grafana_api_path], user[:id]))

Expand Down
3 changes: 3 additions & 0 deletions lib/puppet/type/grafana_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@

newproperty(:password) do
desc 'The password for the user'
def insync?(_is)
provider.check_password
end
end

newproperty(:email) do
Expand Down

0 comments on commit f3e62cb

Please sign in to comment.