cfoundry 0.5.3.rc7 → 0.6.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cfoundry/baseclient.rb +1 -1
- data/lib/cfoundry/concerns/login_helpers.rb +3 -15
- data/lib/cfoundry/rest_client.rb +8 -23
- data/lib/cfoundry/upload_helpers.rb +1 -1
- data/lib/cfoundry/v1/client.rb +0 -20
- data/lib/cfoundry/v2/client.rb +0 -20
- data/lib/cfoundry/version.rb +1 -1
- data/spec/cfoundry/rest_client_spec.rb +0 -71
- data/spec/cfoundry/v1/client_spec.rb +1 -3
- data/spec/support/shared_examples/client_login_examples.rb +1 -39
- metadata +6 -6
data/lib/cfoundry/baseclient.rb
CHANGED
@@ -13,7 +13,7 @@ module CFoundry
|
|
13
13
|
|
14
14
|
def_delegators :rest_client, :target, :target=, :token,
|
15
15
|
:proxy, :proxy=, :trace, :backtrace, :backtrace=,
|
16
|
-
:log, :log
|
16
|
+
:log, :log=
|
17
17
|
|
18
18
|
def initialize(target = "https://api.cloudfoundry.com", token = nil)
|
19
19
|
@rest_client = CFoundry::RestClient.new(target, token)
|
@@ -3,23 +3,11 @@ require "base64"
|
|
3
3
|
module CFoundry
|
4
4
|
module LoginHelpers
|
5
5
|
def login_prompts
|
6
|
-
|
7
|
-
@base.uaa.prompts
|
8
|
-
else
|
9
|
-
{
|
10
|
-
:username => ["text", "Email"],
|
11
|
-
:password => ["password", "Password"]
|
12
|
-
}
|
13
|
-
end
|
6
|
+
@base.uaa.prompts
|
14
7
|
end
|
15
8
|
|
16
9
|
def login(username, password)
|
17
|
-
@base.token =
|
18
|
-
if @base.uaa
|
19
|
-
AuthToken.from_uaa_token_info(@base.uaa.authorize(username, password))
|
20
|
-
else
|
21
|
-
AuthToken.new(@base.create_token({:password => password}, username)[:token])
|
22
|
-
end
|
10
|
+
@base.token = AuthToken.from_uaa_token_info(@base.uaa.authorize(username, password))
|
23
11
|
end
|
24
12
|
end
|
25
|
-
end
|
13
|
+
end
|
data/lib/cfoundry/rest_client.rb
CHANGED
@@ -24,7 +24,7 @@ module CFoundry
|
|
24
24
|
|
25
25
|
attr_reader :target
|
26
26
|
|
27
|
-
attr_accessor :trace, :backtrace, :log, :request_id, :token, :target, :proxy
|
27
|
+
attr_accessor :trace, :backtrace, :log, :request_id, :token, :target, :proxy
|
28
28
|
|
29
29
|
def initialize(target, token = nil)
|
30
30
|
@target = target
|
@@ -115,11 +115,17 @@ module CFoundry
|
|
115
115
|
|
116
116
|
add_headers(request, headers)
|
117
117
|
|
118
|
-
http
|
118
|
+
# TODO: test http proxies
|
119
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
119
120
|
|
120
121
|
# TODO remove this when staging returns streaming responses
|
121
122
|
http.read_timeout = 300
|
122
123
|
|
124
|
+
if uri.is_a?(URI::HTTPS)
|
125
|
+
http.use_ssl = true
|
126
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
127
|
+
end
|
128
|
+
|
123
129
|
before = Time.now
|
124
130
|
http.start do
|
125
131
|
response = http.request(request)
|
@@ -150,27 +156,6 @@ module CFoundry
|
|
150
156
|
raise InvalidTarget.new(@target)
|
151
157
|
end
|
152
158
|
|
153
|
-
def create_http(uri)
|
154
|
-
if (uri.instance_of?(URI::HTTP) && http_proxy) || (uri.instance_of?(URI::HTTPS) && https_proxy)
|
155
|
-
if uri.instance_of?(URI::HTTP)
|
156
|
-
http_proxy_uri = URI.parse(http_proxy)
|
157
|
-
else
|
158
|
-
http_proxy_uri = URI.parse(https_proxy)
|
159
|
-
end
|
160
|
-
http_proxy_user, http_proxy_pass = http_proxy_uri.userinfo.split(/:/) if http_proxy_uri.userinfo
|
161
|
-
http = Net::HTTP::Proxy(http_proxy_uri.host, http_proxy_uri.port, http_proxy_user, http_proxy_pass).new(uri.host, uri.port)
|
162
|
-
else
|
163
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
164
|
-
end
|
165
|
-
|
166
|
-
if uri.is_a?(URI::HTTPS)
|
167
|
-
http.use_ssl = true
|
168
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
169
|
-
end
|
170
|
-
|
171
|
-
return http
|
172
|
-
end
|
173
|
-
|
174
159
|
def construct_url(path)
|
175
160
|
uri = URI.parse(path)
|
176
161
|
return path if uri.scheme
|
data/lib/cfoundry/v1/client.rb
CHANGED
@@ -46,26 +46,6 @@ module CFoundry::V1
|
|
46
46
|
@base.proxy = email
|
47
47
|
end
|
48
48
|
|
49
|
-
# Current http proxy URI. Usually nil.
|
50
|
-
def http_proxy
|
51
|
-
@base.http_proxy
|
52
|
-
end
|
53
|
-
|
54
|
-
# Set the http proxy URI.
|
55
|
-
def http_proxy=(uri)
|
56
|
-
@base.http_proxy = uri
|
57
|
-
end
|
58
|
-
|
59
|
-
# Current https proxy URI. Usually nil.
|
60
|
-
def https_proxy
|
61
|
-
@base.https_proxy
|
62
|
-
end
|
63
|
-
|
64
|
-
# Set the https proxy URI.
|
65
|
-
def https_proxy=(uri)
|
66
|
-
@base.https_proxy = uri
|
67
|
-
end
|
68
|
-
|
69
49
|
# Is the client tracing API requests?
|
70
50
|
def trace
|
71
51
|
@base.trace
|
data/lib/cfoundry/v2/client.rb
CHANGED
@@ -54,26 +54,6 @@ module CFoundry::V2
|
|
54
54
|
@base.proxy = email
|
55
55
|
end
|
56
56
|
|
57
|
-
# Current http proxy URI. Usually nil.
|
58
|
-
def http_proxy
|
59
|
-
@base.http_proxy
|
60
|
-
end
|
61
|
-
|
62
|
-
# Set the http proxy URI.
|
63
|
-
def http_proxy=(uri)
|
64
|
-
@base.http_proxy = uri
|
65
|
-
end
|
66
|
-
|
67
|
-
# Current https proxy URI. Usually nil.
|
68
|
-
def https_proxy
|
69
|
-
@base.https_proxy
|
70
|
-
end
|
71
|
-
|
72
|
-
# Set the https proxy URI.
|
73
|
-
def https_proxy=(uri)
|
74
|
-
@base.https_proxy = uri
|
75
|
-
end
|
76
|
-
|
77
57
|
# Is the client tracing API requests?
|
78
58
|
def trace
|
79
59
|
@base.trace
|
data/lib/cfoundry/version.rb
CHANGED
@@ -278,75 +278,4 @@ describe CFoundry::RestClient do
|
|
278
278
|
end
|
279
279
|
end
|
280
280
|
end
|
281
|
-
|
282
|
-
describe '#create_http' do
|
283
|
-
subject { rest_client.send(:create_http, URI.parse(target_uri)) }
|
284
|
-
let(:target_uri) { "http://cloudfoundry.com" }
|
285
|
-
|
286
|
-
context "when no proxy URI is set" do
|
287
|
-
it "should return an instance of the plain Net:HTTP class" do
|
288
|
-
expect(subject).to be_instance_of(Net::HTTP)
|
289
|
-
expect(subject.use_ssl?).to be_false
|
290
|
-
expect(subject.proxy?).to_not be_true
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
context "when the target is an https URI" do
|
295
|
-
let(:target_uri) { "https://cloudfoundry.com" }
|
296
|
-
it "should return an instance of the plain Net:HTTP class with use_ssl" do
|
297
|
-
expect(subject).to be_instance_of(Net::HTTP)
|
298
|
-
expect(subject.use_ssl?).to be_true
|
299
|
-
expect(subject.proxy?).to_not be_true
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
context "when a http proxy URI without user/password is set " do
|
304
|
-
before { rest_client.http_proxy = "http://exapmle.com:8080" }
|
305
|
-
it "should return an instance of the proxy class" do
|
306
|
-
expect(subject.proxy?).to be_true
|
307
|
-
expect(subject.proxy_address).to eql("exapmle.com")
|
308
|
-
expect(subject.proxy_port).to eql(8080)
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
|
-
context "when a http proxy URI with user/password is set " do
|
313
|
-
before { rest_client.http_proxy = "http://user:pass@exapmle.com:8080" }
|
314
|
-
it "should return an instance of the proxy class" do
|
315
|
-
expect(subject.proxy?).to be_true
|
316
|
-
expect(subject.proxy_user).to eql("user")
|
317
|
-
expect(subject.proxy_pass).to eql("pass")
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
context "when a https proxy URI is set and the target is an https URI" do
|
322
|
-
let(:target_uri) { "https://cloudfoundry.com" }
|
323
|
-
before { rest_client.https_proxy = "http://exapmle.com:8080" }
|
324
|
-
it "should return an instance of the proxy class" do
|
325
|
-
expect(subject.proxy?).to be_true
|
326
|
-
end
|
327
|
-
end
|
328
|
-
|
329
|
-
context "when a https proxy URI is set and the target is an http URI" do
|
330
|
-
let(:target_uri) { "http://cloudfoundry.com" }
|
331
|
-
before { rest_client.https_proxy = "http://exapmle.com:8080" }
|
332
|
-
it "should return an instance of the plain Net:HTTP class" do
|
333
|
-
expect(subject.proxy?).to be_nil
|
334
|
-
end
|
335
|
-
end
|
336
|
-
|
337
|
-
context "when a http proxy URI is set and the target is an https URI" do
|
338
|
-
let(:target_uri) { "https://cloudfoundry.com" }
|
339
|
-
before { rest_client.http_proxy = "http://exapmle.com:8080" }
|
340
|
-
it "should return an instance of the plain Net:HTTP class" do
|
341
|
-
expect(subject.proxy?).to be_nil
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
context "when an invalid proxy URI is set" do
|
346
|
-
before { rest_client.http_proxy = "invalid URI" }
|
347
|
-
it "should raise an error" do
|
348
|
-
expect { subject }.to raise_error(URI::InvalidURIError)
|
349
|
-
end
|
350
|
-
end
|
351
|
-
end
|
352
281
|
end
|
@@ -9,11 +9,9 @@ describe CFoundry::V1::Client do
|
|
9
9
|
|
10
10
|
describe "#login" do
|
11
11
|
include_examples "client login"
|
12
|
-
include_examples "client login without UAA"
|
13
12
|
end
|
14
13
|
|
15
14
|
describe "#login_prompts" do
|
16
15
|
include_examples "client login prompts"
|
17
|
-
include_examples "client login prompts without UAA"
|
18
16
|
end
|
19
|
-
end
|
17
|
+
end
|
@@ -43,42 +43,4 @@ shared_examples_for 'client login' do
|
|
43
43
|
expect(client.token).to be_a(CFoundry::AuthToken)
|
44
44
|
expect(client.token.auth_header).to eq("bearer #{access_token}")
|
45
45
|
end
|
46
|
-
end
|
47
|
-
|
48
|
-
shared_examples_for 'client login prompts without UAA' do
|
49
|
-
let(:prompts) do
|
50
|
-
{
|
51
|
-
:user_id => ["text", "User ID"],
|
52
|
-
:pin => ["password", "Your 8-digit Pin #"]
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
subject { client.login_prompts }
|
57
|
-
|
58
|
-
it 'returns the prompts without UAA' do
|
59
|
-
expect(subject).to eq(prompts)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
shared_examples_for 'client login without UAA' do
|
64
|
-
let(:email) { 'test@test.com' }
|
65
|
-
let(:password) { 'secret' }
|
66
|
-
let(:access_token) { "some-access-token" }
|
67
|
-
|
68
|
-
before do
|
69
|
-
stub(client.base).create_token { access_token }
|
70
|
-
end
|
71
|
-
|
72
|
-
subject { client.login(email, password) }
|
73
|
-
|
74
|
-
it 'returns a CC token' do
|
75
|
-
expect(subject).to be_a(CFoundry::AuthToken)
|
76
|
-
expect(subject.auth_header).to eq("bearer #{access_token}")
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'saves the data as the token' do
|
80
|
-
subject
|
81
|
-
expect(client.token).to be_a(CFoundry::AuthToken)
|
82
|
-
expect(client.token.auth_header).to eq("bearer #{access_token}")
|
83
|
-
end
|
84
|
-
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfoundry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: -2053524930
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
8
|
+
- 6
|
9
|
+
- 0
|
10
10
|
- rc
|
11
|
-
-
|
12
|
-
version: 0.
|
11
|
+
- 1
|
12
|
+
version: 0.6.0.rc1
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Cloud Foundry Team
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2013-
|
21
|
+
date: 2013-03-18 00:00:00 Z
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
24
|
name: multipart-post
|