diff --git a/lib/fog/rackspace/load_balancers.rb b/lib/fog/rackspace/load_balancers.rb index c88aebac1..33ec367e1 100644 --- a/lib/fog/rackspace/load_balancers.rb +++ b/lib/fog/rackspace/load_balancers.rb @@ -31,6 +31,7 @@ module Fog request_path 'fog/rackspace/requests/load_balancers' request :get_ssl_termination request :set_ssl_termination + request :remove_ssl_termination request :create_load_balancer request :get_load_balancer request :list_load_balancers diff --git a/lib/fog/rackspace/models/load_balancers/load_balancer.rb b/lib/fog/rackspace/models/load_balancers/load_balancer.rb index 6096849dd..80ad5ea87 100644 --- a/lib/fog/rackspace/models/load_balancers/load_balancer.rb +++ b/lib/fog/rackspace/models/load_balancers/load_balancer.rb @@ -27,7 +27,6 @@ module Fog attribute :name attribute :state, :aliases => 'status' attribute :nodes - attribute :ssl_termination, :aliases => 'ssltermination' def initialize(attributes) #HACK - Since we are hacking how sub-collections work, we have to make sure the connection is valid first. @@ -61,13 +60,19 @@ module Fog def ssl_termination requires :identity - ssl_termination = connection.get_ssl_termination(identity) - (ssl_termination.status == 404) ? nil : ssl_termination.body["sslTermination"] + ssl_termination = connection.get_ssl_termination(identity).body['sslTermination'] + rescue Fog::Rackspace::LoadBalancers::NotFound + nil end - def enable_ssl_termination(securePort, privatekey, certificate, enabled=true, secureTrafficOnly=false) + def enable_ssl_termination(securePort, privatekey, certificate, options = {}) requires :identity - connection.set_ssl_termination(identity, securePort, privatekey, certificate, enabled, secureTrafficOnly) + connection.set_ssl_termination(identity, securePort, privatekey, certificate, options) + end + + def disable_ssl_termination + requires :identity + connection.remove_ssl_termination(identity) end def virtual_ips diff --git a/lib/fog/rackspace/requests/load_balancers/get_ssl_termination.rb b/lib/fog/rackspace/requests/load_balancers/get_ssl_termination.rb index b27dc2e69..ceb6010dc 100644 --- a/lib/fog/rackspace/requests/load_balancers/get_ssl_termination.rb +++ b/lib/fog/rackspace/requests/load_balancers/get_ssl_termination.rb @@ -4,7 +4,7 @@ module Fog class Real def get_ssl_termination(load_balancer_id) request( - :expects => [200,404], + :expects => [200], :path => "loadbalancers/#{load_balancer_id}/ssltermination", :method => 'GET' ) @@ -12,4 +12,4 @@ module Fog end end end -end \ No newline at end of file +end diff --git a/lib/fog/rackspace/requests/load_balancers/remove_ssl_termination.rb b/lib/fog/rackspace/requests/load_balancers/remove_ssl_termination.rb new file mode 100644 index 000000000..c88726f20 --- /dev/null +++ b/lib/fog/rackspace/requests/load_balancers/remove_ssl_termination.rb @@ -0,0 +1,15 @@ +module Fog + module Rackspace + class LoadBalancers + class Real + def remove_ssl_termination(load_balancer_id) + request( + :expects => [200, 202], + :path => "loadbalancers/#{load_balancer_id}/ssltermination", + :method => 'DELETE' + ) + end + end + end + end +end diff --git a/lib/fog/rackspace/requests/load_balancers/set_ssl_termination.rb b/lib/fog/rackspace/requests/load_balancers/set_ssl_termination.rb index b10d86bd7..cc8b9e6f8 100644 --- a/lib/fog/rackspace/requests/load_balancers/set_ssl_termination.rb +++ b/lib/fog/rackspace/requests/load_balancers/set_ssl_termination.rb @@ -2,16 +2,25 @@ module Fog module Rackspace class LoadBalancers class Real - def set_ssl_termination(load_balancer_id, securePort, privatekey, certificate, enabled, secureTrafficOnly) + def set_ssl_termination(load_balancer_id, securePort, privatekey, certificate, options = {}) data = { securePort: securePort, privatekey: privatekey, - certificate: certificate, - #intermediatecertificate: intermediatecertificate + certificate: certificate } + + if options.has_key? :intermediate_certificate + data['intermediateCertificate'] = options[:intermediate_certificate] + end + if options.has_key? :enabled + data['enabled'] = options[:enabled] + end + if options.has_key? :secure_traffic_only + data['secureTrafficOnly'] - options[:secure_traffic_only] + end request( :body => MultiJson.encode(data), - :expects => [202,404], + :expects => [200, 202], :path => "loadbalancers/#{load_balancer_id}/ssltermination", :method => 'PUT' ) @@ -19,4 +28,4 @@ module Fog end end end -end \ No newline at end of file +end diff --git a/tests/rackspace/models/load_balancers/load_balancer_tests.rb b/tests/rackspace/models/load_balancers/load_balancer_tests.rb index b2ecf41f4..7cbad86ff 100644 --- a/tests/rackspace/models/load_balancers/load_balancer_tests.rb +++ b/tests/rackspace/models/load_balancers/load_balancer_tests.rb @@ -124,6 +124,26 @@ Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer', ['rackspace']) do @instance.reset_error_page end + @instance.wait_for { ready? } + tests("#ssl_termination is nil").returns(nil) do + @instance.ssl_termination + end + + @instance.wait_for { ready? } + tests("#enable_ssl_termination(443, PRIVATE_KEY, CERTIFICATE").succeeds do + @instance.enable_ssl_termination(443, PRIVATE_KEY, CERTIFICATE) + end + + @instance.wait_for { ready? } + tests("#ssl_termination").succeeds do + @instance.ssl_termination + end + + @instance.wait_for { ready? } + tests("#disable_ssl_termination").succeeds do + @instance.disable_ssl_termination + end + @instance.wait_for { ready? } end diff --git a/tests/rackspace/requests/load_balancers/helper.rb b/tests/rackspace/requests/load_balancers/helper.rb index 4074b302c..1d3da9962 100644 --- a/tests/rackspace/requests/load_balancers/helper.rb +++ b/tests/rackspace/requests/load_balancers/helper.rb @@ -35,10 +35,10 @@ LOAD_BALANCER_USAGE_FORMAT = { SSL_TERMINATION_FORMAT = { 'sslTermination' => { 'certificate' => String, - 'privateKey' => String, + 'privatekey' => String, 'enabled' => Fog::Boolean, 'securePort' => Integer, - 'secureTrafficOnly' => Integer, + 'secureTrafficOnly' => Fog::Boolean, 'intermediateCertificate' => Fog::Nullable::String } } @@ -157,3 +157,60 @@ ERROR_PAGE_FORMAT = { 'content' => String } } + +PRIVATE_KEY = '-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAqSXePu8qLmniU7jNxoWq3SLkR8txMsl1gFYftpq7NIFaGfzV +f4ZswYdEYDVWWRepQjS0TvsB0d5+usEUy/pcdZAlQLnn+540iLkvxKPVMzojUbG6 +yOAmjC/xAZuExJHtfCrRHUQ4WQCwqyqANfP81y1inAb0zJGbtWUreV+nv8Ue77qX +77fOuqI6zOHinGZU7l25XGLcVUphgt8UtHZBzz2ahoftZ97DhUyQiSJQCaHXJd3Q +eIHAq9qc7hu+us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eIHAq9qc7hu+usiYZWz34A0l +w/gAl+RYcdvVc8kIwWxpiSieqqBPOwNzN5B0+9uu5sDzMGMFnnSWcNKIPumX0rke +3xFUl3UD6GJwvwIDAQABo4HIMIHFMIGjBgNVHSMEgZswgZiAFIkXQizRaftxVDaL +P/Fb/F2ht017oX2kezB5MQswCQYDVQQGEwJVUzEOMAwGA1UECBMFVGV4YXMxDjAM +BgNVBAcTBVRleGFzMRowGAYDVQQKExFSYWNrU3BhY2UgSG9zdGluZzEUMBIGA1UE +CxMLUmFja0V4cCBDQTQxGDAWBgNVBAMTD2NhNC5yYWNrZXhwLm9yZ4IBAjAdBgNV +HQ4EFgQUQUXHjce1JhjJDA4nhYcbebMrIGYwDQYJKoZIhvcNAQEFBQADggEBACLe +vxcDSx91uQoc1uancb+vfkaNpvfAxOkUtrdRSHGXxvUkf/EJpIyG/M0jt5CLmEpE +UedeCFlRN+Qnsqt589ZemWWJwth/Jbu0wQodfSo1cP0J2GFZDyTd5cWgm0IxD8A/ +ZRGzNnTx3xskv6/lOh7so9ULppEbOsZTNqQ4ahbxbiaR2iDTQGF3XKSHha8O93RB +YlnFahKZ2j0CpYvg0lJjfN0Lvj7Sm6GBA74n2OrGuB14H27wklD+PtIEFniyxKbq +5TDO0l4yDgkR7PsckmZqK22GP9c3fQkmXodtpV1wRjcSAxxVWYm+S24XvMFERs3j +yXEf+VJ0H+voAvxgbAk= +-----END CERTIFICATE-----' + + diff --git a/tests/rackspace/requests/load_balancers/load_balancer_tests.rb b/tests/rackspace/requests/load_balancers/load_balancer_tests.rb index 1dd499fcd..d912aafca 100644 --- a/tests/rackspace/requests/load_balancers/load_balancer_tests.rb +++ b/tests/rackspace/requests/load_balancers/load_balancer_tests.rb @@ -47,14 +47,6 @@ Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer_tests', ['rackspace' @service.update_load_balancer(@lb_id, { :port => 80 }).body end - tests("#ssl_termination(#{@lb_id})").succeeds do - @service.ssl_termination(@lb_id).body - end - - tests("#enable_ssl_termination(#{@lb_id})").succeeds do - @service.enable_ssl_termination(@lb_id, "443", "private", "public", true, false).body - end - until @service.get_load_balancer(@lb_id).body["loadBalancer"]["status"] == STATUS_ACTIVE sleep 10 end diff --git a/tests/rackspace/requests/load_balancers/ssl_termination_tests.rb b/tests/rackspace/requests/load_balancers/ssl_termination_tests.rb new file mode 100644 index 000000000..d5246dad2 --- /dev/null +++ b/tests/rackspace/requests/load_balancers/ssl_termination_tests.rb @@ -0,0 +1,38 @@ +Shindo.tests('Fog::Rackspace::LoadBalancers | ssl_termination', ['rackspace']) do + + pending if Fog.mocking? + + given_a_load_balancer_service do + given_a_load_balancer do + tests('success') do + + @lb.wait_for { ready? } + tests("#set_ssl_termination(#{@lb.id}, 443, PRIVATE_KEY, CERTIFICATE)").succeeds do + @service.set_ssl_termination(@lb.id, 443, PRIVATE_KEY, CERTIFICATE) + end + + @lb.wait_for { ready? } + tests("#get_ssl_termination(#{@lb.id})").formats(SSL_TERMINATION_FORMAT) do + @service.get_ssl_termination(@lb.id).body + end + + @lb.wait_for { ready? } + tests("#remove_ssl_termination(#{@lb.id})").succeeds do + @service.remove_ssl_termination(@lb.id).body + end + + end + + tests('failure') do + @lb.wait_for { ready? } + tests("#get_ssl_termination(#{@lb.id})").raises(Fog::Rackspace::LoadBalancers::NotFound) do + @service.get_ssl_termination(@lb.id).body + end + + tests("#set_ssl_termination(#{@lb.id}, 443, '', CERTIFICATE)").raises(Fog::Rackspace::LoadBalancers::BadRequest) do + @service.set_ssl_termination(@lb.id, 443, '', CERTIFICATE) + end + end + end + end +end