 (defn certname-query
   "Returns a function that will query the given endpoint (`suffix`)
   for the provided `certname`"
-  [suffix]
-  (fn [certname]
-    (-> (query-url-str suffix)
-        (get-or-throw {:query-params {"query" (json/generate-string [:= :certname certname])}})
-        :body)))
-
-(def get-reports (certname-query "/reports"))
-(def get-factsets (certname-query "/factsets"))
-(def get-catalogs (certname-query "/catalogs"))
+  [base-url suffix certname]
+  (-> (query-url-str base-url suffix)
+      (get-or-throw {:query-params {"query" (json/generate-string [:= :certname certname])}})
+      :body))
+
+(defn get-reports
+  ([certname]
+   (get-reports *base-url* certname))
+  ([base-url certname]
+   (certname-query base-url "/reports" certname)))
+
+(defn get-factsets
+  ([certname]
+   (get-factsets *base-url* certname))
+  ([base-url certname]
+   (certname-query base-url "/factsets" certname)))
+
+(defn get-catalogs
+  ([certname]
+   (get-catalogs *base-url* certname))
+  ([base-url certname]
+   (certname-query base-url "/catalogs" certname)))
 
 (defn get-summary-stats []
   (-> (admin-url-str "/summary-stats")

;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn pdb-query-url []
  (assoc *base-url* :prefix "/pdb/query" :version :v4))

(defn query-url-str [url-suffix]
  (create-url-str (pdb-query-url) url-suffix))

(defn pdb-cmd-url []
  (assoc *base-url* :prefix "/pdb/cmd" :version :v1))

(defn cmd-url-str [url-suffix]
  (create-url-str (pdb-cmd-url) url-suffix))

(defn pdb-admin-url []
  (assoc *base-url* :prefix "/pdb/admin" :version :v1))

(defn admin-url-str [url-suffix]
  (create-url-str (pdb-admin-url) url-suffix))

(defn pdb-metrics-url []
  (assoc *base-url* :prefix "/metrics" :version :v1))

(defn metrics-url-str [url-suffix]
  (create-url-str (pdb-metrics-url) url-suffix))

(defn pdb-meta-url []
  (assoc *base-url* :prefix "/pdb/meta" :version :v1))

(defn meta-url-str [url-suffix]
  (create-url-str (pdb-meta-url) url-suffix))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;

   & [opts]]
  (let [resp (get url-str opts)]
    (if (>= (:status resp) 400)
      (throw+ {:url url-str
               :response resp
               :status (:status resp)}
              (format "Failed request to '%s' with status '%s'" url-str (:status resp)))
      resp)))

(pls/defn-validated post
