ops_team 0.2.3 → 0.2.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3df06362d31ad96870848712991804c147d63f780395587ea7237eacabfbb683
4
- data.tar.gz: d125dfaa4423fa07eae13672f5c045f064b084f2c7c05db3e76ab5088b92f410
3
+ metadata.gz: 2ed40f82a2c6312381a243ea6ccbfc12ba46f1742af6a8935a2c59d7fcb783f9
4
+ data.tar.gz: 65ec586f9adb40be64e31f5d581845efc8cc303548b4eea8b7d4b5f6620ae8f1
5
5
  SHA512:
6
- metadata.gz: 8e7f27173645a685d1146c9a8e73565c9cee017e0bdeb834db0258f17b4e9d655d2f19949b386f4b401818ef37d45e4c3552c31b19571c580de0f6c60b3d4638
7
- data.tar.gz: 6f5e9398f184381b503cf579b7e8468db32a5ce9707b6f6818b9f55b6fba94054a96fbfa6d99fc7b0bce0159f63fbf92f53506712fafebe925622753b143eae1
6
+ metadata.gz: 333c1446f7b2d59f33dda51e29f918d8fe2d54d79f60310d952bbf538dad5ae93c0aa8503fe5af1ed4ba964b336514d21a6d7b6e13948539710bccb259fe2a36
7
+ data.tar.gz: dac43c177bb4681f3a66a418175c52bd93af2974793400b8db018385fe7abf5743ad89d1ba0398d0ed3cde39b9d68b56dc1919e664621a2366c77e479ef9e100
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+
3
+ echo $KEY1
4
+ echo $KEY2
@@ -11,7 +11,7 @@ actions:
11
11
  alias: a
12
12
  description: runs 'terraform apply'
13
13
  apply-auto-approve:
14
- command: terraform apply --auto-approve
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: terraform destroy --auto-approve
22
+ command: ops destroy --auto-approve
23
23
  alias: dd
24
24
  description: runs 'terraform destroy' with auto-approve
25
25
  plan:
@@ -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, options)
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
- load_secrets if load_secrets?
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 -n #{@options&.dig("secrets", "path")}`
48
- end
49
40
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AppConfig
4
+ def initialize(filename = "")
5
+ @filename = filename.empty? ? default_filename : filename
6
+ end
7
+
8
+ def load
9
+ config['environment']&.each do |key, value|
10
+ ENV[key] = value.to_s
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def default_filename
17
+ "config/#{environment}/config.json"
18
+ end
19
+
20
+ def config
21
+ @config ||= file_contents ? JSON.parse(file_contents) : {}
22
+ rescue JSON::ParserError => e
23
+ Output.error("Error parsing config data: #{e}")
24
+ {}
25
+ end
26
+
27
+ def file_contents
28
+ @file_contents ||= begin
29
+ File.open(@filename).read
30
+ rescue Errno::ENOENT
31
+ nil
32
+ end
33
+ end
34
+
35
+ def environment
36
+ ENV['environment']
37
+ end
38
+ end
@@ -45,7 +45,7 @@ module Builtins
45
45
  else
46
46
  Output.failed
47
47
  Output.error("Error unmeeting #{dependency.type} dependency '#{dependency.name}':")
48
- puts(dependency.output)
48
+ Output.out(dependency.output)
49
49
  end
50
50
  end
51
51
  end
@@ -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
@@ -46,7 +46,7 @@ module Builtins
46
46
  else
47
47
  Output.failed
48
48
  Output.error("Error meeting #{dependency.type} dependency '#{dependency.name}':")
49
- puts(dependency.output)
49
+ Output.out(dependency.output)
50
50
  end
51
51
  end
52
52
  end
data/lib/ops.rb CHANGED
@@ -29,6 +29,7 @@ class Ops
29
29
  exit(INVALID_SYNTAX_EXIT_CODE) unless syntax_valid?
30
30
 
31
31
  environment.set_variables
32
+ app_config.load
32
33
 
33
34
  return builtin.run if builtin
34
35
 
@@ -70,7 +71,7 @@ class Ops
70
71
 
71
72
  def actions
72
73
  config["actions"].transform_values do |config|
73
- Action.new(config, @args, action_options)
74
+ Action.new(config, @args)
74
75
  end
75
76
  end
76
77
 
@@ -91,10 +92,6 @@ class Ops
91
92
  end
92
93
  end
93
94
 
94
- def action_options
95
- @action_options ||= @config.dig("options", "actions")
96
- end
97
-
98
95
  def env_vars
99
96
  @config.dig("options", "environment") || {}
100
97
  end
@@ -102,6 +99,14 @@ class Ops
102
99
  def environment
103
100
  @environment ||= Environment.new(env_vars)
104
101
  end
102
+
103
+ def app_config_file
104
+ `echo #{Options.get("config.path")}`.chomp
105
+ end
106
+
107
+ def app_config
108
+ @app_config ||= AppConfig.new(app_config_file)
109
+ end
105
110
  end
106
111
 
107
112
  Ops.new(ARGV).run if $PROGRAM_NAME == __FILE__
@@ -3,15 +3,19 @@
3
3
  require 'json'
4
4
 
5
5
  require 'output'
6
+ require 'app_config'
7
+ require 'options'
6
8
 
7
- class Secrets
8
- def initialize(filename = "")
9
- @filename = filename.empty? ? default_filename : filename
10
- end
9
+ class Secrets < AppConfig
10
+ class << self
11
+ def load
12
+ Secrets.new(expand_path(Options.get("secrets.path"))).load
13
+ end
11
14
 
12
- def load
13
- secrets['environment']&.each do |key, value|
14
- ENV[key] = value
15
+ private
16
+
17
+ def expand_path(path)
18
+ `echo #{path}`.chomp
15
19
  end
16
20
  end
17
21
 
@@ -31,18 +35,7 @@ class Secrets
31
35
  "config/#{environment}/secrets.json"
32
36
  end
33
37
 
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
38
  def file_contents
42
- @filename.match(/\.ejson$/) ? `ejson decrypt #{@filename}` : File.open(@filename).read
43
- end
44
-
45
- def environment
46
- ENV['environment']
39
+ @file_contents ||= @filename.match(/\.ejson$/) ? `ejson decrypt #{@filename}` : super
47
40
  end
48
41
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '0.2.3'
5
+ s.version = '0.2.8'
6
6
  s.authors = [
7
7
  'nickthecook@gmail.com'
8
8
  ]
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.3
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - nickthecook@gmail.com
@@ -59,15 +59,18 @@ extra_rdoc_files: []
59
59
  files:
60
60
  - Gemfile
61
61
  - bin/ops
62
+ - bin/print_config
62
63
  - bin/print_secrets
63
64
  - bin/tag
64
65
  - etc/ops.template.yml
65
66
  - etc/ruby.template.yml
66
67
  - etc/terraform.template.yml
67
68
  - lib/action.rb
69
+ - lib/app_config.rb
68
70
  - lib/builtin.rb
69
71
  - lib/builtins/down.rb
70
72
  - lib/builtins/env.rb
73
+ - lib/builtins/exec.rb
71
74
  - lib/builtins/help.rb
72
75
  - lib/builtins/helpers/dependency_handler.rb
73
76
  - lib/builtins/init.rb
@@ -81,7 +84,6 @@ files:
81
84
  - lib/dependencies/dir.rb
82
85
  - lib/dependencies/docker.rb
83
86
  - lib/dependencies/gem.rb
84
- - lib/dependencies/terraform.rb
85
87
  - lib/dependency.rb
86
88
  - lib/environment.rb
87
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