foreplay 0.9.1 → 0.9.2

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: dab6ab214634a4bf887140be748689c069df8697
4
- data.tar.gz: ebc44d5b3b2caf10f54ccb49fb3c5d39cf1f0908
3
+ metadata.gz: b1a465561829258d5e0b9df51f30105c29a77176
4
+ data.tar.gz: 6a14c037d84c88ce58c43daaeda788fd959013e4
5
5
  SHA512:
6
- metadata.gz: 12e8ed27a1c13ed643465bb0804b28a91551dd4e9aa96cccedfbd55f240f436a9ce54a39d132a3af76be8a3d660259e97e4be94cf010a158e3fa81e8429b6953
7
- data.tar.gz: 33200e22c3789e2f84fb3f160d09b5083c8de42ebbbe42839944b8270e8fe205cd9278b8faafbe69b2f7e0d4418019349145d2eeebe2890bad45ab22f183fefe
6
+ metadata.gz: eb510cd1560115068df1197db21bf6b734fc1e25a9e8e4e9937a075eca3405949db739a4547fba4ed732dc630dd6c27ec4efcc6cb14410a3feb6c71a9c0d749b
7
+ data.tar.gz: 58c9c5292ad36dc9366ee34771dbe1f13af30f2ce7ef791506a0fcb04405e6463f376b0fbf52bd8ac80f61afc26e67c23c253ca7b273b6afdb788861de901d68
data/.rubocop.yml CHANGED
@@ -30,6 +30,9 @@ FileName:
30
30
  Description: 'Use snake_case for source file names.'
31
31
  Enabled: true
32
32
 
33
+ Eval:
34
+ Enabled: false
35
+
33
36
  # Work on these:
34
37
 
35
38
  LineLength:
@@ -1,5 +1,3 @@
1
- require 'pp' # debug
2
-
3
1
  class Foreplay::Engine::Secrets
4
2
  attr_reader :environment, :secret_locations
5
3
 
@@ -25,7 +23,7 @@ class Foreplay::Engine::Secrets
25
23
 
26
24
  headers = secret_location['headers']
27
25
  header_string = headers.map { |k, v| " -H \"#{k}: #{v}\"" }.join if headers.is_a? Hash
28
- command = "curl -k -L#{header_string} #{url}"
26
+ command = "curl -k -L#{header_string} #{url}".fake_erb
29
27
  secrets_all = YAML.load(`#{command}`)
30
28
  secrets = secrets_all[environment]
31
29
 
@@ -1,3 +1,3 @@
1
1
  module Foreplay
2
- VERSION = '0.9.1'
2
+ VERSION = '0.9.2'
3
3
  end
data/lib/string.rb CHANGED
@@ -14,4 +14,8 @@ class String
14
14
  def ansi_attributes(*args)
15
15
  "\e[#{args.join(';')}m#{self}\e[0m"
16
16
  end
17
+
18
+ def fake_erb
19
+ gsub(/(<%=\s+([^%]+)\s+%>)/) { |e| eval "_ = #{e.split[1]}" }
20
+ end
17
21
  end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+ require 'foreplay'
3
+
4
+ describe Foreplay::Engine::Secrets do
5
+ context '#fetch' do
6
+ it 'returns nil if there is no secret location' do
7
+ expect(Foreplay::Engine::Secrets.new('x', nil).fetch).to be_nil
8
+ end
9
+
10
+ it 'fails if the secret location is not a hash' do
11
+ expect { Foreplay::Engine::Secrets.new('x', 'y').fetch } .to raise_error(NoMethodError)
12
+ end
13
+
14
+ it 'returns an empty hash if the secret location has no url' do
15
+ expect(Foreplay::Engine::Secrets.new('x', []).fetch).to eq({})
16
+ end
17
+
18
+ it 'returns an empty hash if the secret location does not return valid YAML' do
19
+ expect(Foreplay::Engine::Secrets.new('x', [{ 'url' => 'http://iana.org' }]).fetch).to eq({})
20
+ end
21
+
22
+ it 'returns an empty hash if the secret location does not exist' do
23
+ expect(Foreplay::Engine::Secrets.new('x', [{ 'url' => 'http://iana.org/404' }]).fetch).to eq({})
24
+ end
25
+ end
26
+
27
+ context '#fetch successful' do
28
+ let(:secrets) { { 'a' => 'x', 'b' => 'y', 'c' => 'z' } }
29
+ let(:secret) { Foreplay::Engine::Secrets.new('', ['x']) }
30
+
31
+ before :each do
32
+ allow(secret).to receive(:fetch_from).and_return(secrets)
33
+ end
34
+
35
+ it 'does what it is told' do
36
+ expect(secret.fetch_from).to eq(secrets)
37
+ end
38
+
39
+ it 'returns a hash of secrets' do
40
+ expect(secret.fetch).to eq(secrets)
41
+ end
42
+ end
43
+
44
+ context '#fetch successful with merge' do
45
+ let(:secrets1) { { 'a' => 'x', 'b' => 'f' } }
46
+ let(:secrets2) { { 'b' => 'y', 'c' => 'z' } }
47
+ let(:secrets) { { 'a' => 'x', 'b' => 'y', 'c' => 'z' } }
48
+ let(:secret) { Foreplay::Engine::Secrets.new('', %w(x x)) }
49
+
50
+ before :each do
51
+ allow(secret).to receive(:fetch_from).and_return(secrets1, secrets2)
52
+ end
53
+
54
+ it 'returns a hash of secrets' do
55
+ expect(secret.fetch).to eq(secrets)
56
+ end
57
+ end
58
+ 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.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xenapto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-29 00:00:00.000000000 Z
11
+ date: 2015-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foreman
@@ -238,6 +238,7 @@ files:
238
238
  - lib/string.rb
239
239
  - spec/lib/foreplay/deploy_spec.rb
240
240
  - spec/lib/foreplay/engine_spec.rb
241
+ - spec/lib/foreplay/secrets_spec.rb
241
242
  - spec/lib/foreplay/setup_spec.rb
242
243
  - spec/spec_helper.rb
243
244
  homepage: https://github.com/Xenapto/foreplay
@@ -271,5 +272,6 @@ test_files:
271
272
  - features/support/env.rb
272
273
  - spec/lib/foreplay/deploy_spec.rb
273
274
  - spec/lib/foreplay/engine_spec.rb
275
+ - spec/lib/foreplay/secrets_spec.rb
274
276
  - spec/lib/foreplay/setup_spec.rb
275
277
  - spec/spec_helper.rb