ops_team 0.4.1 → 0.8.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: a818c3a6f9c810468c58fac9589aec995198d01ecdf1c226ba7531e50b7f8976
4
- data.tar.gz: 0d25bf9e8e30e73939e134f2c258a12d087c4724d1ae4819f66813873e289771
3
+ metadata.gz: bb7e6762ba43bcdd97cc72b6bc5a65bf1280d5bb69ad52eab7455f580fe1f7ea
4
+ data.tar.gz: ac3102e06909139501ffef2468bc7005a3c7db215253136c5c08ff6a8d4fc2b2
5
5
  SHA512:
6
- metadata.gz: d1dacb5ff0fc5c4839143ab957d86c20b0e17d304ba11fec4784ea59c496ed86995aed268dca23df8b2e32712934ff6d8f1f248704b3ef628e7d4444a5b81e9d
7
- data.tar.gz: a1bc4be2d8f04c81cc48de7944cb4bbb2e49c9bad7c0962bbefd925ada750ba8fa4cc5690c6e64ee817c7580cd8112d832dd644222a04fdfde31ee8b13eadd0f
6
+ metadata.gz: 2195cba85da82ef592d6368300eaac3bfe856cec816352c82c0acb07c54488ead3abf9e3963d78c4f658c593714e7819834728fa75f6a4cf6432b131da46bb3b
7
+ data.tar.gz: 459f5ad1db23e335cb5ec9f15919a84546f66b98abd4fbb286dce0ddb66ae71c034d298507256317ca382f10572d9898c03fcdc2df741add7ad02811606ee3dd
@@ -1,6 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class AppConfig
4
+ class << self
5
+ def load
6
+ new(app_config_path).load
7
+ end
8
+
9
+ private
10
+
11
+ def app_config_path
12
+ expand_path(Options.get("config.path"))
13
+ end
14
+
15
+ def expand_path(path)
16
+ `echo #{path}`.chomp
17
+ end
18
+ end
19
+
4
20
  def initialize(filename = "")
5
21
  @filename = filename.empty? ? default_filename : filename
6
22
  end
@@ -18,8 +34,8 @@ class AppConfig
18
34
  end
19
35
 
20
36
  def config
21
- @config ||= file_contents ? JSON.parse(file_contents) : {}
22
- rescue JSON::ParserError => e
37
+ @config ||= file_contents ? YAML.safe_load(file_contents) : {}
38
+ rescue YAML::SyntaxError => e
23
39
  Output.error("Error parsing config data: #{e}")
24
40
  {}
25
41
  end
@@ -35,7 +35,10 @@ module Builtins
35
35
 
36
36
  def actions
37
37
  @config["actions"].map do |name, value|
38
- format("%<name>-35s %<desc>s", name: name.yellow, desc: value["description"] || value["command"])
38
+ format("%<name>-35s %<desc>s",
39
+ name: name.yellow,
40
+ desc: value["description"] || value["command"]
41
+ )
39
42
  end
40
43
  end
41
44
  end
@@ -29,7 +29,7 @@ module Builtins
29
29
  def meet_dependencies
30
30
  dependency_handler.dependencies.each do |dependency|
31
31
  # don't even output anything for dependencies that shouldn't be considered on this machine
32
- next unless dependency.should_meet?
32
+ next unless dependency&.should_meet?
33
33
 
34
34
  Output.status("[#{dependency.type}] #{dependency.name}")
35
35
 
@@ -9,7 +9,7 @@ module Dependencies
9
9
  end
10
10
 
11
11
  def meet
12
- execute("#{sudo_string}#{meet_command}")
12
+ execute("#{sudo_string}apt-get install -y #{name}")
13
13
  end
14
14
 
15
15
  def unmeet
@@ -28,9 +28,5 @@ module Dependencies
28
28
 
29
29
  "sudo "
30
30
  end
31
-
32
- def meet_command
33
- "apt-get install -y #{name}"
34
- end
35
31
  end
