ops_team 0.15.1 → 0.18.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: 38e13ae9a92b8cce7726c6edd5d498859a41ecf108f8c4b248b3da8918518c01
4
- data.tar.gz: fdf320662ce91d561814e80445ad696a46231441f0483e178d763c41d06e8d81
3
+ metadata.gz: d591b58dad032824721105b4ce3e45c63ef40078273d77fbb85ddf50c3224f27
4
+ data.tar.gz: f3f72de653d0ad2d3b87ef1ac6c75bfe0543b6030b37954fae1ddf4dd2981e17
5
5
  SHA512:
6
- metadata.gz: e273245669d3a2e966cc55eff9b4536ba8fe1ee1a288e535003d004dae7e982895ee59d01f9fc2921559886d66b846a042f62890d899ae2e6845164d93627529
7
- data.tar.gz: 700f6c5ef42e0b46ff4522544b6140ad7c225abacf77d3ec5f54038690a665a59dec9aee19eaba7e7a0b69c5039be809eb9f391c08bd69a03dee71bfaf46ab0a
6
+ metadata.gz: 42df63cce2068a86cbe127da74fdf4af2dfb33f3bb4d7ed176354566b11adc1ba3adbbc941b0df8440bcdc1cfaf76f4e9e7182c41618cee1ca9695d8fa1bdca7
7
+ data.tar.gz: 451205a2bde8e20689f2b5b1b76d60f3cf3d2db5d74d18c2f71cc21219863bc4a87373c5980833e90d647314eb937b4dc02f13ad940636603d7dd37faf4764e4
@@ -5,12 +5,18 @@ require 'secrets'
5
5
  # represents one action to be performed in the shell
6
6
  # can assemble a command line from a command and args
7
7
  class Action
8
+ class NotAllowedInEnvError < StandardError; end
9
+
8
10
  def initialize(config, args)
9
11
  @config = config
10
12
  @args = args
11
13
  end
12
14
 
13
15
  def run
16
+ unless allowed_in_current_env?
17
+ raise NotAllowedInEnvError, "Action not allowed in #{Environment.environment} environment."
18
+ end
19
+
14
20
  Secrets.load if load_secrets?
15
21
 
16
22
  Kernel.exec(to_s)
@@ -55,4 +61,20 @@ class Action
55
61
  def load_secrets?
56
62
  @config["load_secrets"]
57
63
  end
64
+
65
+ def not_in_envs
66
+ @config["not_in_envs"] || []
67
+ end
68
+
69
+ def in_envs
70
+ @config["in_envs"] || []
71
+ end
72
+
73
+ def allowed_in_current_env?
74
+ return false if not_in_envs.include?(Environment.environment)
75
+
76
+ return false if in_envs.any? && !in_envs.include?(Environment.environment)
77
+
78
+ true
79
+ end
58
80
  end
@@ -28,11 +28,15 @@ class ActionList
28
28
 
29
29
  private
30
30
 
31
+ def actions_list
32
+ @actions_list ||= []
33
+ end
34
+
31
35
  def process_action_list
32
36
  @actions = {}
33
37
  @aliases = {}
34
38
 
35
- @actions_list.each do |name, config|
39
+ actions_list.each do |name, config|
36
40
  action = Action.new(config, @args)
37
41
 
38
42
  @actions[name] = action
@@ -54,12 +54,18 @@ module Builtins
54
54
  def actions
55
55
  return [] unless @config["actions"]
56
56
 
