zaikio-hub 0.8.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -1
- data/Rakefile +1 -3
- data/lib/zaikio/hub/app.rb +12 -0
- 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 +10 -5
- data/lib/zaikio/hub/version.rb +1 -1
- data/lib/zaikio/hub.rb +11 -17
- 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: e6de6ed1ed5cb7442b72ffa036df6de0cf7f371d59d52018b4458850b7e71848
|
4
|
+
data.tar.gz: 5dc770e601267c847094fdb07875651529ec14458676c5d5be558af9c0d15c39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b168642b4f8c6ac5607602a7e2237224e98fe52b4991c3f06b3a61591eeeacb6a6d76a60f63acaa272fe55cb9ee43f42f0a7aea871a3eeca7a2a770abc5f8ae
|
7
|
+
data.tar.gz: 4aca04231bccaf9dc4d85ebf752ef4663f365cc7bc788a8b55d979983047e4eb78e3978bf2bd28ef274186f7408ce2d5288941b08e4bdb40329ed6468ab000dc
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.10.0] - 2022-08-15
|
11
|
+
|
12
|
+
* Update `zaikio-client-helpers` and reuse logic to use `Zaikio::Client.with_token`
|
13
|
+
|
14
|
+
## [0.9.1] - 2022-01-05
|
15
|
+
|
16
|
+
* Fix warning about redefined methods in BasicAuthMiddleware
|
17
|
+
* Permit newer versions of Spyke & JWT gems
|
18
|
+
|
19
|
+
## [0.9.0] - 2021-08-31
|
20
|
+
|
21
|
+
* Added `.connections` and `.apps` for `CurrentOrganization`s that are vendors
|
22
|
+
|
10
23
|
## [0.8.0] - 2021-08-25
|
11
24
|
|
12
25
|
* Added `CurrentOrganization#create_subscription`
|
@@ -77,7 +90,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
77
90
|
### Added
|
78
91
|
- Added subscriptions (migration required)
|
79
92
|
|
80
|
-
[Unreleased]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.
|
93
|
+
[Unreleased]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.9.0..HEAD
|
94
|
+
[0.9.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.8.0..v0.9.0
|
95
|
+
[0.8.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.7.0..v0.8.0
|
81
96
|
[0.7.0]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.2..v0.7.0
|
82
97
|
[0.6.2]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.1..v0.6.2
|
83
98
|
[0.6.1]: https://github.com/zaikio/zaikio-hub-ruby/compare/v0.6.0..v0.6.1
|
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
|
@@ -35,6 +35,11 @@ module Zaikio
|
|
35
35
|
uri: "specialists(/:id)"
|
36
36
|
has_many :sites, class_name: "Zaikio::Hub::Site",
|
37
37
|
uri: "sites(/:id)"
|
38
|
+
# For vendors
|
39
|
+
has_many :connections, class_name: "Zaikio::Hub::Connection",
|
40
|
+
uri: "connections(/:id)"
|
41
|
+
has_many :apps, class_name: "Zaikio::Hub::App",
|
42
|
+
uri: "apps(/:id)"
|
38
43
|
|
39
44
|
def fetch
|
40
45
|
self.attributes = get
|
@@ -49,11 +54,11 @@ module Zaikio
|
|
49
54
|
end
|
50
55
|
|
51
56
|
def create_subscription(status: "active", plan_name: nil)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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)
|
57
62
|
end
|
58
63
|
end
|
59
64
|
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
|
@@ -25,6 +24,7 @@ require "zaikio/hub/current_organization"
|
|
25
24
|
require "zaikio/hub/role"
|
26
25
|
require "zaikio/hub/revoked_access_token"
|
27
26
|
require "zaikio/hub/connection"
|
27
|
+
require "zaikio/hub/app"
|
28
28
|
require "zaikio/hub/subscription"
|
29
29
|
require "zaikio/hub/test_account"
|
30
30
|
|
@@ -43,11 +43,8 @@ module Zaikio
|
|
43
43
|
Base.connection = create_connection
|
44
44
|
end
|
45
45
|
|
46
|
-
def with_token(token)
|
47
|
-
|
48
|
-
yield
|
49
|
-
ensure
|
50
|
-
AuthorizationMiddleware.reset_token
|
46
|
+
def with_token(token, &block)
|
47
|
+
Zaikio::Client.with_token(token, &block)
|
51
48
|
end
|
52
49
|
|
53
50
|
def with_basic_auth(login, password)
|
@@ -58,23 +55,20 @@ module Zaikio
|
|
58
55
|
end
|
59
56
|
|
60
57
|
def current_token_data
|
61
|
-
return unless AuthorizationMiddleware.token
|
58
|
+
return unless Zaikio::Client::Helpers::AuthorizationMiddleware.token
|
62
59
|
|
63
|
-
payload = JWT.decode(
|
60
|
+
payload = JWT.decode(
|
61
|
+
Zaikio::Client::Helpers::AuthorizationMiddleware.token,
|
62
|
+
nil,
|
63
|
+
false
|
64
|
+
).first
|
64
65
|
|
65
66
|
create_token_data(payload)
|
66
67
|
end
|
67
68
|
|
68
69
|
def create_connection
|
69
|
-
self.connection =
|
70
|
-
|
71
|
-
c.request :json
|
72
|
-
c.response :logger, configuration&.logger, headers: false
|
73
|
-
c.use Zaikio::Client::Helpers::Pagination::FaradayMiddleware
|
74
|
-
c.use Zaikio::Client::Helpers::JSONParser
|
75
|
-
c.use AuthorizationMiddleware
|
76
|
-
c.use BasicAuthMiddleware
|
77
|
-
c.adapter Faraday.default_adapter
|
70
|
+
self.connection = Zaikio::Client.create_connection(configuration).tap do |c|
|
71
|
+
c.use BasicAuthMiddleware
|
78
72
|
end
|
79
73
|
end
|
80
74
|
|
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.10.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-15 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.5.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.5.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
|
@@ -129,8 +135,8 @@ files:
|
|
129
135
|
- Rakefile
|
130
136
|
- lib/zaikio/hub.rb
|
131
137
|
- lib/zaikio/hub/address.rb
|
138
|
+
- lib/zaikio/hub/app.rb
|
132
139
|
- lib/zaikio/hub/asset.rb
|
133
|
-
- lib/zaikio/hub/authorization_middleware.rb
|
134
140
|
- lib/zaikio/hub/base.rb
|
135
141
|
- lib/zaikio/hub/basic_auth_middleware.rb
|
136
142
|
- lib/zaikio/hub/business_relationship.rb
|
@@ -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
|