ridley 1.4.0 → 1.4.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: d49b01c05183839d7cef30131ba300c890180655
4
- data.tar.gz: 402b0fbdbf265d4f070803bc80833538ec1dbf72
3
+ metadata.gz: 6ddf15cf964bec841b6ddf37a9fed6456f349bcd
4
+ data.tar.gz: 66bb125b1b2ff3f751cb3ba5bac8488986eaccf6
5
5
  SHA512:
6
- metadata.gz: c00aefbe3246307695bb8dd78c8f97ded171b4e5dc0c7861adfe1f5a8f292558d6ae45d94e37cce0c3a6a8e52892a949e02840d028f7595d24473c6d6a4eca79
7
- data.tar.gz: 622d8a1ebf053ead22c1310e46663ec4ee75021b31499198e8cd57dd3b7f2121f7eff6eb6bb8b943c80f79bb4d3c18050a877ad5705f8ffa8562351c2d7b8daa
6
+ metadata.gz: 11576d2916237550f0f5cc9e67f784ccb0c095c2d4908bce318d8c397c4d3031dac3be5cb603968b036d6e9917811658328b30f04c2bc904cef71fc897d3dead
7
+ data.tar.gz: 6a3b1c1ec0d470cd8f2a31cdce148aa8e09ea976d5d1843a720f9b41421ca6dd549e4781191a7853759aa1ae3cb8e65db00aa01525cdf45747a824e47fd5e42e
data/README.md CHANGED
@@ -141,7 +141,7 @@ Most resources can be listed, retrieved, created, updated, and destroyed. These
141
141
 
142
142
  #### Create
143
143
 
144
- A new Chef Object can be created in a three ways
144
+ A new Chef Object can be created in a four ways
145
145
 
146
146
  _With the `#create` function and an attribute hash_
147
147
 
@@ -166,6 +166,11 @@ obj.name = "reset"
166
166
  obj.save #=> #<Ridley::RoleObject: chef_id:reset>
167
167
  ```
168
168
 
169
+ _With the `#save` function on an instance of a Chef Object built from serialized json_
170
+
171
+ obj = ridley.role.from_file('/path/to/role.json')
172
+ obj.save #=> #<Ridley::RoleObject: chef_id:reset>
173
+
169
174
  Each of these methods produce an identical object on the Chef server. It is up to you on how you'd like to create new resources.
170
175
 
171
176
  #### Read
@@ -17,13 +17,7 @@ module Ridley
17
17
 
18
18
  # @return [String]
19
19
  def boot_command
20
- cmd = template.evaluate(self)
21
-
22
- if sudo
23
- cmd = "sudo #{cmd}"
24
- end
25
-
26
- cmd
20
+ template.evaluate(self)
27
21
  end
28
22
 
29
23
  # @return [String]
@@ -26,6 +26,7 @@ module Ridley::Chef
26
26
  end
27
27
 
28
28
  private
29
+
29
30
  # Find the chefignore file in the current directory
30
31
  #
31
32
  # @return [String, nil]
@@ -44,7 +45,7 @@ module Ridley::Chef
44
45
  end
45
46
  end
46
47
 
47
- return nil
48
+ nil
48
49
  end
49
50
  end
50
51
  end
@@ -1,3 +1,5 @@
1
+ require 'yaml'
2
+
1
3
  module Ridley
2
4
  class DataBagItemObject < ChefObject
3
5
  set_chef_id "id"
@@ -57,18 +59,14 @@ module Ridley
57
59
  #
58
60
  # @return [Hash] a decrypted attribute value
59
61
  def decrypt_value(value)
60
- if encrypted_data_bag_secret.nil?
61
- raise Errors::EncryptedDataBagSecretNotSet
62
+ case format_version_of(value)
63
+ when 0
64
+ decrypt_v0_value(value)
65
+ when 1
66
+ decrypt_v1_value(value)
67
+ else
68
+ raise NotImplementedError, "Currently decrypting only version 0 & 1 databags are supported"
62
69
  end
63
-
64
- decoded_value = Base64.decode64(value)
65
-
66
- cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
67
- cipher.decrypt
68
- cipher.pkcs5_keyivgen(encrypted_data_bag_secret)
69
- decrypted_value = cipher.update(decoded_value) + cipher.final
70
-
71
- YAML.load(decrypted_value)
72
70
  end
73
71
 
74
72
  # Reload the attributes of the instantiated resource
@@ -105,6 +103,44 @@ module Ridley
105
103
 
106
104
  private
107
105
 
106
+ # Shamelessly lifted from https://github.com/opscode/chef/blob/2c0040c95bb942d13ad8c47498df56be43e9a82e/lib/chef/encrypted_data_bag_item.rb#L209-L215
107
+ def format_version_of(encrypted_value)
108
+ if encrypted_value.respond_to?(:key?)
109
+ encrypted_value["version"]
110
+ else
111
+ 0
112
+ end
113
+ end
114
+
115
+ def decrypt_v0_value(value)
116
+ if encrypted_data_bag_secret.nil?
117
+ raise Errors::EncryptedDataBagSecretNotSet
118
+ end
119
+
120
+ decoded_value = Base64.decode64(value)
121
+
122
+ cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
123
+ cipher.decrypt
124
+ cipher.pkcs5_keyivgen(encrypted_data_bag_secret)
125
+ decrypted_value = cipher.update(decoded_value) + cipher.final
126
+
127
+ YAML.load(decrypted_value)
128
+ end
129
+
130
+ def decrypt_v1_value(attrs)
131
+ if encrypted_data_bag_secret.nil?
132
+ raise Errors::EncryptedDataBagSecretNotSet
133
+ end
134
+
135
+ cipher = OpenSSL::Cipher::Cipher.new(attrs[:cipher])
136
+ cipher.decrypt
137
+ cipher.key = Digest::SHA256.digest(encrypted_data_bag_secret)
138
+ cipher.iv = Base64.decode64(attrs[:iv])
139
+ decrypted_value = cipher.update(Base64.decode64(attrs[:encrypted_data])) + cipher.final
140
+
141
+ YAML.load(decrypted_value)["json_wrapper"]
142
+ end
143
+
108
144
  def encrypted_data_bag_secret
109
145
  resource.encrypted_data_bag_secret
110
146
  end
@@ -34,6 +34,26 @@ module Ridley
34
34
  self.class.representation.new(Actor.current, *args)
35
35
  end
36
36
 
37
+ # Used to build a representation from a file with the current Actor's resource
38
+ #
39
+ # @param [String] filename
40
+ # a full filename from which to build this representation (currently only supports .json files)
41
+ #
42
+ # @return [representation.class]
43
+ def from_file(filename)
44
+ from_json(File.read(filename))
45
+ end
46
+
47
+ # Used to build a representation from a serialized json string with the current Actor's resource
48
+ #
49
+ # @param [String] json
50
+ # a representation serialized into json
51
+ #
52
+ # @return [representation.class]
53
+ def from_json(json)
54
+ new(JSON.parse(json))
55
+ end
56
+
37
57
  # @return [Ridley::Connection]
38
58
  def connection
39
59
  @connection_registry[:connection_pool]
@@ -1,3 +1,3 @@
1
1
  module Ridley
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
@@ -44,12 +44,22 @@ describe Ridley::DataBagItemObject do
44
44
  resource.stub(encrypted_data_bag_secret: File.read(fixtures_path.join("encrypted_data_bag_secret").to_s))
45
45
  end
46
46
 
47
- it "decrypts an encrypted value" do
47
+ it "decrypts an encrypted v0 value" do
48
48
  subject.attributes[:test] = "Xk0E8lV9r4BhZzcg4wal0X4w9ZexN3azxMjZ9r1MCZc="
49
49
  subject.decrypt
50
50
  subject.attributes[:test][:database][:username].should == "test"
51
51
  end
52
52
 
53
+ it "decrypts an encrypted v1 value" do
54
+ subject.attributes[:password] = Hashie::Mash.new
55
+ subject.attributes[:password][:version] = 1
56
+ subject.attributes[:password][:cipher] = "aes-256-cbc"
57
+ subject.attributes[:password][:encrypted_data] = "zG+tTjtwOWA4vEYDoUwPYreXLZ1pFyKoWDGezEejmKs="
58
+ subject.attributes[:password][:iv] = "URVhHxv/ZrnABJBvl82qsg=="
59
+ subject.decrypt
60
+ subject.attributes[:password].should == "password123"
61
+ end
62
+
53
63
  it "does not decrypt the id field" do
54
64
  id = "dbi_id"
55
65
  subject.attributes[:id] = id
@@ -48,6 +48,7 @@ describe Ridley::Resource do
48
48
 
49
49
  let(:connection) { double('chef-connection') }
50
50
  let(:response) { double('chef-response', body: Hash.new) }
51
+ let(:resource_json) { '{"some":"valid json"}' }
51
52
 
52
53
  subject { resource_class.new(double('registry')) }
53
54
 
@@ -56,6 +57,22 @@ describe Ridley::Resource do
56
57
  subject.stub(connection: connection)
57
58
  end
58
59
 
60
+ describe "::from_file" do
61
+ it "reads the file and calls ::from_json with contents" do
62
+ File.stub(:read) { resource_json }
63
+ subject.should_receive(:from_json).with(resource_json)
64
+ subject.from_file('/bogus/filename.json')
65
+ end
66
+ end
67
+
68
+ describe "::from_json" do
69
+ it "parses the argument and calls ::new with newly built hash" do
70
+ hashed_json = JSON.parse(resource_json)
71
+ subject.should_receive(:new).with(hashed_json).and_return representation
72
+ subject.from_json(resource_json)
73
+ end
74
+ end
75
+
59
76
  describe "::all" do
60
77
  it "sends GET to /{resource_path}" do
61
78
  connection.should_receive(:get).with(subject.class.resource_path).and_return(response)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridley
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamie Winsor
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-19 00:00:00.000000000 Z
12
+ date: 2013-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable