ops_team 0.17.1 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/action.rb +22 -0
  3. data/lib/ops.rb +4 -0
  4. data/ops_team.gemspec +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a18acecc72ca3ac11486856bf71b2c082d81e3dfa65931141c20c1bb4ec8bc5
4
- data.tar.gz: 852ea38c8598ca1ed3d806b3f5a334cd191e6484827f7141a265d1324c15fe9d
3
+ metadata.gz: 1fe720771051eb12c4f6786c7a9409d8e2ab01e592abb7959349ceba74f47eed
4
+ data.tar.gz: d2fdd069587db893f74d599abf875d15dcad4a09c19b94169496527ba462c77f
5
5
  SHA512:
6
- metadata.gz: 19c70546affd151d331225af93e807acd07c536eca7f4369a2c36df4961cae845cd0adea9eb7446041d6e45e66a82cd5980f8a5f979393fccf0538406dbc4100
7
- data.tar.gz: 471c92c6afd006c0073be40773a568823e37f8795ef74f8aa76e54a4b22a47208187af34274ebe54044d5b59f4f41036621893570f79eab41a035694b771198e
6
+ metadata.gz: 48f067fd6e9379a1b40830defed7652301786020310137c1be4349e8abb5ab45eae478084b6614d807e10db6738531fb1f169c44146445fed77c1b517eabdba5
7
+ data.tar.gz: 32d83b0e2cf94f4178f577b3fbc2b9d232bd10f1de3370f5d516fac9e98f86abe1401749428a486c1f436d0d4646ad332f88701e889ac75764e432978f634000
@@ -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/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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '0.17.1'
5
+ s.version = '0.18.0'
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.17.1
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nickthecook@gmail.com