concourse.rb 0.1.0.pre.7 → 0.3.0.pre.2
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 +12 -11
- data/lib/concourse/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc7f6970b4f036df4bd4f7024da302b54e1b9b883e8a364d52c10ecaa6812db9
|
4
|
+
data.tar.gz: 7a7b6c2ba4fa72c6a76eeb96bc6cea7437e7a11178c3062da6b89afa61e5aa81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d671bb039c40842413f7601b4216d9bd88d9758885a607d0b1f366f616ac0b9daaf054c862434187d2c7832bba85bdb8a78b15b171f20c06ff08dad9a9d959bb
|
7
|
+
data.tar.gz: a6b9d0a6d02c7b0e1d26de960181818b18aa5f39746aa52215bf8bee8d29c0b04f42e14d0e261383ba1fc15b8e46eee3ea4be13e464d0993a33bb076afdb6fb3
|
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
|
@@ -1,15 +1,18 @@
|
|
1
1
|
require 'semantic'
|
2
|
-
require '
|
2
|
+
require 'time'
|
3
3
|
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
|
|
@@ -70,31 +75,27 @@ module Concourse
|
|
70
75
|
|
71
76
|
def token(token_response)
|
72
77
|
token_response_date = @version >= VERSION_6_1 ?
|
73
|
-
|
78
|
+
Time.parse(
|
74
79
|
token_response.headers[Concourse::HeaderNames.date]) :
|
75
80
|
nil
|
76
81
|
token_response_body =
|
77
82
|
JSON.parse(token_response.body, symbolize_names: true)
|
78
83
|
|
79
|
-
seconds_in_a_day = 60 * 60 * 24
|
80
|
-
|
81
84
|
@version >= VERSION_6_1 ?
|
82
|
-
|
85
|
+
Models::Token.new(
|
83
86
|
access_token: token_response_body[:access_token],
|
84
87
|
token_type: token_response_body[:token_type].downcase,
|
85
88
|
expires_at:
|
86
|
-
(token_response_date +
|
87
|
-
(token_response_body[:expires_in] /
|
88
|
-
seconds_in_a_day))
|
89
|
+
(token_response_date + token_response_body[:expires_in])
|
89
90
|
.iso8601,
|
90
91
|
id_token: token_response_body[:id_token]
|
91
|
-
|
92
|
-
|
92
|
+
) :
|
93
|
+
Models::Token.new(
|
93
94
|
access_token: token_response_body[:access_token],
|
94
95
|
token_type: token_response_body[:token_type].downcase,
|
95
96
|
expires_at: token_response_body[:expiry],
|
96
97
|
id_token: token_response_body[:access_token]
|
97
|
-
|
98
|
+
)
|
98
99
|
end
|
99
100
|
end
|
100
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.3.0.pre.2
|
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-04 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
|