selfsdk 0.0.192 → 0.0.195
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chat/file_object.rb +17 -2
- data/lib/messages/fact.rb +3 -6
- data/lib/messages/fact_response.rb +1 -1
- data/lib/messaging.rb +3 -2
- data/lib/services/facts.rb +56 -47
- data/lib/sources.rb +87 -75
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e41a8293552addc1b1de4266ae6116de304f94da70410d0c6edc159e579a6787
|
4
|
+
data.tar.gz: 974a651863325ae66fd015af0cbcaf95757a79baf90b6336b4a79e15780d824b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b53fca4a9a5d211438f38e8c97768b2f84d9513e78adfc10282f1472bd8346e8aa8801659cff543f77d19909bc4588d3f987ca2ee65e909529b48585e5eeabfe
|
7
|
+
data.tar.gz: 643f600065d4fad7c551bf57fd07ac3f316ac9a1f17f496f11aed4d67ec8618371247c1ce2b742d3d6b9a19525689e4e123328bae6e0db3b55e1b4acd21b7a4a
|
data/lib/chat/file_object.rb
CHANGED
@@ -6,7 +6,7 @@ require 'open-uri'
|
|
6
6
|
module SelfSDK
|
7
7
|
module Chat
|
8
8
|
class FileObject
|
9
|
-
attr_accessor :link, :mime, :content, :key, :nonce, :ciphertext
|
9
|
+
attr_accessor :name, :link, :mime, :content, :key, :nonce, :ciphertext
|
10
10
|
|
11
11
|
def initialize(token, url)
|
12
12
|
@token = token
|
@@ -35,7 +35,22 @@ module SelfSDK
|
|
35
35
|
# Incoming objects
|
36
36
|
def build_from_object(input)
|
37
37
|
# Download from CDN
|
38
|
-
ciphertext =
|
38
|
+
ciphertext = ""
|
39
|
+
5.times do
|
40
|
+
begin
|
41
|
+
ciphertext = URI.open(input[:link], "Authorization" => "Bearer #{@token}").read
|
42
|
+
break
|
43
|
+
rescue => e
|
44
|
+
SelfSDK.logger.info e.message
|
45
|
+
SelfSDK.logger.info e.backtrace.join("\n")
|
46
|
+
sleep 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
if ciphertext.empty?
|
51
|
+
SelfSDK.logger.warn "unable to process incoming object"
|
52
|
+
return
|
53
|
+
end
|
39
54
|
|
40
55
|
@content = ciphertext
|
41
56
|
@key = nil
|
data/lib/messages/fact.rb
CHANGED
@@ -14,14 +14,11 @@ module SelfSDK
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def parse(fact)
|
17
|
-
@name =
|
18
|
-
|
19
|
-
@operator = ""
|
20
|
-
@operator = SelfSDK::operator(fact[:operator]) if fact[:operator]
|
21
|
-
|
17
|
+
@name = @messaging.source.normalize_fact_name! fact[:fact]
|
18
|
+
@operator = @messaging.source.normalize_operator!(fact[:operator])
|
22
19
|
@sources = []
|
23
20
|
fact[:sources]&.each do |s|
|
24
|
-
@sources <<
|
21
|
+
@sources << @messaging.source.normalize_source!(s)
|
25
22
|
end
|
26
23
|
|
27
24
|
@expected_value = fact[:expected_value] || ""
|
data/lib/messaging.rb
CHANGED
@@ -17,7 +17,7 @@ module SelfSDK
|
|
17
17
|
DEFAULT_STORAGE_DIR="./.self_storage"
|
18
18
|
ON_DEMAND_CLOSE_CODE=3999
|
19
19
|
|
20
|
-
attr_accessor :client, :jwt, :device_id, :ack_timeout, :timeout, :type_observer, :uuid_observer, :encryption_client
|
20
|
+
attr_accessor :client, :jwt, :device_id, :ack_timeout, :timeout, :type_observer, :uuid_observer, :encryption_client, :source
|
21
21
|
|
22
22
|
# RestClient initializer
|
23
23
|
#
|
@@ -47,6 +47,7 @@ module SelfSDK
|
|
47
47
|
FileUtils.mkdir_p @storage_dir unless File.exist? @storage_dir
|
48
48
|
@offset_file = "#{@storage_dir}/#{@jwt.id}:#{@device_id}.offset"
|
49
49
|
@offset = read_offset
|
50
|
+
@source = SelfSDK::Sources.new("#{__dir__}/sources.json")
|
50
51
|
migrate_old_storage_format
|
51
52
|
|
52
53
|
unless options.include? :no_crypto
|
@@ -283,7 +284,7 @@ module SelfSDK
|
|
283
284
|
end
|
284
285
|
|
285
286
|
def subscribe(type, &block)
|
286
|
-
type =
|
287
|
+
type = @source.message_type(type) if type.is_a? Symbol
|
287
288
|
@type_observer[type] = { block: block }
|
288
289
|
end
|
289
290
|
|
data/lib/services/facts.rb
CHANGED
@@ -62,6 +62,10 @@ module SelfSDK
|
|
62
62
|
return req.send_message
|
63
63
|
end
|
64
64
|
|
65
|
+
if opts[:async] == true
|
66
|
+
return req.send_message
|
67
|
+
end
|
68
|
+
|
65
69
|
# Otherwise the request is synchronous
|
66
70
|
req.request
|
67
71
|
end
|
@@ -135,13 +139,13 @@ module SelfSDK
|
|
135
139
|
fs = []
|
136
140
|
facts.each do |f|
|
137
141
|
fact = if f.is_a?(Hash)
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
+
f
|
143
|
+
else
|
144
|
+
{ fact: f }
|
145
|
+
end
|
142
146
|
# validate_fact!(fact)
|
143
147
|
fs << fact
|
144
|
-
end
|
148
|
+
end
|
145
149
|
fs
|
146
150
|
end
|
147
151
|
|
@@ -152,67 +156,72 @@ module SelfSDK
|
|
152
156
|
raise 'provided fact does not specify a name' if f[:fact].empty?
|
153
157
|
return unless f.has_key? :sources
|
154
158
|
|
155
|
-
valid_sources = [
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
159
|
+
valid_sources = [SOURCE_USER_SPECIFIED,
|
160
|
+
SOURCE_PASSPORT,
|
161
|
+
SOURCE_DRIVING_LICENSE,
|
162
|
+
SOURCE_IDENTITY_CARD,
|
163
|
+
SOURCE_TWITTER,
|
164
|
+
SOURCE_LINKEDIN,
|
165
|
+
SOURCE_FACEBOK]
|
166
|
+
fact_for_passport = [FACT_DOCUMENT_NUMBER,
|
167
|
+
FACT_SURNAME,
|
168
|
+
FACT_GIVEN_NAMES,
|
169
|
+
FACT_DATE_OF_BIRTH,
|
170
|
+
FACT_DATE_OF_EXPIRATION,
|
171
|
+
FACT_SEX,
|
172
|
+
FACT_NATIONALITY,
|
173
|
+
FACT_COUNTRY_OF_ISSUANCE]
|
174
|
+
|
175
|
+
facts_for_dl = [FACT_DOCUMENT_NUMBER,
|
176
|
+
FACT_SURNAME,
|
177
|
+
FACT_GIVEN_NAMES,
|
178
|
+
FACT_DATE_OF_BIRTH,
|
179
|
+
FACT_DATE_OF_ISSUANCE,
|
180
|
+
FACT_DATE_OF_EXPIRATION,
|
181
|
+
FACT_ADDRESS,
|
182
|
+
FACT_ISSUING_AUTHORITY,
|
183
|
+
FACT_PLACE_OF_BIRTH,
|
184
|
+
FACT_COUNTRY_OF_ISSUANCE]
|
185
|
+
|
186
|
+
facts_for_user = [FACT_DOCUMENT_NUMBER,
|
187
|
+
FACT_DISPLAY_NAME,
|
188
|
+
FACT_EMAIL,
|
189
|
+
FACT_PHONE]
|
190
|
+
|
191
|
+
facts_for_twitter = [FACT_ACCOUNT_ID, FACT_NICKNAME]
|
192
|
+
facts_for_linkedin = [FACT_ACCOUNT_ID, FACT_NICKNAME]
|
193
|
+
facts_for_facebook = [FACT_ACCOUNT_ID, FACT_NICKNAME]
|
194
|
+
facts_for_live = [FACT_SELFIE]
|
195
|
+
|
191
196
|
f[:sources].each do |s|
|
192
197
|
raise errInvalidSource unless valid_sources.include? s.to_s
|
193
198
|
|
194
199
|
if s.to_s == SOURCE_PASSPORT || s.to_s == SOURCE_IDENTITY_CARD
|
195
|
-
raise errInvalidFactToSource unless
|
200
|
+
raise errInvalidFactToSource unless fact_for_passport.include? f[:fact]
|
196
201
|
end
|
197
202
|
|
198
203
|
if s.to_s == SOURCE_DRIVING_LICENSE
|
199
|
-
raise errInvalidFactToSource unless
|
204
|
+
raise errInvalidFactToSource unless facts_for_dl.include? f[:fact]
|
200
205
|
end
|
201
206
|
|
202
207
|
if s.to_s == SOURCE_USER_SPECIFIED
|
203
|
-
raise errInvalidFactToSource unless
|
208
|
+
raise errInvalidFactToSource unless facts_for_user.include? f[:fact].to_s
|
204
209
|
end
|
205
210
|
|
206
211
|
if s.to_s == SOURCE_TWITTER
|
207
|
-
raise errInvalidFactToSource unless
|
212
|
+
raise errInvalidFactToSource unless facts_for_twitter.include? f[:fact].to_s
|
208
213
|
end
|
209
214
|
|
210
215
|
if s.to_s == SOURCE_LINKEDIN
|
211
|
-
raise errInvalidFactToSource unless
|
216
|
+
raise errInvalidFactToSource unless facts_for_linkedin.include? f[:fact].to_s
|
212
217
|
end
|
213
218
|
|
214
219
|
if s.to_s == SOURCE_FACEBOOK
|
215
|
-
raise errInvalidFactToSource unless
|
220
|
+
raise errInvalidFactToSource unless facts_for_facebook.include? f[:fact].to_s
|
221
|
+
end
|
222
|
+
|
223
|
+
if s.to_s == SOURCE_LIVE
|
224
|
+
raise errInvalidFactToSource unless facts_for_live.include? f[:fact].to_s
|
216
225
|
end
|
217
226
|
end
|
218
227
|
end
|
data/lib/sources.rb
CHANGED
@@ -2,38 +2,95 @@
|
|
2
2
|
|
3
3
|
# frozen_string_literal: true
|
4
4
|
|
5
|
+
require "json"
|
5
6
|
module SelfSDK
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
7
|
+
class Sources
|
8
|
+
def initialize(sources_file)
|
9
|
+
data = JSON.parse('{
|
10
|
+
"sources": {
|
11
|
+
"user_specified": [
|
12
|
+
"document_number",
|
13
|
+
"display_name",
|
14
|
+
"email_address",
|
15
|
+
"phone_number"
|
16
|
+
],
|
17
|
+
"passport": [
|
18
|
+
"document_number",
|
19
|
+
"surname",
|
20
|
+
"given_names",
|
21
|
+
"date_of_birth",
|
22
|
+
"date_of_expiration",
|
23
|
+
"sex",
|
24
|
+
"nationality",
|
25
|
+
"country_of_issuance"
|
26
|
+
],
|
27
|
+
"driving_license": [
|
28
|
+
"document_number",
|
29
|
+
"surname",
|
30
|
+
"given_names",
|
31
|
+
"date_of_birth",
|
32
|
+
"date_of_issuance",
|
33
|
+
"date_of_expiration",
|
34
|
+
"address",
|
35
|
+
"issuing_authority",
|
36
|
+
"place_of_birth"
|
37
|
+
],
|
38
|
+
"identity_card": [
|
39
|
+
"document_number",
|
40
|
+
"surname",
|
41
|
+
"given_names",
|
42
|
+
"date_of_birth",
|
43
|
+
"date_of_expiration",
|
44
|
+
"sex",
|
45
|
+
"nationality",
|
46
|
+
"country_of_issuance"
|
47
|
+
],
|
48
|
+
"twitter": [
|
49
|
+
"account_id",
|
50
|
+
"nickname"
|
51
|
+
],
|
52
|
+
"linkedin": [
|
53
|
+
"account_id",
|
54
|
+
"nickname"
|
55
|
+
],
|
56
|
+
"facebook": [
|
57
|
+
"account_id",
|
58
|
+
"nickname"
|
59
|
+
],
|
60
|
+
"live": [
|
61
|
+
"selfie_verification"
|
62
|
+
]
|
63
|
+
}
|
64
|
+
}')
|
65
|
+
@sources = data["sources"]
|
66
|
+
@facts = []
|
67
|
+
@sources.each do |source, facts|
|
68
|
+
@facts.push(*facts)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def normalize_fact_name!(fact)
|
73
|
+
fact = fact.to_s
|
74
|
+
raise "invalid fact '#{fact}'" unless @facts.include?(fact)
|
75
|
+
fact
|
76
|
+
end
|
77
|
+
|
78
|
+
def validate_source!(source)
|
79
|
+
raise "invalid source '#{source}'" unless @sources.keys.include?(source.to_s)
|
80
|
+
end
|
81
|
+
|
82
|
+
def normalize_operator!(input)
|
83
|
+
return "" unless input
|
27
84
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
85
|
+
operators = { equals: '==',
|
86
|
+
different: '!=',
|
87
|
+
great_or_equal_than: '>=',
|
88
|
+
less_or_equal: '<=',
|
89
|
+
great_than: '>',
|
90
|
+
less_than: '<' }
|
91
|
+
get(operators, input, "operator")
|
92
|
+
end
|
35
93
|
|
36
|
-
class << self
|
37
94
|
def message_type(s)
|
38
95
|
types = { authentication_request: SelfSDK::Messages::AuthenticationReq::MSG_TYPE,
|
39
96
|
authentication_response: SelfSDK::Messages::AuthenticationResp::MSG_TYPE,
|
@@ -51,51 +108,7 @@ module SelfSDK
|
|
51
108
|
return types[s]
|
52
109
|
end
|
53
110
|
|
54
|
-
|
55
|
-
operators = { equals: '==',
|
56
|
-
different: '!=',
|
57
|
-
great_or_equal_than: '>=',
|
58
|
-
less_or_equal: '<=',
|
59
|
-
great_than: '>',
|
60
|
-
less_than: '<' }
|
61
|
-
get(operators, input, "operator")
|
62
|
-
end
|
63
|
-
|
64
|
-
def fact_name(input)
|
65
|
-
facts = { email_address: FACT_EMAIL,
|
66
|
-
phone_number: FACT_PHONE,
|
67
|
-
display_name: FACT_DISPLAY_NAME,
|
68
|
-
document_number: FACT_DOCUMENT_NUMBER,
|
69
|
-
given_names: FACT_GIVEN_NAMES,
|
70
|
-
surname: FACT_SURNAME,
|
71
|
-
sex: FACT_SEX,
|
72
|
-
issuing_authority: FACT_ISSUING_AUTHORITY,
|
73
|
-
nationality: FACT_NATIONALITY,
|
74
|
-
address: FACT_ADDRESS,
|
75
|
-
place_of_birth: FACT_PLACE_OF_BIRTH,
|
76
|
-
date_of_birth: FACT_DATE_OF_BIRTH,
|
77
|
-
date_of_issuance: FACT_DATE_OF_ISSUANCE,
|
78
|
-
date_of_expiration: FACT_DATE_OF_EXPIRATION,
|
79
|
-
valid_from: FACT_VALID_FROM,
|
80
|
-
valid_to: FACT_VALID_TO,
|
81
|
-
categories: FACT_CATEGORIES,
|
82
|
-
sort_code: FACT_SORT_CODE,
|
83
|
-
country_of_issuance: FACT_COUNTRY_OF_ISSUANCE,
|
84
|
-
account_id: FACT_ACCOUNT_ID,
|
85
|
-
nickname: FACT_NICKNAME }
|
86
|
-
get(facts, input, "fact")
|
87
|
-
end
|
88
|
-
|
89
|
-
def source(input)
|
90
|
-
sources = { user_specified: SOURCE_USER_SPECIFIED,
|
91
|
-
passport: SOURCE_PASSPORT,
|
92
|
-
driving_license: SOURCE_DRIVING_LICENSE,
|
93
|
-
identity_card: SOURCE_IDENTITY_CARD,
|
94
|
-
twitter: SOURCE_TWITTER,
|
95
|
-
linkedin: SOURCE_LINKEDIN,
|
96
|
-
facebook: SOURCE_FACEBOOK }
|
97
|
-
get(sources, input, "source")
|
98
|
-
end
|
111
|
+
private
|
99
112
|
|
100
113
|
def get(options, input, option_type)
|
101
114
|
if input.is_a? Symbol
|
@@ -105,6 +118,5 @@ module SelfSDK
|
|
105
118
|
raise "invalid #{option_type} '#{input}'" unless options.values.include? input
|
106
119
|
input
|
107
120
|
end
|
108
|
-
|
109
121
|
end
|
110
122
|
end
|