Skip to content

Commit f1f23eb

Browse files
author
Inbal Tako
committed
SN-1938 Validate user id
1 parent 1d2525e commit f1f23eb

File tree

2 files changed

+12
-63
lines changed

2 files changed

+12
-63
lines changed

securenative/models/request_context.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,3 @@ def __init__(self, cid=None, vid=None, fp=None, ip=None,
1010
self.headers = headers
1111
self.url = url
1212
self.method = method
13-
14-
15-
class RequestContextBuilder(object):
16-
17-
def __init__(self, cid=None, vid=None, fp=None, ip=None,
18-
remote_ip=None, headers=None, url=None, method=None):
19-
self.cid = cid
20-
self.vid = vid
21-
self.fp = fp
22-
self.ip = ip
23-
self.remote_ip = remote_ip
24-
self.headers = headers
25-
self.url = url
26-
self.method = method
27-
28-
def with_cid(self, cid):
29-
self.cid = cid
30-
return self
31-
32-
def with_vid(self, vid):
33-
self.vid = vid
34-
return self
35-
36-
def with_fp(self, fp):
37-
self.fp = fp
38-
return self
39-
40-
def with_ip(self, ip):
41-
self.ip = ip
42-
return self
43-
44-
def with_remote_ip(self, remote_ip):
45-
self.remote_ip = remote_ip
46-
return self
47-
48-
def with_headers(self, headers):
49-
self.headers = headers
50-
return self
51-
52-
def with_url(self, url):
53-
self.url = url
54-
return self
55-
56-
def with_method(self, method):
57-
self.method = method
58-
return self
59-
60-
def build(self):
61-
return RequestContext(self.cid, self.vid, self.fp, self.ip, self.remote_ip, self.headers, self.url, self.method)

securenative/models/sdk_event.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import uuid
22

3-
from securenative.context.context_builder import ContextBuilder
3+
from securenative.context.securenative_context import SecureNativeContext
44
from securenative.exceptions.securenative_invalid_options_exception import SecureNativeInvalidOptionsException
5-
from securenative.models.request_context import RequestContextBuilder
5+
from securenative.models.request_context import RequestContext
66
from securenative.models.user_traits import UserTraits
77
from securenative.utils.date_utils import DateUtils
88
from securenative.utils.encryption_utils import EncryptionUtils
@@ -11,13 +11,13 @@
1111
class SDKEvent(object):
1212

1313
def __init__(self, event_options, securenative_options):
14-
if event_options.user_id is None or len(event_options.user_id) <=0 or event_options.user_id == "":
14+
if event_options.user_id is None or len(event_options.user_id) <= 0 or event_options.user_id == "":
1515
raise SecureNativeInvalidOptionsException("Invalid event structure; User Id is missing")
1616

1717
if event_options.context is not None:
1818
self.context = event_options.context
1919
else:
20-
self.context = ContextBuilder.default_context_builder().build()
20+
self.context = SecureNativeContext()
2121

2222
if self.context.client_token:
2323
client_token = EncryptionUtils.decrypt(self.context.client_token, securenative_options.api_key)
@@ -38,16 +38,14 @@ def __init__(self, event_options, securenative_options):
3838
self.event_type = event_options.event if event_options.event else ""
3939
self.user_id = event_options.user_id
4040
self.user_traits = user_traits
41-
self.request = RequestContextBuilder() \
42-
.with_cid(client_token.cid if client_token else "") \
43-
.with_vid(client_token.vid if client_token else "") \
44-
.with_fp(client_token.fp if client_token else "") \
45-
.with_ip(self.context.ip if self.context.ip else "") \
46-
.with_remote_ip(self.context.remote_ip if self.context.remote_ip else "") \
47-
.with_method(self.context.method if self.context.method else "") \
48-
.with_url(self.context.url if self.context.url else "") \
49-
.with_headers(self.context.headers if self.context.headers else None) \
50-
.build()
41+
self.request = RequestContext(cid=client_token.cid if client_token else "",
42+
vid=client_token.vid if client_token else "",
43+
fp=client_token.fp if client_token else "",
44+
ip=self.context.ip if self.context.ip else "",
45+
remote_ip=self.context.remote_ip if self.context.remote_ip else "",
46+
headers=self.context.headers if self.context.headers else None,
47+
url=self.context.url if self.context.url else "",
48+
method=self.context.method if self.context.method else "")
5149

5250
self.timestamp = DateUtils.to_timestamp(event_options.timestamp)
5351
self.properties = event_options.properties

0 commit comments

Comments
 (0)