add library funcs for metadata

This commit is contained in:
Stavros kois
2024-07-23 17:25:40 +03:00
parent 3fbd199a36
commit a7202ab556
2 changed files with 74 additions and 1 deletions

73
library/1.0.0/metadata.py Normal file
View File

@@ -0,0 +1,73 @@
from . import utils
def get_header(app_name: str):
return f"""# Welcome to TrueNAS SCALE
Thank you for installing {app_name}!
"""
def get_footer(app_name: str):
return f"""## Documentation
Documentation for {app_name} can be found at https://www.truenas.com/docs.
## Bug reports
If you find a bug in this app, please file an issue at
https://ixsystems.atlassian.net or https://github.com/truenas/apps
## Feature requests or improvements
If you find a feature request for this app, please file an issue at
https://ixsystems.atlassian.net or https://github.com/truenas/apps
"""
def get_notes(app_name: str, body: str = ""):
if not app_name:
utils.throw_error("Expected [app_name] to be set")
body = f"\n{body}\n" if body else "\n"
return f"{get_header(app_name)}{body}{get_footer(app_name)}"
def get_portals(portals: list):
valid_schemes = ["http", "https"]
result = []
for portal in portals:
# Most apps have a single portal, lets default to a standard name
name = portal.get("name", "Web UI")
scheme = portal.get("scheme", "http")
path = portal.get("path", "/")
if not name:
utils.throw_error("Expected [portal.name] to be set")
if name in [p["name"] for p in result]:
utils.throw_error(
f"Expected [portal.name] to be unique, got [{', '.join([p['name'] for p in result]+[name])}]"
)
if scheme not in valid_schemes:
utils.throw_error(
f"Expected [portal.scheme] to be one of [{', '.join(valid_schemes)}], got [{portal['scheme']}]"
)
if not portal.get("port"):
utils.throw_error("Expected [portal.port] to be set")
if not path.startswith("/"):
utils.throw_error(
f"Expected [portal.path] to start with /, got [{portal['path']}]"
)
result.append(
{
"name": name,
"scheme": scheme,
# TODO: Default to something else?
"host": portal.get("host", "0.0.0.0"),
"port": portal["port"],
"path": path,
}
)
return result

View File

@@ -1,2 +1,2 @@
0.0.1: f074617a82a86d2a6cc78a4c8a4296fc9d168e456f12713e50c696557b302133
1.0.0: 9c07d26150ab40c0f19ae3991ee02b338aecf50e6c3619414d114276d08e1c1f
1.0.0: ea8957d684adb84ca0ce60bc44ca536267ed651688141233eaec58387a3c20aa