babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
borkdude 2021-01-05T13:11:31.470Z

Just found a "bug" in babashka: it allows nested fn literals 😆

$ bb -e '(#(+ % (#(+ % 1) 2)) 10)'
13

😂 6
2021-01-05T13:21:30.470700Z

It makes you wonder why this isn’t supported in clojure itself 😅 although maybe better safe than sorry

2021-01-08T04:20:21.040400Z

I think the reason are closures.

(#(+ 1 2 % ((fn [] %))) 3)
;;=> 9

2021-01-08T04:23:46.040800Z

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?

lukasz 2021-01-05T15:52:36.471400Z

First thing that comes to mind, it's hard to reason what to do with nested %

nate 2021-01-05T15:54:08.472100Z

yeah, I think it would be easy to get lost in multiple levels

borkdude 2021-01-05T15:54:20.472600Z

Same as (let [a 1] (let [a 2]))

nate 2021-01-05T15:54:37.472900Z

the computer won't have a hard time, it's us humans that have limited computational ability

Dig 2021-01-05T16:48:42.478700Z

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?

borkdude 2021-01-05T16:50:02.479100Z

@i.slack Are you referring to tzzh-aws?

Dig 2021-01-05T16:50:33.479300Z

pod-babashka-aws

borkdude 2021-01-05T16:51:41.479700Z

Ah right. Yes, it should pick up on (System/getenv "AWS_ACCESS_KEY_ID") (System/getenv "AWS_SECRET_ACCESS_KEY") environment variables.

borkdude 2021-01-05T16:52:02.479900Z

ah sorry, now I read what you said

borkdude 2021-01-05T16:52:17.480200Z

This is something we should support. Can you post an issue?

borkdude 2021-01-05T16:52:48.480300Z

I think we can just pass those properties along to the pod

Dig 2021-01-05T16:53:17.480500Z

yep, i will post the issue

borkdude 2021-01-05T16:53:31.480700Z

@jeroenvandijk ^ so we read the Java properties and then pass them as env variables to the pod, I think that might work

Dig 2021-01-05T16:55:11.480900Z

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

Dig 2021-01-05T16:55:43.481200Z

this way we can leave env vars, since it is working right now

2021-01-05T16:58:14.481400Z

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

borkdude 2021-01-05T16:58:19.481600Z

@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" ...)
`

borkdude 2021-01-05T16:59:04.481800Z

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?

borkdude 2021-01-05T16:59:48.482Z

What would be against just using env vars?

2021-01-05T17:01:38.482500Z

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

borkdude 2021-01-05T17:02:13.482900Z

If you want this, you can pass them manually like this:

(load-pod ["pod-babashka-aws" "-Daws.foo=bar"])

2021-01-05T17:02:49.483100Z

good enough i think

borkdude 2021-01-05T17:02:53.483300Z

This won't work with pods from the pod registry though

borkdude 2021-01-05T17:03:01.483500Z

as they don't have explicit arguments

Dig 2021-01-05T17:03:04.483700Z

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.

borkdude 2021-01-05T17:03:30.483900Z

@i.slack But using the pod in the JVM is already a secondary use case compared to bb I think?

2021-01-05T17:03:39.484100Z

from my memory it was the other way around, but I’ll check

Dig 2021-01-05T17:04:06.484300Z

yes, i am talking about pure aws-api in clojure vs bb in general

borkdude 2021-01-05T17:04:10.484500Z

There might be a nice way to do this using a pod function:

(aws/set-credentials ..)
or something

2021-01-05T17:05:27.485200Z

yeah i think you are right. I’m trying to remember how I used system/properties before

Dig 2021-01-05T17:06:18.485400Z

@borkdude the one potential problem with -Daws ... for credentials, is that they will be visible with ps -fe

2021-01-05T17:06:25.485600Z

Ah I did the opposite. I was using setProperty to set the default so it could be overriden by the ENV vars 😅

2021-01-05T17:09:10.487400Z

I think if we implement the credential provider this issue with properties will sort itself out i think

2021-01-05T17:09:37.487900Z

e.g. if no credential provider given we will forward the relevant system properties if set

2021-01-05T17:09:45.488100Z

(on client creation)

2021-01-05T17:10:41.488500Z

@borkdude So it would be a aws/client and aws/-client again

borkdude 2021-01-05T17:10:50.488900Z

@jeroenvandijk cool

Janne Sauvala 2021-01-05T17:11:41.489700Z

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

Dig 2021-01-05T17:12:59.489900Z

👍

borkdude 2021-01-05T17:13:19.490500Z

@janne.sauvala (System/getProperty "user.dir") or (io/file ".") probably works

Janne Sauvala 2021-01-05T17:16:10.491900Z

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

Dig 2021-01-05T17:16:24.492200Z

@Janne Sauvala (-> *file* io/file .getParent)

borkdude 2021-01-05T17:17:30.492800Z

oh you want the directory of the script itself, yeah *file* is the one you need for that

Janne Sauvala 2021-01-05T17:18:07.493500Z

Yes 🙂 @i.slack’s solution looks neat, thank you!

borkdude 2021-01-05T17:21:29.494200Z

This one works too, but it longer ;)

(str (.getCanonicalPath (io/file *file* "..")))