You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
7.0 KiB
7.0 KiB
<html>
<head>
</head>
</html>
In [ ]:
%%sh
rm templates/template.test
cat << EOF >> templates/template.test
[Settings]
theme = dark
accent = purple
background = None
roles = admin,user,public_user
home_access_groups = admin_only
settings_access_groups = admin_only
custom_app_title = DashMachine
sidebar_default = open
tags = {"name": "foo", "icon": "home", "sort_pos": "2"}
[admin]
role = admin
password = os.getenv(password)
confirm_password = os.getenv(password)
{% for item in items %}
[{{ item.service }}]
prefix = https://
url = {{ item.url }}
{% if item.icon_url %}
icon = item.icon_url
sidebar_icon = item.icon_url
{% else %}
icon = static/images/apps/{{ item.service }}.png
sidebar_icon = static/images/apps/{{ item.service }}.png
{% endif %}
description = default
open_in = iframe
# data_sources = $0_http,$0_health,$0_ping,$0_rest
tags = default
# groups = admin_only
{% endfor %}
{# a comment #}
EOF
In [ ]:
%%sh
cat << EOF >> template.ini
[$0_curl]
platform curl
resource = http://$0.com
value_template My IP: [{value.ip}}
response_type = json
[$0_rest]
platform = rest
resource = http://$0/api
value_template = {{value}}
method = post
authentication = basic
username = my_username
password = my_password
payload = {"var1": "hi", "var2": 1}
headers {"Content-Type": "application/json"}
verify = false
[$0_ping]
platform = ping
resource = 192.168.1.1
[$0_http]
platform = http_status
resource = https://your-website.com/api
method = get
authentication = basic
username = my_username
password = my_password
headers = {"Content-Type": "application/json"}
return_codes = 2XX, 3XX
[$0_health]
platform = healthchecks
prefix = http://
host = localhost
port = 8080
api_key = {{ Healthchecks project API Key }}
project {{ Healthchecks project name }}
verify = true
value_template = { { value_template }}
[$0]
prefix = https://
url = your-website.com
icon = static/images/apps/$0.png
sidebar_icon = static/images/apps/{{ name }}.png
description = default
open_in = iframe
data_sources = $0_http,$0_health,$0_ping,$0_rest
tags = default
groups = admin_only
EOF
In [ ]:
import json
import os
import pprint
import requests
headers = {
"Authorization": os.env(directus_token),
"Content-Type": "application/json",
}
response = requests.get(
"https://cms.donavanaldrich.com/items/containers", headers=headers
)
data = response.json()
items = data["data"]
# name = (items[0]['id'])
# t = Template("Jinja {{ name }}!")
# t.render(name=items[0]['id'])
#
In [ ]:
import json
import re
import requests
my_headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}
response = requests.get(
"http://traefik:8080/api/http/routers",
headers=my_headers,
)
initial = response.json()
# pprint.pprint(initial)
items = []
for x in initial:
rule = x["rule"]
service = x["service"]
find = re.findall("Host\(`([^\)]+)`\)", rule)
if find:
item = {"service": x["service"], "url": find[0]}
else:
pass
items.append(item)
# print(items)
In [ ]:
deduplicated_list = []
deduped_keys = list()
for y in items:
key = y['url']
if key not in deduped_keys:
deduped_keys.append(key)
deduplicated_list.append(y)
pprint.pprint(deduplicated_list)
In [ ]:
from jinja2 import Environment, FileSystemLoader, select_autoescape
items = deduplicated_list
env = Environment(
loader=FileSystemLoader(["templates"]),
# autoescape=select_autoescape()
)
t = env.get_template("template.test")
pprint.pprint(t.render(item=items[0], items=items))
#
with open("test.ini", "w") as external_file:
# add_text = "This text will be added to the file"
print(t.render(item=items[0], items=items), file=external_file)
external_file.close()
In [ ]: