Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Commit

Permalink
Fix app generation for the Samourai app (#44)
Browse files Browse the repository at this point in the history
This also only loads the schema file for validation once instead for every app, which should improve the performance of the app validation
  • Loading branch information
AaronDewes authored Jun 4, 2022
1 parent 22bb680 commit 66c0ca3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions app/lib/composegenerator/v2/utils/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ 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,
)
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,
)
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions app/lib/composegenerator/v3/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions app/lib/composegenerator/v3/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
16 changes: 8 additions & 8 deletions app/lib/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
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)
Expand Down

0 comments on commit 66c0ca3

Please sign in to comment.