Skip to content

Commit

Permalink
dump to string
Browse files Browse the repository at this point in the history
  • Loading branch information
MdreW committed Dec 14, 2021
1 parent ef973d4 commit ce548e4
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions satosa_oidcop/core/storage/mongo.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import base64
import copy
import datetime
import json
import logging
import pymongo
import zlib

from .base import SatosaOidcStorage
from oidcop.session.manager import SessionManager
Expand Down Expand Up @@ -43,21 +43,6 @@ def _connect(self):
self.client_db = self.db[self.storage_conf["collections"]["client"]]
self.session_db = self.db[self.storage_conf["collections"]["session"]]

def compress_text_to_b64(text):
"""Returns a compressed and b64 encoded string
"""
if isinstance(text, str):
text = text.encode()
return base64.b64encode(zlib.compress(text))


def decompress_text(b64text):
"""Returns a decompressed string
"""
if isinstance(b64text, str):
b64text = b64text.encode()
return zlib.decompress(base64.b64decode(b64text))

def get_client_by_id(self, client_id: str):
self._connect()
return self.client_db.find_one({"client_id": client_id}) or {}
Expand All @@ -77,7 +62,7 @@ def store_session_to_db(self, session_manager: SessionManager, claims: dict):
"id_token": "",
"refresh_token": "",
"claims": claims or {},
"dump": self.compress_text_to_b64(_db),
"dump": json.dumps(_db),
"key": ses_man_dump["key"],
"salt": ses_man_dump["salt"],
}
Expand Down Expand Up @@ -169,7 +154,7 @@ def load_session_from_db(
if res:
data["key"] = res["key"]
data["salt"] = res["salt"]
data["db"] = self.decompress_text(res["dump"])
data["db"] = json.loads(res["dump"])
session_manager.flush()
session_manager.load(data)
return data
Expand Down

0 comments on commit ce548e4

Please sign in to comment.