foreman_envsync 1.2.3 → 1.4.1

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: 2d987ff8f7bfd3d2845ea51195f513ab357ae8fef2382d2bb15cc764293c9ef9
4
- data.tar.gz: 55cf9f7a96aed4cdbe4fe0271d0fb45b227d660f4291762f640cf9db7203673a
3
+ metadata.gz: ce024c44d5429e2072e68add6244287999429a4222a73bff1f68244100d5cfd9
4
+ data.tar.gz: 375478ec27003f15f4c462bbd3974149f0d6f665850c9c7ed4ff5ab19c803c07
5
5
  SHA512:
6
- metadata.gz: 9ec0f2236b24b425f33ff68419f3d2732efafc65e36723936e03691c8caf655cfd820028c18e5f2dd206fea4976ab5c3d5931ba270672652b95c98253ef2def4
7
- data.tar.gz: 1bc572c08b399cbc6e816c8701d8bd778e6e590c5d51982b92e35be96d0614b879c292a0ff87bdf900f47a14c98fde8bf0aeee3fa286860ebe4a76e69e369993
6
+ metadata.gz: 14303c21ba7370e97c9950de54ae5d92f15a551b3a829249873295c57190271c57daeddc0fd04bd115bda13ed558d946a7e310868b4004320b2a73f9b7d0cdbd
7
+ data.tar.gz: f30fe471f95524c48271fc1a305007187281719b43e92a3230860a626a032e57c4d5f98819a3503fc5157957061e6879e56b6c8ffe4998acdf10641b80290b92
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)
32
34
  puts
33
- puts "#{YAML.dump(items.sort)}\n" unless items.empty?
35
+ return if items.empty?
36
+
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.3"
4
+ VERSION = "1.4.1"
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.3
4
+ version: 1.4.1
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-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
@@ -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
  - - ">="