Just found a "bug" in babashka: it allows nested fn literals 😆
$ bb -e '(#(+ % (#(+ % 1) 2)) 10)'
13
It makes you wonder why this isn’t supported in clojure itself 😅 although maybe better safe than sorry
I think the reason are closures.
(#(+ 1 2 % ((fn [] %))) 3)
;;=> 9
So in a nested scenario, the above would be amiguous:
(#(+ 1 2 % (#(identity %))) 3)
Like here, is the nested #() closing over the argument of the outer one? Thus the nested one is 0-ary and the outer one is 1-ary?
Or, is the inner one a 1-ary function where we forgot to pass an argument?First thing that comes to mind, it's hard to reason what to do with nested %
yeah, I think it would be easy to get lost in multiple levels
Same as (let [a 1] (let [a 2]))
the computer won't have a hard time, it's us humans that have limited computational ability
is there a way to transfer system properties to pod? the issues came up with new aws pod usage. trying to use same method as in clojure. I could not use environment, since it is not settable inside the jvm, so the second auth is system properties that works well inside the jvm using aws-api. Another approach would be to set an environment variable for pod, is that possible?
@i.slack Are you referring to tzzh-aws?
pod-babashka-aws
Ah right. Yes, it should pick up on (System/getenv "AWS_ACCESS_KEY_ID") (System/getenv "AWS_SECRET_ACCESS_KEY")
environment variables.
ah sorry, now I read what you said
This is something we should support. Can you post an issue?
I think we can just pass those properties along to the pod
yep, i will post the issue
@jeroenvandijk ^ so we read the Java properties and then pass them as env variables to the pod, I think that might work
https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html #2 will pick up system properties, so we can just transfer system properties if they are set
this way we can leave env vars, since it is working right now
ah interesting find. Didn’t think about system properties. We need to implement the credential provider part to support these kind of situations i think
@i.slack System properties should be set at startup:
(load-pod ["pod-babashka-aws" "-Daws.foo=bar"])
or:
(load-pod ["clojure" "-J-D.aws.foo=bar" "-M" ...)
`and it could copy the existing Java properties from the JVM (or bb properties), but this still needs some way of passing through the options manually?
What would be against just using env vars?
There are exotic situations where you want to use other credentials than the ones in the environment vars and override this with System properties, but I’m not sure if we should bother with that
If you want this, you can pass them manually like this:
(load-pod ["pod-babashka-aws" "-Daws.foo=bar"])
good enough i think
This won't work with pods from the pod registry though
as they don't have explicit arguments
the env var take precedence over system properties, the only reason to use system props if it is all happening inside one jvm and cannot set env vars.
@i.slack But using the pod in the JVM is already a secondary use case compared to bb I think?
from my memory it was the other way around, but I’ll check
yes, i am talking about pure aws-api in clojure vs bb in general
There might be a nice way to do this using a pod function:
(aws/set-credentials ..)
or something@jeroenvandijk https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html
yeah i think you are right. I’m trying to remember how I used system/properties before
@borkdude the one potential problem with -Daws ... for credentials, is that they will be visible with ps -fe
Ah I did the opposite. I was using setProperty to set the default so it could be overriden by the ENV vars 😅
I think if we implement the credential provider this issue with properties will sort itself out i think
e.g. if no credential provider given we will forward the relevant system properties if set
(on client creation)
@borkdude So it would be a aws/client
and aws/-client
again
@jeroenvandijk cool
Is there a convenient shortcut to get the dir path where the bb script is that I’m running? If not, I could just use *file*
and then just cutoff the script name from the path - maybe with Java’s File
and .getParentFile
👍
@janne.sauvala (System/getProperty "user.dir")
or (io/file ".")
probably works
The problem with (System/getProperty "user.dir")
is that it prints the path where the script was executed. So if I’m not inside the same dir as the script it won’t work
@Janne Sauvala (-> *file* io/file .getParent)
oh you want the directory of the script itself, yeah *file*
is the one you need for that
Yes 🙂 @i.slack’s solution looks neat, thank you!
This one works too, but it longer ;)
(str (.getCanonicalPath (io/file *file* "..")))