= 'jph.answer.ai' host
API
Basic API for Caddy
Caddy admin
Initial functions
get_id
get_id (path)
Get a ID full URL from a path
'jph.answer.ai') get_id(
'http://localhost:2019/id/jph.answer.ai/'
get_path
get_path (path)
Get a config full URL from a path
'/apps/tls/automation/policies') get_path(
'http://localhost:2019/config/apps/tls/automation/policies/'
gid
gid (path='/')
Gets the id at path
has_id
has_id (id)
Check if id
is set up
gcfg
gcfg (path='/', method='get')
Gets the config at path
has_path
has_path (path)
Check if path
is set up
gcfg()
pid
pid (d, path='/', method='post')
Puts the config d
into path
pcfg
pcfg (d, path='/', method='post')
Puts the config d
into path
# pcfg({})
nested_setdict
nested_setdict (sd, value, *keys)
Returns sd
updated to set value
at the path keys
'a':'b'}, {'c':'d'}, 'apps', 'http', 'servers', 'srv0') nested_setdict({
{'a': 'b', 'apps': {'http': {'servers': {'srv0': {'c': 'd'}}}}}
path2keys
path2keys (path)
Split path
by ‘/’ into a list
'/apps/tls/automation/policies') path2keys(
['apps', 'tls', 'automation', 'policies']
keys2path
keys2path (*keys)
Join keys
into a ‘/’ separated path
'apps', 'tls', 'automation', 'policies') keys2path(
'/apps/tls/automation/policies'
nested_setcfg
nested_setcfg (value, *keys)
init_path
init_path (path, skip=0)
Automation setup
= os.environ.get('CADDY_CF_TOKEN', 'XXX') cf_token
get_acme_config
get_acme_config (token)
add_tls_internal_config
add_tls_internal_config ()
add_acme_config
add_acme_config (cf_token)
# add_acme_config(cf_token)
# gcfg('/apps/tls/automation/policies')[0]
Route setup
init_routes
init_routes (srv_name='srv0', skip=1)
Create basic http server/routes config
init_routes()
setup_pki_trust
setup_pki_trust (install_trust)
Configure PKI certificate authority trust installation
setup_caddy
setup_caddy (cf_token=None, srv_name='srv0', local:bool=False, install_trust:bool=None)
Create SSL config and HTTP app skeleton
Type | Default | Details | |
---|---|---|---|
cf_token | NoneType | None | Cloudflare API token |
srv_name | str | srv0 | Server name in the Caddyfile |
local | bool | False | Whether or not this is for localdev or deployment |
install_trust | bool | None | Install trust store? |
# pcfg({})
setup_caddy(cf_token)
# gcfg(srvs_path)
add_route
add_route (route)
Add route
dict to config
del_id
del_id (id)
Delete route for id
(e.g. a host)
# del_id(host)
add_reverse_proxy
add_reverse_proxy (from_host, to_url)
Create a reverse proxy handler
= 'foo.fast.ai' host
# add_reverse_proxy(host, "localhost:5001")
# gid(host)
add_wildcard_route
add_wildcard_route (domain)
Add a wildcard subdomain
'something.fast.ai') add_wildcard_route(
add_sub_reverse_proxy
add_sub_reverse_proxy (domain, subdomain, port:Union[str,int,Sequence], host='localhost')
Add a reverse proxy to a wildcard subdomain supporting multiple ports
Type | Default | Details | |
---|---|---|---|
domain | |||
subdomain | |||
port | Union | A single port or list of ports | |
host | str | localhost |
'something.fast.ai', 'foo', 5001) add_sub_reverse_proxy(
'foo.something.fast.ai') del_id(