   []
   (.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))

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

(defn exec-sql 
  []
  (try 
    {:ok 
      (get-fst-result 
        (execute-query
          (.createStatement (connect-to-db (get-jdbc-url db-prod-eu)))
          "SELECT NOW();")) }
  (catch Exception e
    {:error "Exception" :fn "exec-sql" :exception (.getMessage e) })))

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


(ns dbmgmt
  (:require
    [clojure.edn          :as     edn    ]
    [clojure.data.json    :as     json   ]
    [clojure.java.io      :as     io     ])
  (:import
    [clojure.lang                           PersistentHashMap PersistentArrayMap  ]
    [java.sql                               Connection DriverManager
                                            SQLException Statement ResultSet      ]
    [java.util                              Properties Date                       ]
    [java.io                                File BufferedReader                   ]
    [java.nio                               ByteBuffer                            ]
    [java.nio.charset                       Charset                               ]
    [com.amazonaws.services.kms             AWSKMS AWSKMSClientBuilder            ]
    [com.amazonaws.services.kms.model       DecryptRequest                        ]
    [com.amazonaws.services.lambda.runtime  Context                               ]
    [com.amazonaws.util                     Base64                                ]
    [java.lang.management                   ManagementFactory  RuntimeMXBean      ])
  (:gen-class
    :methods [^:static [handler [String] String]]))

;; misc

(defn system-properties
  "Returns system-properties as a hashmap {}"
  ^PersistentHashMap []
  (reduce (fn [x [y z]] (assoc x y z)) {} (System/getProperties)))

(defn read-file
