Skip to content

Commit 8258b01

Browse files
author
Inbal Tako
committed
Add context, http client, models and utils
1 parent 6b61dc2 commit 8258b01

35 files changed

Lines changed: 410 additions & 127 deletions

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
requests~=2.23.0
2-
pycrypto~=2.6.1
2+
pycrypto~=2.6.1
3+
aiohttp~=3.6.2
4+
crypto~=1.4.1

securenative/config.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

securenative/config/configuration_builder.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from securenative.config.securenative_options import SecurenativeOptions
1+
from securenative.config.securenative_options import SecureNativeOptions
22
from securenative.enums.failover_strategy import FailOverStrategy
33

44

55
class ConfigurationBuilder(object):
66

77
def __init__(self):
8-
self.api_key = ""
8+
self.api_key = None
99
self.api_url = "https://api.securenative.com/collector/api/v1"
1010
self.interval = 1000
1111
self.max_events = 1000
@@ -57,5 +57,4 @@ def with_fail_over_strategy(self, fail_over_strategy):
5757

5858
@staticmethod
5959
def get_default_securenative_options():
60-
return SecurenativeOptions("", "https://api.securenative.com/collector/api/v1", 1000,
61-
1000, 1500, True, False, "CRITICAL", FailOverStrategy.FAIL_OPEN)
60+
return SecureNativeOptions()

securenative/config/configuration_manager.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ConfigurationManager(object):
99
CUSTOM_CONFIG_FILE_ENV_NAME = "SECURENATIVE_COMFIG_FILE"
1010
config = ConfigParser.ConfigParser()
1111

12-
@staticmethod
12+
@classmethod
1313
def read_resource_file(cls, resource_path):
1414
cls.config.read(resource_path)
1515
sections = cls.config.sections()
@@ -25,7 +25,7 @@ def read_resource_file(cls, resource_path):
2525

2626
return properties
2727

28-
@staticmethod
28+
@classmethod
2929
def _get_resource_path(cls, env_name):
3030
env_value = os.environ.get(env_name)
3131

@@ -38,7 +38,13 @@ def _get_resource_path(cls, env_name):
3838
def config_builder():
3939
return ConfigurationBuilder.default_config_builder()
4040

41-
@staticmethod
41+
@classmethod
42+
def _get_env_or_default(cls, properties, key, default):
43+
if properties[key]:
44+
return properties[key]
45+
return default
46+
47+
@classmethod
4248
def load_config(cls):
4349
builder = ConfigurationBuilder()
4450
options = builder.get_default_securenative_options()

securenative/config/securenative_options.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
class SecurenativeOptions(object):
1+
from securenative.enums.failover_strategy import FailOverStrategy
22

3-
def __init__(self, api_key, api_url, interval, max_events, timeout, auto_send,
4-
disable, log_level, fail_over_strategy):
3+
4+
class SecureNativeOptions(object):
5+
6+
def __init__(self, api_key=None, api_url=None, interval=1000, max_events=1000, timeout=1500, auto_send=True,
7+
disable=False, log_level="CRITICAL", fail_over_strategy=FailOverStrategy.FAIL_OPEN):
58
self.api_key = api_key
69
self.api_url = api_url
710
self.interval = interval
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from securenative.context.securenative_context import SecureNativeContext
2+
3+
4+
class ContextBuilder(object):
5+
6+
def __init__(self):
7+
self.context = SecureNativeContext()
8+
9+
def with_client_token(self, client_token):
10+
self.context.client_token = client_token
11+
return self
12+
13+
def with_ip(self, ip):
14+
self.context.ip = ip
15+
return self
16+
17+
def with_remote_ip(self, remote_ip):
18+
self.context.remote_ip = remote_ip
19+
return self
20+
21+
def with_headers(self, headers):
22+
self.context.headers = headers
23+
return self
24+
25+
def with_url(self, url):
26+
self.context.url = url
27+
return self
28+
29+
def with_method(self, method):
30+
self.context.method = method
31+
return self
32+
33+
def with_body(self, body):
34+
self.context.body = body
35+
return self
36+
37+
@staticmethod
38+
def default_context_builder():
39+
return ContextBuilder()
40+
41+
def from_http_request(self, request): # TODO!
42+
pass
43+
44+
def build(self):
45+
return self.context
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class SecureNativeContext(object):
2+
3+
def __init__(self, client_token=None, ip=None, remote_ip=None, headers=None, url=None, method=None, body=None):
4+
self.client_token = client_token
5+
self.ip = ip
6+
self.remote_ip = remote_ip
7+
self.headers = headers
8+
self.url = url
9+
self.method = method
10+
self.body = body

securenative/enums/api_route.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from enum import Enum
2+
3+
4+
class ApiRoute(Enum):
5+
TRACK = "track"
6+
VERIFY = "verify"

securenative/enums/event_types.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from enum import Enum
2+
3+
4+
class EventTypes(Enum):
5+
LOG_IN = "sn.user.login"
6+
LOG_IN_CHALLENGE = "sn.user.login.challenge"
7+
LOG_IN_FAILURE = "sn.user.login.failure"
8+
LOG_OUT = "sn.user.logout"
9+
SIGN_UP = "sn.user.signup"
10+
AUTH_CHALLENGE = "sn.user.auth.challenge"
11+
AUTH_CHALLENGE_SUCCESS = "sn.user.auth.challenge.success"
12+
AUTH_CHALLENGE_FAILURE = "sn.user.auth.challenge.failure"
13+
TWO_FACTOR_DISABLE = "sn.user.2fa.disable"
14+
EMAIL_UPDATE = "sn.user.email.update"
15+
PASSWORD_REST = "sn.user.password.reset"
16+
PASSWORD_REST_SUCCESS = "sn.user.password.reset.success"
17+
PASSWORD_UPDATE = "sn.user.password.update"
18+
PASSWORD_REST_FAILURE = "sn.user.password.reset.failure"
19+
USER_INVITE = "sn.user.invite"
20+
ROLE_UPDATE = "sn.user.role.update"
21+
PROFILE_UPDATE = "sn.user.profile.update"
22+
PAGE_VIEW = "sn.user.page.view"
23+
VERIFY = "sn.verify"

securenative/enums/risk_level.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from enum import Enum
2+
3+
4+
class RiskLevel(Enum):
5+
LOW = "low"
6+
MEDIUM = "medium"
7+
HIGH = "high"

0 commit comments

Comments
 (0)