Skip to content
Snippets Groups Projects
Unverified Commit a5bbc34d authored by Cam Saul's avatar Cam Saul Committed by GitHub
Browse files

Always apply the :settings section first in the config file (#26462)


* Move the config-from-file code into the advanced-config directory since that's the feature we want to flag on

* Always apply the :settings section first in the config file

* Apply suggestions from code review

Co-authored-by: default avatarmetamben <103100869+metamben@users.noreply.github.com>

Co-authored-by: default avatarmetamben <103100869+metamben@users.noreply.github.com>
parent 254e73f8
No related branches found
No related tags found
No related merge requests found
......@@ -236,13 +236,22 @@
(s/assert* ::config m)
(expand-templates m)))
(defn- sort-by-initialization-order
"Sort the various config sections. The `:settings` section should always be applied first (important, since it can
affect the other sections)."
[config-sections]
(let [{settings-sections true, other-sections false} (group-by (fn [[section-name]]
(= section-name :settings))
config-sections)]
(concat settings-sections other-sections)))
(defn ^{:added "0.45.0"} initialize!
"Initialize Metabase according to the directives in the config file, if it exists."
[]
;; TODO -- this should only do anything if we have an appropriate token (we should get a token for testing this before
;; enabling that check tho)
(when-let [m (config)]
(doseq [[section-name section-config] (:config m)]
(doseq [[section-name section-config] (sort-by-initialization-order (:config m))]
(log/info (u/colorize :magenta (trs "Initializing {0} from config file..." section-name)) (u/emoji "🗄️"))
(advanced-config.file.i/initialize-section! section-name section-config))
(log/info (u/colorize :magenta (trs "Done initializing from file.")) (u/emoji "🗄️")))
......
......@@ -4,6 +4,7 @@
[clojure.test :refer :all]
[clojure.walk :as walk]
[metabase-enterprise.advanced-config.file :as advanced-config.file]
[metabase-enterprise.advanced-config.file.interface :as advanced-config.file.i]
[metabase.test :as mt]
[metabase.util :as u]
[yaml.core :as yaml]))
......@@ -200,3 +201,25 @@
@seen-password?))]
(is (not (contains-password? (ex-message e))))
(is (not (contains-password? (ex-data e))))))))))
(deftest always-init-settings-first-test
(testing "Always apply the :settings section first regardless of the order the YAML file is in."
(doseq [config [{:settings {:my-setting 1000}
:users [{:first_name "Cam"
:last_name "Era"
:email "camera@example.com"
:password "toucans"}]}
{:users [{:first_name "Cam"
:last_name "Era"
:email "camera@example.com"
:password "toucans"}]
:settings {:my-setting 1000}}]]
(testing (format "config = %s" (pr-str config))
(let [initialized-sections (atom [])]
(with-redefs [advanced-config.file.i/initialize-section! (fn [section-name _section-config]
(swap! initialized-sections conj section-name))]
(binding [advanced-config.file/*config* {:version 1, :config config}]
(advanced-config.file/initialize!)
(is (= [:settings
:users]
@initialized-sections)))))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment