foreplay 0.11.0 → 0.11.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: 88819e9e2b64f99fe34c4f2db6644ebba55e9ad6
4
- data.tar.gz: 4e8818325e534443f4e066fc3157d7496dc07a38
3
+ metadata.gz: 693a6cc6b88a2957765b798ac1f1de80a1e99579
4
+ data.tar.gz: c8a26ffe9a1e24c087e59c1555defe29afca81e7
5
5
  SHA512:
6
- metadata.gz: fe138f745c09e417df8a3548dc9e8e0d756336930c4d0b646a04e5a880ce1f15d1ef4cbd73596192150cd50505d2bf4a5acc6fbdadd221ba5dea670a54596640
7
- data.tar.gz: 27a1ec20a0f06a3c374c30904518b1e1c7ca221a604a654ea4393ee0b0bdbe639495a2fbda7926ba4ce76655341058886bcd495c418a1f6e1c8f127c8645e5fc
6
+ metadata.gz: 781a7928b8f5e0023692b1a40db8233433b2f85dbe636a344f7b95173d68a76c69da78cbabcadeb0fa21e274fcc16b12ce603e3e657a6b96ded6a60a41bee604
7
+ data.tar.gz: f2ca0483339c263fe652ddde1def30fde44be01f3e34acfcb38cde390fd5cc830076016e613a55c30a84e776bf2660f1cb8cd69fc67a2296b31efe3d1501dfdb
@@ -21,7 +21,7 @@ module Foreplay
21
21
  @formatted_message ||= header + message
22
22
  .gsub(/\A\s+/, '')
23
23
  .gsub(/\s+\z/, '')
24
- .gsub(/(\r\n|\r|\n)/, "\\1#{margin}")
24
+ .gsub(/(\r\n|\r|\n)/, "\n#{margin}")
25
25
  end
26
26
 
27
27
  def header
@@ -27,12 +27,12 @@ module Foreplay
27
27
  o
28
28
  end
29
29
 
30
- def silent
31
- @silent ||= instructions['verbose'] ? false : step['silent']
30
+ def silent?
31
+ @silent ||= instructions.key?('verbose') ? false : step['silent']
32
32
  end
33
33
 
34
34
  def output(o)
35
- log o, host: host, silent: silent, indent: 1
35
+ log o, host: host, silent: silent?, indent: 1
36
36
  o
37
37
  end
38
38
  end
@@ -1,3 +1,5 @@
1
+ require 'foreplay/engine/secrets/location'
2
+
1
3
  module Foreplay
2
4
  class Engine
3
5
  class Secrets
@@ -12,26 +14,12 @@ module Foreplay
12
14
  return unless secret_locations
13
15
 
14
16
  secrets = {}
15
-
16
- secret_locations.each do |secret_location|
17
- secrets.merge! fetch_from(secret_location) || {}
18
- end
19
-
17
+ secret_locations.each { |secret_location| secrets.merge! location_secrets(secret_location) }
20
18
  secrets
21
19
  end
22
20
 
23
- def fetch_from(secret_location)
24
- url = secret_location['url'] || return
25
-
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}".fake_erb
29
- secrets_all = YAML.load(`#{command}`)
30
- secrets = secrets_all[environment]
31
-
32
- secrets if secrets.is_a? Hash
33
- rescue Psych::SyntaxError
34
- nil
21
+ def location_secrets(secret_location)
22
+ Location.new(secret_location, environment).secrets
35
23
  end
36
24
  end
37
25
  end
@@ -0,0 +1,55 @@
1
+ module Foreplay
2
+ class Engine
3
+ class Secrets
4
+ class Location
5
+ include Foreplay
6
+ attr_reader :secret_location, :environment
7
+
8
+ def initialize(s, e)
9
+ @secret_location = s
10
+ @environment = e
11
+ end
12
+
13
+ def secrets
14
+ return @secrets if @secrets
15
+
16
+ @secrets = all_secrets[environment]
17
+
18
+ if @secrets.is_a? Hash
19
+ log "Loaded #{secrets.keys.length} secrets"
20
+ @secrets
21
+ else
22
+ log 'No secrets found'
23
+ @secrets = {}
24
+ end
25
+ end
26
+
27
+ def all_secrets
28
+ return @all_secrets if @all_secrets
29
+
30
+ @all_secrets = url ? YAML.load(`#{command}`) : {}
31
+ rescue Psych::SyntaxError => e
32
+ log "Exception caught when loading secrets using this command: #{command}"
33
+ log "#{e.class}: #{e.message}".red
34
+ @all_secrets = {}
35
+ end
36
+
37
+ def command
38
+ @command ||= "curl -k -L#{header_string} #{url}".fake_erb
39
+ end
40
+
41
+ def header_string
42
+ @header_string ||= headers.map { |k, v| " -H \"#{k}: #{v}\"" }.join if headers.is_a? Hash
43
+ end
44
+
45
+ def headers
46
+ @headers ||= secret_location['headers']
47
+ end
48
+
49
+ def url
50
+ @url ||= @secret_location['url']
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -32,7 +32,7 @@ module Foreplay
32
32
  end
33
33
 
34
34
  def build_commands
35
- step['silent'] = true
35
+ step['silent'] = !instructions.key?('verbose')
36
36
 
37
37
  if header?
38
38
  @commands = ["echo \"#{header}\" > #{filename}"]
@@ -111,13 +111,13 @@ module Foreplay
111
111
  header.present?
112
112
  end
113
113
 
114
- def silent
114
+ def silent?
115
115
  @silent ||= step['silent']
116
116
  end
117
117
 
118
118
  def announce
119
- log "#{(step['commentary'] || command).yellow}", host: host, silent: silent
120
- log command.cyan, host: host, silent: silent if instructions['verbose'] && step['commentary'] && command
119
+ log "#{(step['commentary'] || command).yellow}", host: host, silent: silent?
120
+ log command.cyan, host: host, silent: silent? if instructions['verbose'] && step['commentary'] && command
121
121
  end
122
122
  end
123
123
  end
@@ -1,3 +1,3 @@
1
1
  module Foreplay
2
- VERSION = '0.11.0'
2
+ VERSION = '0.11.1'
3
3
  end
@@ -29,11 +29,11 @@ describe Foreplay::Engine::Secrets do
29
29
  let(:secret) { Foreplay::Engine::Secrets.new('', ['x']) }
30
30
 
31
31
  before :each do
32
- allow(secret).to receive(:fetch_from).and_return(secrets)
32
+ allow(secret).to receive(:location_secrets).and_return(secrets)
33
33
  end
34
34
 
35
35
  it 'does what it is told' do
36
- expect(secret.fetch_from).to eq(secrets)
36
+ expect(secret.location_secrets).to eq(secrets)
37
37
  end
38
38
 
39
39
  it 'returns a hash of secrets' do
@@ -48,11 +48,22 @@ describe Foreplay::Engine::Secrets do
48
48
  let(:secret) { Foreplay::Engine::Secrets.new('', %w(x x)) }
49
49
 
50
50
  before :each do
51
- allow(secret).to receive(:fetch_from).and_return(secrets1, secrets2)
51
+ allow(secret).to receive(:location_secrets).and_return(secrets1, secrets2)
52
52
  end
53
53
 
54
54
  it 'returns a hash of secrets' do
55
55
  expect(secret.fetch).to eq(secrets)
56
56
  end
57
57
  end
58
+
59
+ context 'Location returns a hash if one is found' do
60
+ let(:location) { Foreplay::Engine::Secrets::Location.new('', 'p') }
61
+ let(:secrets) { { 'p' => { 'a' => 'x', 'b' => 'y', 'c' => 'z' }, 'q' => 'zzz', 'r' => { 'd' => 1 } } }
62
+
63
+ before { allow(location).to receive(:all_secrets).and_return(secrets) }
64
+
65
+ it 'returns the secrets for the right environment' do
66
+ expect(location.secrets).to eq(secrets['p'])
67
+ end
68
+ end
58
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreplay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xenapto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-28 00:00:00.000000000 Z
11
+ date: 2015-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foreman
@@ -229,6 +229,7 @@ files:
229
229
  - lib/foreplay/engine/remote/step.rb
230
230
  - lib/foreplay/engine/role.rb
231
231
  - lib/foreplay/engine/secrets.rb
232
+ - lib/foreplay/engine/secrets/location.rb
232
233
  - lib/foreplay/engine/server.rb
233
234
  - lib/foreplay/engine/step.rb
234
235
  - lib/foreplay/engine/steps.yml