ridley 0.12.1 → 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,16 +5,16 @@ silence_warnings do
5
5
  # Requiring winrm before all other gems because of https://github.com/WinRb/WinRM/issues/39
6
6
  require 'winrm'
7
7
  end
8
- require 'chozo'
8
+
9
+ require 'active_support/inflector'
10
+ require 'addressable/uri'
9
11
  require 'celluloid'
12
+ require 'chozo'
10
13
  require 'faraday'
11
- require 'addressable/uri'
12
- require 'multi_json'
13
- require 'solve'
14
- require 'active_support/inflector'
15
14
  require 'forwardable'
16
- require 'thread'
15
+ require 'multi_json'
17
16
  require 'pathname'
17
+ require 'solve'
18
18
 
19
19
  if jruby?
20
20
  require 'json/pure'
@@ -22,26 +22,28 @@ else
22
22
  require 'json/ext'
23
23
  end
24
24
 
25
- require 'ridley/version'
26
- require 'ridley/errors'
27
-
28
25
  JSON.create_id = nil
29
26
 
30
27
  # @author Jamie Winsor <reset@riotgames.com>
31
28
  module Ridley
32
29
  CHEF_VERSION = '11.4.0'.freeze
33
30
 
34
- autoload :Bootstrapper, 'ridley/bootstrapper'
35
- autoload :Client, 'ridley/client'
36
- autoload :Connection, 'ridley/connection'
37
- autoload :Chef, 'ridley/chef'
38
- autoload :ChefObject, 'ridley/chef_object'
39
- autoload :DSL, 'ridley/dsl'
40
- autoload :Logging, 'ridley/logging'
41
- autoload :Mixin, 'ridley/mixin'
42
- autoload :Resource, 'ridley/resource'
43
- autoload :SandboxUploader, 'ridley/sandbox_uploader'
44
- autoload :HostConnector, 'ridley/host_connector'
31
+ require_relative 'ridley/mixin'
32
+ require_relative 'ridley/bootstrap_bindings'
33
+ require_relative 'ridley/bootstrapper'
34
+ require_relative 'ridley/chef_object'
35
+ require_relative 'ridley/chef_objects'
36
+ require_relative 'ridley/client'
37
+ require_relative 'ridley/connection'
38
+ require_relative 'ridley/chef'
39
+ require_relative 'ridley/host_connector'
40
+ require_relative 'ridley/logging'
41
+ require_relative 'ridley/middleware'
42
+ require_relative 'ridley/resource'
43
+ require_relative 'ridley/resources'
44
+ require_relative 'ridley/sandbox_uploader'
45
+ require_relative 'ridley/version'
46
+ require_relative 'ridley/errors'
45
47
 
46
48
  class << self
47
49
  extend Forwardable
@@ -68,8 +70,3 @@ module Ridley
68
70
  end
69
71
 
70
72
  Celluloid.logger = Ridley.logger
71
-
72
- require 'ridley/bootstrap_bindings'
73
- require 'ridley/middleware'
74
- require 'ridley/chef_objects'
75
- require 'ridley/resources'
@@ -1,5 +1,3 @@
1
- require 'ridley/mixin/bootstrap_binding'
2
-
3
1
  Dir["#{File.dirname(__FILE__)}/bootstrap_bindings/*.rb"].sort.each do |path|
4
- require "ridley/bootstrap_bindings/#{File.basename(path, '.rb')}"
2
+ require_relative "bootstrap_bindings/#{File.basename(path, '.rb')}"
5
3
  end
@@ -1,8 +1,9 @@
1
+ require_relative 'bootstrapper/context'
2
+ require_relative 'logging'
3
+
1
4
  module Ridley
2
5
  # @author Jamie Winsor <reset@riotgames.com>
3
6
  class Bootstrapper
4
- autoload :Context, 'ridley/bootstrapper/context'
5
-
6
7
  include Celluloid
7
8
  include Ridley::Logging
8
9
 
@@ -4,8 +4,8 @@ module Ridley
4
4
  # Classes and modules used for integrating with a Chef Server, the Chef community
5
5
  # site, and Chef Cookbooks
6
6
  module Chef
7
- autoload :Cookbook, 'ridley/chef/cookbook'
8
- autoload :Chefignore, 'ridley/chef/chefignore'
9
- autoload :Digester, 'ridley/chef/digester'
7
+ require_relative 'chef/cookbook'
8
+ require_relative 'chef/chefignore'
9
+ require_relative 'chef/digester'
10
10
  end
11
11
  end
@@ -1,8 +1,8 @@
1
1
  module Ridley::Chef
2
2
  # @author Jamie Winsor <reset@riotgames.com>
3
3
  class Cookbook
4
- autoload :Metadata, 'ridley/chef/cookbook/metadata'
5
- autoload :SyntaxCheck, 'ridley/chef/cookbook/syntax_check'
4
+ require_relative 'cookbook/metadata'
5
+ require_relative 'cookbook/syntax_check'
6
6
 
7
7
  class << self
8
8
  # @param [String] filepath
@@ -1,3 +1,3 @@
1
1
  Dir["#{File.dirname(__FILE__)}/chef_objects/*.rb"].sort.each do |path|
2
- require "ridley/chef_objects/#{File.basename(path, '.rb')}"
2
+ require_relative "chef_objects/#{File.basename(path, '.rb')}"
3
3
  end
@@ -15,7 +15,7 @@ module Ridley
15
15
  :root_files
16
16
  ].freeze
17
17
 
18
- set_chef_id "name"
18
+ set_chef_id "cookbook_name"
19
19
  set_chef_type "cookbook"
20
20
  set_chef_json_class "Chef::Cookbook"
21
21
 
@@ -167,6 +167,14 @@ module Ridley
167
167
  end
168
168
  end
169
169
 
170
+ # Reload the attributes of the instantiated resource
171
+ #
172
+ # @return [Ridley::CookbookObject]
173
+ def reload
174
+ mass_assign(resource.find(self, self.version)._attributes_)
175
+ self
176
+ end
177
+
170
178
  def to_s
171
179
  "#{name}: #{manifest}"
172
180
  end
@@ -1,27 +1,5 @@
1
1
  module Ridley
2
2
  # @author Jamie Winsor <reset@riotgames.com>
3
- #
4
- # @example
5
- # connection = Ridley::Client.new
6
- # connection.role.all
7
- #
8
- # connection.role.find("reset") => Ridley::RoleResource.find(connection, "reset")
9
- #
10
- # @example instantiating new resources
11
- # connection = Ridley::Connection.new
12
- # connection.role.new(name: "hello") => <#Ridley::RoleResource: @name="hello">
13
- #
14
- # New instances of resources can be instantiated by calling new on the Ridley::Context. These messages
15
- # will be send to the Chef resource's class in Ridley and can be treated as a normal Ruby object. Each
16
- # instantiated object will have the connection information contained within so you can do things like
17
- # save a role after changing it's attributes.
18
- #
19
- # r = connection.role.new(name: "new-role")
20
- # r.name => "new-role"
21
- # r.name = "other-name"
22
- # r.save
23
- #
24
- # connection.role.find("new-role") => <#Ridley::RoleResource: @name="new-role">
25
3
  class Client
26
4
  class ConnectionSupervisor < ::Celluloid::SupervisionGroup
27
5
  def initialize(registry, options)
@@ -4,10 +4,10 @@ require 'timeout'
4
4
  module Ridley
5
5
  # @author Kyle Allan <kallan@riotgames.com>
6
6
  module HostConnector
7
- autoload :Response, 'ridley/host_connector/response'
8
- autoload :ResponseSet, 'ridley/host_connector/response_set'
9
- autoload :SSH, 'ridley/host_connector/ssh'
10
- autoload :WinRM, 'ridley/host_connector/winrm'
7
+ require_relative 'host_connector/response'
8
+ require_relative 'host_connector/response_set'
9
+ require_relative 'host_connector/ssh'
10
+ require_relative 'host_connector/winrm'
11
11
 
12
12
  DEFAULT_SSH_PORT = 22.freeze
13
13
  DEFAULT_WINRM_PORT = 5985.freeze
@@ -4,7 +4,7 @@ module Ridley
4
4
  module HostConnector
5
5
  # @author Jamie Winsor <reset@riotgames.com>
6
6
  class SSH
7
- autoload :Worker, 'ridley/host_connector/ssh/worker'
7
+ require_relative 'ssh/worker'
8
8
 
9
9
  class << self
10
10
  # @param [Ridley::NodeObject, Array<Ridley::NodeObject>] nodes
@@ -2,8 +2,8 @@ module Ridley
2
2
  module HostConnector
3
3
  # @author Kyle Allan <kallan@riotgames.com>
4
4
  class WinRM
5
- autoload :CommandUploader, 'ridley/host_connector/winrm/command_uploader'
6
- autoload :Worker, 'ridley/host_connector/winrm/worker'
5
+ require_relative 'winrm/command_uploader'
6
+ require_relative 'winrm/worker'
7
7
 
8
8
  class << self
9
9
  # @param [Ridley::NodeResource, Array<Ridley::NodeResource>] nodes
@@ -3,11 +3,11 @@ module Ridley
3
3
  module Middleware
4
4
  CONTENT_TYPE = 'content-type'.freeze
5
5
 
6
- require 'ridley/middleware/parse_json'
7
- require 'ridley/middleware/chef_response'
8
- require 'ridley/middleware/chef_auth'
9
- require 'ridley/middleware/follow_redirects'
10
- require 'ridley/middleware/retry'
6
+ require_relative 'middleware/parse_json'
7
+ require_relative 'middleware/chef_response'
8
+ require_relative 'middleware/chef_auth'
9
+ require_relative 'middleware/follow_redirects'
10
+ require_relative 'middleware/retry'
11
11
 
12
12
  Faraday.register_middleware :request,
13
13
  chef_auth: -> { Ridley::Middleware::ChefAuth }
@@ -11,12 +11,15 @@ module Ridley
11
11
  #
12
12
  # @param [String] client_name
13
13
  # @param [String] client_key
14
+ # the path OR actual client key
14
15
  #
15
16
  # @option options [String] :host
16
17
  #
17
18
  # @see {#signing_object} for options
18
19
  def authentication_headers(client_name, client_key, options = {})
19
- rsa_key = OpenSSL::PKey::RSA.new(File.read(client_key))
20
+ contents = File.exists?(client_key) ? File.read(client_key) : client_key.to_s
21
+ rsa_key = OpenSSL::PKey::RSA.new(contents)
22
+
20
23
  headers = signing_object(client_name, options).sign(rsa_key).merge(host: options[:host])
21
24
  headers.inject({}) { |memo, kv| memo["#{kv[0].to_s.upcase}"] = kv[1];memo }
22
25
  end
@@ -57,7 +60,7 @@ module Ridley
57
60
  def call(env)
58
61
  signing_options = {
59
62
  http_method: env[:method],
60
- host: env[:url].host || "localhost",
63
+ host: "#{env[:url].host}:#{env[:url].port}",
61
64
  path: env[:url].path,
62
65
  body: env[:body] || ''
63
66
  }
@@ -1,3 +1,3 @@
1
1
  Dir["#{File.dirname(__FILE__)}/mixin/*.rb"].sort.each do |path|
2
- require "ridley/mixin/#{File.basename(path, '.rb')}"
2
+ require_relative "mixin/#{File.basename(path, '.rb')}"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  Dir["#{File.dirname(__FILE__)}/resources/*.rb"].sort.each do |path|
2
- require "ridley/resources/#{File.basename(path, '.rb')}"
2
+ require_relative "resources/#{File.basename(path, '.rb')}"
3
3
  end
@@ -1,8 +1,8 @@
1
- require 'ridley/resources/data_bag_item_resource'
2
-
3
1
  module Ridley
4
2
  # @author Jamie Winsor <reset@riotgames.com>
5
3
  class DataBagResource < Ridley::Resource
4
+ require_relative 'data_bag_item_resource'
5
+
6
6
  set_resource_path "data"
7
7
  represented_by Ridley::DataBagObject
8
8
 
@@ -1,3 +1,3 @@
1
1
  module Ridley
2
- VERSION = "0.12.1"
2
+ VERSION = "0.12.2"
3
3
  end
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.email = ["reset@riotgames.com"]
7
7
  s.description = %q{A reliable Chef API client with a clean syntax}
8
8
  s.summary = s.description
9
- s.homepage = "https://github.com/reset/ridley"
9
+ s.homepage = "https://github.com/RiotGames/ridley"
10
10
  s.license = "Apache 2.0"
11
11
 
12
12
  s.files = `git ls-files`.split($\)
@@ -6,12 +6,29 @@ describe "Client API operations", type: "acceptance" do
6
6
  let(:client_key) { fixtures_path.join('reset.pem').to_s }
7
7
  let(:connection) { Ridley.new(server_url: server_url, client_name: client_name, client_key: client_key) }
8
8
 
9
+ subject { connection.cookbook }
10
+
11
+ describe "downloading a cookbook" do
12
+ before { subject.upload(fixtures_path.join('example_cookbook')) }
13
+ let(:name) { "example_cookbook" }
14
+ let(:version) { "0.1.0" }
15
+ let(:destination) { tmp_path.join("example_cookbook-0.1.0") }
16
+
17
+ context "when the cookbook of the name/version is found" do
18
+ before { subject.download(name, version, destination) }
19
+
20
+ it "downloads the cookbook to the destination" do
21
+ expect(File.exist?(destination.join("metadata.rb"))).to be_true
22
+ end
23
+ end
24
+ end
25
+
9
26
  describe "uploading a cookbook" do
10
27
  let(:path) { fixtures_path.join("example_cookbook") }
11
28
 
12
29
  it "uploads the entire contents of the cookbook in the given path" do
13
- connection.cookbook.upload(path)
14
- cookbook = connection.cookbook.find("example_cookbook", "0.1.0")
30
+ subject.upload(path)
31
+ cookbook = subject.find("example_cookbook", "0.1.0")
15
32
 
16
33
  cookbook.attributes.should have(1).item
17
34
  cookbook.definitions.should have(1).item
@@ -90,4 +90,14 @@ describe Ridley::CookbookObject do
90
90
  subject.manifest.values.should each be_empty
91
91
  end
92
92
  end
93
+
94
+ describe "#reload" do
95
+ it "returns the updated self" do
96
+ other = subject.dup
97
+ other.version = "1.2.3"
98
+ resource.should_receive(:find).with(subject, subject.version).and_return(other)
99
+
100
+ expect(subject.reload).to eq(other)
101
+ end
102
+ end
93
103
  end
@@ -18,6 +18,19 @@ describe Ridley::Middleware::ChefAuth do
18
18
  }
19
19
  subject.authentication_headers(client_name, client_key, options).should be_a(Hash)
20
20
  end
21
+
22
+ context "when the :client_key is an actual key" do
23
+ let(:client_key) { File.read(fixtures_path.join("reset.pem")) }
24
+
25
+ it "returns a Hash of authentication headers" do
26
+ options = {
27
+ http_method: "GET",
28
+ host: "https://api.opscode.com",
29
+ path: "/something.file"
30
+ }
31
+ subject.authentication_headers(client_name, client_key, options).should be_a(Hash)
32
+ end
33
+ end
21
34
  end
22
35
  end
23
36
 
@@ -12,12 +12,6 @@ describe Ridley::CookbookResource do
12
12
  let(:version) { "0.1.0" }
13
13
  let(:destination) { tmp_path.join("example_cookbook-0.1.0").to_s }
14
14
 
15
- context "when the cookbook of the name/version is found" do
16
- it "downloads the cookbook to the destination" do
17
- pending "can't test downloading until https://github.com/jkeiser/chef-zero/issues/5 is fixed"
18
- end
19
- end
20
-
21
15
  context "when the cookbook of the name/version is not found" do
22
16
  before { subject.should_receive(:find).with(name, version).and_return(nil) }
23
17
 
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: 0.12.1
4
+ version: 0.12.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-14 00:00:00.000000000 Z
12
+ date: 2013-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -434,7 +434,7 @@ files:
434
434
  - spec/unit/ridley/resources/search_resource_spec.rb
435
435
  - spec/unit/ridley/sandbox_uploader_spec.rb
436
436
  - spec/unit/ridley_spec.rb
437
- homepage: https://github.com/reset/ridley
437
+ homepage: https://github.com/RiotGames/ridley
438
438
  licenses:
439
439
  - Apache 2.0
440
440
  post_install_message:
@@ -455,7 +455,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
455
455
  version: '0'
456
456
  segments:
457
457
  - 0
458
- hash: -3737954718774524860
458
+ hash: 1382072884355944447
459
459
  requirements: []
460
460
  rubyforge_project:
461
461
  rubygems_version: 1.8.23