lhc 6.1.1 → 6.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhc/endpoint.rb +35 -9
- data/lib/lhc/version.rb +1 -1
- data/spec/endpoint/placeholders_spec.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9144e7e4cdc63f0dfd45813de1d4c75ae28a6c12
|
4
|
+
data.tar.gz: 6e0856848c3c817c4ebfb60f57c385c216cb9c60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 726fbf0e6a53970ce7afbfdb26739381487ba1a9da33f959eb6f75be1d42a4aefaf28673687977fcd2641b5378d23754197f691c028f7b6170e45271db6d7c5c
|
7
|
+
data.tar.gz: 3671e777ec3db226d0082a678eaf378337f0ac0fe93d7a9d523a601344ff74b5856c0903e60a2819648b9fa89b65ac0e847471e87cc2b556e16332556809164b
|
data/lib/lhc/endpoint.rb
CHANGED
@@ -14,16 +14,42 @@ class LHC::Endpoint
|
|
14
14
|
self.options = options
|
15
15
|
end
|
16
16
|
|
17
|
+
def uri
|
18
|
+
@uri ||= parse_url_gracefully(url)
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_url_gracefully(url)
|
22
|
+
URI.parse(url)
|
23
|
+
rescue URI::InvalidURIError
|
24
|
+
url
|
25
|
+
end
|
26
|
+
|
17
27
|
def compile(params)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
params.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
28
|
+
add_basic_auth(
|
29
|
+
without_basic_auth(url).gsub(PLACEHOLDER) do |match|
|
30
|
+
replacement =
|
31
|
+
if params.is_a? Proc
|
32
|
+
params.call(match)
|
33
|
+
else
|
34
|
+
find_value(match, params)
|
35
|
+
end
|
36
|
+
replacement || fail("Compilation incomplete. Unable to find value for #{match.gsub(':', '')}.")
|
37
|
+
end
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_basic_auth(url)
|
42
|
+
return url if !uri || !uri.is_a?(URI) || (uri.user.blank? && uri.password.blank?)
|
43
|
+
new_uri = parse_url_gracefully(url)
|
44
|
+
new_uri.user = uri.user
|
45
|
+
new_uri.password = uri.password
|
46
|
+
new_uri.to_s
|
47
|
+
end
|
48
|
+
|
49
|
+
# Strips basic auth from the url
|
50
|
+
def without_basic_auth(url)
|
51
|
+
return url if !uri || !uri.is_a?(URI) || (uri.user.blank? && uri.password.blank?)
|
52
|
+
url.gsub("#{uri.user}:#{uri.password}@", '')
|
27
53
|
end
|
28
54
|
|
29
55
|
# Endpoint options are immutable
|
data/lib/lhc/version.rb
CHANGED
@@ -16,5 +16,13 @@ describe LHC::Endpoint do
|
|
16
16
|
LHC.get("https://d123token:@api.github.com/search")
|
17
17
|
}).not_to raise_error
|
18
18
|
end
|
19
|
+
|
20
|
+
it 'allows complete basic auth (username password) in url, like used for the gemserer' do
|
21
|
+
stub_request(:get, "https://name:password@gemserver.com")
|
22
|
+
.to_return(body: {}.to_json)
|
23
|
+
expect(->{
|
24
|
+
LHC.get("https://name:password@gemserver.com")
|
25
|
+
}).not_to raise_error
|
26
|
+
end
|
19
27
|
end
|
20
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.1.
|
4
|
+
version: 6.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhc/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|