cru_lib 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/cru_lib.gemspec +13 -8
- data/lib/cru_lib/global_registry_master_person_methods.rb +44 -0
- data/lib/cru_lib/global_registry_methods.rb +4 -5
- data/lib/cru_lib/global_registry_relationship_methods.rb +5 -1
- data/lib/cru_lib/version.rb +1 -1
- data/lib/cru_lib.rb +1 -29
- metadata +24 -28
- data/lib/cru_lib/access_token.rb +0 -50
- data/lib/cru_lib/access_token_protected_concern.rb +0 -30
- data/lib/cru_lib/access_token_serializer.rb +0 -13
- data/lib/cru_lib/api_error.rb +0 -5
- data/lib/cru_lib/api_error_serializer.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 397cabcb415a6a6f962af2204ca61ee8957337c0
|
4
|
+
data.tar.gz: e8e32dfa19555f824d154c93f61eadf70dc9c72f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ff5ae65ae52213533ff4b8c6ec2e6bf45ebf3ac494b4fb76f955990e80a7a3c3e6d46889490bb15e9948003328b07b29dba88ccd64f921bf3d698046e37c357
|
7
|
+
data.tar.gz: a6eccc089b8bf8f4b121ae50b396e82336f7ad0f3465029db8567340868f888cbfa05fc9e6bc36d5567289bcee6cee7202bd8384a021f8228bdabff5ec18acd8
|
data/.gitignore
CHANGED
data/cru_lib.gemspec
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
lib = File.expand_path('../lib', __FILE__)
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
6
|
require 'cru_lib/version'
|
@@ -8,19 +10,22 @@ Gem::Specification.new do |spec|
|
|
8
10
|
spec.version = CruLib::VERSION
|
9
11
|
spec.authors = ['Josh Starcher']
|
10
12
|
spec.email = ['josh.starcher@gmail.com']
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
|
13
|
+
spec.summary = 'Map ActiveRecord to Global Registry'
|
14
|
+
spec.description = 'Provides a common interface for mapping ActiveRecord ' \
|
15
|
+
'models to Global Registry entities and relationships.'
|
16
|
+
spec.homepage = 'https://github.com/CruGlobal/cru_lib'
|
14
17
|
spec.license = 'MIT'
|
15
18
|
|
16
19
|
spec.files = `git ls-files -z`.split("\x0")
|
17
20
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
21
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
22
|
spec.require_paths = ['lib']
|
20
|
-
spec.add_dependency 'global_registry'
|
21
|
-
spec.add_dependency 'active_model_serializers'
|
22
|
-
spec.add_dependency 'redis'
|
23
23
|
|
24
|
-
spec.
|
25
|
-
|
24
|
+
spec.add_dependency 'global_registry', '~> 1.0'
|
25
|
+
|
26
|
+
spec.add_runtime_dependency 'rails', '>= 4.2.0'
|
27
|
+
spec.add_runtime_dependency 'activesupport', '>= 4.2.0'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
30
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
31
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module CruLib
|
2
|
+
module GlobalRegistryMasterPersonMethods
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
include CruLib::GlobalRegistryMethods
|
5
|
+
|
6
|
+
included do
|
7
|
+
after_commit :retrieve_gr_master_person_id, on: [:create, :update]
|
8
|
+
end
|
9
|
+
|
10
|
+
def retrieve_gr_master_person_id
|
11
|
+
return unless respond_to?(:gr_master_person_id)
|
12
|
+
async(:async_retrieve_gr_master_person_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
def async_retrieve_gr_master_person_id
|
16
|
+
fail CruLib::NoGlobalRegistryIdError, "Person #{id} has no global_registry_id; will retry" unless global_registry_id
|
17
|
+
begin
|
18
|
+
person_entity = GlobalRegistry::Entity.find(global_registry_id, 'filters[owned_by]' => 'mdm')
|
19
|
+
rescue RestClient::ResourceNotFound
|
20
|
+
Rails.logger.info "GR entity #{global_registry_id} for Person #{id} does not exist; will _not_ retry"
|
21
|
+
return
|
22
|
+
end
|
23
|
+
mdm_entity_id = Array.wrap(person_entity.dig('entity', 'person', 'master_person:relationship'))
|
24
|
+
.first # although there should not be more than one
|
25
|
+
.try(:[], 'master_person')
|
26
|
+
fail CruLib::NoGlobalRegistryMasterPersonError, "GR entity #{global_registry_id} for Person #{id} has no master_person; will retry" unless mdm_entity_id
|
27
|
+
update_columns(gr_master_person_id: mdm_entity_id)
|
28
|
+
end
|
29
|
+
|
30
|
+
module ClassMethods
|
31
|
+
def skip_fields_for_gr
|
32
|
+
super + %w(gr_master_person_id)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class NoGlobalRegistryIdError < Rollbar::Ignore; end
|
38
|
+
|
39
|
+
class NoGlobalRegistryMasterPersonError < Rollbar::Ignore; end
|
40
|
+
end
|
41
|
+
|
42
|
+
module Rollbar
|
43
|
+
class Ignore < StandardError; end
|
44
|
+
end
|
@@ -6,10 +6,9 @@ module CruLib
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
include CruLib::Async
|
8
8
|
|
9
|
-
|
10
9
|
included do
|
11
|
-
after_commit :push_to_global_registry
|
12
|
-
|
10
|
+
after_commit :push_to_global_registry, on: [ :create, :update ]
|
11
|
+
after_commit :delete_from_global_registry, on: :destroy
|
13
12
|
end
|
14
13
|
|
15
14
|
def delete_from_global_registry
|
@@ -43,7 +42,7 @@ module CruLib
|
|
43
42
|
@attributes_to_push = {}
|
44
43
|
attributes_to_push['client_integration_id'] = id unless self.class.skip_fields_for_gr.include?('client_integration_id')
|
45
44
|
attributes_to_push['client_updated_at'] = updated_at if respond_to?(:updated_at)
|
46
|
-
attributes.
|
45
|
+
attributes.each {|k, v| @attributes_to_push[k.underscore] = self.class.gr_value(k.underscore, v)}
|
47
46
|
@attributes_to_push.select! {|k, v| v.present? && !self.class.skip_fields_for_gr.include?(k)}
|
48
47
|
end
|
49
48
|
@attributes_to_push
|
@@ -102,7 +101,7 @@ module CruLib
|
|
102
101
|
|
103
102
|
columns_to_push.each do |column|
|
104
103
|
unless existing_fields.include?(column[:name])
|
105
|
-
GlobalRegistry::EntityType.post(entity_type: {name: column[:name], parent_id: entity_type['id'], field_type: column[:
|
104
|
+
GlobalRegistry::EntityType.post(entity_type: {name: column[:name], parent_id: entity_type['id'], field_type: column[:field_type]})
|
106
105
|
end
|
107
106
|
end
|
108
107
|
end
|
@@ -46,7 +46,11 @@ module CruLib
|
|
46
46
|
|
47
47
|
global_registry_id = Array.wrap(
|
48
48
|
entity[base_object.class.global_registry_entity_type_name]["#{relationship_name}:relationship"]
|
49
|
-
).detect
|
49
|
+
).detect do |hash|
|
50
|
+
cid = hash['client_integration_id']
|
51
|
+
cid = cid['value'] if cid.is_a?(Hash)
|
52
|
+
cid == id.to_s
|
53
|
+
end['relationship_entity_id']
|
50
54
|
|
51
55
|
update_column(:global_registry_id, global_registry_id)
|
52
56
|
|
data/lib/cru_lib/version.rb
CHANGED
data/lib/cru_lib.rb
CHANGED
@@ -2,35 +2,7 @@ require 'cru_lib/version'
|
|
2
2
|
require 'cru_lib/async'
|
3
3
|
require 'cru_lib/global_registry_methods'
|
4
4
|
require 'cru_lib/global_registry_relationship_methods'
|
5
|
-
require 'cru_lib/
|
6
|
-
require 'cru_lib/access_token_serializer'
|
7
|
-
require 'cru_lib/access_token_protected_concern'
|
8
|
-
require 'cru_lib/api_error'
|
9
|
-
require 'cru_lib/api_error_serializer'
|
10
|
-
require 'redis'
|
5
|
+
require 'cru_lib/global_registry_master_person_methods'
|
11
6
|
|
12
7
|
module CruLib
|
13
|
-
class << self
|
14
|
-
attr_accessor :redis_host, :redis_port, :redis_db, :redis_client
|
15
|
-
|
16
|
-
def configure
|
17
|
-
yield self
|
18
|
-
end
|
19
|
-
|
20
|
-
def redis_host
|
21
|
-
@redis_host ||= 'localhost'
|
22
|
-
end
|
23
|
-
|
24
|
-
def redis_port
|
25
|
-
@redis_port ||= '6379'
|
26
|
-
end
|
27
|
-
|
28
|
-
def redis_db
|
29
|
-
@redis_db ||= 2
|
30
|
-
end
|
31
|
-
|
32
|
-
def redis_client
|
33
|
-
Redis.new(:host => CruLib.redis_host, :port => CruLib.redis_port, :db => CruLib.redis_db)
|
34
|
-
end
|
35
|
-
end
|
36
8
|
end
|
metadata
CHANGED
@@ -1,86 +1,87 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cru_lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Starcher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: global_registry
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 4.2.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 4.2.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: activesupport
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 4.2.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 4.2.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1.
|
61
|
+
version: '1.11'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1.
|
68
|
+
version: '1.11'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
75
|
+
version: '10.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
description:
|
82
|
+
version: '10.0'
|
83
|
+
description: Provides a common interface for mapping ActiveRecord models to Global
|
84
|
+
Registry entities and relationships.
|
84
85
|
email:
|
85
86
|
- josh.starcher@gmail.com
|
86
87
|
executables: []
|
@@ -94,17 +95,13 @@ files:
|
|
94
95
|
- Rakefile
|
95
96
|
- cru_lib.gemspec
|
96
97
|
- lib/cru_lib.rb
|
97
|
-
- lib/cru_lib/access_token.rb
|
98
|
-
- lib/cru_lib/access_token_protected_concern.rb
|
99
|
-
- lib/cru_lib/access_token_serializer.rb
|
100
|
-
- lib/cru_lib/api_error.rb
|
101
|
-
- lib/cru_lib/api_error_serializer.rb
|
102
98
|
- lib/cru_lib/async.rb
|
99
|
+
- lib/cru_lib/global_registry_master_person_methods.rb
|
103
100
|
- lib/cru_lib/global_registry_methods.rb
|
104
101
|
- lib/cru_lib/global_registry_relationship_methods.rb
|
105
102
|
- lib/cru_lib/version.rb
|
106
103
|
- spec/shared_examples_for_global_registry_models.rb
|
107
|
-
homepage:
|
104
|
+
homepage: https://github.com/CruGlobal/cru_lib
|
108
105
|
licenses:
|
109
106
|
- MIT
|
110
107
|
metadata: {}
|
@@ -124,10 +121,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
121
|
version: '0'
|
125
122
|
requirements: []
|
126
123
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.6.8
|
128
125
|
signing_key:
|
129
126
|
specification_version: 4
|
130
|
-
summary:
|
127
|
+
summary: Map ActiveRecord to Global Registry
|
131
128
|
test_files:
|
132
129
|
- spec/shared_examples_for_global_registry_models.rb
|
133
|
-
has_rdoc:
|
data/lib/cru_lib/access_token.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'securerandom'
|
2
|
-
|
3
|
-
module CruLib
|
4
|
-
class AccessToken < ActiveModelSerializers::Model
|
5
|
-
attr_accessor :key_guid, :email, :first_name, :last_name, :token, :pgt
|
6
|
-
|
7
|
-
def initialize(attributes = {})
|
8
|
-
super
|
9
|
-
generate_access_token unless attributes['token']
|
10
|
-
write
|
11
|
-
end
|
12
|
-
|
13
|
-
class << self
|
14
|
-
|
15
|
-
def read(token)
|
16
|
-
json = exist?(token)
|
17
|
-
new(Oj.load(json)) if json
|
18
|
-
end
|
19
|
-
|
20
|
-
def exist?(token)
|
21
|
-
redis_client.get(redis_key(token))
|
22
|
-
end
|
23
|
-
|
24
|
-
def redis_client
|
25
|
-
@redis_client ||= CruLib.redis_client
|
26
|
-
end
|
27
|
-
|
28
|
-
def redis_key(token)
|
29
|
-
['cru_lib:access_token', token].join(':')
|
30
|
-
end
|
31
|
-
|
32
|
-
def del(token)
|
33
|
-
redis_client.del(redis_key(token))
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def generate_access_token
|
40
|
-
loop do
|
41
|
-
attributes[:token] = SecureRandom.uuid.gsub(/\-/, '')
|
42
|
-
break unless self.class.exist?(attributes[:token])
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def write
|
47
|
-
self.class.redis_client.setex(self.class.redis_key(attributes[:token]), 30.minutes.to_i, to_json)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module CruLib
|
2
|
-
module AccessTokenProtectedConcern
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
protected
|
6
|
-
|
7
|
-
def authenticate_request
|
8
|
-
authenticate_token || render_unauthorized
|
9
|
-
end
|
10
|
-
|
11
|
-
def authenticate_token
|
12
|
-
token = oauth_access_token_from_header
|
13
|
-
return unless oauth_access_token_from_header
|
14
|
-
@access_token = AccessToken.read(token)
|
15
|
-
end
|
16
|
-
|
17
|
-
# grabs access_token from header if one is present
|
18
|
-
def oauth_access_token_from_header
|
19
|
-
auth_header = request.env['HTTP_AUTHORIZATION'] || ''
|
20
|
-
match = auth_header.match(/^Bearer\s(.*)/)
|
21
|
-
return match[1] if match.present?
|
22
|
-
false
|
23
|
-
end
|
24
|
-
|
25
|
-
def render_unauthorized
|
26
|
-
headers['WWW-Authenticate'] = %{CAS realm="Application"}
|
27
|
-
render_error('Bad token', status: 401)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/lib/cru_lib/api_error.rb
DELETED