API

Basic API for Caddy

Caddy admin

Initial functions


source

get_id

 get_id (path)

Get a ID full URL from a path

host = 'jph.answer.ai'
get_id('jph.answer.ai')
'http://localhost:2019/id/jph.answer.ai/'

source

get_path

 get_path (path)

Get a config full URL from a path

get_path('/apps/tls/automation/policies')
'http://localhost:2019/config/apps/tls/automation/policies/'

source

gid

 gid (path='/')

Gets the id at path


source

has_id

 has_id (id)

Check if id is set up


source

gcfg

 gcfg (path='/', method='get')

Gets the config at path


source

has_path

 has_path (path)

Check if path is set up

# gcfg()

source

pid

 pid (d, path='/', method='post')

Puts the config d into path


source

pcfg

 pcfg (d, path='/', method='post')

Puts the config d into path

pcfg({})

source

nested_setdict

 nested_setdict (sd, value, *keys)

Returns sd updated to set value at the path keys

nested_setdict({'a':'b'}, {'c':'d'}, 'apps', 'http', 'servers', 'srv0')
{'a': 'b', 'apps': {'http': {'servers': {'srv0': {'c': 'd'}}}}}

source

path2keys

 path2keys (path)

Split path by ‘/’ into a list

path2keys('/apps/tls/automation/policies')
['apps', 'tls', 'automation', 'policies']

source

keys2path

 keys2path (*keys)

Join keys into a ‘/’ separated path

keys2path('apps', 'tls', 'automation', 'policies')
'/apps/tls/automation/policies'

source

nested_setcfg

 nested_setcfg (value, *keys)

source

init_path

 init_path (path, skip=0)

Acme setup

cf_token = os.environ.get('AAI_CF_TOKEN', 'XXX')

source

get_acme_config

 get_acme_config (token)

source

add_acme_config

 add_acme_config (cf_token)
add_acme_config(cf_token)
# gcfg('/apps/tls/automation/policies')[0]

Route setup


source

init_routes

 init_routes (srv_name='srv0')

Create basic http server/routes config

init_routes()

source

setup_caddy

 setup_caddy (cf_token, srv_name='srv0')

Create SSL config and HTTP app skeleton

# pcfg({})
setup_caddy(cf_token)
gcfg(srvs_path)
{'srv0': {'listen': [':80', ':443'], 'routes': []}}

source

add_route

 add_route (route)

Add route dict to config


source

del_id

 del_id (id)

Delete route for id (e.g. a host)

# del_id(host)

source

add_reverse_proxy

 add_reverse_proxy (from_host, to_url)

Create a reverse proxy handler

add_reverse_proxy(host, "localhost:5001")
gcfg(rts_path)
(#1) [{'@id': 'jph.answer.ai', 'handle': [{'handler': 'reverse_proxy', 'upstreams': [{'dial': 'localhost:5001'}]}], 'match': [{'host': ['jph.answer.ai']}], 'terminal': True}]
gid(host)
{ '@id': 'jph.answer.ai',
  'handle': [{'handler': 'reverse_proxy', 'upstreams': [{'dial': 'localhost:5001'}]}],
  'match': [{'host': ['jph.answer.ai']}],
  'terminal': True}