From a8e2dd0fe96fea94161ff3b8f30a3526f93e4dcd Mon Sep 17 00:00:00 2001 From: "Chris (Someguy123)" Date: Fri, 19 Oct 2018 02:37:36 +0100 Subject: [PATCH] Added section on using Lua records with generic SQL --- docs/lua-records.rst | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/lua-records.rst b/docs/lua-records.rst index 1b1e7402e..740e8cc6f 100644 --- a/docs/lua-records.rst +++ b/docs/lua-records.rst @@ -63,6 +63,40 @@ addresses. This will pick from the viable IP addresses the one deemed closest to the user. +Using LUA Records with Generic SQL backends +------------------------------------------- + +It's possible to use Lua records with the Generic SQL backends such as gmysql and gpgsql. + +Be aware that due to the fact that Lua records uses both double and single quotes, you will +need to appropriately escape them in INSERT/UPDATE queries. + +Here is an example from the previous section (``pickclosest``) which should work +for both **MySQL** and **PostgreSQL**:: + + -- Create the zone example.com + INSERT INTO domains (id, name, type) VALUES (1, 'example.com', 'NATIVE'); + + -- Enable Lua records for the zone (if not enabled globally) + INSERT INTO domainmetadata (domain_id, kind, content) + VALUES (1, 'ENABLE-LUA-RECORD', 1); + + -- Create a pickClosest() Lua A record. + -- Double single quotes are used to escape single quotes in both MySQL and PostgreSQL + INSERT INTO records (domain_id, name, type, content, ttl) + VALUES ( + 1, + 'www.example.com', + 'LUA', + 'A "pickclosest({''192.0.2.1'',''192.0.2.2'',''198.51.100.1''})"', + 600 + ); + +The above queries create a zone ``example.com``, enable Lua records for the zone using ``ENABLE-LUA-RECORD``, +and finally insert a LUA A record for the ``www`` subdomain using the previous pickclosest example. + +See `Details & Security`_ for more information about enabling Lua records, and the risks involved. + Record format ------------- .. note:: -- 2.40.0