prerequisites 0.1.0 → 0.2.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/README.md +9 -1
- data/lib/prerequisites.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c98d495db904f14b84415214c21e84cf757ec4835b7bcae81aa04a1e955a447
|
4
|
+
data.tar.gz: 8b6922ed872fa9b10770be6e028162fd6afff1a53abf92716c2801f586a396a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
data/lib/prerequisites.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2020-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|