ops_team 1.7.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/action.rb +17 -12
- data/lib/action_list.rb +1 -1
- data/lib/builtins/down.rb +7 -1
- data/lib/dependencies/custom.rb +32 -4
- data/lib/ops.rb +1 -1
- data/lib/runner.rb +17 -2
- data/ops_team.gemspec +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21ea800cf1d407a6b9e372b422ac29ae6e7ace9597e55181aaef981290382dca
|
4
|
+
data.tar.gz: 37f00565ecdcfa789df0022a83352966e2c54080979321d82baaa2a0e99868aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f5a443b2cc90a6d390a4f8f8805e1ab7236af5a04921177569ae8f64d7288295a83823606cbbc4402be419152a1ae2072e7704b846ee2653191d86bcb2be4ef
|
7
|
+
data.tar.gz: af770963d44d9eca6140d033626751143de5561625fb4180906350eeb0b6c36391c0193267e7ed32c37ce0f47ccc70a332561ed011ccf126538c04badc543146
|
data/lib/action.rb
CHANGED
@@ -5,18 +5,15 @@ 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
|
-
|
8
|
+
attr_reader :name
|
9
9
|
|
10
|
-
def initialize(config, args)
|
10
|
+
def initialize(name, config, args)
|
11
|
+
@name = name
|
11
12
|
@config = config
|
12
13
|
@args = args
|
13
14
|
end
|
14
15
|
|
15
16
|
def run
|
16
|
-
unless allowed_in_current_env?
|
17
|
-
raise NotAllowedInEnvError, "Action not allowed in #{Environment.environment} environment."
|
18
|
-
end
|
19
|
-
|
20
17
|
if perform_shell_expansion?
|
21
18
|
Kernel.exec(to_s)
|
22
19
|
else
|
@@ -62,6 +59,18 @@ class Action
|
|
62
59
|
@config["load_secrets"].nil? ? false : @config["load_secrets"]
|
63
60
|
end
|
64
61
|
|
62
|
+
def execute_in_env?(env)
|
63
|
+
!skip_in_envs.include?(env)
|
64
|
+
end
|
65
|
+
|
66
|
+
def allowed_in_env?(env)
|
67
|
+
return false if not_in_envs.include?(env)
|
68
|
+
|
69
|
+
return false if in_envs.any? && !in_envs.include?(env)
|
70
|
+
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
65
74
|
private
|
66
75
|
|
67
76
|
def to_a
|
@@ -76,12 +85,8 @@ class Action
|
|
76
85
|
@config["in_envs"] || []
|
77
86
|
end
|
78
87
|
|
79
|
-
def
|
80
|
-
|
81
|
-
|
82
|
-
return false if in_envs.any? && !in_envs.include?(Environment.environment)
|
83
|
-
|
84
|
-
true
|
88
|
+
def skip_in_envs
|
89
|
+
@config["skip_in_envs"] || []
|
85
90
|
end
|
86
91
|
|
87
92
|
def perform_shell_expansion?
|
data/lib/action_list.rb
CHANGED
data/lib/builtins/down.rb
CHANGED
@@ -22,7 +22,7 @@ module Builtins
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def dependency_handler
|
25
|
-
Helpers::DependencyHandler.new(
|
25
|
+
Helpers::DependencyHandler.new(deps_to_meet)
|
26
26
|
end
|
27
27
|
|
28
28
|
def unmeet_dependencies
|
@@ -48,5 +48,11 @@ module Builtins
|
|
48
48
|
Output.out(dependency.output)
|
49
49
|
end
|
50
50
|
end
|
51
|
+
|
52
|
+
def deps_to_meet
|
53
|
+
return @config["dependencies"] if @args.empty?
|
54
|
+
|
55
|
+
return @config["dependencies"].select { |dep, names| @args.include?(dep) }
|
56
|
+
end
|
51
57
|
end
|
52
58
|
end
|
data/lib/dependencies/custom.rb
CHANGED
@@ -4,18 +4,46 @@ require 'dependency'
|
|
4
4
|
|
5
5
|
module Dependencies
|
6
6
|
class Custom < Dependency
|
7
|
+
class CustomConfigError < StandardError; end
|
8
|
+
|
9
|
+
def initialize(definition)
|
10
|
+
super
|
11
|
+
@definition = definition
|
12
|
+
@name, @config = parse_definition
|
13
|
+
end
|
14
|
+
|
7
15
|
def met?
|
8
|
-
# we always want to try to meet this dependency
|
9
16
|
false
|
10
17
|
end
|
11
18
|
|
19
|
+
def always_act?
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
12
23
|
def meet
|
13
|
-
|
14
|
-
execute(name)
|
24
|
+
execute(up_command) if up_command
|
15
25
|
end
|
16
26
|
|
17
27
|
def unmeet
|
18
|
-
|
28
|
+
execute(down_command) if down_command
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def up_command
|
34
|
+
@up_command ||= @definition.is_a?(Hash) ? @config&.dig("up") : name
|
35
|
+
end
|
36
|
+
|
37
|
+
def down_command
|
38
|
+
@down_command ||= @config && @config&.dig("down") || nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_definition
|
42
|
+
return @definition, {} if @definition.is_a?(String)
|
43
|
+
return @definition.first if @definition.is_a?(Hash)
|
44
|
+
|
45
|
+
raise CustomConfigError, "Expected custom dependency @definition '#{@definition}' " \
|
46
|
+
"to be a String or a Hash; received #{@definition.class}."
|
19
47
|
end
|
20
48
|
end
|
21
49
|
end
|
data/lib/ops.rb
CHANGED
@@ -59,7 +59,7 @@ class Ops
|
|
59
59
|
rescue AppConfig::ParsingError => e
|
60
60
|
Output.error("Error parsing app config: #{e}")
|
61
61
|
exit(ERROR_LOADING_APP_CONFIG_EXIT_CODE)
|
62
|
-
rescue
|
62
|
+
rescue Runner::NotAllowedInEnvError => e
|
63
63
|
Output.error("Error running action #{@action_name}: #{e}")
|
64
64
|
exit(ACTION_NOT_ALLOWED_IN_ENV_EXIT_CODE)
|
65
65
|
end
|
data/lib/runner.rb
CHANGED
@@ -10,6 +10,7 @@ require 'environment'
|
|
10
10
|
class Runner
|
11
11
|
class UnknownActionError < StandardError; end
|
12
12
|
class ActionConfigError < StandardError; end
|
13
|
+
class NotAllowedInEnvError < StandardError; end
|
13
14
|
|
14
15
|
def initialize(action_name, args, config, config_path)
|
15
16
|
@action_name = action_name
|
@@ -29,8 +30,8 @@ class Runner
|
|
29
30
|
raise ActionConfigError, action.config_errors.join("; ") unless action.config_valid?
|
30
31
|
|
31
32
|
do_before_action
|
32
|
-
|
33
|
-
|
33
|
+
|
34
|
+
run_action
|
34
35
|
end
|
35
36
|
|
36
37
|
def suggestions
|
@@ -72,6 +73,20 @@ class Runner
|
|
72
73
|
@forward ||= Forwards.new(@config, @args).get(@action_name)
|
73
74
|
end
|
74
75
|
|
76
|
+
def run_action
|
77
|
+
unless action.allowed_in_env?(Environment.environment)
|
78
|
+
raise NotAllowedInEnvError, "Action not allowed in #{Environment.environment} environment."
|
79
|
+
end
|
80
|
+
|
81
|
+
unless action.execute_in_env?(Environment.environment)
|
82
|
+
Output.warn("Skipping action '#{action.name}' in environment #{Environment.environment}.")
|
83
|
+
return true
|
84
|
+
end
|
85
|
+
|
86
|
+
Output.notice("Running '#{action}' in environment '#{ENV['environment']}'...")
|
87
|
+
action.run
|
88
|
+
end
|
89
|
+
|
75
90
|
def action
|
76
91
|
return action_list.get(@action_name) if action_list.get(@action_name)
|
77
92
|
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: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nickthecook@gmail.com
|
@@ -114,22 +114,22 @@ dependencies:
|
|
114
114
|
name: net-ssh
|
115
115
|
requirement: !ruby/object:Gem::Requirement
|
116
116
|
requirements:
|
117
|
-
- - "~>"
|
118
|
-
- !ruby/object:Gem::Version
|
119
|
-
version: '6.1'
|
120
117
|
- - ">="
|
121
118
|
- !ruby/object:Gem::Version
|
122
119
|
version: 6.1.0
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '6.1'
|
123
123
|
type: :runtime
|
124
124
|
prerelease: false
|
125
125
|
version_requirements: !ruby/object:Gem::Requirement
|
126
126
|
requirements:
|
127
|
-
- - "~>"
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
version: '6.1'
|
130
127
|
- - ">="
|
131
128
|
- !ruby/object:Gem::Version
|
132
129
|
version: 6.1.0
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '6.1'
|
133
133
|
- !ruby/object:Gem::Dependency
|
134
134
|
name: require_all
|
135
135
|
requirement: !ruby/object:Gem::Requirement
|
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
227
|
- !ruby/object:Gem::Version
|
228
228
|
version: '0'
|
229
229
|
requirements: []
|
230
|
-
rubygems_version: 3.
|
230
|
+
rubygems_version: 3.0.3.1
|
231
231
|
signing_key:
|
232
232
|
specification_version: 4
|
233
233
|
summary: ops_team handles basic automation for your project, driven by self-documenting
|