moose-inventory 1.0.8 → 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.
Files changed (104) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +49 -0
  3. data/.github/workflows/release.yml +58 -0
  4. data/.gitignore +1 -1
  5. data/.gitleaks.toml +9 -0
  6. data/.rubocop.yml +19 -784
  7. data/BACKLOG.md +290 -0
  8. data/Gemfile.lock +95 -0
  9. data/README.md +38 -9
  10. data/Rakefile +1 -1
  11. data/bin/moose-inventory +1 -1
  12. data/docs/release/publishing.md +109 -0
  13. data/docs/release/release-readiness.md +55 -0
  14. data/docs/security-audit-2026-05-21.md +71 -0
  15. data/docs/security-audit-2026-05-26-rerun.md +75 -0
  16. data/docs/security-audit-2026-05-26.md +63 -0
  17. data/lib/moose_inventory/cli/formatter.rb +16 -17
  18. data/lib/moose_inventory/cli/group.rb +4 -1
  19. data/lib/moose_inventory/cli/group_add.rb +89 -75
  20. data/lib/moose_inventory/cli/group_addchild.rb +84 -71
  21. data/lib/moose_inventory/cli/group_addhost.rb +78 -69
  22. data/lib/moose_inventory/cli/group_addvar.rb +37 -37
  23. data/lib/moose_inventory/cli/group_get.rb +23 -26
  24. data/lib/moose_inventory/cli/group_list.rb +12 -15
  25. data/lib/moose_inventory/cli/group_listvars.rb +12 -14
  26. data/lib/moose_inventory/cli/group_rm.rb +104 -76
  27. data/lib/moose_inventory/cli/group_rmchild.rb +99 -54
  28. data/lib/moose_inventory/cli/group_rmhost.rb +64 -60
  29. data/lib/moose_inventory/cli/group_rmvar.rb +5 -5
  30. data/lib/moose_inventory/cli/helpers.rb +76 -0
  31. data/lib/moose_inventory/cli/host.rb +4 -1
  32. data/lib/moose_inventory/cli/host_add.rb +51 -66
  33. data/lib/moose_inventory/cli/host_addgroup.rb +77 -68
  34. data/lib/moose_inventory/cli/host_addvar.rb +6 -6
  35. data/lib/moose_inventory/cli/host_get.rb +15 -18
  36. data/lib/moose_inventory/cli/host_list.rb +3 -3
  37. data/lib/moose_inventory/cli/host_listvars.rb +21 -23
  38. data/lib/moose_inventory/cli/host_rm.rb +9 -9
  39. data/lib/moose_inventory/cli/host_rmgroup.rb +63 -60
  40. data/lib/moose_inventory/cli/host_rmvar.rb +3 -3
  41. data/lib/moose_inventory/config/config.rb +43 -40
  42. data/lib/moose_inventory/db/db.rb +92 -52
  43. data/lib/moose_inventory/db/models.rb +11 -12
  44. data/lib/moose_inventory/inventory_context.rb +50 -0
  45. data/lib/moose_inventory/operations/add_associations.rb +127 -0
  46. data/lib/moose_inventory/operations/add_groups.rb +115 -0
  47. data/lib/moose_inventory/operations/add_hosts.rb +110 -0
  48. data/lib/moose_inventory/operations/group_child_relations.rb +118 -0
  49. data/lib/moose_inventory/operations/group_cleanup.rb +55 -0
  50. data/lib/moose_inventory/operations/remove_associations.rb +101 -0
  51. data/lib/moose_inventory/operations/remove_groups.rb +79 -0
  52. data/lib/moose_inventory/version.rb +1 -1
  53. data/moose-inventory.gemspec +38 -20
  54. data/scripts/check.sh +10 -0
  55. data/scripts/ci/check_permissions.sh +35 -0
  56. data/scripts/ci/check_rubocop.sh +28 -0
  57. data/scripts/ci/check_secrets.sh +26 -0
  58. data/scripts/ci/check_security.sh +68 -0
  59. data/scripts/ci/install_security_tools.sh +47 -0
  60. data/scripts/ci/package_sanity.sh +46 -0
  61. data/scripts/files.rb +1 -4
  62. data/scripts/install_dependencies.sh +19 -0
  63. data/scripts/reports.sh +2 -2
  64. data/spec/lib/moose_inventory/cli/cli_spec.rb +13 -14
  65. data/spec/lib/moose_inventory/cli/group_add_spec.rb +118 -119
  66. data/spec/lib/moose_inventory/cli/group_addchild_spec.rb +49 -51
  67. data/spec/lib/moose_inventory/cli/group_addhost_spec.rb +80 -83
  68. data/spec/lib/moose_inventory/cli/group_addvar_spec.rb +91 -91
  69. data/spec/lib/moose_inventory/cli/group_get_spec.rb +22 -23
  70. data/spec/lib/moose_inventory/cli/group_list_spec.rb +19 -20
  71. data/spec/lib/moose_inventory/cli/group_listvar_spec.rb +35 -36
  72. data/spec/lib/moose_inventory/cli/group_rm_spec.rb +115 -78
  73. data/spec/lib/moose_inventory/cli/group_rmchild_spec.rb +86 -45
  74. data/spec/lib/moose_inventory/cli/group_rmhost_spec.rb +43 -46
  75. data/spec/lib/moose_inventory/cli/group_rmvar_spec.rb +131 -131
  76. data/spec/lib/moose_inventory/cli/group_spec.rb +9 -9
  77. data/spec/lib/moose_inventory/cli/host_add_spec.rb +103 -43
  78. data/spec/lib/moose_inventory/cli/host_addgroup_spec.rb +78 -80
  79. data/spec/lib/moose_inventory/cli/host_addvar_spec.rb +122 -122
  80. data/spec/lib/moose_inventory/cli/host_get_spec.rb +16 -16
  81. data/spec/lib/moose_inventory/cli/host_list_spec.rb +8 -8
  82. data/spec/lib/moose_inventory/cli/host_listvar_spec.rb +50 -52
  83. data/spec/lib/moose_inventory/cli/host_rm_spec.rb +12 -12
  84. data/spec/lib/moose_inventory/cli/host_rmgroup_spec.rb +48 -51
  85. data/spec/lib/moose_inventory/cli/host_rmvar_spec.rb +136 -136
  86. data/spec/lib/moose_inventory/config/config_spec.rb +16 -3
  87. data/spec/lib/moose_inventory/db/db_spec.rb +386 -2
  88. data/spec/lib/moose_inventory/db/models_spec.rb +10 -11
  89. data/spec/lib/moose_inventory/operations/add_associations_spec.rb +77 -0
  90. data/spec/lib/moose_inventory/operations/add_groups_spec.rb +65 -0
  91. data/spec/lib/moose_inventory/operations/add_hosts_spec.rb +69 -0
  92. data/spec/lib/moose_inventory/operations/group_child_relations_spec.rb +76 -0
  93. data/spec/lib/moose_inventory/operations/remove_associations_spec.rb +78 -0
  94. data/spec/lib/moose_inventory/operations/remove_groups_spec.rb +57 -0
  95. data/spec/shared/shared_config_setup.rb +2 -2
  96. data/spec/spec_helper.rb +7 -8
  97. metadata +157 -105
  98. data/.coveralls.yml +0 -0
  99. data/Guardfile +0 -38
  100. data/config/dotfiles/coveralls.yml +0 -0
  101. data/config/dotfiles/gitignore +0 -20
  102. data/config/dotfiles/rubocop.yml +0 -793
  103. data/scripts/guard_quality.sh +0 -3
  104. data/scripts/guard_test.sh +0 -2
