ops_team 0.16.0 → 0.19.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 +4 -4
- data/lib/action.rb +22 -0
- data/lib/action_list.rb +5 -1
- data/lib/builtins/help.rb +10 -4
- data/lib/executor.rb +0 -9
- data/lib/forward.rb +17 -0
- data/lib/forwards.rb +20 -0
- data/lib/hook_handler.rb +8 -1
- data/lib/ops.rb +20 -4
- data/ops_team.gemspec +1 -1
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1ea151f15e3f842a7fee5780096a4571448ccbcc7232bd841832289b863c4bc
|
4
|
+
data.tar.gz: 17fb8d9783359db78d608afb99b61feb5f9cfd10cd5bed378417d900aedacca4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0325447467e8c0fc01483f1fcc3be7da8b4dedb6045c49d0ae7b2072efc7da1ee6fe7e0c281c6f5ccda1e0871caf5641e1ac8b78b99810f6e134a6fef6c35b0e
|
7
|
+
data.tar.gz: 4f6391a41a0fa8c44b65d623fc0c09db7ce00b900df7a0b86d7f2b21337d29a1aecf0854fac2ad95e23c53522f92e7ac9e4c7342518475dbbea2373338c00428
|
data/lib/action.rb
CHANGED
@@ -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
|
data/lib/action_list.rb
CHANGED
@@ -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
|
-
|
39
|
+
actions_list.each do |name, config|
|
36
40
|
action = Action.new(config, @args)
|
37
41
|
|
38
42
|
@actions[name] = action
|
data/lib/builtins/help.rb
CHANGED
@@ -54,12 +54,18 @@ module Builtins
|
|
54
54
|
def actions
|
55
55
|
return [] unless @config["actions"]
|
56
56
|
|
57
|
-
@config["actions"].map do |name,
|
58
|
-
format("%<name>-
|
59
|
-
name: name.yellow,
|
60
|
-
desc:
|
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
|
data/lib/executor.rb
CHANGED
@@ -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
|
data/lib/forward.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'output'
|
4
|
+
|
5
|
+
class Forward
|
6
|
+
def initialize(dir, args)
|
7
|
+
@dir = dir
|
8
|
+
@args = args
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
Output.notice("Forwarding 'ops #{@args.join(" ")}' to '#{@dir}/'...")
|
13
|
+
|
14
|
+
Dir.chdir(@dir)
|
15
|
+
Ops.new(@args).run
|
16
|
+
end
|
17
|
+
end
|
data/lib/forwards.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forward'
|
4
|
+
|
5
|
+
class Forwards
|
6
|
+
def initialize(config, args)
|
7
|
+
@config = config
|
8
|
+
@args = args
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(name)
|
12
|
+
Forward.new(name, @args) if forwards[name]
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def forwards
|
18
|
+
@forwards ||= @config["forwards"] || {}
|
19
|
+
end
|
20
|
+
end
|
data/lib/hook_handler.rb
CHANGED
@@ -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 =
|
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
@@ -13,6 +13,7 @@ require 'environment'
|
|
13
13
|
require 'version'
|
14
14
|
require 'action_list'
|
15
15
|
require 'action_suggester'
|
16
|
+
require 'forwards'
|
16
17
|
|
17
18
|
require_rel "builtins"
|
18
19
|
|
@@ -29,6 +30,7 @@ class Ops
|
|
29
30
|
MIN_VERSION_NOT_MET_EXIT_CODE = 67
|
30
31
|
ACTION_CONFIG_ERROR_EXIT_CODE = 68
|
31
32
|
BUILTIN_SYNTAX_ERROR_EXIT_CODE = 69
|
33
|
+
ACTION_NOT_ALLOWED_IN_ENV_EXIT_CODE = 70
|
32
34
|
|
33
35
|
RECOMMEND_HELP_TEXT = "Run 'ops help' for a list of builtins and actions."
|
34
36
|
|
@@ -100,6 +102,8 @@ class Ops
|
|
100
102
|
end
|
101
103
|
|
102
104
|
def run_action
|
105
|
+
return forward.run if forward
|
106
|
+
|
103
107
|
do_before_all
|
104
108
|
|
105
109
|
return builtin.run if builtin
|
@@ -115,6 +119,9 @@ class Ops
|
|
115
119
|
rescue AppConfig::ParsingError => e
|
116
120
|
Output.error("Error parsing app config: #{e}")
|
117
121
|
exit(ERROR_LOADING_APP_CONFIG_EXIT_CODE)
|
122
|
+
rescue Action::NotAllowedInEnvError => e
|
123
|
+
Output.error("Error running action #{@action_name}: #{e}")
|
124
|
+
exit(ACTION_NOT_ALLOWED_IN_ENV_EXIT_CODE)
|
118
125
|
end
|
119
126
|
|
120
127
|
def do_before_all
|
@@ -123,10 +130,11 @@ class Ops
|
|
123
130
|
end
|
124
131
|
|
125
132
|
def do_before_action
|
126
|
-
|
133
|
+
return if ENV["OPS_RUNNING"] || action.skip_hooks?("before")
|
127
134
|
|
128
135
|
# this prevents before hooks from running in ops executed by ops
|
129
136
|
ENV["OPS_RUNNING"] = "1"
|
137
|
+
hook_handler.do_hooks("before")
|
130
138
|
end
|
131
139
|
|
132
140
|
def hook_handler
|
@@ -144,6 +152,10 @@ class Ops
|
|
144
152
|
Builtins.constants.select { |c| Builtins.const_get(c).is_a? Class }.map(&:downcase)
|
145
153
|
end
|
146
154
|
|
155
|
+
def forward
|
156
|
+
@forward ||= Forwards.new(@config, @args).get(@action_name)
|
157
|
+
end
|
158
|
+
|
147
159
|
def action
|
148
160
|
return action_list.get(@action_name) if action_list.get(@action_name)
|
149
161
|
return action_list.get_by_alias(@action_name) if action_list.get_by_alias(@action_name)
|
@@ -161,8 +173,12 @@ class Ops
|
|
161
173
|
|
162
174
|
def config
|
163
175
|
@config ||= begin
|
164
|
-
|
165
|
-
|
176
|
+
if File.exist?(CONFIG_FILE)
|
177
|
+
YAML.load_file(CONFIG_FILE)
|
178
|
+
else
|
179
|
+
Output.warn("File '#{CONFIG_FILE}' does not exist.") unless @action_name == "init"
|
180
|
+
{}
|
181
|
+
end
|
166
182
|
rescue StandardError => e
|
167
183
|
Output.warn("Error parsing '#{CONFIG_FILE}': #{e}")
|
168
184
|
{}
|
@@ -170,7 +186,7 @@ class Ops
|
|
170
186
|
end
|
171
187
|
|
172
188
|
def env_vars
|
173
|
-
|
189
|
+
config.dig("options", "environment") || {}
|
174
190
|
end
|
175
191
|
|
176
192
|
def environment
|
data/ops_team.gemspec
CHANGED
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.
|
4
|
+
version: 0.19.0
|
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: []
|
@@ -175,6 +175,8 @@ files:
|
|
175
175
|
- lib/dependency.rb
|
176
176
|
- lib/environment.rb
|
177
177
|
- lib/executor.rb
|
178
|
+
- lib/forward.rb
|
179
|
+
- lib/forwards.rb
|
178
180
|
- lib/hook_handler.rb
|
179
181
|
- lib/ops.rb
|
180
182
|
- lib/options.rb
|
@@ -187,7 +189,7 @@ homepage: https://github.com/nickthecook/ops
|
|
187
189
|
licenses:
|
188
190
|
- GPL-3.0-only
|
189
191
|
metadata: {}
|
190
|
-
post_install_message:
|
192
|
+
post_install_message:
|
191
193
|
rdoc_options: []
|
192
194
|
require_paths:
|
193
195
|
- lib
|
@@ -203,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
205
|
version: '0'
|
204
206
|
requirements: []
|
205
207
|
rubygems_version: 3.0.3
|
206
|
-
signing_key:
|
208
|
+
signing_key:
|
207
209
|
specification_version: 4
|
208
210
|
summary: ops_team handles basic operations tasks for your project, driven by YAML
|
209
211
|
config
|