55# %% auto 0
66__all__ = ['automation_path' ,'srvs_path' ,'rts_path' ,'get_id' ,'get_path' ,'gid' ,'has_id' ,'gcfg' ,'has_path' ,'pid' ,'pcfg' ,
77'nested_setdict' ,'path2keys' ,'keys2path' ,'nested_setcfg' ,'init_path' ,'get_acme_config' ,
8- 'add_tls_internal_config' ,'add_acme_config' ,'init_routes' ,'setup_caddy ' ,'add_route ' ,'del_id ' ,
9- 'add_reverse_proxy' ,'add_wildcard_route' ,'add_sub_reverse_proxy' ]
8+ 'add_tls_internal_config' ,'add_acme_config' ,'init_routes' ,'setup_pki_trust ' ,'setup_caddy ' ,'add_route ' ,
9+ 'del_id' , ' add_reverse_proxy' ,'add_wildcard_route' ,'add_sub_reverse_proxy' ]
1010
1111# %% ../nbs/00_core.ipynb 3
1212import os ,subprocess ,httpx ,json
@@ -142,28 +142,36 @@ def init_routes(srv_name='srv0', skip=1):
142142pcfg (ir ,f"{ srvs_path } /{ srv_name } " )
143143
144144# %% ../nbs/00_core.ipynb 37
145+ def setup_pki_trust (install_trust ):
146+ "Configure PKI certificate authority trust installation"
147+ if install_trust is None :return
148+ pki_path = '/apps/pki/certificate_authorities/local'
149+ init_path (pki_path ,skip = 1 )
150+ pcfg ({"install_trust" :install_trust },pki_path )
151+
152+ # %% ../nbs/00_core.ipynb 38
145153def setup_caddy (
146154cf_token = None ,# Cloudflare API token
147155srv_name = 'srv0' ,# Server name in the Caddyfile
148156local :bool = False ,# Whether or not this is for localdev or deployment
149- skip_install_trust :bool = None ):#Skip installing trust store
157+ install_trust :bool = None ):#Install trust store?
150158"Create SSL config and HTTP app skeleton"
151- if skip_install_trust is not None :pcfg (skip_install_trust ,'/skip_install_trust' ,method = 'patch' )
152159if local :add_tls_internal_config ()
153160else :add_acme_config (cf_token )
161+ setup_pki_trust (install_trust )
154162init_routes (srv_name )
155163
156- # %% ../nbs/00_core.ipynb40
164+ # %% ../nbs/00_core.ipynb41
157165def add_route (route ):
158166"Add `route` dict to config"
159167return pcfg (route ,rts_path )
160168
161- # %% ../nbs/00_core.ipynb41
169+ # %% ../nbs/00_core.ipynb42
162170def del_id (id ):
163171"Delete route for `id` (e.g. a host)"
164172xdelete (get_id (id ))
165173
166- # %% ../nbs/00_core.ipynb43
174+ # %% ../nbs/00_core.ipynb44
167175def add_reverse_proxy (from_host ,to_url ):
168176"Create a reverse proxy handler"
169177if has_id (from_host ):del_id (from_host )
@@ -176,7 +184,7 @@ def add_reverse_proxy(from_host, to_url):
176184 }
177185add_route (route )
178186
179- # %% ../nbs/00_core.ipynb47
187+ # %% ../nbs/00_core.ipynb48
180188def add_wildcard_route (domain ):
181189"Add a wildcard subdomain"
182190route = {
@@ -189,7 +197,7 @@ def add_wildcard_route(domain):
189197 }
190198add_route (route )
191199
192- # %% ../nbs/00_core.ipynb49
200+ # %% ../nbs/00_core.ipynb50
193201def add_sub_reverse_proxy (
194202domain ,
195203subdomain ,