foreman_envsync 1.2.2 → 1.4.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: d38a8f525bb525110ab6a663e5fd078d7307fcf723482f325be84b7c52fd8234
4
- data.tar.gz: 32ac2c15a493a6c1ecf3a17672e3318791edeeb3072ecea3d777a9603222f1c1
3
+ metadata.gz: 9bbd2448eb8bc5347c7753ebb733be2dac67c13cb01ef248ebb888ed80697a54
4
+ data.tar.gz: b1793f92f1489b9bc235b870190ced2285d9bdd50c2ec7fa12fc0c71fb1e0769
5
5
  SHA512:
6
- metadata.gz: 8de536088363db02fe41cc82d19a09b1a82796f109100b283271893b6a0dd5c1c7590f9558a4717b82f235ded05440f65fa2e49f4987f44b68058a77dc6707c5
7
- data.tar.gz: 01e819fd4e5d5c1c20a0eb10b36c88363a9c35b85eb8cfc21a8f08b9ae2041137907d5d985d310af79df561caa8e82bf3832787111a29fa09598d0856979f00f
6
+ metadata.gz: 6b1c79bfc420af41375b913a51fd58bc3b38372eadf69710d926b0d38f07c1ea042a3af8793f8e8e6ae2ae34ca203a5e76c88472d39c3f5817c4efcf830cba3d
7
+ data.tar.gz: 69d4d1a6994047dce137702ae3c1c51de952e754137d781b39ef07662f1609a573c2beff3071b7a6ad6d6f0a15bf6f51118896fdc8609ad7ce55ab6cc8a5809b
data/.rubocop.yml CHANGED
@@ -1,5 +1,9 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
1
5
  AllCops:
2
- TargetRubyVersion: 2.5
6
+ TargetRubyVersion: 3.0
3
7
  NewCops: enable
4
8
 
5
9
  Style/StringLiterals:
@@ -15,3 +19,20 @@ Layout/LineLength:
15
19
 
16
20
  Gemspec/RequireMFA:
17
21
  Enabled: false
22
+
23
+ Metrics/AbcSize:
24
+ Enabled: false
25
+ Metrics/BlockLength:
26
+ Enabled: false
27
+ Metrics/ClassLength:
28
+ Enabled: false
29
+ Metrics/CyclomaticComplexity:
30
+ Enabled: false
31
+ Metrics/MethodLength:
32
+ Enabled: false
33
+ Metrics/ModuleLength:
34
+ Enabled: false
35
+ Metrics/ParameterLists:
36
+ Enabled: false
37
+ Metrics/PerceivedComplexity:
38
+ Enabled: false
data/exe/foreman_envsync CHANGED
@@ -8,29 +8,38 @@ require "rest-client"
8
8
  require "socket"
9
9
  require "yaml"
10
10
 
11
- @options = {}
12
- option_parser = OptionParser.new do |opts|
13
- opts.banner = "Usage: foreman_envsync [options]"
14
- opts.separator ""
15
- opts.separator "Specifc options:"
16
-
17
- opts.on("-v", "--verbose", "Enable verbose output") do |o|
18
- @options[:verbose] = [o]
19
- end
20
-
21
- opts.on_tail("-h", "--help", "Show this message") do
22
- puts opts
23
- exit
11
+ def parse_options
12
+ @options = {}
13
+ option_parser = OptionParser.new do |opts|
14
+ opts.banner = "Usage: foreman_envsync [options]"
15
+ opts.separator ""
16
+ opts.separator "Specifc options:"
17
+
18
+ opts.on("-v", "--verbose", "Enable verbose output") do |o|
19
+ @options[:verbose] = [o]
20
+ end
21
+
22
+ opts.on_tail("-h", "--help", "Show this message") do
23
+ puts opts
24
+ exit
25
+ end
24
26
  end
27
+ option_parser.parse!
25
28
  end
26
- option_parser.parse!
27
29
 
28
30
  def verbose_list(msg, items)
29
31
  return unless @options[:verbose] && !items.nil?
30
32
 
31
33
  printf(msg, items.count)
34
+ return if items.empty?
35
+
32
36
  puts
33
- puts "#{YAML.dump(items.sort)}\n" unless items.empty?
37
+ # do not attempt to sorry Array of Hashes
38
+ if items.is_a?(Array) && items.first.is_a?(Hash)
39
+ puts "#{YAML.dump(items)}\n"
40
+ else
41
+ puts "#{YAML.dump(items.sort)}\n"
42
+ end
34
43
  end
35
44
 
36
45
  def cert_file(file)
@@ -103,6 +112,14 @@ def foreman_org_ids
103
112
  hammer_cmd_parse_one(cmd, field)
104
113
  end
105
114
 
115
+ # prefer the puppetserver 7 ca_crt.pem path
116
+ def ssl_ca_file
117
+ %w[
118
+ /etc/puppetlabs/puppetserver/ca/ca_crt.pem
119
+ /etc/puppetlabs/puppet/ssl/ca/ca_crt.pem
120
+ ].find { |f| File.exist?(f) }
121
+ end
122
+
106
123
  def puppetserver_env_list
107
124
  hostname = Socket.gethostname
108
125
 
@@ -112,59 +129,65 @@ def puppetserver_env_list
112
129
  ssl_client_cert: cert_file("/etc/puppetlabs/puppet/ssl/certs/#{hostname}.pem"),
113
130
  ssl_client_key: key_file("/etc/puppetlabs/puppet/ssl/private_keys/#{hostname}.pem"),
114
131
  verify_ssl: true,
115
- ssl_ca_file: "/etc/puppetlabs/puppet/ssl/ca/ca_crt.pem"
132
+ ssl_ca_file: ssl_ca_file
116
133
  )
117
134
 
118
135
  JSON.parse(res)["environments"].keys
119
136
  end
120
137
 
