Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make #ref from parent work inside #include file #92

Open
nha opened this issue May 30, 2020 · 5 comments
Open

make #ref from parent work inside #include file #92

nha opened this issue May 30, 2020 · 5 comments

Comments

@nha
Copy link

nha commented May 30, 2020

At the moment #include works by reading the config on the file:

(read-config

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.

@SevereOverfl0w
Copy link
Contributor

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

@adamtait
Copy link

adamtait commented Jun 8, 2020

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.

@nha
Copy link
Author

nha commented Jun 13, 2020

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}}

@SevereOverfl0w
Copy link
Contributor

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

@nha
Copy link
Author

nha commented Jun 14, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants