babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
borkdude 2020-11-03T08:34:54.150Z

@lukaszkorecki I can add it if you want, it takes about 80kb extra. Can you explain the use case a bit?

borkdude 2020-11-03T10:47:20.150400Z

Btw, I now fixed this example on master:

$ ./bb -e "(take 4 (iterator-seq (.iterator (.doubles (java.util.Random.)))))"
(0.11018020853952415 0.8538439232524406 0.24374736204535452 0.975224420988415)

lukasz 2020-11-03T14:37:37.152100Z

@borkdude I have reimplemented RabbitMQ's password hashing algo, at one point it requires 4 bytes of a random salt, so out of habit I always reach for SecureRandom but in this case good old j.u.Random will suffice. I guess it comes from the fact that MessageDigest is included. Babashka/SCI is so good I keep forgetting it's not "full" Clojure :-)

lukasz 2020-11-03T14:38:36.153100Z

I suppose if it only adds 80kb, it would be worth including, since it adds that "parity" to MessageDigest

lukasz 2020-11-03T14:38:51.153400Z

but, it's not like it's critically needed

borkdude 2020-11-03T14:39:09.153800Z

MessageDigest is included to calculate sha-256 hashes, etc, which is quite common in scripting

lukasz 2020-11-03T14:39:32.154200Z

yep, exactly what I'm doing right now

borkdude 2020-11-03T14:40:51.154700Z

How does j.s.R relate to MessageDigest?

lukasz 2020-11-03T14:42:48.156300Z

It doesn't really, apart from both being a part of java.security. package. It only came up in my use case - I needed both, being used to having both in regular Clojure and implementing various cryptography stuff (which I'm surprised how much I had to do this year :thinking_face: )

dharrigan 2020-11-03T14:45:47.156800Z

If I'm also not mistaken, UUID generation using Java uses the SecureRandom class

borkdude 2020-11-03T14:48:06.157700Z

OK, but we already have that:

borkdude 2020-11-03T14:48:09.157900Z

$ bb '(java.util.UUID/randomUUID)'
#uuid "705b0ba1-d637-45aa-ad35-4aba31cbd9e2"

dharrigan 2020-11-03T14:48:16.158100Z

indeed

borkdude 2020-11-03T14:49:03.158400Z

fwiw, this entire library works with bb: https://github.com/clojure/data.generators

borkdude 2020-11-03T14:49:59.159100Z

I guess you could bind *rnd* to a j.s.R instance for more secure randomness?

lukasz 2020-11-03T14:53:32.159700Z

yeah, could work. Again: it's not incredibly painful to not have SecureRandom, I naively assumed it's already in BB

lukasz 2020-11-03T14:53:55.159900Z

PEKBAC etc etc

borkdude 2020-11-03T14:55:26.160400Z

no problem. if the need arises I would add it, if it would enable access to some interesting library for example

borkdude 2020-11-03T15:05:49.161500Z

btw, @lukaszkorecki are you still considering writing an AWS pod? I noticed https://github.com/BrunoBonacci/graalvm-clojure/tree/master/amazonica-s3 is graal compatible. Together with the new support for transit in pods it might feasible, maybe using some code generation.

lukasz 2020-11-03T15:10:06.164300Z

Good timing - I have just kicked off the work which will involve this. At this point I'm considering using babashka.process and AWS CLI v2 as we are using AWS SSO for credentials, and none of the AWS SDKs (Java, Go etc) support that right now. Also, that gives access to all AWS services in a programatic way - my understanding is that with amazonica and the AWS SDK we had to pick and choose what gets included when compiling using native-image, right?

borkdude 2020-11-03T15:11:59.164900Z

That's correct. The way I usually accomplish this is by putting stuff in a map and looking it up dynamically. This ensures GraalVM will hold on to it. https://github.com/babashka/pod-babashka-lanterna/blob/main/src/pod/babashka/lanterna.clj#L106

lukasz 2020-11-03T15:45:48.166900Z

So yeah, going with aws cli might be more flexible since services you might need to interact with might not be known (we need ECS, S3, SecretsManager, SSM and couple of more, some people might need S3 and DynamoDB only etc).

borkdude 2020-11-03T15:46:29.167300Z

yeah, shelling out to a CLI is a good way to get stuff done

lukasz 2020-11-03T15:48:57.168900Z

The good thing is that the CLI is somewhat structured in the way you call it, so I think it can have a sane API in Clojure in terms of the interface. Something like (aws :ec2 :describe-instances {:instance-ids ["a" "b"] }) We will see.

lukasz 2020-11-03T15:49:12.169400Z

By the way - the post about monitoring ECS with babashka will be published soon :-)

🍿 2
borkdude 2020-11-03T15:51:41.170100Z

@lukaszkorecki :-) Here's an example of a lib that shells out to psql: https://github.com/borkdude/babashka/blob/master/doc/libraries.md#clj-psql Might be cool to publish somewhere at some point.

borkdude 2020-11-03T15:52:12.171200Z

I've heard that the AWS cli sometimes makes breaking changes, not sure how bad those are? Is that what you're referring to with v2?

lukasz 2020-11-03T15:52:22.171400Z

Yep, I'm planning to open source our RMQ monitoring + Docker setup - all tooling is based on BB

lukasz 2020-11-03T15:52:46.171900Z

the AWS CLI pod is speculative atm, I'll be digging into it properly in a week or so

lukasz 2020-11-03T15:53:21.172600Z

V2 broke in the sense that it went straight into python3 (but it vendors) it and it has features that v1 doesn't (SSO integration for example)

lukasz 2020-11-03T15:53:39.173Z

so if you were installing the CLI via python's pip, you were going to have a bad time

borkdude 2020-11-03T17:21:02.173600Z

Wow.... matchete, a library like meander, works with babashka:

$ rlwrap bb -cp "$(clojure -Spath -Sdeps '{:deps {io.xapix/matchete {:mvn/version "1.2.0"}}}')"
user=> (require '[matchete.core :as mc])
nil
user=> (mc/matches '{?k 1} {:x 1 :y 1})"
({?k :y} {?k :x})

👏 5
👀 2