36
32
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dependency'
4
+
5
+ module Dependencies
6
+ class Sshkey < Dependency
7
+ DEFAULT_KEY_SIZE = 2048
8
+ DEFAULT_KEY_ALGO = "rsa"
9
+
10
+ def met?
11
+ File.exist?(priv_key_name) && File.exist?(pub_key_name)
12
+ end
13
+
14
+ def meet
15
+ Secrets.load if Options.get("sshkey.load_secrets")
16
+
17
+ FileUtils.mkdir_p(dir_name) unless File.directory?(dir_name)
18
+
19
+ execute("ssh-keygen -b #{key_size} -t #{key_algo} -f #{priv_key_name} -q -N '#{passphrase}'")
20
+ end
21
+
22
+ def unmeet
23
+ true
24
+ end
25
+
26
+ def should_meet?
27
+ true
28
+ end
29
+
30
+ private
31
+
32
+ def dir_name
33
+ `echo #{File.dirname(name)}`.chomp
34
+ end
35
+
36
+ def priv_key_name
37
+ `echo #{name}`.chomp
38
+ end
39
+
40
+ def pub_key_name
41
+ "#{priv_key_name}.pub"
42
+ end
43
+
44
+ def key_size
45
+ Options.get("sshkey.key_size") || DEFAULT_KEY_SIZE
46
+ end
47
+
48
+ def key_algo
49
+ Options.get("sshkey.key_algo") || DEFAULT_KEY_ALGO
50
+ end
51
+
52
+ def passphrase
53
+ `echo #{configured_passphrase}`.chomp
54
+ end
55
+
56
+ def configured_passphrase
57
+ Options.get("sshkey.passphrase")
58
+ end
59
+ end
60
+ end
@@ -6,11 +6,8 @@ class Environment
6
6
  end
7
7
 
8
8
  def set_variables
9
- @env_hash.each do |key, value|
10
- ENV[key] = value
11
- end
12
-
13
- ENV['environment'] = environment
9
+ set_environment_aliases
10
+ set_configured_variables
14
11
  end
15
12
 
16
13
  def environment
@@ -18,4 +15,22 @@ class Environment
18
15
 
19
16
  ENV['environment']
20
17
  end
18
+
19
+ private
20
+
21
+ def set_environment_aliases
22
+ environment_aliases.each do |alias_name|
23
+ ENV[alias_name] = environment
24
+ end
25
+ end
26
+
27
+ def environment_aliases
28
+ Options.get("environment_aliases") || ['environment']
29
+ end
30
+
31
+ def set_configured_variables
32
+ @env_hash.each do |key, value|
33
+ ENV[key] = `echo #{value}`.chomp
34
+ end
35
+ end
21
36
  end
data/lib/ops.rb CHANGED
@@ -49,11 +49,11 @@ class Ops
49
49
 
50
50
  def run_action
51
51
  environment.set_variables
52
- app_config.load
52
+ AppConfig.load
53
53
 
54
54
  return builtin.run if builtin
55
55
 
56
- Output.warn("Running '#{action}' from #{CONFIG_FILE}...")
56
+ Output.warn("Running '#{action}' from #{CONFIG_FILE} in environment '#{ENV['environment']}'...")
57
57
  action.run
58
58
  end
59
59
 
@@ -106,12 +106,8 @@ class Ops
106
106
  @environment ||= Environment.new(env_vars)
107
107
  end
108
108
 
109
- def app_config_file
110
- `echo #{Options.get("config.path")}`.chomp
111
- end
112
-
113
109
  def app_config
114
- @app_config ||= AppConfig.new(app_config_file)
110
+ @app_config ||= AppConfig.new
115
111
  end
116
112
  end
117
113
 
@@ -8,19 +8,11 @@ require 'options'
8
8
 
9
9
  class Secrets < AppConfig
10
10
  class << self
11
- def load
12
- Secrets.new(secrets_path).load
13
- end
14
-
15
11
  private
16
12
 
17
- def secrets_path
13
+ def app_config_path
18
14
  expand_path(Options.get("secrets.path"))
19
15
  end
20
-
21
- def expand_path(path)
22
- `echo #{path}`.chomp
23
- end
24
16
  end
25
17
 
26
18
  def initialize(filename = "")
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '0.4.1'
5
+ s.version = '0.8.0'
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.4.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nickthecook@gmail.com
@@ -84,6 +84,7 @@ files:
84
84
  - lib/dependencies/dir.rb
85
85
  - lib/dependencies/docker.rb
86
86
  - lib/dependencies/gem.rb
87
+ - lib/dependencies/sshkey.rb
87
88
  - lib/dependency.rb
88
89
  - lib/environment.rb
89
90
  - lib/ops.rb