Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Config ssl #20

Merged
merged 2 commits into from

2 participants

@adamhunter

updated configuring ssl

  • fixed issue where setting ssl in client initialization options did nothing
  • cleaned up use of ssl=, ssl_enable, and ssl_disable
  • because multiple modes can call ssl_{enable,disable} the first call sets the protocol and successive calls will not
@seancribbs

Why threequal?

Idk, force of habit I guess, I can make it ==

@seancribbs

Why did you remove this method?

I didn't remove it, i just made ssl_enable and ssl_disable protected so that is how the diff showed up (https://github.com/basho/riak-ruby-client/blob/f790df177abc12d89f1a78c49539342ad3100314/lib/riak/client/node.rb)

@seancribbs
Owner

+1, merging.

@seancribbs seancribbs merged commit 1db6fb9 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 22, 2012
  1. @adamhunter
  2. @adamhunter

    switched from === to ==

    adamhunter authored
This page is out of date. Refresh to see the latest.
View
21 lib/riak/client.rb
@@ -76,6 +76,7 @@ class Client
# If no nodes are given, a single node is constructed from the remaining
# options given to Client.new.
# @option options [String] :host ('127.0.0.1') The host or IP address for the Riak endpoint
+ # @option options [String] :protocol ('http') The protocol to use for connecting to a node backend
# @option options [Fixnum] :http_port (8098) The port of the Riak HTTP endpoint
# @option options [Fixnum] :pb_port (8087) The port of the Riak Protocol Buffers endpoint
# @option options [String] :prefix ('/riak/') The URL path prefix to the main HTTP endpoint
@@ -83,6 +84,7 @@ class Client
# @option options [Fixnum, String] :client_id (rand(MAX_CLIENT_ID)) The internal client ID used by Riak to route responses
# @option options [String, Symbol] :http_backend (:NetHTTP) which HTTP backend to use
# @option options [String, Symbol] :protobuffs_backend (:Beefcake) which Protocol Buffers backend to use
+ # @option options [Boolean, Hash] :ssl (nil) The SSL options to pass to each node or true for default options
# @raise [ArgumentError] raised if any invalid options are given
def initialize(options={})
if options.include? :port
@@ -114,6 +116,7 @@ def initialize(options={})
self.http_backend = options[:http_backend] || :NetHTTP
self.protobuffs_backend = options[:protobuffs_backend] || :Beefcake
self.client_id = options[:client_id] if options[:client_id]
+ self.ssl = options[:ssl] if options[:ssl]
end
# Yields a backend for operations that are protocol-independent.
@@ -391,20 +394,22 @@ def protocol=(value)
raise ArgumentError, t("protocol_invalid", :invalid => value, :valid => PROTOCOLS.join(', '))
end
+ #TODO
+ @backend = nil
+ @protocol = value
+
case value
when 'https'
nodes.each do |node|
- node.ssl_options ||= {}
+ node.ssl = true unless node.ssl_enabled?
end
when 'http'
nodes.each do |node|
- node.ssl_options = nil
+ node.ssl = false
end
end
- #TODO
- @backend = nil
- @protocol = value
+ @protocol
end
# Takes a pool. Acquires a backend from the pool and yields it with
@@ -467,12 +472,6 @@ def ssl=(value)
@nodes.each do |node|
node.ssl = value
end
-
- if value
- @protocol = 'https'
- else
- @protocol = 'http'
- end
value
end
View
16 lib/riak/client/node.rb
@@ -85,11 +85,18 @@ def ssl=(value)
# Checks if SSL is enabled for HTTP
def ssl_enabled?
- @client.protocol == 'https' || @ssl_options.present?
+ @client.protocol == 'https' && @ssl_options.present?
end
+ def inspect
+ "<#Node #{@host}:#{@http_port}:#{@pb_port}>"
+ end
+
+ protected
+
+
def ssl_enable
- @client.protocol = 'https'
+ @client.protocol = 'https' unless @client.protocol == 'https'
@ssl_options[:pem] = File.read(@ssl_options[:pem_file]) if @ssl_options[:pem_file]
@ssl_options[:verify_mode] ||= "peer" if @ssl_options.stringify_keys.any? {|k,v| %w[pem ca_file ca_path].include?(k)}
@ssl_options[:verify_mode] ||= "none"
@@ -99,13 +106,10 @@ def ssl_enable
end
def ssl_disable
- @client.protocol = 'http'
+ @client.protocol = 'http' unless @client.protocol == 'http'
@ssl_options = nil
end
- def inspect
- "<#Node #{@host}:#{@http_port}:#{@pb_port}>"
- end
end
end
end
View
29 spec/riak/client_spec.rb
@@ -299,17 +299,38 @@
@client = Riak::Client.new
end
+ it "should enable ssl when passed to the initializer" do
+ client = Riak::Client.new(:ssl => true)
+ client.nodes.first.ssl_options.should be_a(Hash)
+ client.nodes.first.ssl_options.should_not be_empty
+ end
+
it "should allow passing ssl options into the initializer" do
- lambda { client = Riak::Client.new(:ssl => {:verify_mode => "peer"}) }.should_not raise_error
+ client = Riak::Client.new(:ssl => {:verify_mode => "peer"})
+ client.nodes.first.ssl_options.should be_a(Hash)
+ client.nodes.first.ssl_options[:verify_mode].should eq("peer")
end
- it "should not have ssl options by default" do
- @client.nodes.first.ssl_options.should be_nil
+ it "should enable ssl options when initializing the client with https but not setting any ssl options" do
+ client = Riak::Client.new(:protocol => 'https')
+ client.nodes.first.ssl_options.should be_a(Hash)
+ client.nodes.first.ssl_options.should_not be_empty
+ end
+
+ it "should allow setting ssl options and specifying the https protocol" do
+ client = Riak::Client.new(:protocol => 'https', :ssl => {:verify_mode => 'peer'})
+ client.nodes.first.ssl_options.should be_a(Hash)
+ client.nodes.first.ssl_options[:verify_mode].should eq("peer")
end
- it "should have a blank hash for ssl options if the protocol is set to https" do
+ it "should enable ssl options when setting the protocol to https but not setting any ssl options" do
@client.protocol = 'https'
@client.nodes.first.ssl_options.should be_a(Hash)
+ @client.nodes.first.ssl_options.should_not be_empty
+ end
+
+ it "should not have ssl options by default" do
+ @client.nodes.first.ssl_options.should be_nil
end
# The api should have an ssl= method for setting up all of the ssl
Something went wrong with that request. Please try again.