<commit_before>;; ## REST server
;;
;; Consolidates our disparate REST endpoints into a single Ring
;; application.

(ns com.puppetlabs.puppetdb.http.server
  (:use [com.puppetlabs.puppetdb.http.command :only (command-app)]
        [com.puppetlabs.puppetdb.http.facts :only (facts-app)]
        [com.puppetlabs.puppetdb.http.metrics :only (metrics-app)]
        [com.puppetlabs.puppetdb.http.resources :only (resources-app)]
        [com.puppetlabs.puppetdb.http.node :only (node-app)]
        [com.puppetlabs.puppetdb.http.status :only (status-app)]
        [com.puppetlabs.puppetdb.http.experimental :only (experimental-app)]
        [com.puppetlabs.middleware :only
         (wrap-with-authorization wrap-with-certificate-cn wrap-with-globals wrap-with-metrics)]
        [com.puppetlabs.utils :only (uri-segments)]
        [net.cgrand.moustache :only (app)]
        [ring.middleware.resource :only (wrap-resource)]
        [ring.middleware.params :only (wrap-params)]))

(def routes
  (app
   ["facts" node]
   {:get (fn [req]
           (facts-app (assoc-in req [:params "node"] node)))}

   ["nodes"]
   {:get node-app}

   ["resources"]
   {:get resources-app}

   ["experimental" &]
   {:get experimental-app}

   ["commands"]
   {:post command-app}

   ["status" &]
   {:get status-app}

   ["metrics" &]
   {:get metrics-app}))

(defn build-app
  "Generate a Ring application that handles PuppetDB requests

  `options` is a list of keys and values where keys can be the following:
<commit_msg>(#15388) Add redirect from '/' to the dashboard<commit_after>;; ## REST server
;;
;; Consolidates our disparate REST endpoints into a single Ring
;; application.

(ns com.puppetlabs.puppetdb.http.server
  (:use [com.puppetlabs.puppetdb.http.command :only (command-app)]
        [com.puppetlabs.puppetdb.http.facts :only (facts-app)]
        [com.puppetlabs.puppetdb.http.metrics :only (metrics-app)]
        [com.puppetlabs.puppetdb.http.resources :only (resources-app)]
        [com.puppetlabs.puppetdb.http.node :only (node-app)]
        [com.puppetlabs.puppetdb.http.status :only (status-app)]
        [com.puppetlabs.puppetdb.http.experimental :only (experimental-app)]
        [com.puppetlabs.middleware :only
         (wrap-with-authorization wrap-with-certificate-cn wrap-with-globals wrap-with-metrics)]
        [com.puppetlabs.utils :only (uri-segments)]
        [net.cgrand.moustache :only (app)]
        [ring.middleware.resource :only (wrap-resource)]
        [ring.middleware.params :only (wrap-params)]
        [ring.util.response :only (redirect)]))

(def routes
  (app
   ["facts" node]
   {:get (fn [req]
           (facts-app (assoc-in req [:params "node"] node)))}

   ["nodes"]
   {:get node-app}

   ["resources"]
   {:get resources-app}

   ["experimental" &]
   {:get experimental-app}

   ["commands"]
   {:post command-app}

   ["status" &]
   {:get status-app}

   ["metrics" &]
   {:get metrics-app}

   [""]
   {:get (constantly (redirect "/dashboard/index.html"))}))

(defn build-app
  "Generate a Ring application that handles PuppetDB requests

  `options` is a list of keys and values where keys can be the following:

{'fraction_non_alphanumeric': 0.1506501744370441, 'fraction_numerical': 0.001585791309863622, 'mean_word_length': 3.199733688415446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6636257', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1101, 'n_words': 235}