-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
87 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/middlewared/middlewared/plugins/apps/ix_apps/portals.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import contextlib | ||
|
||
import yaml | ||
|
||
from apps_validation.portals import IX_NOTES_KEY, IX_PORTAL_KEY, validate_portals_and_notes, ValidationErrors | ||
|
||
from .lifecycle import get_rendered_templates_of_app | ||
|
||
|
||
def normalized_port_value(scheme: str, port: int) -> str: | ||
return '' if ((scheme == 'http' and port == 80) or (scheme == 'https' and port == 443)) else f':{port}' | ||
|
||
|
||
def get_portals_and_app_notes(app_name: str, version: str) -> dict: | ||
rendered_config = {} | ||
for rendered_file in get_rendered_templates_of_app(app_name, version): | ||
with contextlib.suppress(FileNotFoundError, yaml.YAMLError): | ||
with open(rendered_file, 'r') as f: | ||
rendered_config.update(yaml.safe_load(f.read())) | ||
|
||
portal_and_notes_config = { | ||
k: rendered_config[k] | ||
for k in (IX_NOTES_KEY, IX_PORTAL_KEY) | ||
if k in rendered_config | ||
} | ||
config = { | ||
'portals': {}, | ||
'notes': None, | ||
} | ||
if portal_and_notes_config: | ||
try: | ||
validate_portals_and_notes('portal', portal_and_notes_config) | ||
except ValidationErrors: | ||
return config | ||
|
||
portals = {} | ||
for portal in portal_and_notes_config.get(IX_PORTAL_KEY, []): | ||
port_value = normalized_port_value(portal['scheme'], portal['port']) | ||
portals[portal['name']] = f'{portal["scheme"]}://{portal["host"]}{port_value}{portal.get("path", "")}' | ||
|
||
return { | ||
'portals': portals, | ||
'notes': portal_and_notes_config.get(IX_NOTES_KEY), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters