   []
   (.getInputArguments (ManagementFactory/getRuntimeMXBean)))
 
-(defn exec 
+(def select-now "SELECT NOW();")
+
+(defn get-kms
+  [key-name]
+  (println key-name)
+  (let [
+        ^bytes          encryptedKey  (Base64/decode
+                                        (System/getenv key-name))
+        ^AWSKMS         client        (AWSKMSClientBuilder/defaultClient)
+        ^DecryptRequest request       (.withCiphertextBlob
+                                        (DecryptRequest.)
+                                        (ByteBuffer/wrap encryptedKey))
+        ^ByteBuffer     plainTextKey  (.getPlaintext
+                                        (.decrypt client request))
+        ^String         ret           (String.
+                                        (.array plainTextKey) (Charset/forName "UTF-8"))
+        ]
+    ret))
+
+; (fv [param] body)
+
+(defn init
   []
-  (let [sql-ret (exec-sql)]
-    (println (str "Start time :: " (start-time)))
-    (println (str "Input args :: " (get-input-args)))
-    (cond
-      (contains? sql-ret :ok)
-        (println (str "now :: " (.getString (:ok (exec-sql)) "now")))
+  (println (str "Start time :: " (start-time)))
+  (println (str "Input args :: " (get-input-args))))
+
+(defn config-selector
+  [config]
+  (cond
+    (= config :local)
+      { :ok (parse-edn-string
+              (:ok
+                (read-file (File. "conf/prod.edn")))) }
+    (= config :kms)
+      { :ok (get-kms "prod") }
     :else
-      (println (str "Error while executing SQL :: " sql-ret)))))
+      { :err :err }))
 
-(defn -handler 
+
+(defn sql-exec
+  [config] ; :local or :kms
+  (let [ databases (config-selector config) ]
+    (println databases)))
+
+(defn -handler
   [s]
-  (exec)
+  (init)
+  (sql-exec :kms)
   s)
 
-(defn -main 
-  [& args] 
-  (exec))
+(defn -main
+  [& args]
+  (init)
+  (sql-exec :local))


;; nil if enything goes sideways

(def db-prod-eu 
  (:eu 
    (:ok 
      (parse-edn-string 
        (:ok 
          (read-file (File. "conf/prod.edn")))))))

(defn get-jdbc-url 
  ^String [^PersistentArrayMap hm] 
  (str "jdbc:" (:dbtype hm) "://" (:host hm) "/" 
       (:dbname hm) "?" "user=" (:user hm) 
       "&" "password=" (:password hm) 
       "&" "ssl=" (get-in hm [:ssl] "false")
       "&" "sslfactory=" (get-in hm [:sslfactory] "org.postgresql.ssl.NonValidatingFactory")))

(defn connect-to-db 
  ^Connection [^String dburl]
  (DriverManager/getConnection dburl))

(defn create-statement 
  ^Statement [^Connection dbconn]
  (.createStatement dbconn))


  [^ResultSet res]
  (if (.next res) res :err))

(defn get-db-connection
  [db]
  (connect-to-db (get-jdbc-url db)))

(defn exec-sql
  [db-connection statement]
  (try
    {:ok
      (get-fst-result
        (execute-query
          (.createStatement db-connection statement))) }
  (catch Exception e
    {:error "Exception" :fn "exec-sql" :exception (.getMessage e) })))

(defn start-time
  ^Date []
  (Date. (.getStartTime (ManagementFactory/getRuntimeMXBean))))

