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 +4 -4
- data/.rubocop.yml +22 -1
- data/exe/foreman_envsync +80 -65
- data/foreman_envsync.gemspec +1 -1
- data/lib/foreman_envsync/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bbd2448eb8bc5347c7753ebb733be2dac67c13cb01ef248ebb888ed80697a54
|
4
|
+
data.tar.gz: b1793f92f1489b9bc235b870190ced2285d9bdd50c2ec7fa12fc0c71fb1e0769
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
#
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
#
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
verbose_list "found %d foreman
|
176
|
-
|
177
|
-
|
178
|
-
verbose_list "
|
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__)
|
data/foreman_envsync.gemspec
CHANGED
@@ -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 = ">=
|
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"
|
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.
|
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-
|
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:
|
137
|
+
version: 3.0.0
|
138
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
139
|
requirements:
|
140
140
|
- - ">="
|