foreman_envsync 1.3.0 → 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: 4cb65d7e80faa3dc6b65430e9236a1318cd4a1c79153d871d190eae77cd55d91
4
- data.tar.gz: 5fefaad9cc7a341b8d5fd363aca513f3587674dbc5464bf514645facd8fe93d8
3
+ metadata.gz: 9bbd2448eb8bc5347c7753ebb733be2dac67c13cb01ef248ebb888ed80697a54
4
+ data.tar.gz: b1793f92f1489b9bc235b870190ced2285d9bdd50c2ec7fa12fc0c71fb1e0769
5
5
  SHA512:
6
- metadata.gz: 61726939b14ca92469901feb59c77307be75185a0e079a419ad6c61dc7f3467c8a69dc48d05d3fa094707accf34e5f5a7a32c547d2a26305e2fca91bcf05f40f
7
- data.tar.gz: 739e264dc25e67d34b31f61ec583de68a5b1fad1f9270a02abb4f45566126df1ff6e39e3a650a297dc29660cc3cb22612b261e6fb03c1d83c8906494d22c7f59
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)
@@ -126,53 +135,59 @@ def puppetserver_env_list
126
135
  JSON.parse(res)["environments"].keys
127
136
  end
128
137
 
129
- #
130
- # Fetch list of puppet environments from puppetserver API.
131
- #
132
- ps_envs = puppetserver_env_list
133
- verbose_list "found %d puppetserver environment(s).", ps_envs
134
-
135
- #
136
- # Fetch list of puppet environments from foreman. The hammer cli is used to
137
- # avoid having to manage credentials. In theory, foreman supports auth using
138
- # x509 similar to puppetserver but this failed when tested using both `curl` and
139
- # configuring hammer to use x509.
140
- #
141
- f_envs = foreman_env_list
142
- verbose_list "found %d foreman environment(s).", f_envs
143
-
144
- #
145
- # Does foreman have any puppet envs puppetserver is unaware of?
146
- #
147
- extra_envs = f_envs - ps_envs
148
- verbose_list "found %d foreman environment(s) unknown to puppetserver.", extra_envs
149
-
150
- #
151
- # Remove any foreman envs unknown to puppetserver
152
- #
153
- report = extra_envs.collect { |x| foreman_env_delete(x) } unless extra_envs.empty?
154
- verbose_list "deleted %d foreman environment(s).", report.nil? ? nil : report.compact
155
-
156
- # update foreman envs if anything was deleted
157
- f_envs = foreman_env_list unless report.nil?
158
-
159
- #
160
- # Does puppetserver have any envs foreman is unaware of?
161
- #
162
- new_envs = ps_envs - f_envs
163
- verbose_list "found %d puppetserver environment(s) unknown to foreman.", new_envs
164
-
165
- # if not, exit
166
- exit 0 if new_envs.empty?
167
-
168
- #
169
- # Create new foreman env(s) with all existing locations and organizations
170
- #
171
- location_ids = foreman_location_ids
172
- verbose_list "found %d foreman location(s).", location_ids
173
-
174
- org_ids = foreman_org_ids
175
- verbose_list "found %d foreman organization(s).", org_ids
176
-
177
- report = new_envs.collect { |x| foreman_env_create(x, location_ids, org_ids) }
178
- 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.3.0"
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.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Hoblitt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-23 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
@@ -134,7 +134,7 @@ 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
  - - ">="