ops_team 0.1.3 → 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/bin/print_secrets +4 -0
- data/etc/terraform.template.yml +4 -1
- data/lib/action.rb +28 -3
- data/lib/builtins/env.rb +1 -3
- data/lib/builtins/helpers/dependency_handler.rb +1 -1
- data/lib/dependencies/dir.rb +24 -0
- data/lib/environment.rb +21 -0
- data/lib/ops.rb +25 -14
- data/lib/secrets.rb +48 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 869d7f0aed1186432fd6695a4e48157f2914d0b9388d692a0596b2f8c919d524
|
4
|
+
data.tar.gz: 678f918345ef55fb8ddd83819bebe1df1e0568b0032229e4e64d5c54315cf6dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 835562752850437072b3c6fc58a603dfb92fd8d34149e8280df2763a995b689f314fe2d5ace25baa84bb4c71e257aa9b88466e2a14bef1ebb334405c3f261566
|
7
|
+
data.tar.gz: 764c5b69e77aa06812e2211c3960c974e8278f03b212cc6b13308e8fd64236542ada77096b4adb61f0013f431a9ab4cceeaf01ca0c9f36e5f34d7f65a3529afb
|
data/bin/print_secrets
ADDED
data/etc/terraform.template.yml
CHANGED
data/lib/action.rb
CHANGED
@@ -1,18 +1,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'secrets'
|
4
|
+
|
3
5
|
# represents one action to be performed in the shell
|
4
6
|
# can assemble a command line from a command and args
|
5
7
|
class Action
|
6
|
-
def initialize(
|
7
|
-
@
|
8
|
+
def initialize(config, args, options)
|
9
|
+
@config = config
|
8
10
|
@args = args
|
11
|
+
@options = options
|
9
12
|
end
|
10
13
|
|
11
14
|
def run
|
15
|
+
load_secrets if load_secrets?
|
16
|
+
|
12
17
|
Kernel.exec(to_s)
|
13
18
|
end
|
14
19
|
|
15
20
|
def to_s
|
16
|
-
"#{
|
21
|
+
"#{command} #{@args.join(' ')}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def alias
|
25
|
+
@config["alias"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def command
|
29
|
+
@config["command"]
|
30
|
+
end
|
31
|
+
|
32
|
+
def load_secrets?
|
33
|
+
@config["load_secrets"]
|
34
|
+
end
|
35
|
+
|
36
|
+
def load_secrets
|
37
|
+
Secrets.new(secrets_file).load
|
38
|
+
end
|
39
|
+
|
40
|
+
def secrets_file
|
41
|
+
`echo -n #{@options&.dig("secrets", "path")}`
|
17
42
|
end
|
18
43
|
end
|
data/lib/builtins/env.rb
CHANGED
@@ -22,7 +22,7 @@ module Builtins
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def dependencies_for(type, names)
|
25
|
-
dependency_class = Dependencies.const_get(type.capitalize.to_sym)
|
25
|
+
dependency_class = Dependencies.const_get(type.capitalize.to_sym, false)
|
26
26
|
|
27
27
|
names.map { |name| dependency_class.new(name) }
|
28
28
|
rescue NameError
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dependency'
|
4
|
+
|
5
|
+
module Dependencies
|
6
|
+
class Dir < Dependency
|
7
|
+
def met?
|
8
|
+
execute("test -d #{name}")
|
9
|
+
end
|
10
|
+
|
11
|
+
def meet
|
12
|
+
execute("mkdir #{name}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def unmeet
|
16
|
+
# do nothing; we don't want to delete the directory on an `ops down`
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
def should_meet?
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/environment.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Environment
|
4
|
+
def initialize(env_hash)
|
5
|
+
@env_hash = env_hash
|
6
|
+
end
|
7
|
+
|
8
|
+
def set_variables
|
9
|
+
@env_hash.each do |key, value|
|
10
|
+
ENV[key] = value
|
11
|
+
end
|
12
|
+
|
13
|
+
ENV['environment'] = environment
|
14
|
+
end
|
15
|
+
|
16
|
+
def environment
|
17
|
+
return 'dev' if ENV['environment'].nil? || ENV['environment'].empty?
|
18
|
+
|
19
|
+
ENV['environment']
|
20
|
+
end
|
21
|
+
end
|
data/lib/ops.rb
CHANGED
@@ -7,9 +7,10 @@ require 'require_all'
|
|
7
7
|
require 'action'
|
8
8
|
require 'output'
|
9
9
|
require 'options'
|
10
|
+
require 'environment'
|
10
11
|
require_rel "builtins"
|
11
12
|
|
12
|
-
# executes commands
|
13
|
+
# executes commands based on local `ops.yml`
|
13
14
|
class Ops
|
14
15
|
class UnknownActionError < StandardError; end
|
15
16
|
|
@@ -27,6 +28,8 @@ class Ops
|
|
27
28
|
def run
|
28
29
|
exit(INVALID_SYNTAX_EXIT_CODE) unless syntax_valid?
|
29
30
|
|
31
|
+
environment.set_variables
|
32
|
+
|
30
33
|
return builtin.run if builtin
|
31
34
|
|
32
35
|
Output.warn("Running '#{action}' from #{CONFIG_FILE}...")
|
@@ -48,7 +51,7 @@ class Ops
|
|
48
51
|
end
|
49
52
|
|
50
53
|
def builtin
|
51
|
-
@builtin ||= Builtins.const_get(builtin_class_name).new(@args, config)
|
54
|
+
@builtin ||= Builtins.const_get(builtin_class_name, false).new(@args, config)
|
52
55
|
rescue NameError
|
53
56
|
# this means there isn't a builtin with that name in that module
|
54
57
|
nil
|
@@ -59,20 +62,16 @@ class Ops
|
|
59
62
|
end
|
60
63
|
|
61
64
|
def action
|
62
|
-
@
|
63
|
-
|
64
|
-
|
65
|
-
def command
|
66
|
-
@command ||= begin
|
67
|
-
return actions[@action_name]["command"] if actions[@action_name]
|
68
|
-
return aliases[@action_name]["command"] if aliases[@action_name]
|
65
|
+
return actions[@action_name] if actions[@action_name]
|
66
|
+
return aliases[@action_name] if aliases[@action_name]
|
69
67
|
|
70
|
-
|
71
|
-
end
|
68
|
+
raise UnknownActionError, "Unknown action: #{@action_name}"
|
72
69
|
end
|
73
70
|
|
74
71
|
def actions
|
75
|
-
config["actions"]
|
72
|
+
config["actions"].transform_values do |config|
|
73
|
+
Action.new(config, @args, action_options)
|
74
|
+
end
|
76
75
|
end
|
77
76
|
|
78
77
|
def config
|
@@ -86,11 +85,23 @@ class Ops
|
|
86
85
|
|
87
86
|
def aliases
|
88
87
|
@aliases ||= begin
|
89
|
-
actions.each_with_object({}) do |(_name,
|
90
|
-
alias_hash[
|
88
|
+
actions.each_with_object({}) do |(_name, action), alias_hash|
|
89
|
+
alias_hash[action.alias] = action if action.alias
|
91
90
|
end
|
92
91
|
end
|
93
92
|
end
|
93
|
+
|
94
|
+
def action_options
|
95
|
+
@action_options ||= @config.dig("options", "actions")
|
96
|
+
end
|
97
|
+
|
98
|
+
def env_vars
|
99
|
+
@config.dig("options", "environment") || {}
|
100
|
+
end
|
101
|
+
|
102
|
+
def environment
|
103
|
+
@environment ||= Environment.new(env_vars)
|
104
|
+
end
|
94
105
|
end
|
95
106
|
|
96
107
|
Ops.new(ARGV).run if $PROGRAM_NAME == __FILE__
|
data/lib/secrets.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
require 'output'
|
6
|
+
|
7
|
+
class Secrets
|
8
|
+
def initialize(filename = "")
|
9
|
+
@filename = filename.empty? ? default_filename : filename
|
10
|
+
end
|
11
|
+
|
12
|
+
def load
|
13
|
+
secrets['environment']&.each do |key, value|
|
14
|
+
ENV[key] = value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def default_filename
|
21
|
+
return default_ejson_filename if File.exist?(default_ejson_filename)
|
22
|
+
|
23
|
+
default_json_filename
|
24
|
+
end
|
25
|
+
|
26
|
+
def default_ejson_filename
|
27
|
+
"config/#{environment}/secrets.ejson"
|
28
|
+
end
|
29
|
+
|
30
|
+
def default_json_filename
|
31
|
+
"config/#{environment}/secrets.json"
|
32
|
+
end
|
33
|
+
|
34
|
+
def secrets
|
35
|
+
@secrets ||= JSON.parse(file_contents)
|
36
|
+
rescue JSON::ParserError => e
|
37
|
+
Output.error("Error parsing secrets data: #{e}")
|
38
|
+
{}
|
39
|
+
end
|
40
|
+
|
41
|
+
def file_contents
|
42
|
+
@filename.match(/\.ejson$/) ? `ejson decrypt #{@filename}` : File.open(@filename).read
|
43
|
+
end
|
44
|
+
|
45
|
+
def environment
|
46
|
+
ENV['environment']
|
47
|
+
end
|
48
|
+
end
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nickthecook@gmail.com
|
@@ -59,6 +59,7 @@ extra_rdoc_files: []
|
|
59
59
|
files:
|
60
60
|
- Gemfile
|
61
61
|
- bin/ops
|
62
|
+
- bin/print_secrets
|
62
63
|
- bin/tag
|
63
64
|
- etc/ops.template.yml
|
64
65
|
- etc/ruby.template.yml
|
@@ -75,13 +76,16 @@ files:
|
|
75
76
|
- lib/dependencies/brew.rb
|
76
77
|
- lib/dependencies/cask.rb
|
77
78
|
- lib/dependencies/custom.rb
|
79
|
+
- lib/dependencies/dir.rb
|
78
80
|
- lib/dependencies/docker.rb
|
79
81
|
- lib/dependencies/gem.rb
|
80
82
|
- lib/dependencies/terraform.rb
|
81
83
|
- lib/dependency.rb
|
84
|
+
- lib/environment.rb
|
82
85
|
- lib/ops.rb
|
83
86
|
- lib/options.rb
|
84
87
|
- lib/output.rb
|
88
|
+
- lib/secrets.rb
|
85
89
|
- loader.rb
|
86
90
|
homepage: https://github.com/nickthecook/ops
|
87
91
|
licenses:
|
@@ -95,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
99
|
requirements:
|
96
100
|
- - "~>"
|
97
101
|
- !ruby/object:Gem::Version
|
98
|
-
version: '2.
|
102
|
+
version: '2.5'
|
99
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
104
|
requirements:
|
101
105
|
- - ">="
|