ops_team 0.2.4 → 0.2.9
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/etc/terraform.template.yml +2 -2
- data/lib/action.rb +2 -11
- data/lib/app_config.rb +1 -1
- data/lib/builtins/exec.rb +21 -0
- data/lib/ops.rb +16 -14
- data/lib/secrets.rb +13 -0
- data/ops_team.gemspec +1 -1
- metadata +2 -2
- data/lib/dependencies/terraform.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5c2fa7f06155a753554402aa2063aec1bf192aa171a6c2e601619ee6f80e148
|
4
|
+
data.tar.gz: ca9c1bcde247a55ad469e423f5bde3a1ba3a85ad51694b519622e6a572304afc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7baea51515c766fd4409382b91560dd21948b95470d62fad73a6f23c3b58d92a0a0030d55c95dd7de6dfeb0fed73f6b35f7728419da1ca9962598873440cccf3
|
7
|
+
data.tar.gz: c544f035850f131ff02882cf88196f4fc62ab91dc4142ce292cf10531f685415ad349aeaabd52e26f988932eba9fc02888a820502e7efff6fde8478cecfc1941
|
data/etc/terraform.template.yml
CHANGED
@@ -11,7 +11,7 @@ actions:
|
|
11
11
|
alias: a
|
12
12
|
description: runs 'terraform apply'
|
13
13
|
apply-auto-approve:
|
14
|
-
command:
|
14
|
+
command: ops apply --auto-approve
|
15
15
|
alias: aa
|
16
16
|
description: runs 'terraform apply' with auto-approve
|
17
17
|
destroy:
|
@@ -19,7 +19,7 @@ actions:
|
|
19
19
|
alias: d
|
20
20
|
description: runs 'terraform destroy'
|
21
21
|
destroy-auto-approve:
|
22
|
-
command:
|
22
|
+
command: ops destroy --auto-approve
|
23
23
|
alias: dd
|
24
24
|
description: runs 'terraform destroy' with auto-approve
|
25
25
|
plan:
|
data/lib/action.rb
CHANGED
@@ -5,14 +5,13 @@ 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
|
-
def initialize(config, args
|
8
|
+
def initialize(config, args)
|
9
9
|
@config = config
|
10
10
|
@args = args
|
11
|
-
@options = options
|
12
11
|
end
|
13
12
|
|
14
13
|
def run
|
15
|
-
|
14
|
+
Secrets.load if load_secrets?
|
16
15
|
|
17
16
|
Kernel.exec(to_s)
|
18
17
|
end
|
@@ -38,12 +37,4 @@ class Action
|
|
38
37
|
def load_secrets?
|
39
38
|
@config["load_secrets"]
|
40
39
|
end
|
41
|
-
|
42
|
-
def load_secrets
|
43
|
-
Secrets.new(secrets_file).load
|
44
|
-
end
|
45
|
-
|
46
|
-
def secrets_file
|
47
|
-
`echo #{@options&.dig("secrets", "path")}`.chomp
|
48
|
-
end
|
49
40
|
end
|
data/lib/app_config.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'builtin'
|
4
|
+
require 'output'
|
5
|
+
require 'secrets'
|
6
|
+
require 'options'
|
7
|
+
|
8
|
+
module Builtins
|
9
|
+
class Exec < Builtin
|
10
|
+
class << self
|
11
|
+
def description
|
12
|
+
"executes the given command in the `ops` environment, i.e. with environment variables set"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
Secrets.load if Options.get("exec.load_secrets")
|
18
|
+
Kernel.exec(@args.join(" "))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/ops.rb
CHANGED
@@ -16,7 +16,8 @@ class Ops
|
|
16
16
|
|
17
17
|
CONFIG_FILE = "ops.yml"
|
18
18
|
|
19
|
-
INVALID_SYNTAX_EXIT_CODE =
|
19
|
+
INVALID_SYNTAX_EXIT_CODE = 64
|
20
|
+
UNKNOWN_ACTION_EXIT_CODE = 65
|
20
21
|
|
21
22
|
def initialize(argv)
|
22
23
|
@action_name = argv[0]
|
@@ -28,15 +29,10 @@ class Ops
|
|
28
29
|
def run
|
29
30
|
exit(INVALID_SYNTAX_EXIT_CODE) unless syntax_valid?
|
30
31
|
|
31
|
-
|
32
|
-
app_config.load
|
33
|
-
|
34
|
-
return builtin.run if builtin
|
35
|
-
|
36
|
-
Output.warn("Running '#{action}' from #{CONFIG_FILE}...")
|
37
|
-
action.run
|
32
|
+
run_action
|
38
33
|
rescue UnknownActionError => e
|
39
34
|
Output.error("Error: #{e}")
|
35
|
+
exit(UNKNOWN_ACTION_EXIT_CODE)
|
40
36
|
end
|
41
37
|
|
42
38
|
private
|
@@ -51,6 +47,16 @@ class Ops
|
|
51
47
|
end
|
52
48
|
end
|
53
49
|
|
50
|
+
def run_action
|
51
|
+
environment.set_variables
|
52
|
+
app_config.load
|
53
|
+
|
54
|
+
return builtin.run if builtin
|
55
|
+
|
56
|
+
Output.warn("Running '#{action}' from #{CONFIG_FILE}...")
|
57
|
+
action.run
|
58
|
+
end
|
59
|
+
|
54
60
|
def builtin
|
55
61
|
@builtin ||= Builtins.const_get(builtin_class_name, false).new(@args, config)
|
56
62
|
rescue NameError
|
@@ -71,7 +77,7 @@ class Ops
|
|
71
77
|
|
72
78
|
def actions
|
73
79
|
config["actions"].transform_values do |config|
|
74
|
-
Action.new(config, @args
|
80
|
+
Action.new(config, @args)
|
75
81
|
end
|
76
82
|
end
|
77
83
|
|
@@ -92,10 +98,6 @@ class Ops
|
|
92
98
|
end
|
93
99
|
end
|
94
100
|
|
95
|
-
def action_options
|
96
|
-
@action_options ||= @config.dig("options", "actions")
|
97
|
-
end
|
98
|
-
|
99
101
|
def env_vars
|
100
102
|
@config.dig("options", "environment") || {}
|
101
103
|
end
|
@@ -105,7 +107,7 @@ class Ops
|
|
105
107
|
end
|
106
108
|
|
107
109
|
def app_config_file
|
108
|
-
`echo #{
|
110
|
+
`echo #{Options.get("config.path")}`.chomp
|
109
111
|
end
|
110
112
|
|
111
113
|
def app_config
|
data/lib/secrets.rb
CHANGED
@@ -4,8 +4,21 @@ require 'json'
|
|
4
4
|
|
5
5
|
require 'output'
|
6
6
|
require 'app_config'
|
7
|
+
require 'options'
|
7
8
|
|
8
9
|
class Secrets < AppConfig
|
10
|
+
class << self
|
11
|
+
def load
|
12
|
+
Secrets.new(expand_path(Options.get("secrets.path"))).load
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def expand_path(path)
|
18
|
+
`echo #{path}`.chomp
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
9
22
|
private
|
10
23
|
|
11
24
|
def default_filename
|
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.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nickthecook@gmail.com
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- lib/builtin.rb
|
71
71
|
- lib/builtins/down.rb
|
72
72
|
- lib/builtins/env.rb
|
73
|
+
- lib/builtins/exec.rb
|
73
74
|
- lib/builtins/help.rb
|
74
75
|
- lib/builtins/helpers/dependency_handler.rb
|
75
76
|
- lib/builtins/init.rb
|
@@ -83,7 +84,6 @@ files:
|
|
83
84
|
- lib/dependencies/dir.rb
|
84
85
|
- lib/dependencies/docker.rb
|
85
86
|
- lib/dependencies/gem.rb
|
86
|
-
- lib/dependencies/terraform.rb
|
87
87
|
- lib/dependency.rb
|
88
88
|
- lib/environment.rb
|
89
89
|
- lib/ops.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'dependency'
|
4
|
-
|
5
|
-
module Dependencies
|
6
|
-
class Terraform < Dependency
|
7
|
-
def met?
|
8
|
-
false
|
9
|
-
end
|
10
|
-
|
11
|
-
def always_act?
|
12
|
-
true
|
13
|
-
end
|
14
|
-
|
15
|
-
def meet
|
16
|
-
execute("cd #{name} && terraform init && terraform apply -input=false --auto-approve")
|
17
|
-
end
|
18
|
-
|
19
|
-
def unmeet
|
20
|
-
execute("cd #{name} && terraform destroy -input=false --auto-approve")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|