]> git.openstreetmap.org Git - chef.git/blob - cookbooks/wordpress/libraries/wordpress.rb
Use OS root certificiate bundle to avoid wordpress API via chef ruby
[chef.git] / cookbooks / wordpress / libraries / wordpress.rb
1 require "chef/mixin/shell_out"
2
3 require "addressable"
4 require "httpclient"
5 require "json"
6
7 class Chef
8   module Wordpress
9     extend Chef::Mixin::ShellOut
10
11     @api_responses = {}
12
13     class << self
14       def current_version
15         core_version_check["offers"].first["current"]
16       end
17
18       def current_plugin_version(name)
19         plugin_information(name)["version"]
20       end
21
22       private
23
24       def core_version_check
25         api_get("https://api.wordpress.org/core/version-check/1.7")
26       end
27
28       def plugin_information(name)
29         api_get("https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&request[slug]=#{name}")
30       end
31
32       def api_get(url)
33         http_client = ::HTTPClient.new
34         http_client.ssl_config.set_trust_ca("/etc/ssl/certs/ca-certificates.crt")
35         @api_responses[url] ||= ::JSON.parse(http_client.get_content(url))
36       end
37     end
38   end
39 end