ops_team 0.17.1 → 0.20.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/builtins/help.rb +15 -3
- data/lib/executor.rb +0 -9
- data/lib/forward.rb +17 -0
- data/lib/forwards.rb +18 -0
- data/lib/hook_handler.rb +8 -1
- data/lib/ops.rb +13 -1
- data/ops_team.gemspec +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '00009bd6fac219bc943c27592ee2131f110769ef2124697c91b52fcbd123a9a0'
|
4
|
+
data.tar.gz: 9f6c85c4019f6ceb777709f42ba6ebb7640039ed3db521ab15b7b4935dcf5cca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 165158ff1c590509aa9ae88211996cefcd035faf227d0c88132dc0ea4d3cc4013166b20280627b89d20f6ebcdb2371a537d7f734105118d7d45c1356744c5f62
|
7
|
+
data.tar.gz: 73378dff392b26b0da6091e24cba07e66661971469ca7e1ccc0bbdde0eee661ad7dca58a5348228061f649203864e22379a80d96722dc697d69a1e2173839856
|
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/builtins/help.rb
CHANGED
@@ -3,12 +3,15 @@
|
|
3
3
|
require 'colorize'
|
4
4
|
|
5
5
|
require 'builtin'
|
6
|
+
require 'forwards'
|
6
7
|
|
7
8
|
module Builtins
|
8
9
|
class Help < Builtin
|
10
|
+
NAME_WIDTH = 35
|
11
|
+
|
9
12
|
class << self
|
10
13
|
def description
|
11
|
-
"displays available builtins and
|
14
|
+
"displays available builtins, actions, and forwards"
|
12
15
|
end
|
13
16
|
end
|
14
17
|
|
@@ -16,15 +19,24 @@ module Builtins
|
|
16
19
|
Output.out("Builtins:")
|
17
20
|
Output.out(" #{builtins.join("\n ")}")
|
18
21
|
Output.out("")
|
22
|
+
Output.out("Forwards:")
|
23
|
+
Output.out(" #{forwards.join("\n ")}")
|
24
|
+
Output.out("")
|
19
25
|
Output.out("Actions:")
|
20
26
|
Output.out(" #{actions.join("\n ")}")
|
21
27
|
end
|
22
28
|
|
23
29
|
private
|
24
30
|
|
31
|
+
def forwards
|
32
|
+
Forwards.new(@config).forwards.map do |name, dir|
|
33
|
+
format("%<name>-#{NAME_WIDTH}s %<desc>s" , name: name.yellow, desc: "#{dir}")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
25
37
|
def builtins
|
26
38
|
builtin_class_map.map do |klass, name|
|
27
|
-
format("%<name
|
39
|
+
format("%<name>-#{NAME_WIDTH}s %<desc>s", name: name.downcase.to_s.yellow, desc: klass.description)
|
28
40
|
end
|
29
41
|
end
|
30
42
|
|
@@ -55,7 +67,7 @@ module Builtins
|
|
55
67
|
return [] unless @config["actions"]
|
56
68
|
|
57
69
|
@config["actions"].map do |name, action_config|
|
58
|
-
format("%<name
|
70
|
+
format("%<name>-#{NAME_WIDTH}s %<desc>s",
|
59
71
|
name: "#{name.yellow} #{alias_string_for(action_config)}",
|
60
72
|
desc: action_config["description"] || action_config["command"]
|
61
73
|
)
|
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,18 @@
|
|
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(forwards[name], @args) if forwards[name]
|
13
|
+
end
|
14
|
+
|
15
|
+
def forwards
|
16
|
+
@forwards ||= @config["forwards"] || {}
|
17
|
+
end
|
18
|
+
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)
|
data/ops_team.gemspec
CHANGED
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.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nickthecook@gmail.com
|
@@ -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
|