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.
279 lines
7.0 KiB
279 lines
7.0 KiB
{ |
|
"cells": [ |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "f6b2c601-3b50-4514-9e5a-382400244bab", |
|
"metadata": { |
|
"tags": [] |
|
}, |
|
"outputs": [], |
|
"source": [ |
|
"%%sh\n", |
|
"rm templates/template.test\n", |
|
"\n", |
|
"cat << EOF >> templates/template.test\n", |
|
"\n", |
|
"[Settings]\n", |
|
"theme = dark\n", |
|
"accent = purple\n", |
|
"background = None\n", |
|
"roles = admin,user,public_user\n", |
|
"home_access_groups = admin_only\n", |
|
"settings_access_groups = admin_only\n", |
|
"custom_app_title = DashMachine\n", |
|
"sidebar_default = open\n", |
|
"tags = {\"name\": \"foo\", \"icon\": \"home\", \"sort_pos\": \"2\"}\n", |
|
"\n", |
|
"[admin]\n", |
|
"role = admin\n", |
|
"password = os.getenv(password)\n", |
|
"confirm_password = os.getenv(password)\n", |
|
"\n", |
|
"{% for item in items %}\n", |
|
"\n", |
|
"[{{ item.service }}]\n", |
|
"prefix = https://\n", |
|
"url = {{ item.url }}\n", |
|
"{% if item.icon_url %}\n", |
|
"icon = item.icon_url\n", |
|
"sidebar_icon = item.icon_url\n", |
|
"{% else %}\n", |
|
"icon = static/images/apps/{{ item.service }}.png\n", |
|
"sidebar_icon = static/images/apps/{{ item.service }}.png\n", |
|
"{% endif %}\n", |
|
"description = default\n", |
|
"open_in = iframe\n", |
|
"# data_sources = $0_http,$0_health,$0_ping,$0_rest\n", |
|
"tags = default\n", |
|
"# groups = admin_only\n", |
|
"\n", |
|
"{% endfor %}\n", |
|
"\n", |
|
"{# a comment #}\n", |
|
"EOF" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "5e0c08bd-aaff-4236-9b79-df5e2aa14a3e", |
|
"metadata": { |
|
"jupyter": { |
|
"source_hidden": true |
|
}, |
|
"tags": [] |
|
}, |
|
"outputs": [], |
|
"source": [ |
|
"%%sh\n", |
|
"cat << EOF >> template.ini\n", |
|
"\n", |
|
"[$0_curl]\n", |
|
"platform curl\n", |
|
"resource = http://$0.com\n", |
|
"value_template My IP: [{value.ip}}\n", |
|
"response_type = json\n", |
|
"\n", |
|
"[$0_rest]\n", |
|
"platform = rest\n", |
|
"resource = http://$0/api\n", |
|
"value_template = {{value}}\n", |
|
"method = post\n", |
|
"authentication = basic\n", |
|
"username = my_username\n", |
|
"password = my_password\n", |
|
"payload = {\"var1\": \"hi\", \"var2\": 1}\n", |
|
"headers {\"Content-Type\": \"application/json\"}\n", |
|
"verify = false\n", |
|
"\n", |
|
"[$0_ping]\n", |
|
"platform = ping\n", |
|
"resource = 192.168.1.1\n", |
|
"[$0_http]\n", |
|
"platform = http_status\n", |
|
"resource = https://your-website.com/api\n", |
|
"method = get\n", |
|
"authentication = basic\n", |
|
"username = my_username\n", |
|
"password = my_password\n", |
|
"headers = {\"Content-Type\": \"application/json\"}\n", |
|
"return_codes = 2XX, 3XX\n", |
|
"\n", |
|
"[$0_health]\n", |
|
"platform = healthchecks\n", |
|
"prefix = http://\n", |
|
"host = localhost\n", |
|
"port = 8080\n", |
|
"api_key = {{ Healthchecks project API Key }}\n", |
|
"project {{ Healthchecks project name }}\n", |
|
"verify = true\n", |
|
"value_template = { { value_template }}\n", |
|
"\n", |
|
"[$0]\n", |
|
"prefix = https://\n", |
|
"url = your-website.com\n", |
|
"icon = static/images/apps/$0.png\n", |
|
"sidebar_icon = static/images/apps/{{ name }}.png\n", |
|
"description = default\n", |
|
"open_in = iframe\n", |
|
"data_sources = $0_http,$0_health,$0_ping,$0_rest\n", |
|
"tags = default\n", |
|
"groups = admin_only\n", |
|
"\n", |
|
"EOF" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "ad3a0cde-8e53-403d-bbb6-6fc95c392093", |
|
"metadata": { |
|
"scrolled": true, |
|
"tags": [] |
|
}, |
|
"outputs": [], |
|
"source": [ |
|
"import json\n", |
|
"import os\n", |
|
"import pprint\n", |
|
"\n", |
|
"import requests\n", |
|
"\n", |
|
"headers = {\n", |
|
" \"Authorization\": os.env(directus_token),\n", |
|
" \"Content-Type\": \"application/json\",\n", |
|
"}\n", |
|
"response = requests.get(\n", |
|
" \"https://cms.donavanaldrich.com/items/containers\", headers=headers\n", |
|
")\n", |
|
"data = response.json()\n", |
|
"\n", |
|
"items = data[\"data\"]\n", |
|
"# name = (items[0]['id'])\n", |
|
"\n", |
|
"# t = Template(\"Jinja {{ name }}!\")\n", |
|
"# t.render(name=items[0]['id'])\n", |
|
"#" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "3fc3ac9f-22bf-495b-9a23-214219d04543", |
|
"metadata": { |
|
"scrolled": true, |
|
"tags": [] |
|
}, |
|
"outputs": [], |
|
"source": [ |
|
"import json\n", |
|
"import re\n", |
|
"\n", |
|
"import requests\n", |
|
"\n", |
|
"my_headers = {\n", |
|
" \"Content-Type\": \"application/json\",\n", |
|
" \"Accept\": \"application/json\",\n", |
|
"}\n", |
|
"\n", |
|
"response = requests.get(\n", |
|
" \"http://traefik:8080/api/http/routers\",\n", |
|
" headers=my_headers,\n", |
|
")\n", |
|
"\n", |
|
"initial = response.json()\n", |
|
"# pprint.pprint(initial)\n", |
|
"items = []\n", |
|
"\n", |
|
"for x in initial:\n", |
|
" rule = x[\"rule\"]\n", |
|
" service = x[\"service\"]\n", |
|
" find = re.findall(\"Host\\(`([^\\)]+)`\\)\", rule)\n", |
|
" if find:\n", |
|
" item = {\"service\": x[\"service\"], \"url\": find[0]}\n", |
|
" else:\n", |
|
" pass\n", |
|
" items.append(item)\n", |
|
"# print(items)\n" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "147949bd-d0a7-4ebc-af12-b21d3d8fa0b3", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"deduplicated_list = []\n", |
|
"deduped_keys = list()\n", |
|
"for y in items:\n", |
|
" key = y['url']\n", |
|
" if key not in deduped_keys:\n", |
|
" deduped_keys.append(key)\n", |
|
" deduplicated_list.append(y)\n", |
|
"\n", |
|
"pprint.pprint(deduplicated_list)" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "fc0c7be4-acdb-4468-9428-c15f682b4c1e", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [ |
|
"from jinja2 import Environment, FileSystemLoader, select_autoescape\n", |
|
"\n", |
|
"items = deduplicated_list\n", |
|
"\n", |
|
"env = Environment(\n", |
|
" loader=FileSystemLoader([\"templates\"]),\n", |
|
" # autoescape=select_autoescape()\n", |
|
")\n", |
|
"\n", |
|
"t = env.get_template(\"template.test\")\n", |
|
"pprint.pprint(t.render(item=items[0], items=items))\n", |
|
"#\n", |
|
"with open(\"test.ini\", \"w\") as external_file:\n", |
|
" # add_text = \"This text will be added to the file\"\n", |
|
" print(t.render(item=items[0], items=items), file=external_file)\n", |
|
" external_file.close()" |
|
] |
|
}, |
|
{ |
|
"cell_type": "code", |
|
"execution_count": null, |
|
"id": "6c539205-93cd-4b0a-9a0d-6c88696ee92a", |
|
"metadata": {}, |
|
"outputs": [], |
|
"source": [] |
|
} |
|
], |
|
"metadata": { |
|
"kernelspec": { |
|
"display_name": "Python 3.10.4 64-bit", |
|
"language": "python", |
|
"name": "python3" |
|
}, |
|
"language_info": { |
|
"codemirror_mode": { |
|
"name": "ipython", |
|
"version": 3 |
|
}, |
|
"file_extension": ".py", |
|
"mimetype": "text/x-python", |
|
"name": "python", |
|
"nbconvert_exporter": "python", |
|
"pygments_lexer": "ipython3", |
|
"version": "3.10.6" |
|
}, |
|
"vscode": { |
|
"interpreter": { |
|
"hash": "31f2aee4e71d21fbe5cf8b01ff0e069b9275f58929596ceb00d14d90e3e16cd6" |
|
} |
|
} |
|
}, |
|
"nbformat": 4, |
|
"nbformat_minor": 5 |
|
}
|
|
|