opswalrus 1.0.68 → 1.0.69

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
2
  SHA256:
3
- metadata.gz: 35026307769aa075aa52c9fe12f3bf64b86cf06dd3d519ce0a3bed4225ce59a0
4
- data.tar.gz: 7884cfd87ae0862276f941410baeb4d74540a2e5f82ffef54290de897075c1f7
3
+ metadata.gz: bf8bbbf6ab94da7f777b80b69dafef9ff37e490ca47542f5468a133f0ab3ad6a
4
+ data.tar.gz: 93d2e3403290b71946260ccc022e52ebc32a8daf94f2bb9586364948470258c3
5
5
  SHA512:
6
- metadata.gz: 0df0f1a38cf9b32fc26a35e97dab8966206bec399dea45f70a527c95b40355eaacafe065010cd6c5c68550cdb300ba6c4db2bf51b289a16b5261c292e90fbb41
7
- data.tar.gz: 2f3b7bb0293ad6b02a8c539ac7b22fd73c6d689f65bf7f7316aac7c25d26635074a05cce8787e77b01a504da51cde35d36e19d50a91b9183d4ccdbfab1dbd212
6
+ metadata.gz: 669268a317cb43a8b970ac8fadd7578e76b05e34a3bcb0c22c83846f421aca4785644b44738616afe8461afb4d484cd2d1bc9c0dee202b15f13ee2597e3f45c9
7
+ data.tar.gz: f7cc3a65e679bc4b547f8c14506de8cd0dc3ca049c9e09fa3ff4c2b20d35ba95e2d82fef38271ab3dfdc599d79e2beea433e3ab2d572b3df9bd3500752e801a8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- opswalrus (1.0.68)
4
+ opswalrus (1.0.69)
5
5
  activesupport (~> 7.0)
6
6
  bcrypt_pbkdf (~> 1.1)
7
7
  binding_of_caller (~> 1.0)
data/lib/opswalrus/app.rb CHANGED
@@ -449,7 +449,7 @@ module OpsWalrus
449
449
  end
450
450
 
451
451
  def report_inventory(host_references, tags: nil)
452
- selected_hosts = inventory(tags, host_references)
452
+ selected_hosts = inventory(tags, host_references).hosts
453
453
 
454
454
  selected_hosts.each do |host|
455
455
  puts host.summary(verbose?)
@@ -464,7 +464,7 @@ module OpsWalrus
464
464
 
465
465
  host_references = [HostsFile::DEFAULT_FILE_NAME] if (host_references.nil? || host_references.empty?) && File.exist?(HostsFile::DEFAULT_FILE_NAME)
466
466
 
467
- Inventory.new(host_references, tags).hosts
467
+ Inventory.new(host_references, tags)
468
468
  end
469
469
 
470
470
  def edit_inventory(file_path)
@@ -54,7 +54,7 @@ module OpsWalrus
54
54
  # "192.168.56.10"=>{"tags"=>["web", "vagrant"]}
55
55
  # }
56
56
  @yaml.map do |host_ref, host_attrs|
57
- next if ['default', 'defaults', 'secrets', 'ids'].include?(host_ref)
57
+ next if ['default', 'defaults', 'env', 'ids', 'secrets'].include?(host_ref)
58
58
 
59
59
  host_params = host_attrs.is_a?(Hash) ? host_attrs : {}
60
60
 
@@ -122,6 +122,11 @@ module OpsWalrus
122
122
  end
123
123
  end
124
124
 
125
+ # returns a Hash object that may have nested structures
126
+ def env
127
+ @env ||= (@yaml["env"] || {})
128
+ end
129
+
125
130
  def tags(host)
126
131
  host_attrs = @yaml[host]
127
132
 
@@ -148,10 +153,14 @@ module OpsWalrus
148
153
  yaml.sub(/^---\s*/,"") # omit the leading line: ---\n
149
154
  end
150
155
 
156
+ def has_secret?(secret_name)
157
+ secrets[secret_name]
158
+ end
159
+
151
160
  # returns the decrypted value referenced by secret_name
152
161
  def read_secret(secret_name)
153
162
  secret = secrets[secret_name]
154
- secret.decrypt(@cipher)
163
+ secret.decrypt(@cipher) if secret
155
164
  end
156
165
 
157
166
  def encrypt_secrets!()
@@ -1,6 +1,7 @@
1
- require "pathname"
2
- require "tty-editor"
3
- require "yaml"
1
+ require 'active_support/core_ext/hash'
2
+ require 'pathname'
3
+ require 'tty-editor'
4
+ require 'yaml'
4
5
 
5
6
  module OpsWalrus
6
7
  class Inventory
@@ -11,6 +12,18 @@ module OpsWalrus
11
12
  @tags = tags
12
13
  end
13
14
 
15
+ def env
16
+ @env ||= hosts_files.reduce({}) {|memo, hosts_file| memo.deep_merge(hosts_file.env) }
17
+ end
18
+
19
+ def read_secret(secret_name)
20
+ hosts_files.find {|hosts_file| hosts_file.has_secret?(secret_name) }&.read_secret(secret_name)
21
+ end
22
+
23
+ def hosts_files
24
+ @hosts_files ||= @host_references.select {|ref| File.exist?(ref) }.map {|file_path| HostsFile.new(file_path) }
25
+ end
26
+
14
27
  def hosts()
15
28
  hosts_files, host_strings = @host_references.partition {|ref| File.exist?(ref) }
16
29
  inventory_file_hosts = hosts_files.
@@ -192,7 +192,7 @@ module OpsWalrus
192
192
  kwargs = kwargs.transform_keys(&:to_s)
193
193
  tags.concat(kwargs["tags"]) if kwargs["tags"]
194
194
 
195
- @runtime_env.app.inventory(tags)
195
+ @runtime_env.app.inventory(tags).hosts
196
196
  end
197
197
 
198
198
  def exit(exit_status, message = nil)
@@ -244,6 +244,10 @@ module OpsWalrus
244
244
  end
245
245
  end
246
246
 
247
+ def read_secret(secret_name)
248
+ @runtime_env.read_secret(secret_name)
249
+ end
250
+
247
251
  # runs the given command
248
252
  # returns the stdout from the command
249
253
  def sh(desc_or_cmd = nil, cmd = nil, input: nil, &block)
@@ -1,5 +1,6 @@
1
1
  require 'active_support'
2
2
  require 'active_support/core_ext/hash'
3
+ require 'active_support/core_ext/hash/indifferent_access'
3
4
  require 'json'
4
5
  require 'pathname'
5
6
 
@@ -240,8 +240,7 @@ module OpsWalrus
240
240
 
241
241
  def initialize(app)
242
242
  @app = app
243
- # @env = EnvParams.new(ENV)
244
- @env = ENV.to_h.with_indifferent_access.easynav
243
+ @env = @app.inventory.env.deep_merge(ENV.to_h).with_indifferent_access.easynav
245
244
  @bundle_load_path = LoadPath.new(self, @app.bundle_dir)
246
245
  @app_load_path = LoadPath.new(self, @app.pwd)
247
246
 
@@ -262,6 +261,10 @@ module OpsWalrus
262
261
  configure_sshkit
263
262
  end
264
263
 
264
+ def read_secret(secret_name)
265
+ @app.inventory.read_secret(secret_name.to_s)
266
+ end
267
+
265
268
  # input_mapping : Hash[ String | Regex => String ]
266
269
  # sudo_password : String
267
270
  def handle_input(input_mapping, sudo_password: nil, ops_sudo_password: nil, inherit_existing_mappings: true, &block)
@@ -1,3 +1,3 @@
1
1
  module OpsWalrus
2
- VERSION = "1.0.68"
2
+ VERSION = "1.0.69"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opswalrus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.68
4
+ version: 1.0.69
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Ellis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-30 00:00:00.000000000 Z
11
+ date: 2023-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport