33 lines
1.1 KiB
Text
33 lines
1.1 KiB
Text
#!/usr/bin/env nu
|
|
# Derived variables for zot bundle rendering.
|
|
# Receives component record as JSON, outputs extra vars as JSON.
|
|
# CF_TOKEN_<ZONE> env var is injected by install-component-cf before this script runs.
|
|
|
|
def cf_token_from_env [secret_ref: string]: nothing -> string {
|
|
let env_var = ($"CF_TOKEN_($secret_ref | str upcase | str replace --all '-' '_')")
|
|
$env | get -o $env_var | default ""
|
|
}
|
|
|
|
def main [component_json: string]: nothing -> nothing {
|
|
let d = ($component_json | from json)
|
|
|
|
let endpoints = ($d.provides?.endpoints? | default [])
|
|
let dns_names_yaml = if ($endpoints | is-not-empty) {
|
|
$endpoints | each {|e|
|
|
let host = ($e | str replace --regex '^https?://' "")
|
|
$" - ($host)"
|
|
} | str join "\n"
|
|
} else { "" }
|
|
|
|
let cert_secret_ref = ($d.cert?.secret_ref? | default "")
|
|
let cf_dns_token = if ($cert_secret_ref | is-not-empty) {
|
|
cf_token_from_env $cert_secret_ref
|
|
} else { "" }
|
|
|
|
{
|
|
dns_names_yaml: $dns_names_yaml,
|
|
cf_dns_token: $cf_dns_token,
|
|
}
|
|
| to json --raw
|
|
| print
|
|
}
|