aero icon indicating copy to clipboard operation
aero copied to clipboard

make #ref from parent work inside #include file

Open nha opened this issue 4 years ago • 5 comments

At the moment #include works by reading the config on the file: https://github.com/juxt/aero/blob/1749e71f327d94805fdbb50d0cbbd692f696997d/src/aero/core.cljc#L86

This breaks #ref that are in another file "higher" up in the include hierarchy, ex:

(aero.core/read-config (clojure.java.io/resource "config_test.edn"))
;; =>
{:a "AAA"
 :b "AAA"
 :c {:d nil} ;; nil here - should be "AAA"
 }
;; config_test.edn
{:a "AAA"
 :b #ref [:a] ;; OK
 :c #include "config_include.edn"
 }
;;config_include.edn 
{:d #ref [:a]} ;; this is not resolved

Without knowing too much about aero's internals, it seems a possible solution would be to include .edn files without resolving the tags at the 'include level.

nha avatar May 30 '20 15:05 nha

This seems like a confusing feature. What's the use case?

SevereOverfl0w avatar Jun 05 '20 07:06 SevereOverfl0w

I'm not sure about OP but I'm using aero to define data structures that will resemble pages in a website. I have some default properties in my root edn file, which also uses #include to pull in the separate edn files for each page. I was expecting to be able to #ref the configuration keys in the root edn file from the children edn files, and was confused to find aero did not support it.

adamtait avatar Jun 08 '20 05:06 adamtait

The use case is close the one described in the README @SevereOverfl0w : https://github.com/juxt/aero#hide-passwords-in-local-private-files

If you take that example and move :aws-secret-access-key to a different file, say aws.edn:

(spit "secrets.edn"
        (pr-str {:aws-test-key "TEST_KEY"
                 :aws-prod-key "TEST_KEY"}))

  (spit "config.edn"
        "{:secrets #include \"secrets.edn\"
          :aws #include \"aws.edn\"}")

  (spit "aws.edn"
        "{:aws-secret-access-key #ref [:secrets :aws-test-key]}")

  (aero/read-config
    "config.edn"
    {:profile "unused"})

;; =>
 {:secrets {:aws-test-key "TEST_KEY", :aws-prod-key "TEST_KEY"},
  :aws {:aws-secret-access-key nil}}

nha avatar Jun 13 '20 18:06 nha

Would a shared secrets.edn work for your just case? Both config.edn and aws.edn would include it?

SevereOverfl0w avatar Jun 14 '20 07:06 SevereOverfl0w

Yes, there are several options that work right now:

  • #include the shared config in every file referencing it as you suggest (won't work if the secret is in the main config)
  • keep everything in one file
  • adding some post-processing after reading the config

I just thought it would be less surprising if #include was working as if the file being included was part of the parent file. Not a deal-breaker by the way, I am really happy with aero, so if you think it's not worth it / confusing that's fair.

EDIT: changing this in #ref would be a breaking change, so it would have to be another tag

nha avatar Jun 14 '20 13:06 nha