concourse.rb 0.1.0.pre.8 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/concourse.rb +3 -0
- data/lib/concourse/errors.rb +14 -0
- data/lib/concourse/http.rb +40 -0
- data/lib/concourse/models.rb +6 -0
- data/lib/concourse/models/token.rb +32 -0
- data/lib/concourse/sub_clients/skymarshal_client.rb +9 -4
- data/lib/concourse/version.rb +1 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb8b139f1aab79758d10152e99142dca3847e0663fd1d23fd0a7038a243ced17
|
4
|
+
data.tar.gz: 3686d042ec39bc7c9ff2e15fc5b09e9586da235ab67f1daba2ef7a824ac1fc3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddc2b6e3e7789e1ec72e2e7e2359cda1958f4adc0e6e2ecc0c78297612f8a52caf29d67957ba678df1e5575121ba8c649b8e651a3ca869bd70e62548cb1ba283
|
7
|
+
data.tar.gz: b49eb9ea8f046b6cdc5a33a1a95cea3c6d72401edca192989b772011a81d553add099349714774fa1efa59fc176ac1905bcfed4a5fa2fdaa50f4d58e46d9f867
|
data/Gemfile.lock
CHANGED
data/lib/concourse.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Concourse
|
2
|
+
module Errors
|
3
|
+
class ApiError < StandardError
|
4
|
+
def initialize(parameters)
|
5
|
+
@request = parameters[:request]
|
6
|
+
@response = parameters[:response]
|
7
|
+
|
8
|
+
super("Request to #{@request.url} failed " +
|
9
|
+
"with status #{@response.status} " +
|
10
|
+
"and body #{@response.body}")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Concourse
|
2
|
+
module Http
|
3
|
+
class Request
|
4
|
+
attr_reader :url, :headers, :body
|
5
|
+
|
6
|
+
def initialize(url, headers = {}, body = nil)
|
7
|
+
@url = url
|
8
|
+
@headers = headers
|
9
|
+
@body = body
|
10
|
+
end
|
11
|
+
|
12
|
+
def ==(other)
|
13
|
+
other.class == self.class && other.state == state
|
14
|
+
end
|
15
|
+
|
16
|
+
def eql?(other)
|
17
|
+
self == other
|
18
|
+
end
|
19
|
+
|
20
|
+
def hash
|
21
|
+
state.hash
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def state
|
27
|
+
[@url, @headers, @body]
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def assert_successful(request, response)
|
33
|
+
unless response.status < 400
|
34
|
+
raise Errors::ApiError.new(
|
35
|
+
request: request,
|
36
|
+
response: response)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Concourse
|
2
|
+
module Models
|
3
|
+
class Token
|
4
|
+
attr_reader :access_token, :token_type, :expires_at, :id_token
|
5
|
+
|
6
|
+
def initialize(parameters)
|
7
|
+
@access_token = parameters[:access_token]
|
8
|
+
@token_type = parameters[:token_type]
|
9
|
+
@expires_at = parameters[:expires_at]
|
10
|
+
@id_token = parameters[:id_token]
|
11
|
+
end
|
12
|
+
|
13
|
+
def ==(other)
|
14
|
+
other.class == self.class && other.state == state
|
15
|
+
end
|
16
|
+
|
17
|
+
def eql?(other)
|
18
|
+
self == other
|
19
|
+
end
|
20
|
+
|
21
|
+
def hash
|
22
|
+
state.hash
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def state
|
28
|
+
[@access_token, @token_type, @expires_at, @id_token]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -4,12 +4,15 @@ require 'json'
|
|
4
4
|
|
5
5
|
require 'concourse/urls'
|
6
6
|
require 'concourse/headers'
|
7
|
+
require 'concourse/http'
|
7
8
|
|
8
9
|
module Concourse
|
9
10
|
module SubClients
|
10
11
|
class SkymarshalClient
|
11
12
|
VERSION_6_1 = Semantic::Version.new('6.1.0')
|
12
13
|
|
14
|
+
include Concourse::Http
|
15
|
+
|
13
16
|
def initialize(options)
|
14
17
|
@url = options[:url]
|
15
18
|
@version = Semantic::Version.new(options[:version])
|
@@ -20,8 +23,10 @@ module Concourse
|
|
20
23
|
headers = create_token_headers
|
21
24
|
body = create_token_body(parameters)
|
22
25
|
|
26
|
+
token_request = Http::Request.new(url, headers, body)
|
23
27
|
token_response = Excon.post(url, headers: headers, body: body)
|
24
28
|
|
29
|
+
assert_successful(token_request, token_response)
|
25
30
|
token(token_response)
|
26
31
|
end
|
27
32
|
|
@@ -77,20 +82,20 @@ module Concourse
|
|
77
82
|
JSON.parse(token_response.body, symbolize_names: true)
|
78
83
|
|
79
84
|
@version >= VERSION_6_1 ?
|
80
|
-
|
85
|
+
Models::Token.new(
|
81
86
|
access_token: token_response_body[:access_token],
|
82
87
|
token_type: token_response_body[:token_type].downcase,
|
83
88
|
expires_at:
|
84
89
|
(token_response_date + token_response_body[:expires_in])
|
85
90
|
.iso8601,
|
86
91
|
id_token: token_response_body[:id_token]
|
87
|
-
|
88
|
-
|
92
|
+
) :
|
93
|
+
Models::Token.new(
|
89
94
|
access_token: token_response_body[:access_token],
|
90
95
|
token_type: token_response_body[:token_type].downcase,
|
91
96
|
expires_at: token_response_body[:expiry],
|
92
97
|
id_token: token_response_body[:access_token]
|
93
|
-
|
98
|
+
)
|
94
99
|
end
|
95
100
|
end
|
96
101
|
end
|
data/lib/concourse/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: concourse.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toby Clemson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -224,7 +224,11 @@ files:
|
|
224
224
|
- concourse.rb.gemspec
|
225
225
|
- lib/concourse.rb
|
226
226
|
- lib/concourse/client.rb
|
227
|
+
- lib/concourse/errors.rb
|
227
228
|
- lib/concourse/headers.rb
|
229
|
+
- lib/concourse/http.rb
|
230
|
+
- lib/concourse/models.rb
|
231
|
+
- lib/concourse/models/token.rb
|
228
232
|
- lib/concourse/sub_clients.rb
|
229
233
|
- lib/concourse/sub_clients/skymarshal_client.rb
|
230
234
|
- lib/concourse/urls.rb
|
@@ -244,9 +248,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
244
248
|
version: 2.6.0
|
245
249
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
246
250
|
requirements:
|
247
|
-
- - "
|
251
|
+
- - ">="
|
248
252
|
- !ruby/object:Gem::Version
|
249
|
-
version:
|
253
|
+
version: '0'
|
250
254
|
requirements: []
|
251
255
|
rubygems_version: 3.0.1
|
252
256
|
signing_key:
|