foreplay 0.9.0 → 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
  SHA1:
3
- metadata.gz: 792102ce293a729754f551ac87b6289ff1c7c81c
4
- data.tar.gz: 7d74c817f3aa6b8209b73a0d10cd7202a24a37dc
3
+ metadata.gz: dab6ab214634a4bf887140be748689c069df8697
4
+ data.tar.gz: ebc44d5b3b2caf10f54ccb49fb3c5d39cf1f0908
5
5
  SHA512:
6
- metadata.gz: 63dea290c9868a255eaefa222a159d8f9bc38bd8e9df82e7834cf33fc50b77f770b894d14b8070398aa186053ae383b73c45238ee04432f408fd3a35cc394185
7
- data.tar.gz: 40eddda360ffb3caeb8338e96209213f5276893113968ce9b8488434cda06fbd5905178473f70ca0cceafab0b2f2e1d7be6d53493dcb3e71df5de75f11707cc5
6
+ metadata.gz: 12e8ed27a1c13ed643465bb0804b28a91551dd4e9aa96cccedfbd55f240f436a9ce54a39d132a3af76be8a3d660259e97e4be94cf010a158e3fa81e8429b6953
7
+ data.tar.gz: 33200e22c3789e2f84fb3f160d09b5083c8de42ebbbe42839944b8270e8fe205cd9278b8faafbe69b2f7e0d4418019349145d2eeebe2890bad45ab22f183fefe
@@ -0,0 +1,42 @@
1
+ class Foreplay::Engine::Remote::Check
2
+ include Foreplay
3
+ attr_reader :host, :steps, :instructions
4
+
5
+ def initialize(h, s, i)
6
+ @host = h
7
+ @steps = s
8
+ @instructions = i
9
+ end
10
+
11
+ def perform
12
+ steps.each do |step|
13
+ puts "#{host}#{INDENT}#{(step['commentary'] || step['command']).yellow}" unless step['silent'] == true
14
+
15
+ if step.key? 'key'
16
+ list_file_contents step['key']
17
+ else
18
+ list_commands step
19
+ end
20
+ end
21
+
22
+ ''
23
+ end
24
+
25
+ def list_file_contents(id)
26
+ i = instructions[id]
27
+
28
+ if i.is_a? Hash
29
+ i.each { |k, v| puts "#{host}#{INDENT * 2}#{k}: #{v}" }
30
+ else
31
+ puts "#{host}#{INDENT * 2}#{i}"
32
+ end
33
+ end
34
+
35
+ def list_commands(step)
36
+ commands = Foreplay::Engine::Step.new(step, instructions).build
37
+
38
+ commands.each do |command|
39
+ puts "#{host}#{INDENT * 2}#{command}" unless step['silent']
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ class Foreplay::Engine::Remote::Step
2
+ include Foreplay
3
+ attr_reader :host, :shell, :step, :instructions
4
+
5
+ def initialize(h, sh, st, i)
6
+ @host = h
7
+ @shell = sh
8
+ @step = st
9
+ @instructions = i
10
+ end
11
+
12
+ def deploy
13
+ puts "#{host}#{INDENT}#{(step['commentary'] || step['command']).yellow}" unless step['silent'] == true
14
+
15
+ # Output from this step
16
+ output = ''
17
+ previous = '' # We don't need or want the final CRLF
18
+ commands = Foreplay::Engine::Step.new(step, instructions).build
19
+
20
+ commands.each do |command|
21
+ process = shell.execute command
22
+
23
+ process.on_output do |_, o|
24
+ previous = o
25
+ output += previous
26
+ end
27
+
28
+ shell.wait!
29
+
30
+ if step['ignore_error'] == true || process.exit_status == 0
31
+ print output.gsub!(/^/, "#{host}#{INDENT * 2}") unless step['silent'] == true || output.blank?
32
+ else
33
+ terminate(output)
34
+ end
35
+ end
36
+
37
+ output
38
+ end
39
+ end
@@ -1,5 +1,4 @@
1
1
  require 'net/ssh'
2
- require 'pp' # debug
3
2
 
4
3
  class Foreplay::Engine::Remote
5
4
  include Foreplay
@@ -22,31 +21,7 @@ class Foreplay::Engine::Remote
22
21
  puts "#{host}#{INDENT}Successfully connected to #{host} on port #{port}"
23
22
 
24
23
  session.shell do |sh|
25
- steps.each do |step|
26
- puts "#{host}#{INDENT}#{(step['commentary'] || step['command']).yellow}" unless step['silent'] == true
27
-
28
- # Output from this step
29
- output = ''
30
- previous = '' # We don't need or want the final CRLF
31
- commands = Foreplay::Engine::Step.new(step, instructions).build
32
-
33
- commands.each do |command|
34
- process = sh.execute command
35
-
36
- process.on_output do |_, o|
37
- previous = o
38
- output += previous
39
- end
40
-
41
- sh.wait!
42
-
43
- if step['ignore_error'] == true || process.exit_status == 0
44
- print output.gsub!(/^/, "#{host}#{INDENT * 2}") unless step['silent'] == true || output.blank?
45
- else
46
- terminate(output)
47
- end
48
- end
49
- end
24
+ steps.each { |step| output += Foreplay::Engine::Remote::Step.new(host, sh, step, instructions).deploy }
50
25
  end
51
26
 
52
27
  session.close
@@ -55,27 +30,7 @@ class Foreplay::Engine::Remote
55
30
 
56
31
  # Deployment check: just say what we would have done
57
32
  def check
