aboutsummaryrefslogtreecommitdiff
path: root/apps/dreki_web/src/dreki_web_admin_world.erl
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dreki_web/src/dreki_web_admin_world.erl')
-rw-r--r--apps/dreki_web/src/dreki_web_admin_world.erl28
1 files changed, 28 insertions, 0 deletions
diff --git a/apps/dreki_web/src/dreki_web_admin_world.erl b/apps/dreki_web/src/dreki_web_admin_world.erl
new file mode 100644
index 0000000..1ceaaee
--- /dev/null
+++ b/apps/dreki_web/src/dreki_web_admin_world.erl
@@ -0,0 +1,28 @@
+-module(dreki_web_admin_world).
+-behaviour(cowboy_handler).
+-export([init/2]).
+
+init(Req, index) ->
+ Json = #{<<"data">> => #{<<"service">> => <<"dreki">>}},
+ {ok, dreki_web:reply_json(Req, 200, Json), undefined};
+
+init(Req, graph) ->
+ World = dreki_world_dns:as_map(),
+ Json = #{<<"data">> => World},
+ {ok, dreki_web:reply_json(Req, 200, Json), undefined};
+
+init(Req, {graph, dot}) ->
+ World = dreki_world_dns:as_map(),
+ Vertices = [dot_format_vertex(N) || N <- maps:get(vertices, World)],
+ {ok, Dot} = world_graph_dot_dtl:render([{vertices, Vertices}, {edges, maps:get(edges, World)}]),
+ cowboy_req:reply(200, #{<<"content-type">> => <<"text/vnd.graphviz">>}, Dot, Req);
+
+init(Req, _) ->
+ dreki_web_error:init(Req, #{code => 404, status => "Not found"}).
+
+dot_format_vertex(V = #{type := node}) ->
+ V#{shape => <<"box">>, color => <<"#c2410c">>, class => <<"dreki-world-graph-node">>};
+dot_format_vertex(V = #{type := root}) ->
+ V#{shape => <<"polygon">>, color => <<"#a16207">>, class => <<"dreki-world-graph-root">>};
+dot_format_vertex(V = #{type := region}) ->
+ V#{shape => <<"egg">>, color => <<"#4d7c0f">>, class => <<"dreki-world-graph-region">>}.