ops_team 0.3.0 → 0.7.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
2
  SHA256:
3
- metadata.gz: ff1832331084939d3f2b4d0b58fa2e50715051bdff1c82e984dfb289aee64a15
4
- data.tar.gz: e2ecb1f387ce50d5c81500c29f0c67e727d105c66007dc090f67400c1617a4a5
3
+ metadata.gz: 011b0f2a12af0a58c9b48f53d2dd59b9a753eab0acd221ee2675c296c7b109d0
4
+ data.tar.gz: 157963863ac30030921804a37f57ab332502ba465ac9c4ea139b18a297f0618e
5
5
  SHA512:
6
- metadata.gz: cac44a0b4576375fac4210493292537c84b7ef0be6d3c38a16cf17f854058026184f0e96d3a61d4d6a54c226db4b90256844980f5d746120b5e0c3530610c0c0
7
- data.tar.gz: b9d1c6be114864c3890b9a391f0f82f481c1bd556349500e8787fbfe960c30604ce04d8f5f5d94f5445c0912cf941798b414343e3f6a55d56c13ff14c0df8488
6
+ metadata.gz: 9ce81eacd3adb1f7416a96adeabc38b244919ef8e8b17b349cea60e21a68535cc7aaeca57d8af1fb9fb1a03f7b94e98d423f018c2ecd2e9a4da556234ea64f65
7
+ data.tar.gz: 0e0b772bdd70841e197079c93124f53a0d61ea8558add16a4b89e2e7340a1dbeba58222a3631165c03ed3ea35c85c7c596f9834aa0ba3e0445196b27b35e3f41
@@ -1,6 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AppConfig
4
+ class << self
5
+ def load
6
+ new(app_config_path).load
7
+ end
8
+
9
+ private
10
+
11
+ def app_config_path
12
+ expand_path(Options.get("config.path"))
13
+ end
14
+
15
+ def expand_path(path)
16
+ `echo #{path}`.chomp
17
+ end
18
+ end
19
+
4
20
  def initialize(filename = "")
5
21
  @filename = filename.empty? ? default_filename : filename
6
22
  end
@@ -18,8 +34,8 @@ class AppConfig
18
34
  end
19
35
 
20
36
  def config
21
- @config ||= file_contents ? JSON.parse(file_contents) : {}
22
- rescue JSON::ParserError => e
37
+ @config ||= file_contents ? YAML.safe_load(file_contents) : {}
38
+ rescue YAML::SyntaxError => e
23
39
  Output.error("Error parsing config data: #{e}")
24
40
  {}
25
41
  end
@@ -35,7 +35,10 @@ module Builtins
35
35
 
36
36
  def actions
37
37
  @config["actions"].map do |name, value|
38
- format("%<name>-35s %<desc>s", name: name.yellow, desc: value["description"] || value["command"])
38
+ format("%<name>-35s %<desc>s",
39
+ name: name.yellow,
40
+ desc: value["description"] || value["command"]
41
+ )
39
42
  end
40
43
  end
41
44
  end
@@ -6,11 +6,8 @@ class Environment
6
6
  end
7
7
 
8
8
  def set_variables
9
- @env_hash.each do |key, value|
10
- ENV[key] = value
11
- end
12
-
13
- ENV['environment'] = environment
9
+ set_environment_aliases
10
+ set_configured_variables
14
11
  end
15
12
 
16
13
  def environment
@@ -18,4 +15,22 @@ class Environment
18
15
 
19
16
  ENV['environment']
20
17
  end
18
+
19
+ private
20
+
21
+ def set_environment_aliases
22
+ environment_aliases.each do |alias_name|
23
+ ENV[alias_name] = environment
24
+ end
25
+ end
26
+
27
+ def environment_aliases
28
+ Options.get("environment_aliases") || ['environment']
29
+ end
30
+
31
+ def set_configured_variables
32
+ @env_hash.each do |key, value|
33
+ ENV[key] = `echo #{value}`.chomp
34
+ end
35
+ end
21
36
  end
data/lib/ops.rb CHANGED
@@ -49,11 +49,11 @@ class Ops
49
49
 
50
50
  def run_action
51
51
  environment.set_variables
52
- app_config.load
52
+ AppConfig.load
53
53
 
54
54
  return builtin.run if builtin
55
55
 
56
- Output.warn("Running '#{action}' from #{CONFIG_FILE}...")
56
+ Output.warn("Running '#{action}' from #{CONFIG_FILE} in environment '#{ENV['environment']}'...")
57
57
  action.run
58
58
  end
59
59
 
@@ -106,12 +106,8 @@ class Ops
106
106
  @environment ||= Environment.new(env_vars)
107
107
  end
108
108
 
109
- def app_config_file
110
- `echo #{Options.get("config.path")}`.chomp
111
- end
112
-
113
109
  def app_config
114
- @app_config ||= AppConfig.new(app_config_file)
110
+ @app_config ||= AppConfig.new
115
111
  end
116
112
  end
117
113
 
@@ -8,23 +8,21 @@ require 'options'
8
8
 
9
9
  class Secrets < AppConfig
10
10
  class << self
11
- def load
12
- Secrets.new(expand_path(Options.get("secrets.path"))).load
13
- end
14
-
15
11
  private
16
12
 
17
- def expand_path(path)
18
- `echo #{path}`.chomp
13
+ def app_config_path
14
+ expand_path(Options.get("secrets.path"))
19
15
  end
20
16
  end
21
17
 
18
+ def initialize(filename = "")
19
+ @filename = filename.empty? ? default_filename : actual_filename_for(filename)
20
+ end
21
+
22
22
  private
23
23
 
24
24
  def default_filename
25
- return default_ejson_filename if File.exist?(default_ejson_filename)
26
-
27
- default_json_filename
25
+ File.exist?(default_ejson_filename) ? default_ejson_filename : default_json_filename
28
26
  end
29
27
 
30
28
  def default_ejson_filename
@@ -35,6 +33,10 @@ class Secrets < AppConfig
35
33
  "config/#{environment}/secrets.json"
36
34
  end
37
35
 
36
+ def actual_filename_for(filename)
37
+ File.exist?(filename) ? filename : filename.sub(".ejson", ".json")
38
+ end
39
+
38
40
  def file_contents
39
41
  @file_contents ||= @filename.match(/\.ejson$/) ? `ejson decrypt #{@filename}` : super
40
42
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '0.3.0'
5
+ s.version = '0.7.0'
6
6
  s.authors = [
7
7
  'nickthecook@gmail.com'
8
8
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ops_team
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nickthecook@gmail.com