Skip to content

Commit 1f04f02

Browse files
committed
Change URL decorator to use exec instead of eval
1 parent b2191a4 commit 1f04f02

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

snakemake_storage_plugin_xrootd/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ class StorageProviderSettings(StorageProviderSettingsBase):
8888
default=None,
8989
metadata={
9090
"help": (
91-
"A Python expression (given as str) to decorate the URL (which is "
92-
"available as variable `url` in the expression) e.g. to decorate it "
93-
"with an auth token."
91+
"Python code (given as str) to decorate the URL (which is "
92+
"available as variable `url` which will run through `exec`"
93+
"and must put the new URL in a variable `new_url`) e.g. to"
94+
"decorate it with an auth token."
9495
),
9596
"env_var": False,
9697
"required": False,
@@ -132,7 +133,9 @@ def __post_init__(self):
132133

133134
def url_decorator(self, url: str) -> str:
134135
if self.settings.url_decorator is not None:
135-
return eval(self.settings.url_decorator, {"url": url})
136+
local_vars = {}
137+
exec(self.settings.url_decorator, globals={"url": url}, locals=local_vars)
138+
return local_vars["new_url"]
136139
return url
137140

138141
def _check_status(self, status: XRootDStatus, error_preamble: str):

tests/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ def get_storage_provider_settings(self) -> Optional[StorageProviderSettingsBase]
5858
return StorageProviderSettings(
5959
host="localhost",
6060
port=XROOTD_TEST_PORT,
61-
url_decorator="url + '?authz=anonymous'",
61+
url_decorator="new_url = url + '?authz=anonymous'",
6262
)

0 commit comments

Comments
 (0)