Skip to content

Commit 98cbc9d

Browse files
authored
Merge branch 'master' into kpaulisse-frozen-string-literal
2 parents 6c13abe + 4aceadc commit 98cbc9d

11 files changed

Lines changed: 137 additions & 10 deletions

File tree

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.6
1+
0.5.7

doc/advanced-bootstrap.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,28 @@ The [example configuration file](/examples/octocatalog-diff.cfg.rb) contains an
3131
# settings[:bootstrap_script] = '/etc/puppetlabs/repo-bootstrap.sh' # Absolute path
3232
# settings[:bootstrap_script] = 'script/bootstrap' # Relative path
3333
```
34+
35+
## Bootstrap environment
36+
37+
When the bootstrap script runs, a limited set of environment variables are passed from the shell running octocatalog-diff. Only these variables are set:
38+
39+
- `HOME`
40+
- `PATH`
41+
- `PWD` (set to the base directory of your Puppet checkout)
42+
- `BASEDIR` (as explicitly set with `--basedir` CLI option or `settings[:basedir]` setting)
43+
44+
If you wish to set additional environment variables for your bootstrap script, you may do so via the `--bootstrap-environment VAR=value` command line flag, or by defining `settings[:bootstrap_environment] = { 'VAR' => 'value' }` in your configuration file.
45+
46+
As an example, consider that your bootstrap script is written in Python, and needs the `PYTHONPATH` variable set to `/usr/local/lib/python-custom`. Even if this environment variable is set when octocatalog-diff is run, it will not be available to the bootstrap script. You may supply it via the command line:
47+
48+
```
49+
octocatalog-diff --bootstrap-environment PYTHONPATH=/usr/local/lib/python-custom ...
50+
```
51+
52+
Or you may specify it in your configuration file:
53+
54+
```
55+
settings[:bootstrap_environment] = {
56+
'PYTHONPATH' => '/usr/local/lib/python-custom'
57+
}
58+
```

doc/configuration-enc.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,37 @@ For example, when compiling the catalog for `some-node.github.net`, Puppet will
6767
```
6868
6969
Sometimes the ENC script requires credentials or makes other assumptions about the system on which it is running. To be able to run the ENC script on systems other than your Puppet master, you will need to ensure that any such credentials are supplied and other assumptions are met.
70+
71+
## Environment
72+
73+
When the ENC is executed, the following environment variables are set to match the environment of the shell in which octocatalog-diff executes:
74+
75+
- `HOME`
76+
- `PATH`
77+
- `PWD` (set to the temporary directory as previously described)
78+
79+
No other environment variables are passed from the shell. If you wish to pass additional environment variables, you must explicitly list them with the `--pass-env-vars` CLI flag or `settings[:pass_env_vars]` array in your configuration file.
80+
81+
As an example, consider that your ENC is written in Python, and needs the `PYTHONPATH` variable set to `/usr/local/lib/python-custom`. Even if this environment variable is set when octocatalog-diff is run, it will not be available to the ENC script. You may pass the variable via the command line:
82+
83+
```
84+
octocatalog-diff --pass-env-vars PYTHONPATH ...
85+
```
86+
87+
Or you may specify it in your configuration file:
88+
89+
```
90+
settings[:pass_env_vars] = [ 'PYTHONPATH' ]
91+
```
92+
93+
If you wish to specify multiple environment variables to pass:
94+
95+
```
96+
octocatalog-diff --pass-env-vars PYTHONPATH,SECONDVAR,THIRDVAR ...
97+
```
98+
99+
or
100+
101+
```
102+
settings[:pass_env_vars] = [ 'PYTHONPATH', 'SECONDVAR', 'THIRDVAR' ]
103+
```

lib/octocatalog-diff/catalog-util/builddir.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def install_hiera_config(logger, options)
199199

200200
# Munge datadir in hiera config file
201201
obj = YAML.load_file(file_src)
202-
%w(yaml json).each do |key|
202+
(obj[:backends] || %w(yaml json)).each do |key|
203203
next unless obj.key?(key.to_sym)
204204
if options[:hiera_path_strip].is_a?(String)
205205
next if obj[key.to_sym][:datadir].nil?

lib/octocatalog-diff/catalog/puppetmaster.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@ def build(logger = Logger.new(StringIO.new))
7070

7171
# Returns a hash of parameters for each supported version of the Puppet Server Catalog API.
7272
# @return [Hash] Hash of parameters
73+
#
74+
# Note: The double escaping of the facts here is implemented to correspond to a long standing
75+
# bug in the Puppet code. See https://github.com/puppetlabs/puppet/pull/1818 and
76+
# https://docs.puppet.com/puppet/latest/http_api/http_catalog.html#parameters for explanation.
7377
def puppet_catalog_api
7478
{
7579
2 => {
7680
url: "https://#{@options[:puppet_master]}/#{@options[:branch]}/catalog/#{@node}",
7781
parameters: {
7882
'facts_format' => 'pson',
79-
'facts' => @facts.fudge_timestamp.without('trusted').to_pson,
83+
'facts' => CGI.escape(@facts.fudge_timestamp.without('trusted').to_pson),
8084
'transaction_uuid' => SecureRandom.uuid
8185
}
8286
},
@@ -85,7 +89,7 @@ def puppet_catalog_api
8589
parameters: {
8690
'environment' => @options[:branch],
8791
'facts_format' => 'pson',
88-
'facts' => @facts.fudge_timestamp.without('trusted').to_pson,
92+
'facts' => CGI.escape(@facts.fudge_timestamp.without('trusted').to_pson),
8993
'transaction_uuid' => SecureRandom.uuid
9094
}
9195
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"apt_update_last_success":1458162123,
3+
"architecture":"amd64",
4+
"datacenter":"xyz",
5+
"fqdn":"rspec-node.xyz.github.net",
6+
"math":"1+2=3",
7+
"percent":"25%20=5",
8+
"_timestamp":"2014-12-02 14:56:20 -0600"
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#--- !ruby/object:Puppet::Node::Facts
2+
name: rspec-node.xyz.github.net
3+
values:
4+
apt_update_last_success: 1458162123
5+
architecture: amd64
6+
datacenter: xyz
7+
fqdn: rspec-node.xyz.github.net
8+
math: "1+2=3"
9+
percent: "25%20=5"
10+
"_timestamp": 2014-12-02 12:56:20.865795 -08:00
11+
expiration: 2014-12-02 13:11:20.521667 -08:00
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
:backends:
3+
- eyaml
4+
- yaml
5+
- json
6+
:yaml:
7+
:datadir: /var/lib/puppet/environments/%{::environment}/hieradata
8+
:eyaml:
9+
:datadir: /var/lib/puppet/environments/%{::environment}/hieradata
10+
:json:
11+
:datadir: /var/lib/puppet/environments/%{::environment}/hieradata
12+
:hierarchy:
13+
- servers/%{::fqdn}
14+
- datacenter/%{::datacenter}
15+
- platform/%{::virtual}
16+
- os/%{::operatingsystem}/%{::lsbdistcodename}
17+
- os/%{::operatingsystem}
18+
- common
19+
:merge_behavior: deeper
20+
:logger: console

spec/octocatalog-diff/integration/puppetmaster_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def self.parse_body(body)
4747
end
4848

4949
def self.facts_match(body)
50-
facts = JSON.parse(parse_body(body)['facts'])
50+
facts = JSON.parse(CGI.unescape(parse_body(body)['facts']))
5151
facts.delete('_timestamp')
5252
desired_facts = {
5353
'name' => 'rspec-node.xyz.github.net',

spec/octocatalog-diff/tests/catalog-util/builddir_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,27 @@
233233
expect(logger_str.string).to match(%r{WARNING: Hiera datadir for yaml.+/environments/production/aksdfjlkfjk})
234234
end
235235
end
236+
237+
context 'using other backends' do
238+
it 'should rewrite all datadir' do
239+
options = default_options.merge(
240+
hiera_config: OctocatalogDiff::Spec.fixture_path('repos/default/config/hiera-other-backends.yaml'),
241+
hiera_path: 'hieradata'
242+
)
243+
logger, logger_str = OctocatalogDiff::Spec.setup_logger
244+
testobj = OctocatalogDiff::CatalogUtil::BuildDir.new(options, logger)
245+
hiera_yaml = File.join(testobj.tempdir, 'hiera.yaml')
246+
expect(File.file?(hiera_yaml)).to eq(true)
247+
hiera_cfg = YAML.load_file(hiera_yaml)
248+
expect(hiera_cfg[:backends]).to eq(%w(eyaml yaml json))
249+
expect(hiera_cfg[:yaml]).to eq(datadir: File.join(testobj.tempdir, 'environments', 'production', 'hieradata'))
250+
expect(hiera_cfg[:eyaml]).to eq(datadir: File.join(testobj.tempdir, 'environments', 'production', 'hieradata'))
251+
expect(hiera_cfg[:json]).to eq(datadir: File.join(testobj.tempdir, 'environments', 'production', 'hieradata'))
252+
expect(logger_str.string).not_to match(/Hiera datadir for yaml doesn't seem to exist/)
253+
expect(logger_str.string).not_to match(/Hiera datadir for eyaml doesn't seem to exist/)
254+
expect(logger_str.string).not_to match(/Hiera datadir for json doesn't seem to exist/)
255+
end
256+
end
236257
end
237258

238259
describe '#install_fact_file' do

0 commit comments

Comments
 (0)