diff --git a/src/command/impl/addSubPathCommand.py b/src/command/impl/addSubPathCommand.py index 963d3b2..b9eac73 100644 --- a/src/command/impl/addSubPathCommand.py +++ b/src/command/impl/addSubPathCommand.py @@ -13,16 +13,16 @@ class AddSubPathCommand(Command): router = args[0] domain = args[1] - subPathName = args[0] + "-sub-path-" + domain path = args[2] serviceHost = args[3] + subPathName = "strip-" + router + "-" + path + "-prefix" # Fix the path if path.startswith("/") == False: path = "/" + path if traefikConfig.hasPathRewrite(subPathName): - print(f"Path rewrite already exists for \"{router}\"") + print(f"Sub path for \"{router}\" already exists") return if traefikConfig.hasRouter(router) == False: diff --git a/src/command/impl/removeSubPathCommand.py b/src/command/impl/removeSubPathCommand.py new file mode 100644 index 0000000..53be608 --- /dev/null +++ b/src/command/impl/removeSubPathCommand.py @@ -0,0 +1,27 @@ +from colorama import Fore +from command.command import Command +from traefik.traefikConfig import TraefikConfig +from utils.dockerUtils import restartTraefik + +class RemoveCommand(Command): + def __init__(self): + super().__init__("remove-sub-path", "Remove sub path from a domain", "remove-sub-path ") + + def execute(self, traefikConfig: TraefikConfig, args): + if len(args) < 0: + self.printUsage() + return + + name = args[0] + + if not traefikConfig.hasRouter(name): + print(f"Router \"{name}\" does not exist") + return + + print(f"Removing \"{name}\"") + + traefikConfig.removeRouter(name) + + traefikConfig.save() + + restartTraefik() \ No newline at end of file diff --git a/src/traefik/traefikConfig.py b/src/traefik/traefikConfig.py index bea1a82..04aa230 100644 --- a/src/traefik/traefikConfig.py +++ b/src/traefik/traefikConfig.py @@ -50,6 +50,10 @@ class TraefikConfig: "service": name } + # Add trailing slash + if not serviceHost.endswith("/"): + serviceHost += "/" + # Add service self.configYml["http"]["services"][name] = { "loadBalancer": {