Skip to content

Commit 11f7774

Browse files
authored
Merge pull request #7 from ioparaskev/xmlsec_tmpfiles
Add `delete_tmpfiles` as config file option
2 parents 29da4ac + 2d41f18 commit 11f7774

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

docs/howto/config.rst

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
.. _howto_config:
22

3-
Environment variables
4-
=====================
5-
6-
PYSAML2_DELETE_TMPFILES
7-
^^^^^^^^^^^^^^^^^^^^^^^
8-
9-
If set to "False" will keep temporary xml files in the system temporary storage.
10-
Default: "true"; delete temporary files.
11-
123

134
Configuration of pySAML2 entities
145
=================================
@@ -44,6 +35,7 @@ The basic structure of the configuration file is therefore like this::
4435
"key_file" : "my.key",
4536
"cert_file" : "ca.pem",
4637
"xmlsec_binary" : "/usr/local/bin/xmlsec1",
38+
"delete_tmpfiles": True,
4739
"metadata": {
4840
"local": ["edugain.xml"],
4941
},
@@ -326,6 +318,17 @@ Example::
326318

327319
"xmlsec_binary": "/usr/local/bin/xmlsec1",
328320

321+
delete_tmpfiles
322+
^^^^^^^^^^^^^^^
323+
324+
In many cases temporary files will have to be created during the
325+
encryption/decryption/signing/validation process.
326+
This option defines whether these temporary files will be automatically deleted when
327+
they are no longer needed. Setting this to False, will keep these files until they are
328+
manually deleted or automatically deleted by the OS (i.e Linux rules for /tmp).
329+
Absence of this option, defaults to True.
330+
331+
329332
valid_for
330333
^^^^^^^^^
331334

@@ -826,6 +829,7 @@ We start with a simple but fairly complete Service provider configuration::
826829
"key_file" : "./mykey.pem",
827830
"cert_file" : "./mycert.pem",
828831
"xmlsec_binary" : "/usr/local/bin/xmlsec1",
832+
"delete_tmpfiles": True,
829833
"attribute_map_dir": "./attributemaps",
830834
"metadata": {
831835
"local": ["idp.xml"]
@@ -874,6 +878,7 @@ A slightly more complex configuration::
874878
"key_file" : "./mykey.pem",
875879
"cert_file" : "./mycert.pem",
876880
"xmlsec_binary" : "/usr/local/bin/xmlsec1",
881+
"delete_tmpfiles": True,
877882
"metadata" : {
878883
"local": ["example.xml"],
879884
"remote": [{

src/saml2/config.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"allow_unknown_attributes",
7070
"crypto_backend",
7171
"id_attr_name",
72+
"delete_tmpfiles",
7273
]
7374

7475
SP_ARGS = [
@@ -243,7 +244,7 @@ def __init__(self, homedir="."):
243244
self.attribute = []
244245
self.attribute_profile = []
245246
self.requested_attribute_name_format = NAME_FORMAT_URI
246-
self.delete_tmpfiles = get_environ_delete_tmpfiles()
247+
self.delete_tmpfiles = True
247248

248249
def setattr(self, context, attr, val):
249250
if context == "":
@@ -359,6 +360,12 @@ def load(self, cnf, metadata_construction=False):
359360
except TypeError: # Something that can't be a string
360361
setattr(self, arg, cnf[arg])
361362

363+
if not self.delete_tmpfiles:
364+
logger.warning(
365+
"delete_tmpfiles is set to False, "
366+
"temporary files will not be deleted."
367+
)
368+
362369
if "service" in cnf:
363370
for typ in ["aa", "idp", "sp", "pdp", "aq"]:
364371
try:
@@ -596,17 +603,3 @@ def config_factory(_type, config):
596603

597604
conf.context = _type
598605
return conf
599-
600-
601-
def get_environ_delete_tmpfiles():
602-
default = "true"
603-
value = os.environ.get("PYSAML2_DELETE_TMPFILES", default)
604-
result = value.lower() == default
605-
606-
if not result:
607-
logger.warning(
608-
"PYSAML2_DELETE_TMPFILES set to False, "
609-
"temporary xml files will not be deleted."
610-
)
611-
612-
return result

0 commit comments

Comments
 (0)