Generates a docs page with an example configuration file for Metabase. The example config includes all configurable settings and their default values. | (ns metabase.cmd.config-file-gen (:require [clj-yaml.core :as yaml] [clojure.java.io :as io] [metabase.cmd.env-var-dox :as dox])) |
Get settings and their default values | |
Some default values require resetting. For example, the | (def settings-to-reset '(:saml-attribute-email)) |
Sets certain default values to nil. | (defn reset-default-values [settings] (reduce (fn [settings k] (assoc settings k nil)) settings settings-to-reset)) |
Gets valid config settings. | (defn settings [] (dox/filter-env-vars (dox/get-settings))) |
Get a setting's name and its default. | (defn get-name-and-default [{:keys [munged-name default]}] {(keyword munged-name) default}) |
Add settings to YAML template | |
Creates a sorted map of settings from their names and defaults. | (defn create-settings-map [settings] (->> settings (map get-name-and-default) (into (sorted-map)))) |
Preps settings for the configuration file. | (defn- config-settings [] (-> (settings) (create-settings-map) (reset-default-values))) |
Adds settings to the configuration template. | (defn- add-settings [config] (assoc-in config [:config :settings] (config-settings))) |
Build Markdown file | |
Used as header for config file doc. | (def markdown-intro "metabase/cmd/resources/config-file-intro.md") |
Used as footer for config file doc. | (def markdown-outro "metabase/cmd/resources/config-file-outro.md") |
Take a YAML string and builds a Markdown page for docs on a configuration file. | (defn- build-markdown-page [config-yaml] (str (slurp (io/resource markdown-intro)) config-yaml (slurp (io/resource markdown-outro)))) |
Takes configuration map that includes settings data and preps YAML for embedding in Markdown doc. | (defn- format-yaml [config-with-settings] (yaml/generate-string config-with-settings :dumper-options {:flow-style :block})) |
Generates a configuration file Markdown doc with config template for Metabase with settings and their default values. | (defn- create-config-doc [yaml-template] (-> yaml-template (io/resource) (slurp) (yaml/parse-string) (add-settings) (format-yaml) (build-markdown-page))) |
Docs location for the config file template. | (def config-file-path "docs/configuring-metabase/config-template.md") |
Base template that we'll add the settings to. | (def yaml-template "metabase/cmd/resources/config-template.yaml") |
Generates a configuration file doc with template and saves to docs directory. | (defn generate-config-file-doc! [] (println "Creating config file doc with template...") (spit (io/file config-file-path) (create-config-doc yaml-template)) (println (str "Config doc file created: `" config-file-path "`."))) |