mirror of
https://github.com/Red5d/docker-autocompose
synced 2026-01-03 07:08:01 +00:00
Escape $$ in labels and env (#77)
This commit is contained in:
committed by
GitHub
parent
d3aa07ee74
commit
9ac4048783
@@ -13,6 +13,17 @@ pyaml.add_representer(bool,lambda s,o: s.represent_scalar('tag:yaml.org,2002:boo
|
|||||||
IGNORE_VALUES = [None, "", [], "null", {}, "default", 0, ",", "no"]
|
IGNORE_VALUES = [None, "", [], "null", {}, "default", 0, ",", "no"]
|
||||||
|
|
||||||
|
|
||||||
|
def shell_escape_string(input_string):
|
||||||
|
# Currently known issues:
|
||||||
|
# - Basic Auth strings (e.g. set via Træfik labels) contain $ characters, which must be doubled. See https://stackoverflow.com/a/40621373/5885325
|
||||||
|
replaced_string = input_string
|
||||||
|
for substitution in (
|
||||||
|
("$", "$$"),
|
||||||
|
):
|
||||||
|
replaced_string = replaced_string.replace(substitution[0], substitution[1])
|
||||||
|
return replaced_string
|
||||||
|
|
||||||
|
|
||||||
def list_container_names():
|
def list_container_names():
|
||||||
c = docker.from_env()
|
c = docker.from_env()
|
||||||
return [container.name for container in c.containers.list(all=True)]
|
return [container.name for container in c.containers.list(all=True)]
|
||||||
@@ -282,6 +293,14 @@ def generate(cname, createvolumes=False):
|
|||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
# No ports exposed/bound. Continue without them.
|
# No ports exposed/bound. Continue without them.
|
||||||
ports = None
|
ports = None
|
||||||
|
|
||||||
|
# fixup strings in labels and env
|
||||||
|
if values["labels"] is not None:
|
||||||
|
for label_key, label_value in values["labels"].items():
|
||||||
|
values["labels"][label_key] = shell_escape_string(label_value)
|
||||||
|
if values["environment"] is not None:
|
||||||
|
for idx, env_variable in enumerate(values["environment"]):
|
||||||
|
values["environment"][idx] = shell_escape_string(env_variable)
|
||||||
|
|
||||||
# Iterate through values to finish building yaml dict.
|
# Iterate through values to finish building yaml dict.
|
||||||
for key in values:
|
for key in values:
|
||||||
|
|||||||
Reference in New Issue
Block a user