57
- @config["actions"].map do |name, value|
58
- format("%<name>-35s %<desc>s",
59
- name: name.yellow,
60
- desc: value["description"] || value["command"]
57
+ @config["actions"].map do |name, action_config|
58
+ format("%<name>-40s %<desc>s",
59
+ name: "#{name.yellow} #{alias_string_for(action_config)}",
60
+ desc: action_config["description"] || action_config["command"]
61
61
  )
62
62
  end.sort
63
63
  end
64
+
65
+ def alias_string_for(action_config)
66
+ return "[#{action_config["alias"]}]" if action_config["alias"]
67
+
68
+ ""
69
+ end
64
70
  end
65
71
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'version'
4
+ require 'secrets'
5
+ require 'app_config'
4
6
 
5
7
  class Environment
6
8
  class << self
@@ -26,6 +28,8 @@ class Environment
26
28
  def set_ops_variables
27
29
  ENV["OPS_YML_DIR"] = Dir.pwd
28
30
  ENV["OPS_VERSION"] = Version.version.to_s
31
+ ENV["OPS_SECRETS_FILE"] = Secrets.config_path_for(Environment.environment)
32
+ ENV["OPS_CONFIG_FILE"] = AppConfig.config_path_for(Environment.environment)
29
33
  end
30
34
 
31
35
  def set_environment_aliases
@@ -3,15 +3,6 @@
3
3
  class Executor
4
4
  attr_reader :output, :exit_code
5
5
 
6
- class << self
7
- def execute(command)
8
- @output, status = Open3.capture2e(command)
9
- @exit_code = status.exitstatus
10
-
11
- [@output, @exit_code]
12
- end
13
- end
14
-
15
6
  def initialize(command)
16
7
  @command = command
17
8
  end
@@ -25,11 +25,18 @@ class HookHandler
25
25
  def execute_hooks(name)
26
26
  hooks(name).each do |hook|
27
27
  Output.notice("Running #{name} hook: #{hook}")
28
- output, exit_code = Executor.execute(hook)
28
+ output, exit_code = execute_hook(hook)
29
29
 
30
30
  next if exit_code.zero?
31
31
 
32
32
  raise HookExecError, "#{name} hook '#{hook}' failed with exit code #{exit_code}:\n#{output}"
33
33
  end
34
34
  end
35
+
36
+ def execute_hook(name)
37
+ executor = Executor.new(name)
38
+ executor.execute
39
+
40
+ [executor.output, executor.exit_code]
41
+ end
35
42
  end
data/lib/ops.rb CHANGED
@@ -29,6 +29,7 @@ class Ops
29
29
  MIN_VERSION_NOT_MET_EXIT_CODE = 67
30
30
  ACTION_CONFIG_ERROR_EXIT_CODE = 68
31
31
  BUILTIN_SYNTAX_ERROR_EXIT_CODE = 69
32
+ ACTION_NOT_ALLOWED_IN_ENV_EXIT_CODE = 70
32
33
 
33
34
  RECOMMEND_HELP_TEXT = "Run 'ops help' for a list of builtins and actions."
34
35
 
@@ -115,6 +116,9 @@ class Ops
115
116
  rescue AppConfig::ParsingError => e
116
117
  Output.error("Error parsing app config: #{e}")
117
118
  exit(ERROR_LOADING_APP_CONFIG_EXIT_CODE)
119
+ rescue Action::NotAllowedInEnvError => e
120
+ Output.error("Error running action #{@action_name}: #{e}")
121
+ exit(ACTION_NOT_ALLOWED_IN_ENV_EXIT_CODE)
118
122
  end
119
123
 
120
124
  def do_before_all
@@ -123,10 +127,11 @@ class Ops
123
127
  end
124
128
 
125
129
  def do_before_action
126
- hook_handler.do_hooks("before") unless ENV["OPS_RUNNING"] || action.skip_hooks?("before")
130
+ return if ENV["OPS_RUNNING"] || action.skip_hooks?("before")
127
131
 
128
132
  # this prevents before hooks from running in ops executed by ops
129
133
  ENV["OPS_RUNNING"] = "1"
134
+ hook_handler.do_hooks("before")
130
135
  end
131
136
 
132
137
  def hook_handler
@@ -161,8 +166,12 @@ class Ops
161
166
 
162
167
  def config
163
168
  @config ||= begin
164
- Output.warn("File '#{CONFIG_FILE}' does not exist.") unless File.exist?(CONFIG_FILE)
165
- YAML.load_file(CONFIG_FILE)
169
+ if File.exist?(CONFIG_FILE)
170
+ YAML.load_file(CONFIG_FILE)
171
+ else
172
+ Output.warn("File '#{CONFIG_FILE}' does not exist.") unless @action_name == "init"
173
+ {}
174
+ end
166
175
  rescue StandardError => e
167
176
  Output.warn("Error parsing '#{CONFIG_FILE}': #{e}")
168
177
  {}
@@ -170,7 +179,7 @@ class Ops
170
179
  end
171
180
 
172
181
  def env_vars
173
- @config.dig("options", "environment") || {}
182
+ config.dig("options", "environment") || {}
174
183
  end
175
184
 
176
185
  def environment
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '0.15.1'
5
+ s.version = '0.18.1'
6
6
  s.authors = [
7
7
  'nickthecook@gmail.com'
8
8
  ]
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ops_team
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nickthecook@gmail.com
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2020-08-12 00:00:00.000000000 Z
@@ -130,8 +130,8 @@ dependencies:
130
130
  - - ">="
131
131
  - !ruby/object:Gem::Version
132
132
  version: 1.1.6
133
- description:
134
- email:
133
+ description:
134
+ email:
135
135
  executables:
136
136
  - ops
137
137
  extensions: []
@@ -187,7 +187,7 @@ homepage: https://github.com/nickthecook/ops
187
187
  licenses:
188
188
  - GPL-3.0-only
189
189
  metadata: {}
190
- post_install_message:
190
+ post_install_message:
191
191
  rdoc_options: []
192
192
  require_paths:
193
193
  - lib
@@ -203,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
203
  version: '0'
204
204
  requirements: []
205
205
  rubygems_version: 3.0.3
206
- signing_key:
206
+ signing_key:
207
207
  specification_version: 4
208
208
  summary: ops_team handles basic operations tasks for your project, driven by YAML
209
209
  config