cru_lib 0.0.2.4 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cru_lib.gemspec +11 -9
- data/lib/cru_lib/access_token.rb +49 -0
- data/lib/cru_lib/access_token_protected_concern.rb +34 -0
- data/lib/cru_lib/access_token_serializer.rb +13 -0
- data/lib/cru_lib/api_error.rb +5 -0
- data/lib/cru_lib/api_error_serializer.rb +13 -0
- data/lib/cru_lib/global_registry_methods.rb +4 -4
- data/lib/cru_lib/global_registry_relationship_methods.rb +1 -5
- data/lib/cru_lib/version.rb +1 -1
- data/lib/cru_lib.rb +30 -1
- metadata +36 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a613a3c3c5d3fa1d8a2b331e0a5d56a437c49c14
|
4
|
+
data.tar.gz: b1979b984158dbd5c9f74e4d0bd6b2e4be00c6c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf2b90f0bf13e82182d39b5edf3a887aa85255fc62ca366830e0f32e36611b19647715014caf7dbe426fb6bd0a529619fcbea1357a067ae1bf9601686faf5797
|
7
|
+
data.tar.gz: 4c89e114302da48e30b6a7e6d332f5664f6657dc2622a0808fe7e54a5decaa3d335ea87aa69d4e1aec3ba0477a50d84e637e9afff5a4b0b2ab29d3cca2387a27
|
data/cru_lib.gemspec
CHANGED
@@ -4,21 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'cru_lib/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'cru_lib'
|
8
8
|
spec.version = CruLib::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Josh Starcher']
|
10
|
+
spec.email = ['josh.starcher@gmail.com']
|
11
11
|
spec.summary = %q{Misc libraries for Cru}
|
12
12
|
spec.description = %q{Collection of common ruby logic used by a number of Cru apps}
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = [
|
20
|
-
spec.add_dependency
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
spec.add_dependency 'global_registry'
|
21
|
+
spec.add_dependency 'active_model_serializers'
|
22
|
+
spec.add_dependency 'redis'
|
21
23
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
25
|
+
spec.add_development_dependency 'rake'
|
24
26
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module CruLib
|
4
|
+
class AccessToken < ActiveModelSerializers::Model
|
5
|
+
attr_accessor :key_guid, :email, :first_name, :last_name, :token
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def redis_key(token)
|
9
|
+
['cru_lib:access_token', token].join(':')
|
10
|
+
end
|
11
|
+
|
12
|
+
def read(token)
|
13
|
+
json = exist?(token)
|
14
|
+
if json
|
15
|
+
attributes = Oj.load(json)
|
16
|
+
attributes['token'] = token
|
17
|
+
access_token = new(attributes)
|
18
|
+
access_token.write
|
19
|
+
access_token
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def exist?(token)
|
24
|
+
redis_client.get(redis_key(token))
|
25
|
+
end
|
26
|
+
|
27
|
+
def redis_client
|
28
|
+
@redis_client ||= CruLib.redis_client
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def generate_access_token
|
34
|
+
loop do
|
35
|
+
attributes[:token] = SecureRandom.uuid.gsub(/\-/, '')
|
36
|
+
break unless self.class.exist?(attributes[:token])
|
37
|
+
end
|
38
|
+
write
|
39
|
+
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def write
|
45
|
+
self.class.redis_client.setex(self.class.redis_key(token), 30.minutes.to_i, to_json)
|
46
|
+
end
|
47
|
+
private
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module CruLib
|
2
|
+
module AccessTokenProtectedConcern
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
before_action :authenticate_request
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def authenticate_request
|
12
|
+
authenticate_token || render_unauthorized
|
13
|
+
end
|
14
|
+
|
15
|
+
def authenticate_token
|
16
|
+
token = oauth_access_token_from_header
|
17
|
+
return unless oauth_access_token_from_header
|
18
|
+
@access_token = AccessToken.read(token)
|
19
|
+
end
|
20
|
+
|
21
|
+
# grabs access_token from header if one is present
|
22
|
+
def oauth_access_token_from_header
|
23
|
+
auth_header = request.env['HTTP_AUTHORIZATION'] || ''
|
24
|
+
match = auth_header.match(/^Bearer\s(.*)/)
|
25
|
+
return match[1] if match.present?
|
26
|
+
false
|
27
|
+
end
|
28
|
+
|
29
|
+
def render_unauthorized
|
30
|
+
headers['WWW-Authenticate'] = %{CAS realm="Application"}
|
31
|
+
render_error('Bad token', status: 401)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -8,8 +8,8 @@ module CruLib
|
|
8
8
|
|
9
9
|
|
10
10
|
included do
|
11
|
-
after_commit :push_to_global_registry
|
12
|
-
|
11
|
+
after_commit :push_to_global_registry
|
12
|
+
after_destroy :delete_from_global_registry
|
13
13
|
end
|
14
14
|
|
15
15
|
def delete_from_global_registry
|
@@ -43,7 +43,7 @@ module CruLib
|
|
43
43
|
@attributes_to_push = {}
|
44
44
|
attributes_to_push['client_integration_id'] = id unless self.class.skip_fields_for_gr.include?('client_integration_id')
|
45
45
|
attributes_to_push['client_updated_at'] = updated_at if respond_to?(:updated_at)
|
46
|
-
attributes.
|
46
|
+
attributes.collect {|k, v| @attributes_to_push[k.underscore] = self.class.gr_value(k.underscore, v)}
|
47
47
|
@attributes_to_push.select! {|k, v| v.present? && !self.class.skip_fields_for_gr.include?(k)}
|
48
48
|
end
|
49
49
|
@attributes_to_push
|
@@ -102,7 +102,7 @@ module CruLib
|
|
102
102
|
|
103
103
|
columns_to_push.each do |column|
|
104
104
|
unless existing_fields.include?(column[:name])
|
105
|
-
GlobalRegistry::EntityType.post(entity_type: {name: column[:name], parent_id: entity_type['id'], field_type: column[:
|
105
|
+
GlobalRegistry::EntityType.post(entity_type: {name: column[:name], parent_id: entity_type['id'], field_type: column[:type]})
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
@@ -46,11 +46,7 @@ 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
|
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']
|
49
|
+
).detect { |hash| hash['client_integration_id'] == id.to_s }['relationship_entity_id']
|
54
50
|
|
55
51
|
update_column(:global_registry_id, global_registry_id)
|
56
52
|
|
data/lib/cru_lib/version.rb
CHANGED
data/lib/cru_lib.rb
CHANGED
@@ -1,7 +1,36 @@
|
|
1
|
-
require
|
1
|
+
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_dependency 'cru_lib/access_token'
|
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
11
|
|
6
12
|
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
|
7
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.0.3
|
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: 2015-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: global_registry
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: active_model_serializers
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: redis
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: bundler
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +94,11 @@ files:
|
|
66
94
|
- Rakefile
|
67
95
|
- cru_lib.gemspec
|
68
96
|
- 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
|
69
102
|
- lib/cru_lib/async.rb
|
70
103
|
- lib/cru_lib/global_registry_methods.rb
|
71
104
|
- lib/cru_lib/global_registry_relationship_methods.rb
|
@@ -91,10 +124,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
124
|
version: '0'
|
92
125
|
requirements: []
|
93
126
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.5
|
127
|
+
rubygems_version: 2.4.5
|
95
128
|
signing_key:
|
96
129
|
specification_version: 4
|
97
130
|
summary: Misc libraries for Cru
|
98
131
|
test_files:
|
99
132
|
- spec/shared_examples_for_global_registry_models.rb
|
100
|
-
has_rdoc:
|