forked from michael.heier/citadel-core
Fix app generation for the Samourai app (#44)
This also only loads the schema file for validation once instead for every app, which should improve the performance of the app validation
This commit is contained in:
parent
22bb680c35
commit
66c0ca350b
|
@ -47,7 +47,7 @@ def getContainerHiddenService(
|
|||
if isinstance(container.hiddenServicePorts, int):
|
||||
return getHiddenServiceString(
|
||||
"{} {}".format(metadata.name, container.name),
|
||||
metadata.id,
|
||||
metadata.id if isMainContainer else "{}-{}".format(metadata.id, container.name),
|
||||
container.hiddenServicePorts,
|
||||
containerIp,
|
||||
container.hiddenServicePorts,
|
||||
|
@ -55,7 +55,7 @@ def getContainerHiddenService(
|
|||
elif isinstance(container.hiddenServicePorts, list):
|
||||
return getHiddenServiceMultiPort(
|
||||
"{} {}".format(metadata.name, container.name),
|
||||
metadata.id,
|
||||
metadata.id if isMainContainer else "{}-{}".format(metadata.id, container.name),
|
||||
containerIp,
|
||||
container.hiddenServicePorts,
|
||||
)
|
||||
|
@ -77,14 +77,14 @@ def getContainerHiddenService(
|
|||
else:
|
||||
additionalHiddenServices[key] = value
|
||||
for key, value in additionalHiddenServices.items():
|
||||
otherHiddenServices += "\n"
|
||||
if isinstance(value, int):
|
||||
otherHiddenServices += "# {} {} {} Hidden Service\nHiddenServiceDir /var/lib/tor/app-{}-{}\n".format(
|
||||
metadata.name, container.name, key, metadata.id, container.name
|
||||
metadata.name, container.name, key, metadata.id, key
|
||||
)
|
||||
otherHiddenServices += "HiddenServicePort {} {}:{}".format(
|
||||
value, containerIp, value
|
||||
)
|
||||
otherHiddenServices += "\n"
|
||||
elif isinstance(value, list):
|
||||
otherHiddenServices += getHiddenServiceMultiPort(
|
||||
"{} {}".format(metadata.name, key), "{}-{}".format(metadata.id, key), containerIp, value
|
||||
|
|
|
@ -85,11 +85,12 @@ def createComposeConfigFromV3(app: dict, nodeRoot: str):
|
|||
newApp = configureIps(newApp, networkingFile, envFile)
|
||||
# This is validated earlier
|
||||
for container in newApp.containers:
|
||||
container.ports = container.requiredPorts
|
||||
for tcpPort in container.requiredPorts:
|
||||
container.ports.append("{}:{}".format(tcpPort, tcpPort))
|
||||
del container.requiredPorts
|
||||
for container in newApp.containers:
|
||||
for udpPort in container.requiredUdpPorts:
|
||||
container.ports.append("{}/udp".format(udpPort))
|
||||
container.ports.append("{}/udp:{}/udp".format(udpPort, udpPort))
|
||||
del container.requiredUdpPorts
|
||||
newApp = configureMainPort(newApp, nodeRoot)
|
||||
newApp = configureHiddenServices(newApp, nodeRoot)
|
||||
|
|
|
@ -77,6 +77,8 @@ def configureMainPort(app: AppStage2, nodeRoot: str) -> AppStage3:
|
|||
# If it doesn't contain a :, it's the port itself
|
||||
if mainPort == False:
|
||||
mainPort = mainContainer.ports[0]
|
||||
if mainPort.find(":") != -1:
|
||||
mainPort = mainPort.split(":")[1]
|
||||
else:
|
||||
mainContainer.ports = [portToAppend]
|
||||
|
||||
|
|
|
@ -7,18 +7,18 @@ import yaml
|
|||
from jsonschema import validate
|
||||
import yaml
|
||||
|
||||
scriptDir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
|
||||
|
||||
with open(os.path.join(scriptDir, 'app-standard-v1.yml'), 'r') as f:
|
||||
schemaVersion1 = yaml.safe_load(f)
|
||||
with open(os.path.join(scriptDir, 'app-standard-v2.yml'), 'r') as f:
|
||||
schemaVersion2 = yaml.safe_load(f)
|
||||
with open(os.path.join(scriptDir, 'app-standard-v3.yml'), 'r') as f:
|
||||
schemaVersion3 = yaml.safe_load(f)
|
||||
|
||||
# Validates app data
|
||||
# Returns true if valid, false otherwise
|
||||
scriptDir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")
|
||||
def validateApp(app: dict):
|
||||
with open(os.path.join(scriptDir, 'app-standard-v1.yml'), 'r') as f:
|
||||
schemaVersion1 = yaml.safe_load(f)
|
||||
with open(os.path.join(scriptDir, 'app-standard-v2.yml'), 'r') as f:
|
||||
schemaVersion2 = yaml.safe_load(f)
|
||||
with open(os.path.join(scriptDir, 'app-standard-v3.yml'), 'r') as f:
|
||||
schemaVersion3 = yaml.safe_load(f)
|
||||
|
||||
if 'version' in app and str(app['version']) == "1":
|
||||
try:
|
||||
validate(app, schemaVersion1)
|
||||
|
|
Loading…
Reference in New Issue
Block a user