-
Notifications
You must be signed in to change notification settings - Fork 15
/
test.py
58 lines (50 loc) · 1.89 KB
/
test.py
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
import time
import passboltapi
def get_my_passwords(passbolt_obj):
result = list()
for i in passbolt_obj.get(url="/resources.json?api-version=v2")["body"]:
result.append({
"id": i["id"],
"name": i["name"],
"username": i["username"],
"uri": i["uri"]
})
print(i)
for i in result:
resource = passbolt_obj.get(
"/secrets/resource/{}.json?api-version=v2".format(i["id"]))
i["password"] = passbolt_obj.decrypt(resource["body"]["data"])
print(result)
def get_passwords_basic():
# A simple example to show how to retrieve passwords of a user.
# Note the config file is placed in the project directory.
passbolt_obj = passboltapi.PassboltAPI(config_path="config.ini")
result = list()
for i in passbolt_obj.get(url="/resources.json?api-version=v2")["body"]:
result.append({
"id": i["id"],
"name": i["name"],
"username": i["username"],
"uri": i["uri"]
})
print(i)
for i in result:
resource = passbolt_obj.get(
"/secrets/resource/{}.json?api-version=v2".format(i["id"]))
i["password"] = passbolt_obj.decrypt(resource["body"]["data"])
print(result)
passbolt_obj.close_session()
# Or using context managers
# with passboltapi.PassboltAPI(config_path="config.ini") as passbolt:
# get passwords....
if __name__ == '__main__':
folder_id = "1d932dc0-d0a3-4a44-80c7-4701f84dc307"
with passboltapi.PassboltAPI(config_path="config.ini") as passbolt:
# required: passbolt.import_public_keys() when the folder has more users.
print(passbolt.create_resource(
name='Sample Name',
username='Sample username',
password='password_test',
uri='https://www.passbolt_uri.com',
folder_id=folder_id
))