forked from travis-ci/dpl
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request travis-ci#420 from HPI-BP2015H/launchpad
Launchpad support
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'net/http' | ||
require 'net/https' | ||
|
||
module DPL | ||
class Provider | ||
class Launchpad < Provider | ||
|
||
def initialize(context, options) | ||
super | ||
@http = Net::HTTP.new('api.launchpad.net', 443) | ||
@http.use_ssl = true | ||
end | ||
|
||
def check_auth | ||
end | ||
|
||
def needs_key? | ||
false | ||
end | ||
|
||
def push_app | ||
response = api_call('/1.0/' + options[:slug] + '/+code-import', {'ws.op' => 'requestImport'}) | ||
error('Deploy failed! Launchpad credentials invalid. ' + response.code.to_s) if response.code == '401' | ||
error('Error: ' + response.code.to_s + ' ' + response.body) unless response.kind_of? Net::HTTPSuccess | ||
end | ||
|
||
private | ||
|
||
def api_call(path, data) | ||
req = Net::HTTP::Post.new(path) | ||
req.set_form_data(data) | ||
req['Authorization'] = authorization | ||
return @http.request(req) | ||
end | ||
|
||
def authorization | ||
return 'OAuth oauth_consumer_key="Travis%20Deploy", ' + | ||
'oauth_nonce="' + rand(36**32).to_s(36) + '",' + | ||
'oauth_signature="%26' + options[:oauth_token_secret] + '",' + | ||
'oauth_signature_method="PLAINTEXT",' + | ||
'oauth_timestamp="' + Time::now().to_i.to_s + '",' + | ||
'oauth_token="' + options[:oauth_token] + '",' + | ||
'oauth_version="1.0"' | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'spec_helper' | ||
require 'dpl/provider/cloudcontrol' | ||
|
||
describe DPL::Provider::Launchpad do | ||
subject :provider do | ||
described_class.new(DummyContext.new, :slug => '~user/repo/branch', :oauth_token => 'uezinoosinmxkewhochq', :oauth_token_secret => 'dinb6fao4jh0kfdn5mich31cbikdkpjplkmadhi80h93kbbaableeeg41mm0jab9jif8ch7i2k9a80n5') | ||
end | ||
|
||
its(:needs_key?) { should be false } | ||
|
||
describe '#push_app' do | ||
it 'on api success' do | ||
expect(provider).to receive(:api_call).with('/1.0/~user/repo/branch/+code-import', {'ws.op' => 'requestImport'}).and_return Net::HTTPSuccess.new("HTTP/1.1", 200, "Ok") | ||
provider.push_app | ||
end | ||
|
||
it 'on api failure' do | ||
expect(provider).to receive(:api_call).with('/1.0/~user/repo/branch/+code-import', {'ws.op' => 'requestImport'}).and_return double("Net::HTTPUnauthorized", code: 401, body: "", class: Net::HTTPUnauthorized) | ||
expect { provider.push_app }.to raise_error(DPL::Error) | ||
end | ||
end | ||
|
||
describe 'private method' do | ||
describe '#authorization' do | ||
it 'should return correct oauth' do | ||
result = provider.instance_eval { authorization } | ||
expect(result).to include('oauth_token="uezinoosinmxkewhochq",') | ||
expect(result).to include('oauth_signature="%26dinb6fao4jh0kfdn5mich31cbikdkpjplkmadhi80h93kbbaableeeg41mm0jab9jif8ch7i2k9a80n5",') | ||
end | ||
end | ||
end | ||
|
||
end |