ops_team 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af22f3dad0669e5cae68bc2bfbe6f8c2e7227bc11d74a4295d59c9e7fa4ea79e
4
- data.tar.gz: bed9b0448b2b2051d6e2d817f7f48bab44c1b901d5586b157d81491bdd0dd2a2
3
+ metadata.gz: 869d7f0aed1186432fd6695a4e48157f2914d0b9388d692a0596b2f8c919d524
4
+ data.tar.gz: 678f918345ef55fb8ddd83819bebe1df1e0568b0032229e4e64d5c54315cf6dd
5
5
  SHA512:
6
- metadata.gz: f46ef6fb3cdc4fb430405b73d7f1c9c0f0261fe313d7ff02275b2ea1a31be6c3283cb3c232fd601af34c852ba3ae3eb4ceb00f7db2253a519d92ca8e01413a55
7
- data.tar.gz: 1462ee358b52b81e48526bb276723eb2f9fce3e16d8ee72089182544606c2e8501d045af0505e10a09e6527317ebd729eaa71042bebbc533521ae379f2a92f13
6
+ metadata.gz: 835562752850437072b3c6fc58a603dfb92fd8d34149e8280df2763a995b689f314fe2d5ace25baa84bb4c71e257aa9b88466e2a14bef1ebb334405c3f261566
7
+ data.tar.gz: 764c5b69e77aa06812e2211c3960c974e8278f03b212cc6b13308e8fd64236542ada77096b4adb61f0013f431a9ab4cceeaf01ca0c9f36e5f34d7f65a3529afb
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+
3
+ echo "$SECRET1"
4
+ echo "$SECRET2"
@@ -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(command, args)
7
- @command = command
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
- "#{@command} #{@args.join(' ')}"
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
@@ -9,8 +9,6 @@ module Builtins
9
9
  Output.print(environment)
10
10
  end
11
11
 
12
- private
13
-
14
12
  def environment
15
13
  ENV['environment']
16
14
  end
@@ -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 defined in local `ops.yml`
13
+ # executes commands based on local `ops.yml`
13
14
  class Ops
14
15
  class UnknownActionError < StandardError; end
15
16
 
@@ -27,7 +28,7 @@ class Ops
27
28
  def run
28
29
  exit(INVALID_SYNTAX_EXIT_CODE) unless syntax_valid?
29
30
 
30
- ENV['environment'] ||= 'dev'
31
+ environment.set_variables
31
32
 
32
33
  return builtin.run if builtin
33
34
 
@@ -61,20 +62,16 @@ class Ops
61
62
  end
62
63
 
63
64
  def action
64
- @action ||= Action.new(command, @args)
65
- end
66
-
67
- def command
68
- @command ||= begin
69
- return actions[@action_name]["command"] if actions[@action_name]
70
- 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]
71
67
 
72
- raise UnknownActionError, "Unknown action: #{@action_name}"
73
- end
68
+ raise UnknownActionError, "Unknown action: #{@action_name}"
74
69
  end
75
70
 
76
71
  def actions
77
- config["actions"]
72
+ config["actions"].transform_values do |config|
73
+ Action.new(config, @args, action_options)
74
+ end
78
75
  end
79
76
 
80
77
  def config
@@ -88,11 +85,23 @@ class Ops
88
85
 
89
86
  def aliases
90
87
  @aliases ||= begin
91
- actions.each_with_object({}) do |(_name, body), alias_hash|
92
- alias_hash[body["alias"]] = body if body.include?("alias")
88
+ actions.each_with_object({}) do |(_name, action), alias_hash|
89
+ alias_hash[action.alias] = action if action.alias
93
90
  end
94
91
  end
95
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
96
105
  end
97
106
 
98
107
  Ops.new(ARGV).run if $PROGRAM_NAME == __FILE__
@@ -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.1.7
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
@@ -80,9 +81,11 @@ files:
80
81
  - lib/dependencies/gem.rb
81
82
  - lib/dependencies/terraform.rb
82
83
  - lib/dependency.rb
84
+ - lib/environment.rb
83
85
  - lib/ops.rb
84
86
  - lib/options.rb
85
87
  - lib/output.rb
88
+ - lib/secrets.rb
86
89
  - loader.rb
87
90
  homepage: https://github.com/nickthecook/ops
88
91
  licenses: