wcc-data 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wcc/data/faraday_client_app_token_auth.rb +63 -44
- data/lib/wcc/data/nucleus/campus.rb +3 -3
- data/lib/wcc/data/version.rb +1 -1
- data/wcc-data.gemspec +5 -5
- metadata +11 -51
- data/.env.example +0 -3
- data/.gitignore +0 -18
- data/.rspec +0 -2
- data/Gemfile +0 -6
- data/Rakefile +0 -36
- data/bin/rspec +0 -17
- data/circle.yml +0 -6
- data/spec/spec_helper.rb +0 -24
- data/spec/support/inheritable_class_attribute_examples.rb +0 -16
- data/spec/wcc/data/config_spec.rb +0 -113
- data/spec/wcc/data/enumerated_type_spec.rb +0 -176
- data/spec/wcc/data/faraday_client_app_token_auth_spec.rb +0 -237
- data/spec/wcc/data/mapper/attributes_spec.rb +0 -94
- data/spec/wcc/data/mapper/json_response_spec.rb +0 -57
- data/spec/wcc/data/mapper/rest_configuration_spec.rb +0 -43
- data/spec/wcc/data/mapper/rest_query_spec.rb +0 -50
- data/spec/wcc/data/model_spec.rb +0 -33
- data/spec/wcc/data/nucleus/campus_spec.rb +0 -34
- data/spec/wcc/data/rack_client_app_token_auth_spec.rb +0 -219
- data/spec/wcc/data/response_spec.rb +0 -57
- data/spec/wcc/data/rest_endpoint_spec.rb +0 -71
- data/spec/wcc/data/service_spec.rb +0 -128
- data/spec/wcc/data_spec.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed9c9cae5ed9d3566afbd53908f37886cb6a381f
|
4
|
+
data.tar.gz: a173ff9c272eadf478712f8605c10e185cbe3ce1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83cd358cadf5a0e0d34b8ddd3cc1b73c07ec0f497ba0d0463fbfadd4e78cf209040b3587350f011ad049aa92191e59f3c327e85ec7a3478c4128531b4b191a72
|
7
|
+
data.tar.gz: 151051a864e8fee6678bb057291bcd4f98ecdd25cb4d4683b6c61e58f84092de3eb7ca13eace78a3ab56c2ddcb238f8df463076208835564d052e9259c7a3ef1
|
@@ -1,64 +1,83 @@
|
|
1
|
+
|
2
|
+
begin
|
3
|
+
gem 'faraday'
|
4
|
+
require 'faraday'
|
5
|
+
rescue Gem::LoadError
|
6
|
+
# suppress
|
7
|
+
end
|
8
|
+
|
9
|
+
|
1
10
|
module WCC::Data
|
2
|
-
|
3
|
-
class
|
4
|
-
|
5
|
-
|
11
|
+
if defined?(Faraday)
|
12
|
+
class FaradayClientAppTokenAuth < Faraday::Middleware
|
13
|
+
class RedisCache
|
14
|
+
DEFAULT_CACHE_KEY = "org.watermark.data.client-app-token-cache-store"
|
15
|
+
attr_reader :connection, :cache_key
|
6
16
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
17
|
+
def initialize(connection, cache_key: DEFAULT_CACHE_KEY)
|
18
|
+
@connection = connection
|
19
|
+
@cache_key = cache_key
|
20
|
+
end
|
11
21
|
|
12
|
-
|
13
|
-
|
14
|
-
|
22
|
+
def [](hostname)
|
23
|
+
connection.call { |r| r.hget cache_key, hostname }
|
24
|
+
end
|
15
25
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
26
|
+
def []=(hostname, token)
|
27
|
+
if token
|
28
|
+
connection.call { |r| r.hset cache_key, hostname, token }
|
29
|
+
else
|
30
|
+
connection.call { |r| r.hdel cache_key, hostname }
|
31
|
+
end
|
21
32
|
end
|
22
33
|
end
|
23
|
-
end
|
24
34
|
|
25
|
-
|
35
|
+
attr_reader :cache, :token_factory
|
26
36
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
37
|
+
def initialize(app, cache: default_cache, token_factory: method(:default_token_factory))
|
38
|
+
super(app)
|
39
|
+
@cache = cache
|
40
|
+
@token_factory = token_factory
|
41
|
+
end
|
32
42
|
|
33
|
-
|
34
|
-
|
35
|
-
|
43
|
+
def token_for(host)
|
44
|
+
@cache[host] ||= token_factory.(host)
|
45
|
+
end
|
36
46
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
def call(env, retry_on_forbidden: true)
|
48
|
+
request_body = env[:body]
|
49
|
+
host = env[:url].host
|
50
|
+
env[:request_headers]["Authorization"] = "Bearer #{token_for(host)}"
|
51
|
+
@app.call(env).on_complete do |response_env|
|
52
|
+
response = Faraday::Response.new(response_env)
|
53
|
+
cache[host] = nil unless response.success?
|
54
|
+
if response.status == 403 && retry_on_forbidden
|
55
|
+
env[:body] = request_body
|
56
|
+
call(env, retry_on_forbidden: false)
|
57
|
+
end
|
47
58
|
end
|
48
59
|
end
|
49
|
-
end
|
50
60
|
|
51
|
-
|
61
|
+
private
|
52
62
|
|
53
|
-
|
54
|
-
|
55
|
-
|
63
|
+
def default_token_factory(host)
|
64
|
+
WCC::Data::Nucleus::ClientAppToken.create(hostname: host).token
|
65
|
+
end
|
56
66
|
|
57
|
-
|
58
|
-
|
67
|
+
def default_cache
|
68
|
+
RedisCache.new(Sidekiq.method(:redis))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
else
|
72
|
+
class FaradayClientAppTokenAuth
|
73
|
+
def initialize(app, cache: default_cache, token_factory: method(:default_token_factory))
|
74
|
+
raise NotSupportedError, 'Please include the "faraday" gem to use this authentication method'
|
75
|
+
end
|
59
76
|
end
|
60
77
|
end
|
61
78
|
end
|
62
79
|
|
63
|
-
Faraday
|
80
|
+
if defined?(Faraday)
|
81
|
+
Faraday::Middleware.register_middleware :client_app_token => lambda { WCC::Data::FaradayClientAppTokenAuth }
|
82
|
+
end
|
64
83
|
|
@@ -27,11 +27,11 @@ module WCC::Data::Nucleus
|
|
27
27
|
code: 'FTW',
|
28
28
|
name: 'Fort Worth',
|
29
29
|
key: :ft_worth,
|
30
|
-
street: '
|
30
|
+
street: '8000 Western Hills Blvd',
|
31
31
|
city: 'Fort Worth',
|
32
32
|
state: 'TX',
|
33
|
-
zip: '
|
34
|
-
geo: [32.
|
33
|
+
zip: '76108',
|
34
|
+
geo: [32.739972, -97.455414]
|
35
35
|
},
|
36
36
|
{
|
37
37
|
id: 3,
|
data/lib/wcc/data/version.rb
CHANGED
data/wcc-data.gemspec
CHANGED
@@ -13,14 +13,14 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files =
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.files = Dir['lib/**/*'] + %w[LICENSE.txt README.md wcc-data.gemspec]
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
18
|
+
spec.require_paths = ['lib']
|
20
19
|
|
21
|
-
spec.required_ruby_version = '
|
20
|
+
spec.required_ruby_version = '>= 2.2'
|
22
21
|
|
23
|
-
|
22
|
+
# Required if you use faraday_client_app_token_auth but must be included separately
|
23
|
+
spec.add_development_dependency "faraday", "~> 0.8"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.3"
|
26
26
|
spec.add_development_dependency "dotenv", "~> 0.10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wcc-data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Watermark Dev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -17,7 +17,7 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0.8'
|
20
|
-
type: :
|
20
|
+
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
@@ -97,20 +97,12 @@ dependencies:
|
|
97
97
|
description: Watermark's library for interapp communication via APIs
|
98
98
|
email:
|
99
99
|
- dev@watermark.org
|
100
|
-
executables:
|
101
|
-
- rspec
|
100
|
+
executables: []
|
102
101
|
extensions: []
|
103
102
|
extra_rdoc_files: []
|
104
103
|
files:
|
105
|
-
- ".env.example"
|
106
|
-
- ".gitignore"
|
107
|
-
- ".rspec"
|
108
|
-
- Gemfile
|
109
104
|
- LICENSE.txt
|
110
105
|
- README.md
|
111
|
-
- Rakefile
|
112
|
-
- bin/rspec
|
113
|
-
- circle.yml
|
114
106
|
- lib/wcc/data.rb
|
115
107
|
- lib/wcc/data/config.rb
|
116
108
|
- lib/wcc/data/enumerated_type.rb
|
@@ -136,34 +128,18 @@ files:
|
|
136
128
|
- lib/wcc/data/rest_endpoint.rb
|
137
129
|
- lib/wcc/data/service.rb
|
138
130
|
- lib/wcc/data/version.rb
|
139
|
-
- spec/spec_helper.rb
|
140
|
-
- spec/support/inheritable_class_attribute_examples.rb
|
141
|
-
- spec/wcc/data/config_spec.rb
|
142
|
-
- spec/wcc/data/enumerated_type_spec.rb
|
143
|
-
- spec/wcc/data/faraday_client_app_token_auth_spec.rb
|
144
|
-
- spec/wcc/data/mapper/attributes_spec.rb
|
145
|
-
- spec/wcc/data/mapper/json_response_spec.rb
|
146
|
-
- spec/wcc/data/mapper/rest_configuration_spec.rb
|
147
|
-
- spec/wcc/data/mapper/rest_query_spec.rb
|
148
|
-
- spec/wcc/data/model_spec.rb
|
149
|
-
- spec/wcc/data/nucleus/campus_spec.rb
|
150
|
-
- spec/wcc/data/rack_client_app_token_auth_spec.rb
|
151
|
-
- spec/wcc/data/response_spec.rb
|
152
|
-
- spec/wcc/data/rest_endpoint_spec.rb
|
153
|
-
- spec/wcc/data/service_spec.rb
|
154
|
-
- spec/wcc/data_spec.rb
|
155
131
|
- wcc-data.gemspec
|
156
132
|
homepage: ''
|
157
133
|
licenses:
|
158
134
|
- MIT
|
159
135
|
metadata: {}
|
160
|
-
post_install_message:
|
136
|
+
post_install_message:
|
161
137
|
rdoc_options: []
|
162
138
|
require_paths:
|
163
139
|
- lib
|
164
140
|
required_ruby_version: !ruby/object:Gem::Requirement
|
165
141
|
requirements:
|
166
|
-
- - "
|
142
|
+
- - ">="
|
167
143
|
- !ruby/object:Gem::Version
|
168
144
|
version: '2.2'
|
169
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -172,25 +148,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
148
|
- !ruby/object:Gem::Version
|
173
149
|
version: '0'
|
174
150
|
requirements: []
|
175
|
-
rubyforge_project:
|
176
|
-
rubygems_version: 2.5.2
|
177
|
-
signing_key:
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 2.5.2.3
|
153
|
+
signing_key:
|
178
154
|
specification_version: 4
|
179
155
|
summary: Watermark's library for interapp communication via APIs
|
180
|
-
test_files:
|
181
|
-
- spec/spec_helper.rb
|
182
|
-
- spec/support/inheritable_class_attribute_examples.rb
|
183
|
-
- spec/wcc/data/config_spec.rb
|
184
|
-
- spec/wcc/data/enumerated_type_spec.rb
|
185
|
-
- spec/wcc/data/faraday_client_app_token_auth_spec.rb
|
186
|
-
- spec/wcc/data/mapper/attributes_spec.rb
|
187
|
-
- spec/wcc/data/mapper/json_response_spec.rb
|
188
|
-
- spec/wcc/data/mapper/rest_configuration_spec.rb
|
189
|
-
- spec/wcc/data/mapper/rest_query_spec.rb
|
190
|
-
- spec/wcc/data/model_spec.rb
|
191
|
-
- spec/wcc/data/nucleus/campus_spec.rb
|
192
|
-
- spec/wcc/data/rack_client_app_token_auth_spec.rb
|
193
|
-
- spec/wcc/data/response_spec.rb
|
194
|
-
- spec/wcc/data/rest_endpoint_spec.rb
|
195
|
-
- spec/wcc/data/service_spec.rb
|
196
|
-
- spec/wcc/data_spec.rb
|
156
|
+
test_files: []
|
data/.env.example
DELETED
data/.gitignore
DELETED
data/.rspec
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|
2
|
-
require 'dotenv/tasks'
|
3
|
-
|
4
|
-
PROJECT_PATH = File.dirname(__FILE__)
|
5
|
-
LIB_PATH = File.join(PROJECT_PATH, "lib")
|
6
|
-
|
7
|
-
task :default => :test
|
8
|
-
|
9
|
-
desc 'run test examples'
|
10
|
-
task :test do
|
11
|
-
exec 'rspec .'
|
12
|
-
end
|
13
|
-
|
14
|
-
task :environment => :dotenv do
|
15
|
-
$LOAD_PATH.unshift(LIB_PATH)
|
16
|
-
require 'wcc/data'
|
17
|
-
end
|
18
|
-
|
19
|
-
task :development => [:environment] do
|
20
|
-
WCC::Data.setup do |config|
|
21
|
-
conn = config.applications[:nucleus].connection
|
22
|
-
conn.use Faraday::Response::Logger
|
23
|
-
conn.basic_auth(ENV['NUCLEUS_CLIENT_ID'], ENV['NUCLEUS_CLIENT_SECRET'])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
desc 'launch IRB shell with base environment loaded'
|
28
|
-
task :irb => :environment do
|
29
|
-
require 'irb'
|
30
|
-
ARGV.clear
|
31
|
-
IRB.start
|
32
|
-
end
|
33
|
-
|
34
|
-
desc 'launch IRB shell with development environment loaded'
|
35
|
-
task :console => [:development, :irb]
|
36
|
-
|
data/bin/rspec
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
#
|
4
|
-
# This file was generated by Bundler.
|
5
|
-
#
|
6
|
-
# The application 'rspec' is installed as part of a gem, and
|
7
|
-
# this file is here to facilitate running it.
|
8
|
-
#
|
9
|
-
|
10
|
-
require "pathname"
|
11
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
-
Pathname.new(__FILE__).realpath)
|
13
|
-
|
14
|
-
require "rubygems"
|
15
|
-
require "bundler/setup"
|
16
|
-
|
17
|
-
load Gem.bin_path("rspec-core", "rspec")
|
data/circle.yml
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
SPEC_DIR = File.dirname(__FILE__)
|
2
|
-
FIXTURES_DIR = File.join(SPEC_DIR, "fixtures")
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift File.join(SPEC_DIR, "..", "lib")
|
5
|
-
$LOAD_PATH.unshift SPEC_DIR
|
6
|
-
|
7
|
-
require 'dotenv'
|
8
|
-
Dotenv.load
|
9
|
-
|
10
|
-
require 'wcc/data'
|
11
|
-
require 'sidekiq'
|
12
|
-
|
13
|
-
Dir[File.join(SPEC_DIR, "support", "*.rb")].each do |support_file|
|
14
|
-
require "support/#{File.basename(support_file, ".rb")}"
|
15
|
-
end
|
16
|
-
|
17
|
-
RSpec.configure do |config|
|
18
|
-
config.run_all_when_everything_filtered = true
|
19
|
-
config.filter_run :focus
|
20
|
-
|
21
|
-
config.order = 'random'
|
22
|
-
|
23
|
-
ENV['NUCLEUS_URL'] ||= 'http://login.wcc'
|
24
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
shared_examples_for :inheritable_class_attributes do |name|
|
2
|
-
let(:subclass) { Class.new(subject) }
|
3
|
-
|
4
|
-
it "inherited value is the same as parent class" do
|
5
|
-
subject.send(:instance_variable_set, :"@#{name}", foo: :bar)
|
6
|
-
expect(subject.send(name)).to eq(foo: :bar)
|
7
|
-
expect(subclass.send(name)).to eq(foo: :bar)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "inherited reference is unique from the parent class" do
|
11
|
-
subject.send(:instance_variable_set, :"@#{name}", foo: :bar)
|
12
|
-
subclass.send(name)[:bar] = :baz
|
13
|
-
expect(subject.send(name)).to eq(foo: :bar)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|