121
- #
122
- # Fetch list of puppet environments from puppetserver API.
123
- #
124
- ps_envs = puppetserver_env_list
125
- verbose_list "found %d puppetserver environment(s).", ps_envs
126
-
127
- #
128
- # Fetch list of puppet environments from foreman. The hammer cli is used to
129
- # avoid having to manage credentials. In theory, foreman supports auth using
130
- # x509 similar to puppetserver but this failed when tested using both `curl` and
131
- # configuring hammer to use x509.
132
- #
133
- f_envs = foreman_env_list
134
- verbose_list "found %d foreman environment(s).", f_envs
135
-
136
- #
137
- # Does foreman have any puppet envs puppetserver is unaware of?
138
- #
139
- extra_envs = f_envs - ps_envs
140
- verbose_list "found %d foreman environment(s) unknown to puppetserver.", extra_envs
141
-
142
- #
143
- # Remove any foreman envs unknown to puppetserver
144
- #
145
- report = extra_envs.collect { |x| foreman_env_delete(x) } unless extra_envs.empty?
146
- verbose_list "deleted %d foreman environment(s).", report.nil? ? nil : report.compact
147
-
148
- # update foreman envs if anything was deleted
149
- f_envs = foreman_env_list unless report.nil?
150
-
151
- #
152
- # Does puppetserver have any envs foreman is unaware of?
153
- #
154
- new_envs = ps_envs - f_envs
155
- verbose_list "found %d puppetserver environment(s) unknown to foreman.", new_envs
156
-
157
- # if not, exit
158
- exit 0 if new_envs.empty?
159
-
160
- #
161
- # Create new foreman env(s) with all existing locations and organizations
162
- #
163
- location_ids = foreman_location_ids
164
- verbose_list "found %d foreman location(s).", location_ids
165
-
166
- org_ids = foreman_org_ids
167
- verbose_list "found %d foreman organization(s).", org_ids
168
-
169
- report = new_envs.collect { |x| foreman_env_create(x, location_ids, org_ids) }
170
- verbose_list "created %d foreman environment(s).", report
138
+ def main
139
+ parse_options
140
+
141
+ #
142
+ # Fetch list of puppet environments from puppetserver API.
143
+ #
144
+ ps_envs = puppetserver_env_list
145
+ verbose_list "found %d puppetserver environment(s).", ps_envs
146
+
147
+ #
148
+ # Fetch list of puppet environments from foreman. The hammer cli is used to
149
+ # avoid having to manage credentials. In theory, foreman supports auth using
150
+ # x509 similar to puppetserver but this failed when tested using both `curl` and
151
+ # configuring hammer to use x509.
152
+ #
153
+ f_envs = foreman_env_list
154
+ verbose_list "found %d foreman environment(s).", f_envs
155
+
156
+ #
157
+ # Does foreman have any puppet envs puppetserver is unaware of?
158
+ #
159
+ extra_envs = f_envs - ps_envs
160
+ verbose_list "found %d foreman environment(s) unknown to puppetserver.", extra_envs
161
+
162
+ #
163
+ # Remove any foreman envs unknown to puppetserver
164
+ #
165
+ report = extra_envs.collect { |x| foreman_env_delete(x) } unless extra_envs.empty?
166
+ verbose_list "deleted %d foreman environment(s).", report.nil? ? nil : report.compact
167
+
168
+ # update foreman envs if anything was deleted
169
+ f_envs = foreman_env_list unless report.nil?
170
+
171
+ #
172
+ # Does puppetserver have any envs foreman is unaware of?
173
+ #
174
+ new_envs = ps_envs - f_envs
175
+ verbose_list "found %d puppetserver environment(s) unknown to foreman.", new_envs
176
+
177
+ # if not, exit
178
+ exit 0 if new_envs.empty?
179
+
180
+ #
181
+ # Create new foreman env(s) with all existing locations and organizations
182
+ #
183
+ location_ids = foreman_location_ids
184
+ verbose_list "found %d foreman location(s).", location_ids
185
+
186
+ org_ids = foreman_org_ids
187
+ verbose_list "found %d foreman organization(s).", org_ids
188
+
189
+ report = new_envs.collect { |x| foreman_env_create(x, location_ids, org_ids) }
190
+ verbose_list "created %d foreman environment(s).", report
191
+ end
192
+
193
+ main if File.basename($PROGRAM_NAME) == File.basename(__FILE__)
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "Sync pupperserver envs with foreman"
12
12
  spec.homepage = "https://github.com/lsst-it/foreman_envsync"
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = ">= 2.5.0"
14
+ spec.required_ruby_version = ">= 3.0.0"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["source_code_uri"] = "https://github.com/lsst-it/foreman_envsync"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanEnvsync
4
- VERSION = "1.2.2"
4
+ VERSION = "1.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_envsync
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Hoblitt
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-04 00:00:00.000000000 Z
11
+ date: 2022-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hammer_cli
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description:
97
+ description:
98
98
  email:
99
99
  - josh@hoblitt.com
100
100
  executables:
@@ -126,7 +126,7 @@ metadata:
126
126
  source_code_uri: https://github.com/lsst-it/foreman_envsync
127
127
  changelog_uri: https://github.com/lsst-it/foreman_envsync/blob/master/CHANGELOG.md
128
128
  rubygems_mfa_required: 'false'
129
- post_install_message:
129
+ post_install_message:
130
130
  rdoc_options: []
131
131
  require_paths:
132
132
  - lib
@@ -134,15 +134,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - ">="
136
136
  - !ruby/object:Gem::Version
137
- version: 2.5.0
137
+ version: 3.0.0
138
138
  required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  requirements: []
144
- rubygems_version: 3.1.6
145
- signing_key:
144
+ rubygems_version: 3.3.7
145
+ signing_key:
146
146
  specification_version: 4
147
147
  summary: Sync pupperserver envs with foreman
148
148
  test_files: []