ops_team 0.2.8 → 0.5.1

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: 2ed40f82a2c6312381a243ea6ccbfc12ba46f1742af6a8935a2c59d7fcb783f9
4
- data.tar.gz: 65ec586f9adb40be64e31f5d581845efc8cc303548b4eea8b7d4b5f6620ae8f1
3
+ metadata.gz: 4f88b6c88e15edac660d47999114c165b4471ec74dea7ac5428908a8426a7062
4
+ data.tar.gz: 98746bb244d653277c299dc750d58100a01394a0109499c0ac72fd5772e80e60
5
5
  SHA512:
6
- metadata.gz: 333c1446f7b2d59f33dda51e29f918d8fe2d54d79f60310d952bbf538dad5ae93c0aa8503fe5af1ed4ba964b336514d21a6d7b6e13948539710bccb259fe2a36
7
- data.tar.gz: dac43c177bb4681f3a66a418175c52bd93af2974793400b8db018385fe7abf5743ad89d1ba0398d0ed3cde39b9d68b56dc1919e664621a2366c77e479ef9e100
6
+ metadata.gz: f1cab3c3fe85c61f55cd70d7fffd7513e9c55796e8b1d6fae7d9d0fd7c21685fbba31216adea935d09396ab4140b05bb514e62cd1255ad45f554a0a1832d4fcb
7
+ data.tar.gz: 70025e88ddd590901f058989a59eba054ff0af8cbf238a78bfd2150ef41504dc5b33f3726f72c166802e1613373a978d05320611cd793db028dc09e590bb1a5b
@@ -14,7 +14,7 @@ module Builtins
14
14
  end
15
15
  end
16
16
 
17
- def run
17
+ def run
18
18
  unless gemspec
19
19
  Output.error("Unable to load gemspec at '#{GEMSPEC_FILE}")
20
20
  return false
@@ -9,7 +9,7 @@ module Dependencies
9
9
  end
10
10
 
11
11
  def meet
12
- execute("apt-get install -y #{name}")
12
+ execute("#{sudo_string}#{meet_command}")
13
13
  end
14
14
 
15
15
  def unmeet
@@ -20,5 +20,17 @@ module Dependencies
20
20
  def should_meet?
21
21
  `uname`.chomp == "Linux"
22
22
  end
23
+
24
+ private
25
+
26
+ def sudo_string
27
+ return "" if ENV['USER'] == "root" || Options.get("apt.use_sudo") == false
28
+
29
+ "sudo "
30
+ end
31
+
32
+ def meet_command
33
+ "apt-get install -y #{name}"
34
+ end
23
35
  end
24
36
  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] = value.to_s
34
+ end
35
+ end
21
36
  end
data/lib/ops.rb CHANGED
@@ -16,7 +16,8 @@ class Ops
16
16
 
17
17
  CONFIG_FILE = "ops.yml"
18
18
 
19
- INVALID_SYNTAX_EXIT_CODE = 1
19
+ INVALID_SYNTAX_EXIT_CODE = 64
20
+ UNKNOWN_ACTION_EXIT_CODE = 65
20
21
 
21
22
  def initialize(argv)
22
23
  @action_name = argv[0]
@@ -28,15 +29,10 @@ class Ops
28
29
  def run
29
30
  exit(INVALID_SYNTAX_EXIT_CODE) unless syntax_valid?
30
31
 
31
- environment.set_variables
32
- app_config.load
33
-
34
- return builtin.run if builtin
35
-
36
- Output.warn("Running '#{action}' from #{CONFIG_FILE}...")
37
- action.run
32
+ run_action
38
33
  rescue UnknownActionError => e
39
34
  Output.error("Error: #{e}")
35
+ exit(UNKNOWN_ACTION_EXIT_CODE)
40
36
  end
41
37
 
42
38
  private
@@ -51,6 +47,16 @@ class Ops
51
47
  end
52
48
  end
53
49
 
50
+ def run_action
51
+ environment.set_variables
52
+ app_config.load
53
+
54
+ return builtin.run if builtin
55
+
56
+ Output.warn("Running '#{action}' from #{CONFIG_FILE} in environment '#{ENV['environment']}'...")
57
+ action.run
58
+ end
59
+
54
60
  def builtin
55
61
  @builtin ||= Builtins.const_get(builtin_class_name, false).new(@args, config)
56
62
  rescue NameError
@@ -3,7 +3,7 @@
3
3
  class Options
4
4
  class << self
5
5
  def get(path)
6
- @options.dig(*path.split('.'))
6
+ @options&.dig(*path.split('.'))
7
7
  end
8
8
 
9
9
  def set(options)
@@ -9,22 +9,28 @@ require 'options'
9
9
  class Secrets < AppConfig
10
10
  class << self
11
11
  def load
12
- Secrets.new(expand_path(Options.get("secrets.path"))).load
12
+ Secrets.new(secrets_path).load
13
13
  end
14
14
 
15
15
  private
16
16
 
17
+ def secrets_path
18
+ expand_path(Options.get("secrets.path"))
19
+ end
20
+
17
21
  def expand_path(path)
18
22
  `echo #{path}`.chomp
19
23
  end
20
24
  end
21
25
 
26
+ def initialize(filename = "")
27
+ @filename = filename.empty? ? default_filename : actual_filename_for(filename)
28
+ end
29
+
22
30
  private
23
31
 
24
32
  def default_filename
25
- return default_ejson_filename if File.exist?(default_ejson_filename)
26
-
27
- default_json_filename
33
+ File.exist?(default_ejson_filename) ? default_ejson_filename : default_json_filename
28
34
  end
29
35
 
30
36
  def default_ejson_filename
@@ -35,6 +41,10 @@ class Secrets < AppConfig
35
41
  "config/#{environment}/secrets.json"
36
42
  end
37
43
 
44
+ def actual_filename_for(filename)
45
+ File.exist?(filename) ? filename : filename.sub(".ejson", ".json")
46
+ end
47
+
38
48
  def file_contents
39
49
  @file_contents ||= @filename.match(/\.ejson$/) ? `ejson decrypt #{@filename}` : super
40
50
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '0.2.8'
5
+ s.version = '0.5.1'
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.2.8
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nickthecook@gmail.com