Mercurial Hosting > luan
comparison host/Config.luan @ 1628:520707a70379
add host
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 07 Dec 2021 23:29:58 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1627:07be5015159d | 1628:520707a70379 |
---|---|
1 local Luan = require "luan:Luan.luan" | |
2 local error = Luan.error | |
3 local ipairs = Luan.ipairs or error() | |
4 local Io = require "luan:Io.luan" | |
5 local uri = Io.uri or error() | |
6 local Package = require "luan:Package.luan" | |
7 local load = Package.load or error() | |
8 local Logging = require "luan:logging/Logging.luan" | |
9 local logger = Logging.logger "Config" | |
10 | |
11 | |
12 uri("file:local").mkdir() | |
13 local password_file = uri("file:local/password.txt") | |
14 local password = password_file.exists() and password_file.read_text() or "password" | |
15 local site_config = nil | |
16 local site_name | |
17 for _, site_dir in ipairs( uri("file:sites").children() or {} ) do | |
18 local name = site_dir.name() | |
19 local config = load("file:sites/"..name.."/site/private/host/Config.luan") | |
20 if config == false then | |
21 continue | |
22 end | |
23 if config.password ~= password and config.old_password ~= password then | |
24 logger.warn("wrong password for "..name) | |
25 continue | |
26 end | |
27 if site_config == nil then | |
28 site_config = config | |
29 site_name = name | |
30 else | |
31 logger.error("conflicting Config in "..name.." and "..site_name) | |
32 end | |
33 end | |
34 if site_config ~= nil then | |
35 logger.info("using Config from "..site_name) | |
36 local site_password = site_config.password or error() | |
37 if site_password ~= password then | |
38 password_file.write_text(password) | |
39 end | |
40 return site_config | |
41 end | |
42 if password ~= "password" then | |
43 password_file.write_text("password") | |
44 end | |
45 | |
46 | |
47 local Config = {} | |
48 | |
49 Config.password = "password" | |
50 | |
51 --[[ an example | |
52 Config.postgres = { | |
53 class = "org.postgresql.Driver" | |
54 url = "jdbc:postgresql://localhost:5432/postgres" | |
55 user = "someone" | |
56 password = "password" | |
57 } | |
58 ]] | |
59 | |
60 return Config |