Support new Passbolt API

* Some password objects are now JSON objects
  that need to be decoded.
This commit is contained in:
Sven Seeberg 2021-03-14 13:02:11 +01:00
parent 20370e41dd
commit 967a38869e
Signed by: sven.seeberg
GPG Key ID: 29559DD5A83806B5
1 changed files with 15 additions and 2 deletions

View File

@ -30,11 +30,24 @@ def generate_pillar(passbolt_obj, group_uuid):
for i in result:
resource = passbolt_obj.get("/secrets/resource/{}.json?api-version=v2".
format(i["id"]))
salt['passbolt'][i["id"]] = passbolt_obj.decrypt(
resource["body"]["data"])
data = passbolt_obj.decrypt(resource["body"]["data"])
salt['passbolt'][i["id"]] = decode_json(data)
return salt
def decode_json(data):
"""
The passbolt API returns legacy strings or JSON objects.
Try to decode JSON, and if invalid return string.
"""
import json
try:
data = json.loads(data)
except json.decoder.JSONDecodeError:
return data
return data["password"]
def fetch_passbolt_passwords(group_uuid):
"""
Generate Passbolt API object and call API fetch function