forked from passwork-me/pip-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_password.py
More file actions
78 lines (67 loc) · 2.85 KB
/
add_password.py
File metadata and controls
78 lines (67 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from loguru import logger
from passwork.passwork_api import PassworkAPI
def add_password(api: PassworkAPI, password_adding_fields: dict, vault_id: str = None, password_id: str = None, verify: bool=True) -> dict:
"""
Add a new password to Passwork.
Args:
api (PassworkAPI): An instance of PassworkAPI class initialized with appropriate credentials.
vault_id (str): The ID of the vault to add the password to. If not provided, the vault ID will be retrieved
from the password itself.
password_id (str): The ID of an existing password. If provided, its vault ID will be used instead of vault_id.
password_adding_fields (dict): Fields for the new password
Returns:
dict: Information about the added password.
This function doesn't provide the API login and logout, API should be logged in at the call of function,
after that you can call logout of API in your upper-level code
Example usage:
api = PassworkAPI(options_override=options_override)\n
added_password_info = add_password(api, password_fields, vault_id=VAULT_ID, password_id=PASSWORD_ID)\n
logger.success(f"Password with id {added_password_info['id']} has been added")
"""
# password_adding_fields example:
# {
# "name": "test",
# "url": "https://passwork.com",
# "login": "PassLogin",
# "description": "Password for testing",
# "folderId": None,
# "password": "password",
# "shortcutId": None,
# "tags": [],
# "snapshot": None,
# "color": "3",
# "custom": [
# {
# "name": "Additional login 1",
# "value": "PassLogin1",
# "type": "text"
# },
# {
# "name": "Additional password 1",
# "value": "password1",
# "type": "password"
# },
# {
# "name": "TOTP 1",
# "value": "JBSWY3DPEHPK3PXP",
# "type": "totp"
# }
# ],
# "attachments": [
# {
# "path": "../upload_attachments/file1.svg",
# "name": "file1.svg"
# },
# {
# "path": "../upload_attachments/file2.png",
# "name": "file2.png"
# }
# ]
# }
vault_id = vault_id if vault_id else api.get_password(password_id=password_id)["vaultId"]
password_adding_fields["vaultId"] = vault_id
vault_item = api.get_vault(vault_id=vault_id, verify=verify)
vault_password = api.get_vault_password(vault_item=vault_item)
added_password_info = api.add_password(password_adding_fields, vault_item, vault_password, verify)
logger.success(f"Password with id {added_password_info['id']} has been added")
return added_password_info