ops_team 0.8.7 → 0.9.1

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: d595d1f23daf3cab0833a010f9fc99feadaee8fe63e5f98f6a6943b7e39db0f0
4
- data.tar.gz: af36bed405ec7982a89e6d4837098ccb92d227d37a6beba086dc0b7e33ab33c2
3
+ metadata.gz: 70498a1ccc87cf4bf2ddd7ad29028785f02d8dc5a6c8ea44f181a1db5d8e8fea
4
+ data.tar.gz: e43c220a41cf3956c14bc077ead9abf64f5502960ad46c6c49915a3a51a4b76d
5
5
  SHA512:
6
- metadata.gz: d50db908a70f94f1d3db693856dc664900386e95c33c90a77aedc8766c8e1b33d72d742668230dcf2c2b546ecee132e8320c6c9fa58df02065fb43a134b3364b
7
- data.tar.gz: 88b9e6bb4410fe491673ec101a65d48b7f51746682e55dea06ba2747a250b0ba1fdb23849171b3a17ac2fd3690331fb5155463edad23451fcdd5f00ef2ad049c
6
+ metadata.gz: be7def6a15311c5bed82a39b898a22d9aaeacd7058abecd1cdea47cef341439b78af9c9271cccf8ecdf5f9445c6be1d8fb76d44650a18654e0b22dd69b64dbd7
7
+ data.tar.gz: ad1cb8908108aae55c985b8b513421ad4669143a40a79db2fa064c1f4b07615b82fc736af36d766432204f459bd0cc467af8fa8743b8ff3c03b5af9aa4f259b5
@@ -17,7 +17,7 @@ class Action
17
17
  end
18
18
 
19
19
  def to_s
20
- "#{command} #{@args.join(' ')}"
20
+ "#{command} #{@args.join(' ')}".strip
21
21
  end
22
22
 
23
23
  def alias
@@ -1,10 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Builtin
4
+ attr_reader :args, :config
5
+
4
6
  class << self
5
7
  def description
6
8
  "no description"
7
9
  end
10
+
11
+ def class_for(name:)
12
+ Builtins.const_get(builtin_class_name_for(name: name), false)
13
+ end
14
+
15
+ private
16
+
17
+ def builtin_class_name_for(name:)
18
+ name.capitalize.to_sym
19
+ end
8
20
  end
9
21
 
10
22
  def initialize(args, config)
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'builtin'
4
+
5
+ module Builtins
6
+ class Background < Builtin
7
+ DEFAULT_SHELL = "bash"
8
+ DEFAULT_LOG_FILE_PREFIX = "/tmp/ops_bglog_"
9
+
10
+ class << self
11
+ def description
12
+ "runs the given command in a background session"
13
+ end
14
+
15
+ def log_filename
16
+ "#{log_filename_prefix}#{Ops.project_name}"
17
+ end
18
+
19
+ private
20
+
21
+ def log_filename_prefix
22
+ Options.get("background.log_filename_prefix") || DEFAULT_LOG_FILE_PREFIX
23
+ end
24
+ end
25
+
26
+ def run
27
+ subprocess = fork do
28
+ run_ops(args)
29
+ end
30
+
31
+ Process.detach(subprocess)
32
+ end
33
+
34
+ private
35
+
36
+ def run_ops(args)
37
+ Output.warn("Running '#{args.join(' ')}' with stderr and stdout redirected to '#{Background.log_filename}'")
38
+ $stdout.sync = $stderr.sync = true
39
+ $stdout.reopen(Background.log_filename, "w")
40
+ $stderr.reopen($stdout)
41
+
42
+ Ops.new(args).run
43
+ end
44
+
45
+ def shell
46
+ Options.get("background.shell") || DEFAULT_SHELL
47
+ end
48
+ end
49
+
50
+ # set an alias
51
+ Bg = Background
52
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'builtin'
4
+ require 'builtins/background'
5
+
6
+ module Builtins
7
+ class BackgroundLog < Builtin
8
+ class << self
9
+ def description
10
+ "displays the log from the current or most recent background task from this project"
11
+ end
12
+ end
13
+
14
+ def run
15
+ unless File.exist?(Background.log_filename)
16
+ Output.warn("No background log found at '#{Background.log_filename}'.")
17
+ return 0
18
+ end
19
+
20
+ Output.notice("Displaying background log '#{Background.log_filename}'...")
21
+ exec("tail #{args.join(' ')} '#{Background.log_filename}'")
22
+ end
23
+ end
24
+
25
+ # set an alias
26
+ Bglog = BackgroundLog
27
+ end
@@ -35,6 +35,8 @@ module Dependencies
35
35
  private
