octofacts-updater 0.5.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 05efcd40e8410c43eb2fd197165de57b754d0e28
4
- data.tar.gz: ad65e6ce8d288593e0b2b03075fcda6f52fbd4cb
2
+ SHA256:
3
+ metadata.gz: 378e8881afb698fafb804327ef23d85614d8b2d556c7c4945d82fe4f7fbc6cb2
4
+ data.tar.gz: 9c45ac588e4115cde24c2bb2a9d4028f514cec0bd0caf1c59673f0dad53f9662
5
5
  SHA512:
6
- metadata.gz: 507c0eecd6dd8c7c281e6734f1dbdde0731ee2e8cfcedd2bc5f9d7fc68fc7805207d5032d3ffc1d20df0e75154afb3786e0ff6f93d03af9e271592d9d45996ec
7
- data.tar.gz: e017a38aa6681a768d06cc085f4dc4480e4ef736d6782fd6f05a9d2b24b391bc5911b9e0d47791f080ea3321c96b3117f44cd864e60ba2108f95c22c675e60f7
6
+ metadata.gz: 3c64cad8078c0e1efd1198dbb556de9733c89f954afc287925365f65b0913f446c5ff823e435e0af347561913cb72a09f68102f9a794c07a646e3997a1e0ea06
7
+ data.tar.gz: ba83a060abd2fc746d99a1214b7f5e0bb285b4e5c2bfb4e93150a584c84ccdc67bfac163dd7c8a76bc84edcca1e98872551e25489695d2e8d878b842b7b11a3f
data/.version CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.6.0
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
-
2
+ # frozen_string_literal: true
3
+ #
3
4
  require "bundler/setup"
4
5
  require "octofacts_updater"
5
6
  cli = OctofactsUpdater::CLI.new(ARGV)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # :nocov:
2
3
  require "optparse"
3
4
 
@@ -16,8 +17,8 @@ module OctofactsUpdater
16
17
  end
17
18
 
18
19
  opts.on("-c", "--config <config_file>", String, "Path to configuration file") do |f|
19
- raise "Invalid configuration file" unless File.file?(f)
20
- @opts[:config] = f
20
+ @opts[:config] = File.expand_path(f)
21
+ raise "Invalid configuration file #{@opts[:config].inspect}" unless File.file?(@opts[:config])
21
22
  end
22
23
 
23
24
  opts.on("-H", "--hostname <hostname>", String, "FQDN of the host whose facts are to be gathered") do |h|
@@ -67,11 +68,12 @@ module OctofactsUpdater
67
68
  end
68
69
 
69
70
  def usage
70
- puts "Usage: octofacts-updater --action <action> [--config-file /path/to/config.yaml] [other options]"
71
+ puts "Usage: octofacts-updater --action <action> [--config /path/to/config.yaml] [other options]"
71
72
  puts ""
72
73
  puts "Available actions:"
73
- puts " bulk: Update fixtures and index in bulk"
74
- puts " facts: Obtain facts for one node (requires --hostname <hostname>)"
74
+ puts " bulk: Update fixtures and index in bulk"
75
+ puts " facts: Obtain facts for one node (requires --hostname <hostname>)"
76
+ puts " reindex: Build a new index from the existing fact fixtures"
75
77
  puts ""
76
78
  end
77
79
 
@@ -106,6 +108,7 @@ module OctofactsUpdater
106
108
 
107
109
  return handle_action_bulk if opts[:action] == "bulk"
108
110
  return handle_action_facts if opts[:action] == "facts"
111
+ return handle_action_bulk if opts[:action] == "reindex"
109
112
 
110
113
  usage
111
114
  exit 255
@@ -126,19 +129,39 @@ module OctofactsUpdater
126
129
  end
127
130
  end
128
131
 
129
- def handle_action_bulk
130
- facts_to_index = @config.fetch("index", {})["indexed_facts"]
131
- unless facts_to_index.is_a?(Array)
132
- raise ArgumentError, "Must declare index:indexed_facts in configuration to use bulk update"
133
- end
132
+ def nodes_for_bulk
133
+ if opts[:action] == "reindex"
134
+ @opts[:quick] = true
135
+
136
+ path = if opts[:path]
137
+ File.expand_path(opts[:path])
138
+ elsif @config.fetch("index", {})["node_path"]
139
+ File.expand_path(@config.fetch("index", {})["node_path"], File.dirname(opts[:config]))
140
+ else
141
+ raise ArgumentError, "Must set --path, or define index:node_path to a valid directory in configuration"
142
+ end
143
+
144
+ unless File.directory?(path)
145
+ raise Errno::ENOENT, "--path must be a directory (#{path.inspect} is not)"
146
+ end
134
147
 
135
- nodes = if opts[:host_list]
148
+ Dir.glob("#{path}/*.yaml").map { |f| File.basename(f, ".yaml") }
149
+ elsif opts[:host_list]
136
150
  opts[:host_list]
137
151
  elsif opts[:hostname]
138
152
  [opts[:hostname]]
139
153
  else
140
154
  OctofactsUpdater::FactIndex.load_file(index_file).nodes(true)
141
155
  end
156
+ end
157
+
158
+ def handle_action_bulk
159
+ facts_to_index = @config.fetch("index", {})["indexed_facts"]
160
+ unless facts_to_index.is_a?(Array)
161
+ raise ArgumentError, "Must declare index:indexed_facts in configuration to use bulk update"
162
+ end
163
+
164
+ nodes = nodes_for_bulk
142
165
  if nodes.empty?
143
166
  raise ArgumentError, "Cannot run bulk update with no nodes to check"
144
167
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # This class represents a fact, either structured or unstructured.
2
3
  # The fact has a name and a value. The name is a string, and the value
3
4
  # can either be a string/integer/boolean (unstructured) or a hash (structured).
@@ -65,20 +66,20 @@ module OctofactsUpdater
65
66
  end
66
67
 
67
68
  parts = if name_in.is_a?(String)
68
- name_in.split("::")
69
- elsif name_in.is_a?(Array)
70
- name_in.map do |item|
71
- if item.is_a?(String)
72
- item
73
- elsif item.is_a?(Hash) && item.key?("regexp")
74
- Regexp.new(item["regexp"])
75
- else
76
- raise ArgumentError, "Unable to interpret structure item: #{item.inspect}"
77
- end
78
- end
79
- else
80
- raise ArgumentError, "Unable to interpret structure: #{name_in.inspect}"
81
- end
69
+ name_in.split("::")
70
+ elsif name_in.is_a?(Array)
71
+ name_in.map do |item|
72
+ if item.is_a?(String)
73
+ item
74
+ elsif item.is_a?(Hash) && item.key?("regexp")
75
+ Regexp.new(item["regexp"])
76
+ else
77
+ raise ArgumentError, "Unable to interpret structure item: #{item.inspect}"
78
+ end
79
+ end
80
+ else
81
+ raise ArgumentError, "Unable to interpret structure: #{name_in.inspect}"
82
+ end
82
83
 
83
84
  set_structured_value(@value, parts, new_value)
84
85
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # This class represents a fact index, which is ultimately represented by a YAML file of
2
3
  # each index fact, the values seen, and the node(s) containing each value.
3
4
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # This class represents a fact fixture, which is a set of facts along with a node name.
2
3
  # Facts are OctofactsUpdater::Fact objects, and internally are stored as a hash table
3
4
  # with the key being the fact name and the value being the OctofactsUpdater::Fact object.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # This class provides the base methods for fact manipulation plugins.
2
3
 
3
4
  require "digest"
@@ -61,7 +62,8 @@ module OctofactsUpdater
61
62
  #
62
63
  # Returns a String with the same length as string_in.
63
64
  def self.randomize_long_string(string_in)
64
- seed = Digest::MD5.hexdigest(string_in).to_i(36)
65
+ seed = Digest::SHA512.hexdigest(string_in).to_i(36)
66
+
65
67
  prng = Random.new(seed)
66
68
  chars = [("a".."z"), ("A".."Z"), ("0".."9")].flat_map(&:to_a)
67
69
  (1..(string_in.length)).map { chars[prng.rand(chars.length)] }.join
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # This file is part of the octofacts updater fact manipulation plugins. This plugin provides
2
3
  # methods to update facts that are IP addresses in order to anonymize or randomize them.
3
4
 
@@ -1,4 +1,5 @@
1
1
  # This file is part of the octofacts updater fact manipulation plugins. This plugin provides
2
+ # frozen_string_literal: true
2
3
  # methods to update facts that are SSH keys, since we do not desire to commit SSH keys from
3
4
  # actual hosts into the source code repository.
4
5
 
@@ -1,4 +1,5 @@
1
1
  # This file is part of the octofacts updater fact manipulation plugins. This plugin provides
2
+ # frozen_string_literal: true
2
3
  # methods to do static operations on facts -- delete, add, or set to a known value.
3
4
 
4
5
  # Delete. This method deletes the fact or the identified portion. Setting the value to nil
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # This contains handy utility methods that might be used in any of the other classes.
2
3
 
3
4
  require "yaml"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # This class contains methods to interact with an external node classifier.
2
3
 
3
4
  require "open3"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # This class reads a YAML file from the local file system so that it can be used as a source
2
3
  # in octofacts-updater. This was originally intended for a quickstart tutorial, since it requires
3
4
  # no real configuration. However it could also be used in production, if the user wants to create
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # This class interacts with puppetdb to pull the facts from the recent
2
3
  # run of Puppet on a given node. This uses octocatalog-diff on the back end to
3
4
  # pull the facts from puppetdb.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # This class interacts with a puppetserver to obtain facts from that server's YAML cache.
2
3
  # This is achieved by SSH-ing to the server and obtaining the fact file directly from the
3
4
  # puppetserver's cache. This can also be used to SSH to an actual node and run a command,
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module OctofactsUpdater
2
3
  VERSION = File.read(File.expand_path("../../.version", File.dirname(__FILE__))).strip
3
4
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "octofacts_updater/cli"
2
3
  require "octofacts_updater/fact"
3
4
  require "octofacts_updater/fact_index"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octofacts-updater
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub, Inc.
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-10-06 00:00:00.000000000 Z
13
+ date: 2024-08-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: diffy
@@ -32,14 +32,14 @@ dependencies:
32
32
  requirements:
33
33
  - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: 1.4.1
35
+ version: 2.1.0
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 1.4.1
42
+ version: 2.1.0
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: octokit
45
45
  requirement: !ruby/object:Gem::Requirement
@@ -68,8 +68,10 @@ dependencies:
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: '2.9'
71
- description: |
72
- Octofacts-updater is a series of scripts to construct the fact fixture files and index files consumed by octofacts.
71
+ description: 'Octofacts-updater is a series of scripts to construct the fact fixture
72
+ files and index files consumed by octofacts.
73
+
74
+ '
73
75
  email: opensource+octofacts@github.com
74
76
  executables:
75
77
  - octofacts-updater
@@ -106,15 +108,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
108
  requirements:
107
109
  - - ">="
108
110
  - !ruby/object:Gem::Version
109
- version: 2.1.0
111
+ version: 2.7.0
110
112
  required_rubygems_version: !ruby/object:Gem::Requirement
111
113
  requirements:
112
114
  - - ">="
113
115
  - !ruby/object:Gem::Version
114
116
  version: '0'
115
117
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.2.5
118
+ rubygems_version: 3.4.19
118
119
  signing_key:
119
120
  specification_version: 4
120
121
  summary: Scripts to update octofacts fixtures from recent Puppet runs