58
- steps.each do |step|
59
- puts "#{host}#{INDENT}#{(step['commentary'] || step['command']).yellow}" unless step['silent'] == true
60
-
61
- if step.key? 'key'
62
- i = instructions[step['key']]
63
-
64
- if i.is_a? Hash
65
- i.each { |k, v| puts "#{host}#{INDENT * 2}#{k}: #{v}" }
66
- else
67
- puts "#{host}#{INDENT * 2}#{i}"
68
- end
69
- else
70
- commands = Foreplay::Engine::Step.new(step, instructions).build
71
-
72
- commands.each do |command|
73
- puts "#{host}#{INDENT * 2}#{command}" unless step['silent']
74
- end
75
- end
76
- end
77
-
78
- ''
33
+ Foreplay::Engine::Remote::Check.new(host, steps, instructions).perform
79
34
  end
80
35
 
81
36
  def user
@@ -97,37 +52,37 @@ class Foreplay::Engine::Remote
97
52
  def options
98
53
  return @options if @options
99
54
 
100
- password = instructions['password']
101
- keyfile = instructions['keyfile']
102
- private_key = instructions['private_key']
103
-
104
- keyfile.sub! '~', ENV['HOME'] || '/' unless keyfile.blank? # Remote shell won't expand this for us
105
-
106
- # SSH authentication methods
107
55
  @options = { verbose: :warn, port: port }
56
+ password = instructions['password']
108
57
 
109
58
  if password.blank?
110
- # If there's no password we must supply a private key
111
- if private_key.blank?
112
- message = 'No authentication methods supplied. '\
113
- 'You must supply a private key, key file or password in the configuration file'
114
- terminate(message) if keyfile.blank?
115
- # Get the key from the key file
116
- puts "#{INDENT}Using private key from #{keyfile}"
117
- private_key = File.read keyfile
118
- else
119
- puts "#{INDENT}Using private key from the configuration file"
120
- end
121
-
122
59
  @options[:key_data] = [private_key]
123
60
  else
124
- # Use the password supplied
125
61
  @options[:password] = password
126
62
  end
127
63
 
128
64
  @options
129
65
  end
130
66
 
67
+ def private_key
68
+ pk = instructions['private_key']
69
+ pk.blank? ? private_key_from_file : pk
70
+ end
71
+
72
+ def private_key_from_file
73
+ keyfile = instructions['keyfile']
74
+ keyfile.sub! '~', ENV['HOME'] || '/' unless keyfile.blank? # Remote shell won't expand this for us
75
+
76
+ terminate(
77
+ 'No authentication methods supplied. '\
78
+ 'You must supply a private key, key file or password in the configuration file'
79
+ ) if keyfile.blank?
80
+
81
+ # Get the key from the key file
82
+ puts "#{INDENT}Using private key from #{keyfile}"
83
+ File.read keyfile
84
+ end
85
+
131
86
  def start_session(host, user, options)
132
87
  Net::SSH.start(host, user, options)
133
88
  rescue SocketError => e
@@ -1,3 +1,5 @@
1
+ require 'pp' # debug
2
+
1
3
  class Foreplay::Engine::Secrets
2
4
  attr_reader :environment, :secret_locations
3
5
 
@@ -12,20 +14,22 @@ class Foreplay::Engine::Secrets
12
14
  secrets = {}
13
15
 
14
16
  secret_locations.each do |secret_location|
15
- secrets.merge! fetch_from(secret_location)
17
+ secrets.merge! fetch_from(secret_location) || {}
16
18
  end
17
19
 
18
20
  secrets
19
21
  end
20
22
 
21
23
  def fetch_from(secret_location)
22
- return unless secret_location['url']
24
+ url = secret_location['url'] || return
23
25
 
24
- headers = secret_location['headers'].map { |k, v| " -H \"#{k}: #{v}\"" }.join
25
- command = "curl -k -L#{headers} #{secret_location['url']}"
26
+ headers = secret_location['headers']
27
+ header_string = headers.map { |k, v| " -H \"#{k}: #{v}\"" }.join if headers.is_a? Hash
28
+ command = "curl -k -L#{header_string} #{url}"
29
+ secrets_all = YAML.load(`#{command}`)
30
+ secrets = secrets_all[environment]
26
31
 
27
- secrets_all = YAML.load(`#{command}`)
28
- secrets_all[environment]
32
+ secrets if secrets.is_a? Hash
29
33
  rescue Psych::SyntaxError
30
34
  nil
31
35
  end
@@ -1,3 +1,3 @@
1
1
  module Foreplay
2
- VERSION = '0.9.0'
2
+ VERSION = '0.9.1'
3
3
  end
data/lib/foreplay.rb CHANGED
@@ -3,6 +3,8 @@ require 'foreplay/foreplay'
3
3
  require 'foreplay/launcher'
4
4
  require 'foreplay/engine'
5
5
  require 'foreplay/engine/remote'
6
+ require 'foreplay/engine/remote/check'
7
+ require 'foreplay/engine/remote/step'
6
8
  require 'foreplay/engine/role'
7
9
  require 'foreplay/engine/secrets'
8
10
  require 'foreplay/engine/server'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreplay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xenapto
@@ -223,6 +223,8 @@ files:
223
223
  - lib/foreplay/cli.rb
224
224
  - lib/foreplay/engine.rb
225
225
  - lib/foreplay/engine/remote.rb
226
+ - lib/foreplay/engine/remote/check.rb
227
+ - lib/foreplay/engine/remote/step.rb
226
228
  - lib/foreplay/engine/role.rb
227
229
  - lib/foreplay/engine/secrets.rb
228
230
  - lib/foreplay/engine/server.rb