Skip to content

Commit cc2161f

Browse files
committed
Config can be passed as dictionary argument
1 parent bf41e66 commit cc2161f

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,21 @@ Create a config file with the following contents.
2121
USER_PRIVATE_KEY_FILE = <optional: passbolt_private.asc>
2222
PASSPHRASE = <passbolt_password>
2323

24+
Or as a dictionary
25+
26+
config = {
27+
"PASSBOLT": {
28+
"SERVER": "http://<server_ip or domain>"
29+
....(same as above)
30+
}
31+
}
32+
2433
## Usage
2534

2635
>>>import passboltapi
2736
>>>passbolt = passboltapi.PassboltAPI(config_path="config.ini")
37+
# Or pass the configuration settings as a dict
38+
>>>passbolt = passboltapi.PassboltAPI(config=<dictionary as the given example config.ini>)
2839

2940
# Now you may do any get, post, put and delete request.
3041
>>>r = passbolt.get(url="/resources.json?api-version=v2")

passboltapi/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@
99

1010
class PassboltAPI:
1111

12-
def __init__(self, config_path, new_keys=False, delete_old_keys=False):
12+
def __init__(self, config=None, config_path=None, new_keys=False, delete_old_keys=False):
1313
"""
14+
:param config: Config as a dictionary
1415
:param config_path: Path to the config file.
1516
:param delete_old_keys: Set true if old keys need to be deleted
1617
"""
18+
self.config = config
19+
if config_path:
20+
self.config = configparser.ConfigParser()
21+
self.config.read_file(open(config_path, "r"))
1722
self.requests_session = requests.Session()
18-
self.config = configparser.ConfigParser()
19-
self.config.read_file(open(config_path, "r"))
2023

24+
if not self.config:
25+
raise ValueError("Missing config. Provide config as dictionary or path to configuration file.")
2126
if not self.config["PASSBOLT"]["SERVER"]:
2227
raise ValueError("Missing value for SERVER in config.ini")
2328

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
install_requires = fp.read()
2929

3030
DESCRIPTION = "A python client for Passbolt."
31-
VERSION = "0.1.5"
31+
VERSION = "0.1.6"
3232

3333

3434
with open("README.md", "r") as fh:

0 commit comments

Comments
 (0)