Skip to content

Commit

Permalink
Merge 2102af6 into 93d74f6
Browse files Browse the repository at this point in the history
  • Loading branch information
justincampbell committed Nov 24, 2014
2 parents 93d74f6 + 2102af6 commit 687df4f
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 17 deletions.
4 changes: 3 additions & 1 deletion lib/stacker_bee/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def middlewares

builder.use Middleware::EndpointNormalizer, api: self.class.api
builder.use Middleware::RemoveEmptyStrings
builder.use Middleware::CloudStackAPI, api_key: configuration.api_key
builder.use Middleware::CloudStackAPI,
api_key: configuration.api_key,
url: configuration.url

configuration.middlewares.call builder

Expand Down
3 changes: 1 addition & 2 deletions lib/stacker_bee/middleware/cloud_stack_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ module StackerBee
module Middleware
class CloudStackAPI < Base
RESPONSE_TYPE = 'json'
DEFAULT_PATH = '/client/api/'

def before(env)
env.request.params.merge!(
api_key: api_key,
command: env.request.endpoint_name,
response: RESPONSE_TYPE
)
env.request.path ||= DEFAULT_PATH
env.request.path ||= URI.parse(url).path
end
end
end
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion spec/integration/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
describe 'A response to a request sent to the CloudStack API', :vcr do
subject { client.list_accounts }

let(:url) { CONFIG['url'] }
let(:config_url) { CONFIG['url'] }
let(:uri) { URI.parse(config_url) }
let(:url) { uri.to_s }
let(:config_hash) do
{
url: url,
Expand Down Expand Up @@ -35,6 +37,13 @@
end
end

context 'with a nonexistant path', :regression do
before { uri.path = '/not/a/real/endpoint' }
it 'raises a client error' do
expect { subject }.to raise_error(StackerBee::ClientError)
end
end

context 'trailing slash in URL', :regression do
let(:url) { CONFIG['url'].gsub(/\/$/, '') + '/' }
it 'makes request with trailing slash' do
Expand Down
17 changes: 4 additions & 13 deletions spec/units/stacker_bee/middleware/cloud_stack_api_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
describe StackerBee::Middleware::CloudStackAPI do
let(:env) do
StackerBee::Middleware::Environment.new(
endpoint_name: 'endpoint-name',
path: path
endpoint_name: 'endpoint-name'
)
end
let(:middleware) { described_class.new(api_key: 'API-KEY', params: {}) }
let(:path) { nil }
let(:middleware) { described_class.new(api_key: 'API-KEY', url: url) }
let(:url) { 'http://localhost:1234/my/path' }

before do
middleware.before(env)
Expand All @@ -15,15 +14,7 @@
describe 'request' do
subject { env.request }

context 'when the path is not set' do
let(:path) { nil }
its(:path) { should == described_class::DEFAULT_PATH }
end

context 'when the path is already set' do
let(:path) { 'already set' }
its(:path) { should == path }
end
its(:path) { should == '/my/path' }
end

describe 'params' do
Expand Down

0 comments on commit 687df4f

Please sign in to comment.