Skip to content

Commit 370a950

Browse files
author
Inbal Tako
committed
Fix config file parsing
1 parent 1532b85 commit 370a950

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ SecureNative can automatically load your config from *securenative.ini* file or
4646
from securenative.securenative import SecureNative
4747

4848

49+
# 1. Config file path is given by environment variable
4950
securenative = SecureNative.init()
51+
52+
# 2. Config file path is specified directly
53+
securenative = SecureNative.init('path/to/securenative.ini')
5054
```
5155
### Option 2: Initialize via API Key
5256

securenative/config/configuration_manager.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import os
2-
from configparser import ConfigParser, NoSectionError
2+
from configparser import ConfigParser
33

44
from securenative.config.configuration_builder import ConfigurationBuilder
5+
from securenative.exceptions.securenative_config_exception import SecureNativeConfigException
56

67

78
class ConfigurationManager(object):
@@ -11,7 +12,10 @@ class ConfigurationManager(object):
1112

1213
@classmethod
1314
def read_resource_file(cls, resource_path):
14-
cls.config.read(resource_path)
15+
try:
16+
cls.config.read(resource_path)
17+
except Exception as e:
18+
raise SecureNativeConfigException("Invalid config file; %s", e)
1519

1620
properties = {}
1721
for key, value in cls.config.defaults().items():
@@ -41,11 +45,10 @@ def _get_env_or_default(cls, properties, key, default):
4145
return default
4246

4347
@classmethod
44-
def load_config(cls):
48+
def load_config(cls, resource_path):
4549
options = ConfigurationBuilder().get_default_securenative_options()
4650

47-
resource_path = cls.DEFAULT_CONFIG_FILE
48-
if os.environ.get(cls.CUSTOM_CONFIG_FILE_ENV_NAME):
51+
if not resource_path:
4952
resource_path = os.environ.get(cls.CUSTOM_CONFIG_FILE_ENV_NAME)
5053

5154
properties = cls.read_resource_file(resource_path)

securenative/securenative.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def init_with_api_key(cls, api_key):
5454
raise SecureNativeSDKException(u'This SDK was already initialized.')
5555

5656
@classmethod
57-
def init(cls):
58-
options = ConfigurationManager.load_config()
57+
def init(cls, resource_path=None):
58+
options = ConfigurationManager.load_config(resource_path)
5959
return cls.init_with_options(options)
6060

6161
@classmethod

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
long_description_content_type="text/markdown",
2424
install_requires=[
2525
"requests",
26-
"pycrypto",
26+
"pycryptodome",
2727
],
2828
classifiers=[
2929
'Development Status :: 5 - Production/Stable',

0 commit comments

Comments
 (0)