Skip to content

Commit

Permalink
v1-lib: escape $ in volume options (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros-k authored Nov 1, 2024
1 parent 232c7d8 commit 279653a
Show file tree
Hide file tree
Showing 15 changed files with 13 additions and 38 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
49 changes: 12 additions & 37 deletions library/1.1.5/storage.py → library/1.1.6/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@ def _get_name_for_temporary(data):
if not data.get("mount_path"):
utils.throw_error("Expected [mount_path] to be set for temporary volume")

return (
data["mount_path"]
.lstrip("/")
.lower()
.replace("/", "_")
.replace(".", "_")
.replace(" ", "_")
)
return data["mount_path"].lstrip("/").lower().replace("/", "_").replace(".", "_").replace(" ", "_")


# Returns a volume mount object (Used in container's "volumes" level)
Expand Down Expand Up @@ -178,9 +171,7 @@ def _get_tmpfs_vol_config(data):

if config.get("mode"):
if not mode_regex.match(str(config["mode"])):
utils.throw_error(
f"Expected [mode] to be a octal string for [tmpfs] type, got [{config['mode']}]"
)
utils.throw_error(f"Expected [mode] to be a octal string for [tmpfs] type, got [{config['mode']}]")
tmpfs.update({"mode": int(config["mode"], 8)})

return {"tmpfs": tmpfs}
Expand Down Expand Up @@ -250,9 +241,7 @@ def _get_docker_vol_type(data):
utils.throw_error("Expected [type] to be set for storage")

if data["type"] not in ALL_TYPES:
utils.throw_error(
f"Expected storage [type] to be one of {ALL_TYPES}, got [{data['type']}]"
)
utils.throw_error(f"Expected storage [type] to be one of {ALL_TYPES}, got [{data['type']}]")

if data["type"] in BIND_TYPES:
return "bind"
Expand All @@ -265,15 +254,11 @@ def _get_docker_vol_type(data):
def _process_host_path_config(data):
if data.get("host_path_config", {}).get("acl_enable", False):
if not data["host_path_config"].get("acl", {}).get("path"):
utils.throw_error(
"Expected [host_path_config.acl.path] to be set for [host_path] type with ACL enabled"
)
utils.throw_error("Expected [host_path_config.acl.path] to be set for [host_path] type with ACL enabled")
return data["host_path_config"]["acl"]["path"]

if not data.get("host_path_config", {}).get("path"):
utils.throw_error(
"Expected [host_path_config.path] to be set for [host_path] type"
)
utils.throw_error("Expected [host_path_config.path] to be set for [host_path] type")

return data["host_path_config"]["path"]

Expand All @@ -285,9 +270,7 @@ def _process_volume_config(data):
def _process_ix_volume_config(data, ix_volumes):
path = ""
if not data.get("ix_volume_config", {}).get("dataset_name"):
utils.throw_error(
"Expected [ix_volume_config.dataset_name] to be set for [ix_volume] type"
)
utils.throw_error("Expected [ix_volume_config.dataset_name] to be set for [ix_volume] type")

if not ix_volumes:
utils.throw_error("Expected [ix_volumes] to be set for [ix_volume] type")
Expand Down Expand Up @@ -319,16 +302,12 @@ def _process_cifs(data):

if data["cifs_config"].get("options"):
if not isinstance(data["cifs_config"]["options"], list):
utils.throw_error(
"Expected [cifs_config.options] to be a list for [cifs] type"
)
utils.throw_error("Expected [cifs_config.options] to be a list for [cifs] type")

disallowed_opts = ["user", "password", "domain"]
for opt in data["cifs_config"]["options"]:
if not isinstance(opt, str):
utils.throw_error(
"Expected [cifs_config.options] to be a list of strings for [cifs] type"
)
utils.throw_error("Expected [cifs_config.options] to be a list of strings for [cifs] type")

key = opt.split("=")[0]
for disallowed in disallowed_opts:
Expand All @@ -345,7 +324,7 @@ def _process_cifs(data):
"driver_opts": {
"type": "cifs",
"device": f"//{server}/{path}",
"o": f"{','.join(opts)}",
"o": f"{','.join([utils.escape_dollar(opt) for opt in opts])}",
},
}

Expand All @@ -370,24 +349,20 @@ def _process_nfs(data):
disallowed_opts = ["addr"]
for opt in data["nfs_config"]["options"]:
if not isinstance(opt, str):
utils.throw_error(
"Expected [nfs_config.options] to be a list of strings for [nfs] type"
)
utils.throw_error("Expected [nfs_config.options] to be a list of strings for [nfs] type")

key = opt.split("=")[0]
for disallowed in disallowed_opts:
if key == disallowed:
utils.throw_error(
f"Expected [nfs_config.options] to not start with [{disallowed}] for [nfs] type"
)
utils.throw_error(f"Expected [nfs_config.options] to not start with [{disallowed}] for [nfs] type")

opts.append(opt)

volume = {
"driver_opts": {
"type": "nfs",
"device": f":{data['nfs_config']['path']}",
"o": f"{','.join(opts)}",
"o": f"{','.join([utils.escape_dollar(opt) for opt in opts])}",
},
}

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion library/hashes.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
0.0.1: f074617a82a86d2a6cc78a4c8a4296fc9d168e456f12713e50c696557b302133
1.1.5: 51332f2b032a0c473693458cd93daa96d56604241878e538c07cb85b8be66727
1.1.6: 0f6c609f0e7b2b737114163d22e389eb9aef5de009b1161d6f4ba7acecfd81ee
2.0.7: a483d30e0180b3e5f0cff93a55b867dbebe8e3b7561cacc376bfde91865f40d8

0 comments on commit 279653a

Please sign in to comment.