prerequisites 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -1
  3. data/lib/prerequisites.rb +16 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8ff637be0e81f14cf0f706d1fa4c9ec7fa3ae9959fa96212b20153365049863
4
- data.tar.gz: a3b75123ad34c9faf976a2f762fc2eb8b4b0f4d298d31b40d6e585aee355d932
3
+ metadata.gz: 5c98d495db904f14b84415214c21e84cf757ec4835b7bcae81aa04a1e955a447
4
+ data.tar.gz: 8b6922ed872fa9b10770be6e028162fd6afff1a53abf92716c2801f586a396a6
5
5
  SHA512:
6
- metadata.gz: 869c46534e715fc19e9369c5a8fcb438f3a716b1574285b1990e87136f7f8130e9485d76098229a769bdbbd44808da27f57c387e65fdb8fc392aad64fd2d4550
7
- data.tar.gz: 2fb73fb4bf3306abe07e9712821158b8ba92e0b46bbfb25ab2fac8b69372bc6e828fa7d2d75a21f5e49f585b058199fa40a90bf1b41ccee390daeed5d3e73851
6
+ metadata.gz: aefdf61eb481eb6870cc23b4ab2881af6ccdf5d815a098b05ec8c9f5b877e2f2a7539849050db4a1e75b897f2a74ccc47484337e2c9ae4b0e7da75d1b8bd9584
7
+ data.tar.gz: 79ef2d6c736705b85fe21b0607020f745d79050a37a60d131a445bb02f467c503720db9fc847f315be05ca912b17d0cab30a75a93dc251ade800d5e9e8c2946b
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A ruby gem to make it easy to test that a set of prerequisite conditions are in place.
4
4
 
5
- This is particularly useful when using ruby as 'glue' code for sysadmin or other tasks.
5
+ This can be useful when using ruby as 'glue' code for sysadmin or other tasks.
6
6
 
7
7
  ## Installation
8
8
 
@@ -23,6 +23,9 @@ This example checks that:
23
23
  * Environment variables "FOO" and "BAR" are set
24
24
  * Environment variable "BAZ" is set to the value "whatever"
25
25
  * Executables "grep", "git", and "kubectl" are in your $PATH
26
+ * The shell commands execute successfully
27
+
28
+ > NB: You should ensure that any commands you list in the `shell_commands` section have no side-effects. These are supposed to be pre-flight checks.
26
29
 
27
30
  ```
28
31
  config = {
@@ -35,6 +38,10 @@ config = {
35
38
  "grep",
36
39
  "git",
37
40
  "kubectl"
41
+ ],
42
+ shell_commands: [
43
+ "echo whatever | grep what",
44
+ "kubectl config current-context | grep myk8scluster"
38
45
  ]
39
46
  }
40
47
 
@@ -45,5 +52,6 @@ If any of these conditions are not met, the code will raise an error of class:
45
52
 
46
53
  * Prerequisites::EnvironmentVariableError
47
54
  * Prerequisites::ExecutableError
55
+ * Prerequisites::ShellCommandError
48
56
 
49
57
  ...depending on the problem.
@@ -10,6 +10,7 @@ class Prerequisites
10
10
  def check
11
11
  environment_variables
12
12
  executables_in_path
13
+ shell_commands
13
14
  end
14
15
 
15
16
  private
@@ -35,6 +36,20 @@ class Prerequisites
35
36
  true
36
37
  end
37
38
 
39
+ def shell_commands
40
+ config.dig(:shell_commands).to_a.each do |cmd|
41
+ _, _, status = Open3.capture3(cmd)
42
+
43
+ unless status.success?
44
+ raise Prerequisites::ShellCommandError.new(
45
+ "Shell command check failed: #{cmd}"
46
+ )
47
+ end
48
+ end
49
+
50
+ true
51
+ end
52
+
38
53
  def check_env_var_is_set(env_var)
39
54
  unless ENV.key?(env_var)
40
55
  raise Prerequisites::EnvironmentVariableError.new(
@@ -64,3 +79,4 @@ end
64
79
 
65
80
  class Prerequisites::EnvironmentVariableError < RuntimeError; end
66
81
  class Prerequisites::ExecutableError < RuntimeError; end
82
+ class Prerequisites::ShellCommandError < RuntimeError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prerequisites
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Salgado
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-22 00:00:00.000000000 Z
11
+ date: 2020-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec