ridley 1.4.1 → 1.5.0

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: 6ddf15cf964bec841b6ddf37a9fed6456f349bcd
4
- data.tar.gz: 66bb125b1b2ff3f751cb3ba5bac8488986eaccf6
3
+ metadata.gz: 27b40a345544eb449674ad567eaead7152ede778
4
+ data.tar.gz: e3497d278e48998c2ac805cc851e3cc3561c0b84
5
5
  SHA512:
6
- metadata.gz: 11576d2916237550f0f5cc9e67f784ccb0c095c2d4908bce318d8c397c4d3031dac3be5cb603968b036d6e9917811658328b30f04c2bc904cef71fc897d3dead
7
- data.tar.gz: 6a3b1c1ec0d470cd8f2a31cdce148aa8e09ea976d5d1843a720f9b41421ca6dd549e4781191a7853759aa1ae3cb8e65db00aa01525cdf45747a824e47fd5e42e
6
+ metadata.gz: aba56e71a839b5343a3fdca96dd56ad10ff855f80ba3821cbee5c53bc3539d2e5e3547004139947b5f1353b72361ebadfbd086c7c4d3fc655ccae56bda8b4abc
7
+ data.tar.gz: 0d38cd57cd4c756c10af5be8a3d036d4658adb2596a37c90477d01e049b38d9ff5490552cae7427c14de58dc9b320d8385eeb1e22a015c6c0c717ede99e874c2
data/README.md CHANGED
@@ -42,6 +42,15 @@ Creating a new instance of Ridley requires the following options:
42
42
  - client_name
43
43
  - client_key
44
44
 
45
+ client_key can be either a file path or the client key as a string. You can also optionally supply an encrypted data bag secret for decrypting encrypted data bags. The option is "encrypted_data_bag_secret" This can be a file name or the key itself as a string.
46
+
47
+ ridley = Ridley.new(
48
+ server_url: "https://api.opscode.com/organizations/ridley",
49
+ client_name: "reset",
50
+ client_key: "some key data",
51
+ encrypted_data_bag_secret: "File path or key as a string"
52
+ )
53
+
45
54
  Ridley exposes a number of functions that return resources which you can use to retrieve or create objects on your Chef server. Here is a simple example of getting a list of all the roles on your Chef server.
46
55
 
47
56
  ```ruby
@@ -124,8 +124,8 @@ module Ridley
124
124
  # @option options [Integer] :pool_size (4)
125
125
  # size of the connection pool
126
126
  #
127
- # @raise [Errors::ClientKeyFileNotFound] if the option for :client_key does not contain
128
- # a file path pointing to a readable client key
127
+ # @raise [Errors::ClientKeyFileNotFoundOrInvalid] if the option for :client_key does not contain
128
+ # a file path pointing to a readable client key, or is a string containing a valid key
129
129
  def initialize(options = {})
130
130
  @options = options.reverse_merge(
131
131
  ssh: Hash.new,
@@ -139,22 +139,23 @@ module Ridley
139
139
  @chef_version = @options[:chef_version]
140
140
  @validator_client = @options[:validator_client]
141
141
 
142
- @options[:client_key] = File.expand_path(@options[:client_key])
143
-
144
142
  if @options[:validator_path]
145
143
  @validator_path = File.expand_path(@options[:validator_path])
146
144
  end
147
145
 
148
- if @options[:encrypted_data_bag_secret_path]
149
- @encrypted_data_bag_secret_path = File.expand_path(@options[:encrypted_data_bag_secret_path])
150
- end
151
-
152
- @options[:encrypted_data_bag_secret] = encrypted_data_bag_secret
146
+ @options[:encrypted_data_bag_secret] ||= begin
147
+ if @options[:encrypted_data_bag_secret_path]
148
+ @encrypted_data_bag_secret_path = File.expand_path(@options[:encrypted_data_bag_secret_path])
149
+ end
153
150
 
154
- unless @options[:client_key].present? && File.exist?(@options[:client_key])
155
- raise Errors::ClientKeyFileNotFound, "client key not found at: '#{@options[:client_key]}'"
151
+ encrypted_data_bag_secret
156
152
  end
157
153
 
154
+ unless verify_client_key(@options[:client_key])
155
+ @options[:client_key] = File.expand_path(@options[:client_key])
156
+ raise Errors::ClientKeyFileNotFoundOrInvalid, "client key is invalid or not found at: '#{@options[:client_key]}'" unless File.exist?(@options[:client_key]) && verify_client_key(::IO.read(@options[:client_key]))
157
+ end
158
+
158
159
  @connection_registry = Celluloid::Registry.new
159
160
  @resources_registry = Celluloid::Registry.new
160
161
  @connection_supervisor = ConnectionSupervisor.new(@connection_registry, @options)
@@ -273,6 +274,13 @@ module Ridley
273
274
 
274
275
  private
275
276
 
277
+ def verify_client_key(key)
278
+ OpenSSL::PKey::RSA.new(key)
279
+ true
280
+ rescue
281
+ false
282
+ end
283
+
276
284
  def connection
277
285
  @connection_registry[:connection_pool]
278
286
  end
@@ -44,7 +44,7 @@ module Ridley
44
44
  end
45
45
 
46
46
  class BootstrapError < RidleyError; end
47
- class ClientKeyFileNotFound < BootstrapError; end
47
+ class ClientKeyFileNotFoundOrInvalid < BootstrapError; end
48
48
  class EncryptedDataBagSecretNotFound < BootstrapError; end
49
49
 
50
50
  class HostConnectionError < RidleyError; end
@@ -1,5 +1,7 @@
1
1
  module Ridley
2
2
  class CookbookResource < Ridley::Resource
3
+ task_class TaskThread
4
+
3
5
  set_resource_path "cookbooks"
4
6
  represented_by Ridley::CookbookObject
5
7
 
@@ -1,3 +1,3 @@
1
1
  module Ridley
2
- VERSION = "1.4.1"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -87,18 +87,24 @@ describe Ridley::Client do
87
87
  }.to raise_error(ArgumentError, "Missing required option(s): 'client_key'")
88
88
  end
89
89
 
90
- it "raises a ClientKeyFileNotFound if the filepath for client_key is not found" do
90
+ it "raises a ClientKeyFileNotFound if the client_key is not found or an invalid key" do
91
91
  config[:client_key] = "/tmp/nofile.xxsa"
92
92
 
93
93
  expect {
94
94
  described_class.new(config)
95
- }.to raise_error(Ridley::Errors::ClientKeyFileNotFound)
95
+ }.to raise_error(Ridley::Errors::ClientKeyFileNotFoundOrInvalid)
96
96
  end
97
97
 
98
98
  it "expands the path of the client_key" do
99
- config[:client_key] = "~/"
99
+ config[:client_key] = "spec/fixtures/reset.pem"
100
100
 
101
- described_class.new(config).client_key.should_not == "~/"
101
+ described_class.new(config).client_key[0..4].should_not == "spec/"
102
+ end
103
+
104
+ it "accepts a client key as a string" do
105
+ key = File.read(fixtures_path.join("reset.pem").to_s)
106
+ config[:client_key] = key.dup
107
+ described_class.new(config).client_key.should == key
102
108
  end
103
109
 
104
110
  it "assigns a 'ssh' attribute from the given 'ssh' option" do
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.1
4
+ version: 1.5.0
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-31 00:00:00.000000000 Z
12
+ date: 2013-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable