zaikio-hub 0.9.0 → 0.11.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/CHANGELOG.md +18 -1
- data/Rakefile +1 -3
- data/lib/zaikio/hub/basic_auth_middleware.rb +0 -2
- data/lib/zaikio/hub/client.rb +2 -0
- data/lib/zaikio/hub/configuration.rb +9 -32
- data/lib/zaikio/hub/current_organization.rb +5 -5
- data/lib/zaikio/hub/token_data.rb +51 -0
- data/lib/zaikio/hub/version.rb +1 -1
- data/lib/zaikio/hub.rb +12 -26
- metadata +15 -9
- data/lib/zaikio/hub/authorization_middleware.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc8cad3e052fb8b2a20e218a59ecbaafb01811adc2b166cc512797f9c7d36047
|
4
|
+
data.tar.gz: ff4b1176481847d8cc8dd015d6275d2630ff85886d441d8906be591590ec27fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b05da9a0bf4d590c5fdf7ffd535c3f0d27baaa3cde3d2a4764a4ef5cdd8f8a5414fa5777ac33a3908893096492aa880e1eac9e0a34d6b68eb5fe0115f441214
|
7
|
+
data.tar.gz: 7e6ab83a077728d97fb54800aa13bff979a7895fa24b0960d62c14ea4cb36363ac7393be3ff7428548a14c19154116327820b129617ad04a1da224fefc867383
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.11.0] - 2022-08-30
|
11
|
+
|
12
|
+
* Extract token data logic into its own `Zaikio::Hub::TokenData` class
|
13
|
+
This also exposes the `sub` attribute of the token as `TokenData#subject`.
|
14
|
+
* Support newer versions of `jwt` and `spyke`
|
15
|
+
|
16
|
+
## [0.10.0] - 2022-08-15
|
17
|
+
|
18
|
+
* Update `zaikio-client-helpers` and reuse logic to use `Zaikio::Client.with_token`
|
19
|
+
|
20
|
+
## [0.9.1] - 2022-01-05
|
21
|
+
|
22
|
+
* Fix warning about redefined methods in BasicAuthMiddleware
|
23
|
+
* Permit newer versions of Spyke & JWT gems
|
24
|
+
|
10
25
|
## [0.9.0] - 2021-08-31
|
11
26
|
|
12
27
|
* Added `.connections` and `.apps` for `CurrentOrganization`s that are vendors
|
@@ -81,7 +96,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
81
96
|
### Added
|
82
97
|
- Added subscriptions (migration required)
|
83
98
|
|
84
|
-
[Unreleased]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.
|
99
|
+
[Unreleased]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.11.0..HEAD
|
100
|
+
[0.11.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.10.0..v0.11.0
|
101
|
+
[0.10.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.9.0..v0.10.0
|
85
102
|
[0.9.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.8.0..v0.9.0
|
86
103
|
[0.8.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.7.0..v0.8.0
|
87
104
|
[0.7.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.2..v0.7.0
|
data/Rakefile
CHANGED
@@ -29,9 +29,7 @@ task default: :test
|
|
29
29
|
|
30
30
|
namespace :test do
|
31
31
|
desc 'Runs RuboCop on specified directories'
|
32
|
-
RuboCop::RakeTask.new(:rubocop)
|
33
|
-
task.fail_on_error = false
|
34
|
-
end
|
32
|
+
RuboCop::RakeTask.new(:rubocop)
|
35
33
|
end
|
36
34
|
|
37
35
|
Rake::Task[:test].enhance ['test:rubocop']
|
data/lib/zaikio/hub/client.rb
CHANGED
@@ -2,38 +2,15 @@ require "logger"
|
|
2
2
|
|
3
3
|
module Zaikio
|
4
4
|
module Hub
|
5
|
-
class Configuration
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
attr_accessor :host
|
15
|
-
attr_reader :environment
|
16
|
-
attr_writer :logger
|
17
|
-
|
18
|
-
def initialize
|
19
|
-
@environment = :sandbox
|
20
|
-
end
|
21
|
-
|
22
|
-
def logger
|
23
|
-
@logger ||= Logger.new($stdout)
|
24
|
-
end
|
25
|
-
|
26
|
-
def environment=(env)
|
27
|
-
@environment = env.to_sym
|
28
|
-
@host = host_for(environment)
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def host_for(environment)
|
34
|
-
HOSTS.fetch(environment) do
|
35
|
-
raise StandardError.new, "Invalid Zaikio::Hub environment '#{environment}'"
|
36
|
-
end
|
5
|
+
class Configuration < Zaikio::Client::Helpers::Configuration
|
6
|
+
def self.hosts
|
7
|
+
{
|
8
|
+
development: "https://hub.zaikio.test/api/v1",
|
9
|
+
test: "https://hub.zaikio.test/api/v1",
|
10
|
+
staging: "https://hub.staging.zaikio.com/api/v1",
|
11
|
+
sandbox: "https://hub.sandbox.zaikio.com/api/v1",
|
12
|
+
production: "https://hub.zaikio.com/api/v1"
|
13
|
+
}.freeze
|
37
14
|
end
|
38
15
|
end
|
39
16
|
end
|
@@ -54,11 +54,11 @@ module Zaikio
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def create_subscription(status: "active", plan_name: nil)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
return unless Zaikio::Hub.current_token_data.subject_type == "Organization"
|
58
|
+
|
59
|
+
result = self.class.request(:post, "organization/subscription",
|
60
|
+
subscription: { status: status, plan_name: plan_name })
|
61
|
+
Zaikio::Hub::Subscription.new(result.data)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Zaikio
|
2
|
+
module Hub
|
3
|
+
class TokenData
|
4
|
+
attr_reader :audience, :on_behalf_of, :subject, :scopes
|
5
|
+
|
6
|
+
def self.from(payload)
|
7
|
+
subjects = payload["sub"].split(">")
|
8
|
+
|
9
|
+
new(
|
10
|
+
audience: payload["aud"].first,
|
11
|
+
on_behalf_of: subjects.first,
|
12
|
+
subject: subjects.last,
|
13
|
+
scopes: payload["scope"]
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(audience:, on_behalf_of:, subject:, scopes:)
|
18
|
+
@audience = audience
|
19
|
+
@on_behalf_of = on_behalf_of
|
20
|
+
@subject = subject
|
21
|
+
@scopes = scopes
|
22
|
+
end
|
23
|
+
|
24
|
+
def on_behalf_of_type
|
25
|
+
@on_behalf_of_type ||= type_for(:on_behalf_of)
|
26
|
+
end
|
27
|
+
|
28
|
+
def on_behalf_of_id
|
29
|
+
@on_behalf_of_id ||= id_for(:on_behalf_of)
|
30
|
+
end
|
31
|
+
|
32
|
+
def subject_type
|
33
|
+
@subject_type ||= type_for(:subject)
|
34
|
+
end
|
35
|
+
|
36
|
+
def subject_id
|
37
|
+
@subject_id ||= id_for(:subject)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def type_for(key)
|
43
|
+
public_send(key).split("/").first
|
44
|
+
end
|
45
|
+
|
46
|
+
def id_for(key)
|
47
|
+
public_send(key).split("/").last
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/zaikio/hub/version.rb
CHANGED
data/lib/zaikio/hub.rb
CHANGED
@@ -3,7 +3,6 @@ require "spyke"
|
|
3
3
|
require "zaikio-client-helpers"
|
4
4
|
|
5
5
|
require "zaikio/hub/configuration"
|
6
|
-
require "zaikio/hub/authorization_middleware"
|
7
6
|
require "zaikio/hub/basic_auth_middleware"
|
8
7
|
|
9
8
|
# Models
|
@@ -28,6 +27,7 @@ require "zaikio/hub/connection"
|
|
28
27
|
require "zaikio/hub/app"
|
29
28
|
require "zaikio/hub/subscription"
|
30
29
|
require "zaikio/hub/test_account"
|
30
|
+
require "zaikio/hub/token_data"
|
31
31
|
|
32
32
|
module Zaikio
|
33
33
|
module Hub
|
@@ -44,11 +44,8 @@ module Zaikio
|
|
44
44
|
Base.connection = create_connection
|
45
45
|
end
|
46
46
|
|
47
|
-
def with_token(token)
|
48
|
-
|
49
|
-
yield
|
50
|
-
ensure
|
51
|
-
AuthorizationMiddleware.reset_token
|
47
|
+
def with_token(token, &block)
|
48
|
+
Zaikio::Client.with_token(token, &block)
|
52
49
|
end
|
53
50
|
|
54
51
|
def with_basic_auth(login, password)
|
@@ -59,36 +56,25 @@ module Zaikio
|
|
59
56
|
end
|
60
57
|
|
61
58
|
def current_token_data
|
62
|
-
return unless AuthorizationMiddleware.token
|
59
|
+
return unless Zaikio::Client::Helpers::AuthorizationMiddleware.token
|
63
60
|
|
64
|
-
payload = JWT.decode(
|
61
|
+
payload = JWT.decode(
|
62
|
+
Zaikio::Client::Helpers::AuthorizationMiddleware.token,
|
63
|
+
nil,
|
64
|
+
false
|
65
|
+
).first
|
65
66
|
|
66
67
|
create_token_data(payload)
|
67
68
|
end
|
68
69
|
|
69
70
|
def create_connection
|
70
|
-
self.connection =
|
71
|
-
|
72
|
-
c.request :json
|
73
|
-
c.response :logger, configuration&.logger, headers: false
|
74
|
-
c.use Zaikio::Client::Helpers::Pagination::FaradayMiddleware
|
75
|
-
c.use Zaikio::Client::Helpers::JSONParser
|
76
|
-
c.use AuthorizationMiddleware
|
77
|
-
c.use BasicAuthMiddleware
|
78
|
-
c.adapter Faraday.default_adapter
|
71
|
+
self.connection = Zaikio::Client.create_connection(configuration).tap do |c|
|
72
|
+
c.use BasicAuthMiddleware
|
79
73
|
end
|
80
74
|
end
|
81
75
|
|
82
76
|
def create_token_data(payload)
|
83
|
-
|
84
|
-
|
85
|
-
OpenStruct.new(
|
86
|
-
audience: payload["aud"].first,
|
87
|
-
on_behalf_of_id: subjects.first.split("/").last,
|
88
|
-
subject_id: subjects.last.split("/").last,
|
89
|
-
subject_type: subjects.last.split("/").first,
|
90
|
-
scopes: payload["scope"]
|
91
|
-
)
|
77
|
+
TokenData.from(payload)
|
92
78
|
end
|
93
79
|
end
|
94
80
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zaikio-hub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- crispymtn
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2022-08-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: concurrent-ruby
|
@@ -30,16 +30,22 @@ dependencies:
|
|
30
30
|
name: jwt
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- - "
|
33
|
+
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: 2.2.1
|
36
|
+
- - "<"
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 2.6.0
|
36
39
|
type: :runtime
|
37
40
|
prerelease: false
|
38
41
|
version_requirements: !ruby/object:Gem::Requirement
|
39
42
|
requirements:
|
40
|
-
- - "
|
43
|
+
- - ">="
|
41
44
|
- !ruby/object:Gem::Version
|
42
45
|
version: 2.2.1
|
46
|
+
- - "<"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.6.0
|
43
49
|
- !ruby/object:Gem::Dependency
|
44
50
|
name: multi_json
|
45
51
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,7 +95,7 @@ dependencies:
|
|
89
95
|
version: 5.3.4
|
90
96
|
- - "<"
|
91
97
|
- !ruby/object:Gem::Version
|
92
|
-
version: 6.
|
98
|
+
version: 6.2.0
|
93
99
|
type: :runtime
|
94
100
|
prerelease: false
|
95
101
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -99,21 +105,21 @@ dependencies:
|
|
99
105
|
version: 5.3.4
|
100
106
|
- - "<"
|
101
107
|
- !ruby/object:Gem::Version
|
102
|
-
version: 6.
|
108
|
+
version: 6.2.0
|
103
109
|
- !ruby/object:Gem::Dependency
|
104
110
|
name: zaikio-client-helpers
|
105
111
|
requirement: !ruby/object:Gem::Requirement
|
106
112
|
requirements:
|
107
113
|
- - "~>"
|
108
114
|
- !ruby/object:Gem::Version
|
109
|
-
version: '0.
|
115
|
+
version: '0.3'
|
110
116
|
type: :runtime
|
111
117
|
prerelease: false
|
112
118
|
version_requirements: !ruby/object:Gem::Requirement
|
113
119
|
requirements:
|
114
120
|
- - "~>"
|
115
121
|
- !ruby/object:Gem::Version
|
116
|
-
version: '0.
|
122
|
+
version: '0.3'
|
117
123
|
description: Ruby API Client for Zaikio's Hub
|
118
124
|
email:
|
119
125
|
- op@crispymtn.com
|
@@ -131,7 +137,6 @@ files:
|
|
131
137
|
- lib/zaikio/hub/address.rb
|
132
138
|
- lib/zaikio/hub/app.rb
|
133
139
|
- lib/zaikio/hub/asset.rb
|
134
|
-
- lib/zaikio/hub/authorization_middleware.rb
|
135
140
|
- lib/zaikio/hub/base.rb
|
136
141
|
- lib/zaikio/hub/basic_auth_middleware.rb
|
137
142
|
- lib/zaikio/hub/business_relationship.rb
|
@@ -152,6 +157,7 @@ files:
|
|
152
157
|
- lib/zaikio/hub/specialist.rb
|
153
158
|
- lib/zaikio/hub/subscription.rb
|
154
159
|
- lib/zaikio/hub/test_account.rb
|
160
|
+
- lib/zaikio/hub/token_data.rb
|
155
161
|
- lib/zaikio/hub/version.rb
|
156
162
|
homepage: https://www.zaikio.com/
|
157
163
|
licenses:
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require "faraday"
|
2
|
-
require "jwt"
|
3
|
-
require "concurrent"
|
4
|
-
|
5
|
-
module Zaikio
|
6
|
-
module Hub
|
7
|
-
class AuthorizationMiddleware < Faraday::Middleware
|
8
|
-
def self.token
|
9
|
-
@token ||= Concurrent::ThreadLocalVar.new { nil }
|
10
|
-
@token.value
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.token=(value)
|
14
|
-
@token ||= Concurrent::ThreadLocalVar.new { nil }
|
15
|
-
@token.value = value
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.reset_token
|
19
|
-
self.token = nil
|
20
|
-
end
|
21
|
-
|
22
|
-
def call(request_env)
|
23
|
-
if self.class.token
|
24
|
-
request_env[:request_headers]["Authorization"] = "Bearer #{self.class.token}"
|
25
|
-
end
|
26
|
-
|
27
|
-
@app.call(request_env).on_complete do |response_env|
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|