Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions msal_extensions/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ def get_location(self):
raise NotImplementedError


def _open(location):
return os.open(location, os.O_RDWR | os.O_CREAT | os.O_TRUNC, 0o600)
# The 600 seems no-op on NTFS/Windows, and that is fine


class FilePersistence(BasePersistence):
"""A generic persistence, storing data in a plain-text file"""

Expand All @@ -117,7 +122,7 @@ def __init__(self, location):
def save(self, content):
# type: (str) -> None
"""Save the content into this persistence"""
with open(self._location, 'w+') as handle: # pylint: disable=unspecified-encoding
with os.fdopen(_open(self._location), 'w+') as handle:
handle.write(content)

def load(self):
Expand Down Expand Up @@ -173,7 +178,7 @@ def __init__(self, location, entropy=''):
def save(self, content):
# type: (str) -> None
data = self._dp_agent.protect(content)
with open(self._location, 'wb+') as handle:
with os.fdopen(_open(self._location), 'wb+') as handle:
handle.write(data)

def load(self):
Expand Down