puppetdb_foreman 1.0.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3ea822b096259679b0aac25ca37ca562f552abe
4
- data.tar.gz: 64db6e9af941c5085eb51c24873f37b5bafc710a
3
+ metadata.gz: 4442df53231ba6c0098bfa2bc9773fada6549e61
4
+ data.tar.gz: 5fec4a311d6e1878d8c6a56bc33b9b84166bae15
5
5
  SHA512:
6
- metadata.gz: 2ca16956c6343ceec6d612811fca6edbd88f3d62bdbbcaf9ef7c7bc483b24f0dd0f6e89a5deb22edbf4b76276683c95e705f53ced530aadcd230cadfa674c4d9
7
- data.tar.gz: 7e6358c5f26ea6622d23ac698ee36246fdb2c5eb963ea3d8a8200acd2000b41afb84c863c2b476a46bb0ba35df95ca7749d80576170a3e18bbe1dbf0533ba2cf
6
+ metadata.gz: beb7c7e7ae56a366877ef6db40c4ca3863aabc1c429d8b38a7b312cd0690fbe01d19f85457b56bd23cb73501b8126658f66cff521ea3b2d1cbf0ed5da1905b32
7
+ data.tar.gz: 61744f43af61f238a8c6eb039c6816e82d11d7a998ccf81af79016ab4ed6a621cb40f640f9cabdf3f9e7ff73ba74ff12b99445bd521440cddfd06a30114910f0
@@ -14,22 +14,47 @@ module PuppetdbForeman
14
14
  uri = URI.parse(Setting[:puppetdb_address])
15
15
  req = Net::HTTP::Post.new(uri.path)
16
16
  req['Accept'] = 'application/json'
17
- req.body = 'payload={"command":"deactivate node","version":1,"payload":"\"'+name+'\""}'
17
+ req.content_type = 'application/json'
18
+
18
19
  res = Net::HTTP.new(uri.host, uri.port)
19
20
  res.use_ssl = uri.scheme == 'https'
20
21
  if res.use_ssl?
21
- if Setting[:ssl_ca_file]
22
- res.ca_file = Setting[:ssl_ca_file]
22
+ if Setting[:puppetdb_ssl_ca_file]
23
+ res.ca_file = Setting[:puppetdb_ssl_ca_file]
23
24
  res.verify_mode = OpenSSL::SSL::VERIFY_PEER
24
25
  else
25
26
  res.verify_mode = OpenSSL::SSL::VERIFY_NONE
26
27
  end
27
- if Setting[:ssl_certificate] && Setting[:ssl_priv_key]
28
- res.cert = OpenSSL::X509::Certificate.new(File.read(Setting[:ssl_certificate]))
29
- res.key = OpenSSL::PKey::RSA.new(File.read(Setting[:ssl_priv_key]), nil)
28
+ if Setting[:puppetdb_ssl_certificate] &&
29
+ Setting[:puppetdb_ssl_private_key]
30
+ res.cert = OpenSSL::X509::Certificate.new(
31
+ File.read(Setting[:puppetdb_ssl_certificate]))
32
+ res.key = OpenSSL::PKey::RSA.new(
33
+ File.read(Setting[:puppetdb_ssl_private_key]), nil)
30
34
  end
35
+
36
+ end
37
+
38
+ if uri.path.start_with?("/pdb")
39
+ logger.debug "Using PuppetDB API v3"
40
+ req.body = {
41
+ "command" => "deactivate node",
42
+ "version" => 3,
43
+ "payload" => {
44
+ "certname" => name,
45
+ "producer_timestamp" => "#{Time.now.iso8601}"
46
+ }
47
+ }.to_json
48
+ else
49
+ logger.debug "Using PuppetDB API v1"
50
+ req.body = {
51
+ "command" => "deactivate node",
52
+ "version" => 1,
53
+ "payload" => name
54
+ }.to_json
31
55
  end
32
56
  res.start { |http| http.request(req) }
57
+
33
58
  rescue => e
34
59
  errors.add(:base, _("Could not deactivate host on PuppetDB: #{e}"))
35
60
  end
@@ -6,11 +6,17 @@ class Setting::Puppetdb < ::Setting
6
6
  default_enabled = SETTINGS[:puppetdb][:enabled]
7
7
  default_address = SETTINGS[:puppetdb][:address]
8
8
  default_dashboard_address = SETTINGS[:puppetdb][:dashboard_address]
9
+ default_ssl_ca_file= SETTINGS[:puppetdb][:ssl_ca_file]
10
+ default_ssl_certificate = SETTINGS[:puppetdb][:ssl_certificate]
11
+ default_ssl_private_key = SETTINGS[:puppetdb][:ssl_private_key]
9
12
  end
10
13
 
11
14
  default_enabled = false if default_enabled.nil?
12
- default_address ||= 'https://puppetdb:8081/v2/commands'
13
- default_dashboard_address ||= 'http://puppetdb:8080/dashboard'
15
+ default_address ||= 'https://puppetdb:8081/pdb/cmd/v1'
16
+ default_dashboard_address ||= 'http://puppetdb:8080/pdb/dashboard'
17
+ default_ssl_ca_file ||= "#{SETTINGS[:ssl_ca_file]}"
18
+ default_ssl_certificate ||= "#{SETTINGS[:ssl_certificate]}"
19
+ default_ssl_private_key ||= "#{SETTINGS[:ssl_priv_key]}"
14
20
 
15
21
  Setting.transaction do
16
22
  [
@@ -29,5 +35,23 @@ class Setting::Puppetdb < ::Setting
29
35
  self.set('puppetdb_dashboard_address', _('Foreman will proxy PuppetDB Performance Dashboard requests to this address'), default_dashboard_address)
30
36
  ].compact.each { |s| self.create s.update(:category => 'Setting::Puppetdb')}
31
37
  end
38
+
39
+ Setting.transaction do
40
+ [
41
+ self.set('puppetdb_ssl_ca_file', _('Foreman will send PuppetDB requests with this CA file'), default_ssl_ca_file)
42
+ ].compact.each { |s| self.create s.update(:category => 'Setting::Puppetdb')}
43
+ end
44
+
45
+ Setting.transaction do
46
+ [
47
+ self.set('puppetdb_ssl_certificate', _('Foreman will send PuppetDB requests with this certificate file'), default_ssl_certificate)
48
+ ].compact.each { |s| self.create s.update(:category => 'Setting::Puppetdb')}
49
+ end
50
+
51
+ Setting.transaction do
52
+ [
53
+ self.set('puppetdb_ssl_private_key', _('Foreman will send PuppetDB requests with this key file'), default_ssl_private_key)
54
+ ].compact.each { |s| self.create s.update(:category => 'Setting::Puppetdb')}
55
+ end
32
56
  end
33
57
  end
@@ -1,3 +1,3 @@
1
1
  module PuppetdbForeman
2
- VERSION = '1.0.4'
2
+ VERSION = '2.0.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppetdb_foreman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Lobato Garcia
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  version: '0'
48
48
  requirements: []
49
49
  rubyforge_project:
50
- rubygems_version: 2.5.0
50
+ rubygems_version: 2.4.5.1
51
51
  signing_key:
52
52
  specification_version: 4
53
53
  summary: This is a Foreman plugin to interact with PuppetDB.