36
36
 
37
37
  def generate_key
38
+ Output.warn("\nNo passphrase set for SSH key '#{priv_key_name}'") if passphrase.nil? || passphrase.empty?
39
+
38
40
  execute("ssh-keygen -b #{opt_key_size} -t #{opt_key_algo} -f #{priv_key_name} -q -N '#{passphrase}'")
39
41
  end
40
42
 
@@ -51,12 +53,11 @@ module Dependencies
51
53
  end
52
54
 
53
55
  def unencrypted_key
54
- Net::SSH::KeyFactory.load_private_key(priv_key_name, passphrase)
56
+ Net::SSH::KeyFactory.load_private_key(priv_key_name, passphrase.empty? ? nil : passphrase)
55
57
  end
56
58
 
57
59
  def key_comment
58
- # the current directory is usually named for the project
59
- File.basename(::Dir.pwd)
60
+ Ops.project_name
60
61
  end
61
62
 
62
63
  def dir_name
@@ -84,7 +85,20 @@ module Dependencies
84
85
  end
85
86
 
86
87
  def opt_passphrase
87
- Options.get("sshkey.passphrase")
88
+ @opt_passphrase ||= begin
89
+ return "$#{Options.get('sshkey.passphrase_var')}" if Options.get("sshkey.passphrase_var")
90
+
91
+ output_passphrase_warning if Options.get("sshkey.passphrase")
92
+
93
+ Options.get("sshkey.passphrase")
94
+ end
95
+ end
96
+
97
+ def output_passphrase_warning
98
+ Output.warn(
99
+ "\n'options.sshkey.passphrase' is deprecated and will be removed in a future release. " \
100
+ "Use 'options.sshkey.passphrase_var' instead."
101
+ )
88
102
  end
89
103
 
90
104
  def opt_add_keys?
data/lib/ops.rb CHANGED
@@ -19,6 +19,12 @@ class Ops
19
19
  INVALID_SYNTAX_EXIT_CODE = 64
20
20
  UNKNOWN_ACTION_EXIT_CODE = 65
21
21
 
22
+ class << self
23
+ def project_name
24
+ File.basename(::Dir.pwd)
25
+ end
26
+ end
27
+
22
28
  def initialize(argv)
23
29
  @action_name = argv[0]
24
30
  @args = argv[1..-1]
@@ -58,16 +64,12 @@ class Ops
58
64
  end
59
65
 
60
66
  def builtin
61
- @builtin ||= Builtins.const_get(builtin_class_name, false).new(@args, config)
67
+ @builtin ||= Builtin.class_for(name: @action_name).new(@args, config)
62
68
  rescue NameError
63
69
  # this means there isn't a builtin with that name in that module
64
70
  nil
65
71
  end
66
72
 
67
- def builtin_class_name
68
- @action_name.capitalize.to_sym
69
- end
70
-
71
73
  def action
72
74
  return actions[@action_name] if actions[@action_name]
73
75
  return aliases[@action_name] if aliases[@action_name]
@@ -40,6 +40,8 @@ class Output
40
40
  @err.puts(msg.yellow)
41
41
  end
42
42
 
43
+ alias_method :notice, :warn
44
+
43
45
  def error(msg)
44
46
  @err.puts(msg.red)
45
47
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ops_team'
5
- s.version = '0.8.7'
5
+ s.version = '0.9.1'
6
6
  s.authors = [
7
7
  'nickthecook@gmail.com'
8
8
  ]
9
- s.date = '2020-05-29'
9
+ s.date = '2020-08-11'
10
10
  s.summary = 'ops_team handles basic operations tasks for your project, driven by YAML config'
11
11
  s.homepage = 'https://github.com/nickthecook/ops'
12
12
  s.files = Dir[
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ops_team
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.7
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nickthecook@gmail.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-29 00:00:00.000000000 Z
11
+ date: 2020-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt_pbkdf
@@ -148,6 +148,8 @@ files:
148
148
  - lib/action.rb
149
149
  - lib/app_config.rb
150
150
  - lib/builtin.rb
151
+ - lib/builtins/background.rb
152
+ - lib/builtins/background_log.rb
151
153
  - lib/builtins/down.rb
152
154
  - lib/builtins/env.rb
153
155
  - lib/builtins/exec.rb