kafo_parsers 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8d072d78df31b4b5a3951eb1f9a543b672d3f83d427e5c5d06608a76ac32f78
4
- data.tar.gz: 83c95ee4652b98f292c8d214e5ff6ea9c4f2dd5cc823e80abcb955173f2857a0
3
+ metadata.gz: 9de270f92023f0577232bb8165246fd6afc2da7bcc18992b8b979d178f19526b
4
+ data.tar.gz: 7718b9cad1349e1a4800de3c360deaa13c87cbe7bc2c24fd11dbf50949cb6f7b
5
5
  SHA512:
6
- metadata.gz: 80cbea32e05363b8620776800943e93c931094b74d2eced273f129c1a058e381199ec2708e997da3eb970ff201a92ed4b5837675baf4d3020f6679fcf72a074e
7
- data.tar.gz: 7073e6ecc7cc140c3298a447d552929686fb58047118b8e118cfbf8fa8581e7d9592e6403775620497d6a1d629ec99a672e3f23660dec86c21ac57b32f764027
6
+ metadata.gz: dba6b56a64cbdfe15b137e08cf6d79d4ab488c8fc6a3c980070a43fe75995cd61404f8119401073522aa589ba6dee5922fcc4705d0186c9c57f8c8fe6007f602
7
+ data.tar.gz: 8b5a282f6aa2c30a6a7ade395b27c0142c134ea9f703a87dc83b9abd42ef8805aed9b6bed70d1779a1880de837af700fd222976ad83efe48c09a318eef5184a1
@@ -1,5 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  require 'json'
3
+ require 'open3'
4
+
3
5
  require 'kafo_parsers/doc_parser'
4
6
  require 'kafo_parsers/param_doc_parser'
5
7
 
@@ -25,11 +27,11 @@ module KafoParsers
25
27
  end
26
28
 
27
29
  def self.available?
28
- `#{puppet_bin} help strings 2>&1`
29
- if $?.success?
30
+ _stdout, _stderr, status = run_puppet(['help', 'strings'])
31
+ if status.success?
30
32
  return true
31
33
  else
32
- raise KafoParsers::ParserNotAvailable.new("#{puppet_bin} does not have strings module installed")
34
+ raise KafoParsers::ParserNotAvailable.new("#{puppet_bin} does not have strings module installed.")
33
35
  end
34
36
  end
35
37
 
@@ -37,10 +39,11 @@ module KafoParsers
37
39
  @file = file = File.expand_path(file)
38
40
  raise KafoParsers::ModuleName, "File not found #{file}, check your answer file" unless File.exist?(file)
39
41
 
40
- command = "#{self.class.puppet_bin} strings generate --format json #{file}"
41
- @raw_json = `#{command}`
42
- unless $?.success?
43
- raise KafoParsers::ParseError, "'#{command}' returned error\n#{@raw_json}"
42
+ command = ['strings', 'generate', '--format', 'json', file]
43
+ @raw_json, stderr, status = self.class.run_puppet(command)
44
+
45
+ unless status.success?
46
+ raise KafoParsers::ParseError, "'#{command}' returned error:\n #{@raw_json}\n #{stderr}"
44
47
  end
45
48
 
46
49
  begin
@@ -130,6 +133,22 @@ module KafoParsers
130
133
 
131
134
  private
132
135
 
136
+ def self.run_puppet(command)
137
+ env_vars = self.puppet_bin.start_with?('/opt/puppetlabs') ? clean_env_vars : ::ENV
138
+ command = command.unshift(self.puppet_bin)
139
+ Open3.capture3(env_vars, *command, :unsetenv_others => true)
140
+ end
141
+
142
+ def self.clean_env_vars
143
+ # Cleaning ENV vars and keeping required vars only because,
144
+ # When using SCL it adds GEM_HOME and GEM_PATH ENV vars.
145
+ whitelisted_vars = %w[HOME USER LANG]
146
+
147
+ cleaned_env = ::ENV.select { |var| whitelisted_vars.include?(var) || var.start_with?('LC_') }
148
+ cleaned_env['PATH'] = '/sbin:/bin:/usr/sbin:/usr/bin:/opt/puppetlabs/bin'
149
+ cleaned_env
150
+ end
151
+
133
152
  # default values using puppet strings includes $ symbol, e.g. "$::foreman::params::ssl"
134
153
  #
135
154
  # values are reported as strings which is issue especially for :under
@@ -1,3 +1,3 @@
1
1
  module KafoParsers
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kafo_parsers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Hulan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-15 00:00:00.000000000 Z
11
+ date: 2020-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  version: '0'
147
147
  requirements: []
148
148
  rubyforge_project:
149
- rubygems_version: 2.7.6
149
+ rubygems_version: 2.7.6.2
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: Puppet module parsers