Skip to content

Commit f476892

Browse files
authored
Merge branch 'master' into kpaulisse-frozen-string-literal
2 parents 98cbc9d + dedfdf3 commit f476892

5 files changed

Lines changed: 126 additions & 30 deletions

File tree

doc/optionsref.md

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,52 +67,53 @@ Usage: octocatalog-diff [command line options]
6767
--puppet-binary STRING Full path to puppet binary globally
6868
--to-puppet-binary STRING Full path to puppet binary for the to branch
6969
--from-puppet-binary STRING Full path to puppet binary for the from branch
70-
--[no-]from-puppetdb Pull "from" catalog from PuppetDB instead of compiling
7170
--[no-]parallel Enable or disable parallel processing
72-
--puppetdb-ssl-ca FILENAME CA certificate that signed the PuppetDB certificate
73-
--puppetdb-ssl-client-cert FILENAME
74-
SSL client certificate to connect to PuppetDB
71+
--[no-]from-puppetdb Pull "from" catalog from PuppetDB instead of compiling
7572
--puppetdb-ssl-client-password-file FILENAME
7673
Read password for SSL client key from a file
7774
--puppetdb-ssl-client-password PASSWORD
7875
Password for SSL client key to connect to PuppetDB
79-
--facts-terminus STRING Facts terminus: one of yaml, facter
80-
--puppetdb-url URL PuppetDB base URL
8176
--puppetdb-ssl-client-key FILENAME
8277
SSL client key to connect to PuppetDB
83-
--puppet-master-ssl-client-key STRING
84-
Full path to key file for SSL client auth to Puppet Master globally
85-
--to-puppet-master-ssl-client-key STRING
86-
Full path to key file for SSL client auth to Puppet Master for the to branch
87-
--from-puppet-master-ssl-client-key STRING
88-
Full path to key file for SSL client auth to Puppet Master for the from branch
89-
--puppet-master STRING Hostname or Hostname:PortNumber for Puppet Master globally
90-
--to-puppet-master STRING Hostname or Hostname:PortNumber for Puppet Master for the to branch
91-
--from-puppet-master STRING Hostname or Hostname:PortNumber for Puppet Master for the from branch
92-
--puppet-master-api-version STRING
93-
Puppet Master API version (2 for Puppet 3.x, 3 for Puppet 4.x) globally
94-
--to-puppet-master-api-version STRING
95-
Puppet Master API version (2 for Puppet 3.x, 3 for Puppet 4.x) for the to branch
96-
--from-puppet-master-api-version STRING
97-
Puppet Master API version (2 for Puppet 3.x, 3 for Puppet 4.x) for the from branch
78+
--puppetdb-ssl-ca FILENAME CA certificate that signed the PuppetDB certificate
79+
--puppetdb-ssl-client-cert FILENAME
80+
SSL client certificate to connect to PuppetDB
81+
--facts-terminus STRING Facts terminus: one of yaml, facter
82+
--puppetdb-url URL PuppetDB base URL
83+
--puppetdb-api-version N Version of PuppetDB API (3 or 4)
9884
--puppet-master-ssl-ca STRING
9985
Full path to CA certificate that signed the Puppet Master certificate globally
10086
--to-puppet-master-ssl-ca STRING
10187
Full path to CA certificate that signed the Puppet Master certificate for the to branch
10288
--from-puppet-master-ssl-ca STRING
10389
Full path to CA certificate that signed the Puppet Master certificate for the from branch
104-
--puppet-master-ssl-client-cert STRING
105-
Full path to certificate file for SSL client auth to Puppet Master globally
106-
--to-puppet-master-ssl-client-cert STRING
107-
Full path to certificate file for SSL client auth to Puppet Master for the to branch
108-
--from-puppet-master-ssl-client-cert STRING
109-
Full path to certificate file for SSL client auth to Puppet Master for the from branch
90+
--puppet-master-ssl-client-key STRING
91+
Full path to key file for SSL client auth to Puppet Master globally
92+
--to-puppet-master-ssl-client-key STRING
93+
Full path to key file for SSL client auth to Puppet Master for the to branch
94+
--from-puppet-master-ssl-client-key STRING
95+
Full path to key file for SSL client auth to Puppet Master for the from branch
11096
--fact-override STRING1[,STRING2[,...]]
11197
Override fact globally
11298
--to-fact-override STRING1[,STRING2[,...]]
11399
Override fact for the to branch
114100
--from-fact-override STRING1[,STRING2[,...]]
115101
Override fact for the from branch
102+
--puppet-master-ssl-client-cert STRING
103+
Full path to certificate file for SSL client auth to Puppet Master globally
104+
--to-puppet-master-ssl-client-cert STRING
105+
Full path to certificate file for SSL client auth to Puppet Master for the to branch
106+
--from-puppet-master-ssl-client-cert STRING
107+
Full path to certificate file for SSL client auth to Puppet Master for the from branch
108+
--puppet-master-api-version STRING
109+
Puppet Master API version (2 for Puppet 3.x, 3 for Puppet 4.x) globally
110+
--to-puppet-master-api-version STRING
111+
Puppet Master API version (2 for Puppet 3.x, 3 for Puppet 4.x) for the to branch
112+
--from-puppet-master-api-version STRING
113+
Puppet Master API version (2 for Puppet 3.x, 3 for Puppet 4.x) for the from branch
114+
--puppet-master STRING Hostname or Hostname:PortNumber for Puppet Master globally
115+
--to-puppet-master STRING Hostname or Hostname:PortNumber for Puppet Master for the to branch
116+
--from-puppet-master STRING Hostname or Hostname:PortNumber for Puppet Master for the from branch
116117
--pe-enc-url URL Base URL for Puppet Enterprise ENC endpoint
117118
--pe-enc-token-file PATH Path containing token for PE node classifier, relative or absolute
118119
--pe-enc-token TOKEN Token to access the Puppet Enterprise ENC API
@@ -124,10 +125,10 @@ Usage: octocatalog-diff [command line options]
124125
--no-ignore-tags Disable ignoring based on tags
125126
--ignore-tags STRING1[,STRING2[,...]]
126127
Specify tags to ignore
127-
--[no-]suppress-absent-file-details
128-
Suppress certain attributes of absent files
129128
--pass-env-vars VAR1[,VAR2[,...]]
130129
Environment variables to pass
130+
--[no-]suppress-absent-file-details
131+
Suppress certain attributes of absent files
131132
132133
```
133134

@@ -828,6 +829,19 @@ https://your-pe-console-server:4433/classifier-api (<a href="../lib/octocatalog-
828829
</td>
829830
</tr>
830831

832+
<tr>
833+
<td valign=top>
834+
<pre><code>--puppetdb-api-version N</code></pre>
835+
</td>
836+
<td valign=top>
837+
Version of PuppetDB API (3 or 4)
838+
</td>
839+
<td valign=top>
840+
Specify the API version to use for the PuppetDB. The current values supported are '3' or '4', and '4' is
841+
the default. (<a href="../lib/octocatalog-diff/catalog-diff/cli/options/puppetdb_api_version.rb">puppetdb_api_version.rb</a>)
842+
</td>
843+
</tr>
844+
831845
<tr>
832846
<td valign=top>
833847
<pre><code>--puppetdb-ssl-ca FILENAME</code></pre>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Specify the API version to use for the PuppetDB. The current values supported are '3' or '4', and '4' is
2+
# the default.
3+
# @param parser [OptionParser object] The OptionParser argument
4+
# @param options [Hash] Options hash being constructed; this is modified in this method.
5+
OctocatalogDiff::CatalogDiff::Cli::Options::Option.newoption(:puppetdb_api_version) do
6+
has_weight 319
7+
8+
def parse(parser, options)
9+
parser.on('--puppetdb-api-version N', OptionParser::DecimalInteger, 'Version of PuppetDB API (3 or 4)') do |x|
10+
options[:puppetdb_api_version] = x
11+
raise ArgumentError, 'Only PuppetDB versions 3 and 4 are supported' unless [3, 4].include?(x)
12+
end
13+
end
14+
end

lib/octocatalog-diff/facts/puppetdb.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ module OctocatalogDiff
88
class Facts
99
# Deal with facts in PuppetDB
1010
class PuppetDB
11+
# Supporting multiple versions of the PuppetDB API.
12+
PUPPETDB_QUERY_FACTS_URL = {
13+
'3' => '/v3/nodes/<NODE>/facts',
14+
'4' => '/pdb/query/v4/nodes/<NODE>/facts'
15+
}.freeze
16+
1117
# Retrieve facts from PuppetDB for a specified node.
1218
# @param :puppetdb_url [String|Array] => URL to PuppetDB
1319
# @param :retry [Fixnum] => Retry after timeout (default 0 retries, can be more)
@@ -17,7 +23,8 @@ def self.fact_retriever(options = {}, node)
1723
# Set up some variables from options
1824
raise ArgumentError, 'puppetdb_url is required' unless options[:puppetdb_url].is_a?(String)
1925
raise ArgumentError, 'node must be a non-empty string' unless node.is_a?(String) && node != ''
20-
uri = "/pdb/query/v4/nodes/#{node}/facts"
26+
puppetdb_api_version = options.fetch(:puppetdb_api_version, 4)
27+
uri = PUPPETDB_QUERY_FACTS_URL.fetch(puppetdb_api_version.to_s).gsub('<NODE>', node)
2128
retries = options.fetch(:retry, 0).to_i
2229

2330
# Construct puppetdb object and options
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require_relative '../options_helper'
2+
3+
describe OctocatalogDiff::CatalogDiff::Cli::Options do
4+
describe '#opt_puppetdb_api_version' do
5+
it 'should handle --puppetdb-api-version with API version 3' do
6+
result = run_optparse(['--puppetdb-api-version', '3'])
7+
expect(result[:puppetdb_api_version]).to eq(3)
8+
end
9+
10+
it 'should handle --puppetdb-api-version with API version 4' do
11+
result = run_optparse(['--puppetdb-api-version', '4'])
12+
expect(result[:puppetdb_api_version]).to eq(4)
13+
end
14+
15+
it 'should fail if --puppetdb-api-version is unsupported' do
16+
expect { run_optparse(['--puppetdb-api-version', '9000']) }.to raise_error(ArgumentError)
17+
end
18+
end
19+
end

spec/octocatalog-diff/tests/facts/puppetdb_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,48 @@
3232
end
3333
end
3434

35+
context 'PuppetDB API compatibility layer' do
36+
before(:each) do
37+
clazz = double('OctocatalogDiff::PuppetDB')
38+
allow(clazz).to receive(:get) { |args| [{ 'certname' => 'foo.bar.com', 'name' => 'uri', 'value' => args }] }
39+
allow(OctocatalogDiff::PuppetDB).to receive(:new).and_return(clazz)
40+
end
41+
42+
it 'should use the correct URL for API v3' do
43+
opts = {
44+
puppetdb_api_version: 3,
45+
puppetdb_url: 'https://foo.bar.baz:8081'
46+
}
47+
result = OctocatalogDiff::Facts::PuppetDB.fact_retriever(opts, 'foo.bar.com')
48+
expect(result).to eq('name' => 'foo.bar.com', 'values' => { 'uri' => '/v3/nodes/foo.bar.com/facts' })
49+
end
50+
51+
it 'should use the correct URL for API v4' do
52+
opts = {
53+
puppetdb_api_version: 4,
54+
puppetdb_url: 'https://foo.bar.baz:8081'
55+
}
56+
result = OctocatalogDiff::Facts::PuppetDB.fact_retriever(opts, 'foo.bar.com')
57+
expect(result).to eq('name' => 'foo.bar.com', 'values' => { 'uri' => '/pdb/query/v4/nodes/foo.bar.com/facts' })
58+
end
59+
60+
it 'should default to API v4' do
61+
opts = {
62+
puppetdb_url: 'https://foo.bar.baz:8081'
63+
}
64+
result = OctocatalogDiff::Facts::PuppetDB.fact_retriever(opts, 'foo.bar.com')
65+
expect(result).to eq('name' => 'foo.bar.com', 'values' => { 'uri' => '/pdb/query/v4/nodes/foo.bar.com/facts' })
66+
end
67+
68+
it 'should fail if an unrecognized API version is provided' do
69+
opts = {
70+
puppetdb_api_version: 9000,
71+
puppetdb_url: 'https://foo.bar.baz:8081'
72+
}
73+
expect { OctocatalogDiff::Facts::PuppetDB.fact_retriever(opts, 'foo.bar.com') }.to raise_error(KeyError)
74+
end
75+
end
76+
3577
context 'mocking methods for error testing' do
3678
describe '#fact_retriever' do
3779
let(:opts) { { puppetdb_url: 'https://mocked-puppetdb.somedomain.xyz:8081', node: 'valid-facts' } }

0 commit comments

Comments
 (0)