@@ -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
@@ -4,7 +4,7 @@ RSpec.shared_context 'shared config init', a: :b do
4
4
  @mockarg_parts = {
5
5
  config: File.join(spec_dir, 'config/config.yml'),
6
6
  format: 'yaml',
7
- env: 'test'
7
+ env: 'test',
8
8
  }
9
9
 
10
10
  @mockargs = []
@@ -16,6 +16,6 @@ RSpec.shared_context 'shared config init', a: :b do
16
16
  @config = Moose::Inventory::Config
17
17
  @config.init(@mockargs)
18
18
 
19
- @db = Moose::Inventory::DB
19
+ @db = Moose::Inventory::DB
20
20
  end
21
21
  end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,7 @@
1
1
  if RUBY_VERSION >= '1.9'
2
2
  require 'simplecov'
3
- require 'coveralls'
4
-
5
3
  SimpleCov.formatters = [
6
- SimpleCov::Formatter::HTMLFormatter # ,
7
- # Coveralls::SimpleCov::Formatter
4
+ SimpleCov::Formatter::HTMLFormatter
8
5
  ]
9
6
 
10
7
  SimpleCov.start do
@@ -31,11 +28,12 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__),
31
28
  require 'rspec'
32
29
  require 'json'
33
30
  require 'yaml'
31
+ require 'fileutils'
34
32
  require 'find'
35
33
  require 'moose_inventory'
36
34
 
37
35
  RSpec.configure do |config|
38
- #config.filter_run focus: true # <- enable to allow test focus
36
+ # config.filter_run focus: true # <- enable to allow test focus
39
37
  config.color = true
40
38
  config.tty = true
41
39
  config.formatter = :progress #:documentation # :progress, :html, :textmate
@@ -87,7 +85,7 @@ RSpec.configure do |config|
87
85
  def expected(actual, desired)
88
86
  desired[:aborted].nil? && desired[:aborted] = false
89
87
  desired[:STDOUT].nil? && desired[:STDOUT] = ''
90
- desired[:STDERR].nil? && desired[:STDERR] = ''
88
+ desired[:STDERR].nil? && desired[:STDERR] = ''
91
89
 
92
90
  expect(actual[:unexpected]).to eq(false)
93
91
  expect(actual[:aborted]).to eq(desired[:aborted])
@@ -96,9 +94,10 @@ RSpec.configure do |config|
96
94
  end
97
95
 
98
96
  def clobber_db_files
97
+ FileUtils.mkdir_p('tmp')
99
98
  paths = []
100
- Find.find('tmp/') { |path| paths << path if path =~ /.*\.db$/ }
101
- paths.each { |file| File.delete(file) }
99
+ Find.find('tmp') { |path| paths << path if path =~ /.*\.db$/ }
100
+ paths.each { |file| File.delete(file) }
102
101
  end
103
102
 
104
103
  def spec_root