diff src/luan/host/Util.luan @ 1396:a5f61890ad84

add check_postgres_password
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 10 Sep 2019 13:41:22 -0600
parents 8fe777ba5045
children 1979cff9aad2
line wrap: on
line diff
--- a/src/luan/host/Util.luan	Mon Sep 09 01:22:23 2019 -0600
+++ b/src/luan/host/Util.luan	Tue Sep 10 13:41:22 2019 -0600
@@ -54,14 +54,16 @@
 	file.delete()
 	file.write_text("return "..stringify{password=password}.."\n")
 	digest_authentication(dir,password)
+end
 
-	-- postgres
-	local fn = Luan.load_file("file:postgres.luan") or error()
-	local pg = fn()
-	if pg == nil then
+local fn = Luan.load_file("file:postgres.luan") or error()
+local pg_admin = fn()
+
+function Util.set_postgres_password(domain,password)
+	if pg_admin == nil then
 		return
 	end
-	local db = database(pg)
+	local db = database(pg_admin)
 	local exists = db.query("select rolname from pg_roles where rolname=?",domain)() ~= nil;
 	--logger.info("exists "..exists)
 	if exists then
@@ -70,4 +72,17 @@
 	db.close()
 end
 
+function Util.check_postgres_password(domain,password)
+	if pg_admin == nil then
+		return
+	end
+	local db = database{
+		class = "org.postgresql.Driver"
+		url = "jdbc:postgresql://localhost:5432/"..domain
+		user = domain
+		password = password
+	}
+	db.close()
+end
+
 return Util