octofacts-updater 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.version +1 -1
- data/bin/octofacts-updater +2 -1
- data/lib/octofacts_updater/cli.rb +34 -11
- data/lib/octofacts_updater/fact.rb +15 -14
- data/lib/octofacts_updater/fact_index.rb +1 -0
- data/lib/octofacts_updater/fixture.rb +1 -0
- data/lib/octofacts_updater/plugin.rb +3 -1
- data/lib/octofacts_updater/plugins/ip.rb +1 -0
- data/lib/octofacts_updater/plugins/ssh.rb +1 -0
- data/lib/octofacts_updater/plugins/static.rb +1 -0
- data/lib/octofacts_updater/service/base.rb +1 -0
- data/lib/octofacts_updater/service/enc.rb +1 -0
- data/lib/octofacts_updater/service/local_file.rb +1 -0
- data/lib/octofacts_updater/service/puppetdb.rb +1 -0
- data/lib/octofacts_updater/service/ssh.rb +1 -0
- data/lib/octofacts_updater/version.rb +1 -0
- data/lib/octofacts_updater.rb +1 -0
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 378e8881afb698fafb804327ef23d85614d8b2d556c7c4945d82fe4f7fbc6cb2
|
4
|
+
data.tar.gz: 9c45ac588e4115cde24c2bb2a9d4028f514cec0bd0caf1c59673f0dad53f9662
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c64cad8078c0e1efd1198dbb556de9733c89f954afc287925365f65b0913f446c5ff823e435e0af347561913cb72a09f68102f9a794c07a646e3997a1e0ea06
|
7
|
+
data.tar.gz: ba83a060abd2fc746d99a1214b7f5e0bb285b4e5c2bfb4e93150a584c84ccdc67bfac163dd7c8a76bc84edcca1e98872551e25489695d2e8d878b842b7b11a3f
|
data/.version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/bin/octofacts-updater
CHANGED
@@ -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
|
-
|
20
|
-
@opts[:config]
|
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
|
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:
|
74
|
-
puts " facts:
|
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
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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 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::
|
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,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 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 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,
|
data/lib/octofacts_updater.rb
CHANGED
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.
|
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:
|
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.
|
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.
|
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
|
-
|
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.
|
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
|
-
|
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
|