diff host/Config.luan @ 1628:520707a70379

add host
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 07 Dec 2021 23:29:58 -0700
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/host/Config.luan	Tue Dec 07 23:29:58 2021 -0700
@@ -0,0 +1,60 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local ipairs = Luan.ipairs or error()
+local Io = require "luan:Io.luan"
+local uri = Io.uri or error()
+local Package = require "luan:Package.luan"
+local load = Package.load or error()
+local Logging = require "luan:logging/Logging.luan"
+local logger = Logging.logger "Config"
+
+
+uri("file:local").mkdir()
+local password_file = uri("file:local/password.txt")
+local password = password_file.exists() and password_file.read_text() or "password"
+local site_config = nil
+local site_name
+for _, site_dir in ipairs( uri("file:sites").children() or {} ) do
+	local name = site_dir.name()
+	local config = load("file:sites/"..name.."/site/private/host/Config.luan")
+	if config == false then
+		continue
+	end
+	if config.password ~= password and config.old_password ~= password then
+		logger.warn("wrong password for "..name)
+		continue
+	end
+	if site_config == nil then
+		site_config = config
+		site_name = name
+	else
+		logger.error("conflicting Config in "..name.." and "..site_name)
+	end
+end
+if site_config ~= nil then
+	logger.info("using Config from "..site_name)
+	local site_password = site_config.password or error()
+	if site_password ~= password then
+		password_file.write_text(password)
+	end
+	return site_config
+end
+if password ~= "password" then
+	password_file.write_text("password")
+end
+
+
+local Config = {}
+
+Config.password = "password"
+
+--[[  an example
+Config.postgres = {
+	class = "org.postgresql.Driver"
+	url = "jdbc:postgresql://localhost:5432/postgres"
+	user = "someone"
+	password = "password"
+}
+]]
+
+return Config