moose-inventory 1.0.9 → 2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +15 -1
- data/.github/workflows/release.yml +58 -0
- data/.gitleaks.toml +9 -0
- data/.rubocop.yml +28 -0
- data/BACKLOG.md +130 -24
- data/Gemfile.lock +36 -1
- data/README.md +26 -6
- data/Rakefile +1 -1
- data/docs/release/publishing.md +44 -48
- data/docs/release/release-readiness.md +14 -0
- data/docs/security-audit-2026-05-26-rerun.md +75 -0
- data/docs/security-audit-2026-05-26.md +63 -0
- data/lib/moose_inventory/cli/group.rb +3 -0
- data/lib/moose_inventory/cli/group_add.rb +89 -73
- data/lib/moose_inventory/cli/group_addchild.rb +77 -60
- data/lib/moose_inventory/cli/group_addhost.rb +78 -65
- data/lib/moose_inventory/cli/group_rm.rb +101 -71
- data/lib/moose_inventory/cli/group_rmchild.rb +99 -53
- data/lib/moose_inventory/cli/group_rmhost.rb +64 -56
- data/lib/moose_inventory/cli/helpers.rb +76 -0
- data/lib/moose_inventory/cli/host.rb +3 -0
- data/lib/moose_inventory/cli/host_add.rb +47 -62
- data/lib/moose_inventory/cli/host_addgroup.rb +73 -64
- data/lib/moose_inventory/cli/host_rmgroup.rb +58 -55
- data/lib/moose_inventory/db/db.rb +27 -7
- data/lib/moose_inventory/inventory_context.rb +50 -0
- data/lib/moose_inventory/operations/add_associations.rb +127 -0
- data/lib/moose_inventory/operations/add_groups.rb +115 -0
- data/lib/moose_inventory/operations/add_hosts.rb +110 -0
- data/lib/moose_inventory/operations/group_child_relations.rb +118 -0
- data/lib/moose_inventory/operations/group_cleanup.rb +55 -0
- data/lib/moose_inventory/operations/remove_associations.rb +101 -0
- data/lib/moose_inventory/operations/remove_groups.rb +79 -0
- data/lib/moose_inventory/version.rb +1 -1
- data/moose-inventory.gemspec +3 -0
- data/scripts/check.sh +2 -0
- data/scripts/ci/check_permissions.sh +3 -0
- data/scripts/ci/check_rubocop.sh +28 -0
- data/scripts/ci/check_secrets.sh +26 -0
- data/scripts/ci/check_security.sh +18 -0
- data/scripts/ci/install_security_tools.sh +47 -0
- data/scripts/install_dependencies.sh +2 -0
- data/spec/lib/moose_inventory/cli/group_rm_spec.rb +40 -0
- data/spec/lib/moose_inventory/cli/group_rmchild_spec.rb +45 -0
- data/spec/lib/moose_inventory/db/db_spec.rb +162 -0
- data/spec/lib/moose_inventory/operations/add_associations_spec.rb +77 -0
- data/spec/lib/moose_inventory/operations/add_groups_spec.rb +65 -0
- data/spec/lib/moose_inventory/operations/add_hosts_spec.rb +69 -0
- data/spec/lib/moose_inventory/operations/group_child_relations_spec.rb +76 -0
- data/spec/lib/moose_inventory/operations/remove_associations_spec.rb +78 -0
- data/spec/lib/moose_inventory/operations/remove_groups_spec.rb +57 -0
- metadata +90 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'inventory_context'
|
|
5
|
+
require 'operations/group_child_relations'
|
|
6
|
+
|
|
7
|
+
RSpec.describe Moose::Inventory::Operations::GroupChildRelations do
|
|
8
|
+
before(:all) do
|
|
9
|
+
@mockargs = [
|
|
10
|
+
'--config', File.join(spec_root, 'config/config.yml'),
|
|
11
|
+
'--format', 'yaml',
|
|
12
|
+
'--env', 'test'
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
Moose::Inventory::Config.init(@mockargs)
|
|
16
|
+
@db = Moose::Inventory::DB
|
|
17
|
+
@db.init if @db.db.nil?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
before(:each) do
|
|
21
|
+
@db.reset
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def operation
|
|
25
|
+
described_class.new(
|
|
26
|
+
context: Moose::Inventory::InventoryContext.new(db: @db)
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'adds child groups and reports duplicate and auto-create events' do
|
|
31
|
+
parent = @db.models[:group].create(name: 'parent')
|
|
32
|
+
existing = @db.models[:group].create(name: 'existing')
|
|
33
|
+
parent.add_child(existing)
|
|
34
|
+
|
|
35
|
+
result = operation.add_children(
|
|
36
|
+
parent_group: parent,
|
|
37
|
+
parent_name: 'parent',
|
|
38
|
+
child_names: %w[existing created]
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
expect(result.warning_count).to eq(2)
|
|
42
|
+
expect(result.events.map(&:type)).to include(
|
|
43
|
+
:child_association_exists,
|
|
44
|
+
:child_group_missing
|
|
45
|
+
)
|
|
46
|
+
expect(parent.children_dataset[name: 'created']).not_to be_nil
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'removes child groups and recursively deletes orphan groups when requested' do
|
|
50
|
+
parent = @db.models[:group].create(name: 'parent')
|
|
51
|
+
child = @db.models[:group].create(name: 'child')
|
|
52
|
+
grandchild = @db.models[:group].create(name: 'grandchild')
|
|
53
|
+
host = @db.models[:host].create(name: 'child-host')
|
|
54
|
+
child.add_host(host)
|
|
55
|
+
parent.add_child(child)
|
|
56
|
+
child.add_child(grandchild)
|
|
57
|
+
|
|
58
|
+
result = operation.remove_children(
|
|
59
|
+
parent_group: parent,
|
|
60
|
+
parent_name: 'parent',
|
|
61
|
+
child_names: %w[missing child],
|
|
62
|
+
delete_orphans: true
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
expect(result.warning_count).to eq(1)
|
|
66
|
+
expect(result.events.map(&:type)).to include(
|
|
67
|
+
:child_association_missing,
|
|
68
|
+
:recursively_delete_orphaned_group,
|
|
69
|
+
:destroying_group,
|
|
70
|
+
:adding_automatic_group_to_host
|
|
71
|
+
)
|
|
72
|
+
expect(@db.models[:group].find(name: 'child')).to be_nil
|
|
73
|
+
expect(@db.models[:group].find(name: 'grandchild')).to be_nil
|
|
74
|
+
expect(host.groups_dataset[name: 'ungrouped']).not_to be_nil
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'inventory_context'
|
|
5
|
+
require 'operations/remove_associations'
|
|
6
|
+
|
|
7
|
+
RSpec.describe Moose::Inventory::Operations::RemoveAssociations do
|
|
8
|
+
before(:all) do
|
|
9
|
+
@mockargs = [
|
|
10
|
+
'--config', File.join(spec_root, 'config/config.yml'),
|
|
11
|
+
'--format', 'yaml',
|
|
12
|
+
'--env', 'test'
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
Moose::Inventory::Config.init(@mockargs)
|
|
16
|
+
@db = Moose::Inventory::DB
|
|
17
|
+
@db.init if @db.db.nil?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
before(:each) do
|
|
21
|
+
@db.reset
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def operation
|
|
25
|
+
described_class.new(
|
|
26
|
+
context: Moose::Inventory::InventoryContext.new(db: @db)
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'removes groups from a host and reports missing associations and ungrouped reattachment' do
|
|
31
|
+
host = @db.models[:host].create(name: 'host1')
|
|
32
|
+
group = @db.models[:group].create(name: 'group1')
|
|
33
|
+
other = @db.models[:group].create(name: 'group2')
|
|
34
|
+
host.add_group(group)
|
|
35
|
+
host.add_group(other)
|
|
36
|
+
|
|
37
|
+
result = operation.host_from_groups(
|
|
38
|
+
host: host,
|
|
39
|
+
host_name: 'host1',
|
|
40
|
+
group_names: %w[group1 missing group2]
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
expect(result.warning_count).to eq(1)
|
|
44
|
+
expect(result.events.map(&:type)).to include(
|
|
45
|
+
:host_group_association_missing,
|
|
46
|
+
:adding_automatic_group
|
|
47
|
+
)
|
|
48
|
+
expect(host.groups_dataset[name: 'group1']).to be_nil
|
|
49
|
+
expect(host.groups_dataset[name: 'group2']).to be_nil
|
|
50
|
+
expect(host.groups_dataset[name: 'ungrouped']).not_to be_nil
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'removes hosts from a group and reports missing associations and ungrouped reattachment' do
|
|
54
|
+
group = @db.models[:group].create(name: 'group1')
|
|
55
|
+
host1 = @db.models[:host].create(name: 'host1')
|
|
56
|
+
host2 = @db.models[:host].create(name: 'host2')
|
|
57
|
+
extra = @db.models[:group].create(name: 'extra')
|
|
58
|
+
host2.add_group(extra)
|
|
59
|
+
group.add_host(host1)
|
|
60
|
+
group.add_host(host2)
|
|
61
|
+
|
|
62
|
+
result = operation.group_from_hosts(
|
|
63
|
+
group: group,
|
|
64
|
+
group_name: 'group1',
|
|
65
|
+
host_names: %w[host1 missing host2]
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
expect(result.warning_count).to eq(1)
|
|
69
|
+
expect(result.events.map(&:type)).to include(
|
|
70
|
+
:group_host_association_missing,
|
|
71
|
+
:adding_automatic_group
|
|
72
|
+
)
|
|
73
|
+
expect(group.hosts_dataset[name: 'host1']).to be_nil
|
|
74
|
+
expect(group.hosts_dataset[name: 'host2']).to be_nil
|
|
75
|
+
expect(host1.groups_dataset[name: 'ungrouped']).not_to be_nil
|
|
76
|
+
expect(host2.groups_dataset[name: 'ungrouped']).to be_nil
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'inventory_context'
|
|
5
|
+
require 'operations/remove_groups'
|
|
6
|
+
|
|
7
|
+
RSpec.describe Moose::Inventory::Operations::RemoveGroups do
|
|
8
|
+
before(:all) do
|
|
9
|
+
@mockargs = [
|
|
10
|
+
'--config', File.join(spec_root, 'config/config.yml'),
|
|
11
|
+
'--format', 'yaml',
|
|
12
|
+
'--env', 'test'
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
Moose::Inventory::Config.init(@mockargs)
|
|
16
|
+
@db = Moose::Inventory::DB
|
|
17
|
+
@db.init if @db.db.nil?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
before(:each) do
|
|
21
|
+
@db.reset
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def operation
|
|
25
|
+
described_class.new(
|
|
26
|
+
context: Moose::Inventory::InventoryContext.new(db: @db)
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'reports missing groups as warnings' do
|
|
31
|
+
result = operation.call(names: ['missing'], recursive: false)
|
|
32
|
+
|
|
33
|
+
expect(result.warning_count).to eq(1)
|
|
34
|
+
expect(result.events.map(&:type)).to include(:group_missing)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'removes groups and recursively cleans orphaned children when requested' do
|
|
38
|
+
parent = @db.models[:group].create(name: 'parent')
|
|
39
|
+
child = @db.models[:group].create(name: 'child')
|
|
40
|
+
host = @db.models[:host].create(name: 'child-host')
|
|
41
|
+
child.add_host(host)
|
|
42
|
+
parent.add_child(child)
|
|
43
|
+
|
|
44
|
+
result = operation.call(names: ['parent'], recursive: true)
|
|
45
|
+
|
|
46
|
+
expect(result.warning_count).to eq(0)
|
|
47
|
+
expect(result.events.map(&:type)).to include(
|
|
48
|
+
:removing_child_association,
|
|
49
|
+
:recursively_delete_orphaned_group,
|
|
50
|
+
:adding_automatic_group_to_host,
|
|
51
|
+
:destroying_group
|
|
52
|
+
)
|
|
53
|
+
expect(@db.models[:group].find(name: 'parent')).to be_nil
|
|
54
|
+
expect(@db.models[:group].find(name: 'child')).to be_nil
|
|
55
|
+
expect(host.groups_dataset[name: 'ungrouped']).not_to be_nil
|
|
56
|
+
end
|
|
57
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: moose-inventory
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: '2.0'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Russell Davies
|
|
@@ -163,6 +163,46 @@ dependencies:
|
|
|
163
163
|
- - "<"
|
|
164
164
|
- !ruby/object:Gem::Version
|
|
165
165
|
version: '3'
|
|
166
|
+
- !ruby/object:Gem::Dependency
|
|
167
|
+
name: bundler-audit
|
|
168
|
+
requirement: !ruby/object:Gem::Requirement
|
|
169
|
+
requirements:
|
|
170
|
+
- - ">="
|
|
171
|
+
- !ruby/object:Gem::Version
|
|
172
|
+
version: '0.9'
|
|
173
|
+
- - "<"
|
|
174
|
+
- !ruby/object:Gem::Version
|
|
175
|
+
version: '1'
|
|
176
|
+
type: :development
|
|
177
|
+
prerelease: false
|
|
178
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
179
|
+
requirements:
|
|
180
|
+
- - ">="
|
|
181
|
+
- !ruby/object:Gem::Version
|
|
182
|
+
version: '0.9'
|
|
183
|
+
- - "<"
|
|
184
|
+
- !ruby/object:Gem::Version
|
|
185
|
+
version: '1'
|
|
186
|
+
- !ruby/object:Gem::Dependency
|
|
187
|
+
name: parallel
|
|
188
|
+
requirement: !ruby/object:Gem::Requirement
|
|
189
|
+
requirements:
|
|
190
|
+
- - ">="
|
|
191
|
+
- !ruby/object:Gem::Version
|
|
192
|
+
version: '1.10'
|
|
193
|
+
- - "<"
|
|
194
|
+
- !ruby/object:Gem::Version
|
|
195
|
+
version: '2.0'
|
|
196
|
+
type: :development
|
|
197
|
+
prerelease: false
|
|
198
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
199
|
+
requirements:
|
|
200
|
+
- - ">="
|
|
201
|
+
- !ruby/object:Gem::Version
|
|
202
|
+
version: '1.10'
|
|
203
|
+
- - "<"
|
|
204
|
+
- !ruby/object:Gem::Version
|
|
205
|
+
version: '2.0'
|
|
166
206
|
- !ruby/object:Gem::Dependency
|
|
167
207
|
name: rake
|
|
168
208
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -197,6 +237,26 @@ dependencies:
|
|
|
197
237
|
- - "~>"
|
|
198
238
|
- !ruby/object:Gem::Version
|
|
199
239
|
version: '3'
|
|
240
|
+
- !ruby/object:Gem::Dependency
|
|
241
|
+
name: rubocop
|
|
242
|
+
requirement: !ruby/object:Gem::Requirement
|
|
243
|
+
requirements:
|
|
244
|
+
- - ">="
|
|
245
|
+
- !ruby/object:Gem::Version
|
|
246
|
+
version: '1.72'
|
|
247
|
+
- - "<"
|
|
248
|
+
- !ruby/object:Gem::Version
|
|
249
|
+
version: '2'
|
|
250
|
+
type: :development
|
|
251
|
+
prerelease: false
|
|
252
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
253
|
+
requirements:
|
|
254
|
+
- - ">="
|
|
255
|
+
- !ruby/object:Gem::Version
|
|
256
|
+
version: '1.72'
|
|
257
|
+
- - "<"
|
|
258
|
+
- !ruby/object:Gem::Version
|
|
259
|
+
version: '2'
|
|
200
260
|
- !ruby/object:Gem::Dependency
|
|
201
261
|
name: simplecov
|
|
202
262
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -220,7 +280,10 @@ extensions: []
|
|
|
220
280
|
extra_rdoc_files: []
|
|
221
281
|
files:
|
|
222
282
|
- ".github/workflows/ci.yml"
|
|
283
|
+
- ".github/workflows/release.yml"
|
|
223
284
|
- ".gitignore"
|
|
285
|
+
- ".gitleaks.toml"
|
|
286
|
+
- ".rubocop.yml"
|
|
224
287
|
- BACKLOG.md
|
|
225
288
|
- Gemfile
|
|
226
289
|
- Gemfile.lock
|
|
@@ -231,6 +294,8 @@ files:
|
|
|
231
294
|
- docs/release/publishing.md
|
|
232
295
|
- docs/release/release-readiness.md
|
|
233
296
|
- docs/security-audit-2026-05-21.md
|
|
297
|
+
- docs/security-audit-2026-05-26-rerun.md
|
|
298
|
+
- docs/security-audit-2026-05-26.md
|
|
234
299
|
- lib/moose_inventory.rb
|
|
235
300
|
- lib/moose_inventory/cli/application.rb
|
|
236
301
|
- lib/moose_inventory/cli/formatter.rb
|
|
@@ -246,6 +311,7 @@ files:
|
|
|
246
311
|
- lib/moose_inventory/cli/group_rmchild.rb
|
|
247
312
|
- lib/moose_inventory/cli/group_rmhost.rb
|
|
248
313
|
- lib/moose_inventory/cli/group_rmvar.rb
|
|
314
|
+
- lib/moose_inventory/cli/helpers.rb
|
|
249
315
|
- lib/moose_inventory/cli/host.rb
|
|
250
316
|
- lib/moose_inventory/cli/host_add.rb
|
|
251
317
|
- lib/moose_inventory/cli/host_addgroup.rb
|
|
@@ -260,11 +326,22 @@ files:
|
|
|
260
326
|
- lib/moose_inventory/db/db.rb
|
|
261
327
|
- lib/moose_inventory/db/exceptions.rb
|
|
262
328
|
- lib/moose_inventory/db/models.rb
|
|
329
|
+
- lib/moose_inventory/inventory_context.rb
|
|
330
|
+
- lib/moose_inventory/operations/add_associations.rb
|
|
331
|
+
- lib/moose_inventory/operations/add_groups.rb
|
|
332
|
+
- lib/moose_inventory/operations/add_hosts.rb
|
|
333
|
+
- lib/moose_inventory/operations/group_child_relations.rb
|
|
334
|
+
- lib/moose_inventory/operations/group_cleanup.rb
|
|
335
|
+
- lib/moose_inventory/operations/remove_associations.rb
|
|
336
|
+
- lib/moose_inventory/operations/remove_groups.rb
|
|
263
337
|
- lib/moose_inventory/version.rb
|
|
264
338
|
- moose-inventory.gemspec
|
|
265
339
|
- scripts/check.sh
|
|
266
340
|
- scripts/ci/check_permissions.sh
|
|
341
|
+
- scripts/ci/check_rubocop.sh
|
|
342
|
+
- scripts/ci/check_secrets.sh
|
|
267
343
|
- scripts/ci/check_security.sh
|
|
344
|
+
- scripts/ci/install_security_tools.sh
|
|
268
345
|
- scripts/ci/package_sanity.sh
|
|
269
346
|
- scripts/files.rb
|
|
270
347
|
- scripts/install_dependencies.sh
|
|
@@ -299,6 +376,12 @@ files:
|
|
|
299
376
|
- spec/lib/moose_inventory/config/config_spec.rb
|
|
300
377
|
- spec/lib/moose_inventory/db/db_spec.rb
|
|
301
378
|
- spec/lib/moose_inventory/db/models_spec.rb
|
|
379
|
+
- spec/lib/moose_inventory/operations/add_associations_spec.rb
|
|
380
|
+
- spec/lib/moose_inventory/operations/add_groups_spec.rb
|
|
381
|
+
- spec/lib/moose_inventory/operations/add_hosts_spec.rb
|
|
382
|
+
- spec/lib/moose_inventory/operations/group_child_relations_spec.rb
|
|
383
|
+
- spec/lib/moose_inventory/operations/remove_associations_spec.rb
|
|
384
|
+
- spec/lib/moose_inventory/operations/remove_groups_spec.rb
|
|
302
385
|
- spec/shared/shared_config_setup.rb
|
|
303
386
|
- spec/spec_helper.rb
|
|
304
387
|
homepage: https://github.com/RusDavies/moose-inventory
|
|
@@ -352,5 +435,11 @@ test_files:
|
|
|
352
435
|
- spec/lib/moose_inventory/config/config_spec.rb
|
|
353
436
|
- spec/lib/moose_inventory/db/db_spec.rb
|
|
354
437
|
- spec/lib/moose_inventory/db/models_spec.rb
|
|
438
|
+
- spec/lib/moose_inventory/operations/add_associations_spec.rb
|
|
439
|
+
- spec/lib/moose_inventory/operations/add_groups_spec.rb
|
|
440
|
+
- spec/lib/moose_inventory/operations/add_hosts_spec.rb
|
|
441
|
+
- spec/lib/moose_inventory/operations/group_child_relations_spec.rb
|
|
442
|
+
- spec/lib/moose_inventory/operations/remove_associations_spec.rb
|
|
443
|
+
- spec/lib/moose_inventory/operations/remove_groups_spec.rb
|
|
355
444
|
- spec/shared/shared_config_setup.rb
|
|
356
445
|
- spec/spec_helper.rb
|