diff --git a/src/bitwardentools/client.py b/src/bitwardentools/client.py index ce27a91..09eef6d 100644 --- a/src/bitwardentools/client.py +++ b/src/bitwardentools/client.py @@ -145,17 +145,17 @@ def rewrite_acls_collection(i, skip=None): skip = re.compile(skip) if isinstance(i, dict): for v, k in { - "Data": "data", - "Id": "id", - "AccessAll": "accessAll", - "Email": "email", - "Name": "name", - "Status": "status", - "Collections": "collections", - "UserId": "userId", - "Type": "type", - "HidePasswords": "hidePasswords", - "ReadOnly": "readOnly", + "data": "data", + "id": "id", + "accessAll": "accessAll", + "email": "email", + "name": "name", + "status": "status", + "collections": "collections", + "userId": "userId", + "type": "type", + "hidePasswords": "hidePasswords", + "readOnly": "readOnly", }.items(): if skip and (skip.search(v) or skip.search(k)): i.pop(v, None) @@ -367,9 +367,9 @@ def get_types(t): def get_type(obj, default=""): if isinstance(obj, BWFactory): - objtyp = getattr(obj, "Object", getattr(obj, "object", "")) + objtyp = getattr(obj, "object", getattr(obj, "object", "")) elif isinstance(obj, dict): - objtyp = obj.get("Object", obj.get("object", "")) + objtyp = obj.get("object", obj.get("object", "")) else: objtyp = default return objtyp.lower() @@ -484,7 +484,7 @@ def construct( try: object_class_name = jsond["object"] except KeyError: - object_class_name = jsond["Object"] + object_class_name = jsond["object"] if object_class_name.lower().startswith("cipher"): try: typ = jsond["Type"] @@ -834,8 +834,8 @@ def login( token["hashed_password"] = hashed_password token["master_key"] = master_key token["email"] = email - for k, f in {"Key": "user_key", "PrivateKey": "orgs_key"}.items(): - key = k != "PrivateKey" and master_key or token.get("user_key") + for k, f in {"key": "user_key", "privateKey": "orgs_key"}.items(): + key = k != "privateKey" and master_key or token.get("user_key") token[f] = bwcrypto.decrypt(token[k], key) self.tokens[email] = token return token @@ -1008,9 +1008,9 @@ def get_organizations(self, sync=None, cache=None, token=None): assert _CACHE.get("sync") except AssertionError: sdata = self.api_sync(sync=sync) - for orga in sdata.get("Profile", {}).get("Organizations", []): + for orga in sdata.get("profile", {}).get("organizations", []): orga = deepcopy(orga) - orga["Object"] = "organization" + orga["object"] = "organization" obj = BWFactory.construct(orga, client=self, unmarshall=True) self.cache(obj) _CACHE["sync"] = True @@ -1394,12 +1394,12 @@ def get_organization_key(self, orga, token=None, sync=None): enc_okey = ( dict( [ - (a["Id"], a) - for a in sdata.get("Profile", {}).get("Organizations", []) + (a["id"], a) + for a in sdata.get("profile", {}).get("organizations", []) ] ) .get(orga.id, {}) - .get("Key", None) + .get("key", None) ) if enc_okey: break @@ -1514,7 +1514,7 @@ def get_collections(self, orga=None, sync=None, cache=None, token=None): assert _CACHE["sync"] except AssertionError: for enccol in ( - self.r("/api/collections", method="get").json().get("Data", []) + self.r("/api/collections", method="get").json().get("data", []) ): col = BWFactory.construct(enccol, client=self, unmarshall=True) _, colk = self.get_organization_key(col.organizationId, token=token) @@ -1702,12 +1702,12 @@ def get_ciphers( exc.response = resp raise exc dciphers = [] - for cipher in ciphers.get("Data", []): + for cipher in ciphers.get("data", []): try: dciphers.append(self.decrypt(cipher, token=token)) except bwcrypto.DecryptError: - self._broken_ciphers[cipher["Id"]] = cipher - L.info(f'Cant decrypt cipher {cipher["Id"]}, broken ?') + self._broken_ciphers[cipher["id"]] = cipher + L.info(f'Cant decrypt cipher {cipher["id"]}, broken ?') for cipher in dciphers: obj = BWFactory.construct(cipher, client=self, unmarshall=True) self.cache(obj, vaultier=vaultier) @@ -3189,7 +3189,7 @@ def confirm_invitation(self, orga, email, name=None, sync=None, token=None): self.assert_bw_response(resp) userorgkey = b64decode(resp.json()["PublicKey"]) encoded_key = bwcrypto.encrypt_asym(orgkey[1], userorgkey) - payload = {"Key": encoded_key} + payload = {"key": encoded_key} try: u = f"/api/organizations/{orga.id}/users/{acl['id']}/confirm" resp = self.r(u, json=payload, token=token)