Fork me on GitHub
#babashka
<
2021-11-17
>
yubrshen04:11:17

How to overcome the problem of "curl: (60) The certificate issuer's certificate has expired"? (I'm not sure if this is unique of bb or Clojure in general) In a new virtual machine (production) after setting of bb 0.6.5 (without Clojure), running the repl with trace below: user=> (require '[babashka.curl :as curl]) nil user=> (let [api-host "" api-version "v1" service "current" output-format "json" key "xxxxxx" latitude -122.2284271 longitude 123.812209 endpoint (str api-host "/" api-version "/" service "." output-format "?key=" key "&q=" latitude "," longitude)] (curl/get endpoint)) clojure.lang.ExceptionInfo: curl: (60) The certificate issuer's certificate has expired. Check your system date and time. More details here: curl performs SSL certificate verification by default, using a "bundle" of Certificate Authority (CA) public keys (CA certs). If the default bundle file isn't adequate, you can specify an alternate file using the --cacert option. If this HTTPS server uses a certificate signed by a CA represented in the bundle, the certificate verification probably failed due to a problem with the certificate (it might be expired, or the name might not match the domain name in the URL). If you'd like to turn off curl's verification of the certificate, use the -k (or --insecure) option. The same code it works on my development machine with bb (0.6.5) repl. Could you give me some pointer how to make it work with bb? Thanks!

dharrigan05:11:41

It works for me, on my machine, using bb 0.6.5. My guess is that there is a proxy somewhere in production that is intercepting the requests and doing a MITM?

dharrigan05:11:12

(I copy and pasted your example and ran it without any issues)

yubrshen06:11:29

You're right. In my development environment, it also works. But for the production environment, it doesn't. I wonder how to fix it for the production machine.

pavlosmelissinos07:11:49

Probably not related to babashka. I bet you get the same error if you run the curl command directly from the shell. ssh to the machine and run curl -V. What version is it?

dharrigan07:11:16

Well, you could pass a raw argument to curl, with -k

dharrigan07:11:23

that will make the https request insecure

dharrigan07:11:42

whether or not you're happy with that...

yubrshen15:11:34

Thanks for the helpful tips! I'll try to pass -k as a raw argument. Here is the curl's version, and performing it to another host: Last login: Tue Nov 16 20:18:43 2021 from 10.29.136.22 [[email protected] ~]$ curl --version curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.21 Basic ECC zlib/1.2.7 libidn/1.28 libssh2/1.4.3 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets [[email protected] ~]$ curl "" <html> <head><title>301 Moved Permanently</title></head> <body bgcolor="white"> <center><h1>301 Moved Permanently</h1></center> <hr><center>CloudFront</center> </body> </html> It seems to be host specific. I'll try to do command line with the host of my interest. The production machine with the same script, it used to work, but stop working at the end of September.

yubrshen19:11:46

Yes, --insecure in :raw-args works: (curl/get endpoint {:raw-args ["--insecure"]}) Now, I need to understand what the implication of "insecure", to avoid security trouble. Thanks again!

Karol Wójcik09:11:11

I'm trying to use the newest neil, but I'm receiving the following error:

➜  frisco-react git:(master) neil help   
----- Error --------------------------------------------------------------------
Type:     java.nio.file.NoSuchFileException
Message:  /home/fierycod/.m2/repository/borkdude/rewrite-edn/0.0.2/rewrite-edn-0.0.2.jar
Location: 13:1
I'm sure this is problem with deps caching and I'm curious if there is some way to resolve it once and forever.

borkdude09:11:58

did you wipe your m2 while not wiping .cpcache folders?

Karol Wójcik10:11:23

Are there global .cpcaches?

borkdude10:11:54

~/.clojure/.cpcache

borkdude10:11:01

this is where bb saves all the invocations

Karol Wójcik10:11:50

Thank you so much

borkdude10:11:13

I tried running markdown-clj with babashka and it almost worked, barring one small detail which I will PR back to the original repository. https://github.com/babashka/markdown-clj I tried this in my blog and it works well. All markdown-clj tests are also passing.

🤓 1
FiVo10:11:57

Is there a way to dispatch a command with something like shell/sh asynchronously and get the stdout as stream so I can do something with it? I essentially just want it to pipe it back out to stdout.

borkdude10:11:15

@finn.volkel You can use babashka.process with :inherit true or use babashka.tasks/shell

borkdude10:11:04

(require '[babashka.process :as p])
(-> (p/process "ls -la" {:inherit true}) p/check)
(babashka.tasks/shell "ls -la")
That is pretty much equivalent

👍 1
FiVo10:11:18

Awesome, didn't know about the two.

bruno.bonacci10:11:37

The London Clojurians are happy to announce: nbb: ad-hoc scripting for Clojure on Node.js (by Michiel Borkent) https://www.meetup.com/London-Clojurians/events/282138836/

5
bruno.bonacci11:11:49

many thanks to @borkdude for another great tool! 👏:skin-tone-2:

shem11:11:53

i'm trying to feed data to influx but curl gives me this

shem11:11:40

Cannot run program "curl": error=7, Argument list too long

shem11:11:30

the input is a text atom, given as :body

borkdude11:11:01

@shem which OS are you on

borkdude11:11:31

@shem Not sure. You can try to write it to a temp file first and then use (io/file ...) Alternatively you can use java.net.http or org.httpkit.client

shem11:11:12

ok, i'll check these. thanks

borkdude11:11:07

passing an (io/file ..) will make babashka.curl use that option

shem12:11:59

works perfectly!

mike_ananev12:11:01

Hello! I have two files: bb.edn with tasks, script.clj for code used in tasks. How to load script.clj from bb.edn?

borkdude12:11:19

You can do it two ways. Add :paths ["."] in bb.edn and then use :requires ([script]) (use (ns script) at the top).

borkdude12:11:27

Or you can use (load-file "script.clj")

mike_ananev12:11:05

Thank, you. load-file works.

borkdude12:11:38

I wondered, did you already give the presentation at the meetup?

mike_ananev12:11:25

The meetup did not take place because of the covid. To make a reference I'm writing an article about babashka in Devops pipelines in a bank. I send it to PR department at the end of this week. When article will be published on behalf of bank I'll send you a link.

borkdude12:11:27

Thank you :)

borkdude12:11:44

New blog post: making markdown-clj babashka compatible. https://blog.michielborkent.nl/markdown-clj-babashka-compatible.html

😎 3
borkdude 1
heow13:11:40

great job!

borkdude14:11:53

Now it also works with #nbb:

$ nbb -cp src/clj:src/cljc:src/cljs -e "(require '[markdown.core :as md]) (md/md->html \"# 100\")"
"<h1>100</h1>"

borkdude18:11:43

markdown-clj on clojars now works with babashka and nbb: https://clojars.org/markdown-clj/versions/1.10.7

Jacob Rosenzweig20:11:49

Does babashka have a concept of a main function? I see alot of examples define a function and then invoke said function at the end of a script.

Jacob Rosenzweig20:11:49

I'm writing a bunch of aws-cli abstractions and they're essentially CLI scripts for me to run. Just want to know what the idiomatic way of doing that would be.

borkdude20:11:19

yes, it has. you can invoke any function using bb -m foo/bar or just foo -m foo if you want to include foo/-main

borkdude20:11:49

usually you will put those in bb.edn so you can just write bb foo

borkdude20:11:40

but it's also fine to just run immediately when running bb foo.clj the pattern for this is: https://book.babashka.org/#main_file

borkdude20:11:18

(when (= *file* (System/getProperty "babashka.file"))
  (apply -main *command-line-args*))

👍 1
Jacob Rosenzweig21:11:50

That worked. Another dumb question but I tried adding a dep to the deps.edn but I can't seem to import it when I run my script via bb /src/org/script.clj

Jacob Rosenzweig21:11:55

It can't find the namespace of the package

Jacob Rosenzweig21:11:40

E.g.

{:paths ["src" "resources"]
 :deps {org.clojure/clojure {:mvn/version "1.10.3"}
        com.cognitect.aws/api {:mvn/version "0.8.524"}
        com.cognitect.aws/endpoints {:mvn/version "1.1.12.110"}
        com.cognitect.aws/s3 {:mvn/version "814.2.991.0"}}
 :aliases
 {:build {:deps {io.github.seancorfield/build-clj
                 {:git/tag "v0.4.0" :git/sha "54e39ae"}}
          :ns-default build}
  :test {:extra-paths ["test"]
         :extra-deps {org.clojure/test.check {:mvn/version "1.1.0"}
                      io.github.cognitect-labs/test-runner
                      {:git/tag "v0.5.0" :git/sha "48c3c67"}}}}}
And my ns import:
(ns org.s3-commands
  (:require 
   [clojure.java.shell :refer [sh]]
   [clojure.tools.cli :refer [parse-opts]]
   [cognitect.aws.client.api :as aws]))

borkdude22:11:35

@U02313K7TSL For libraries you're going to use in babashka, put those in bb.edn

borkdude22:11:50

The cognitect aws-api library isn't compatible with babashka unfortunately. For babashka you will need to use https://github.com/babashka/pod-babashka-aws

borkdude22:11:16

If you want to share all top level libraries from deps.edn in bb.edn , you can put this in bb.edn:

{:deps {current/project {:local/root "."}}}

Jacob Rosenzweig22:11:43

That's all great info. I think I'm going to give this another go when I have more time to burn. Thank you. 🙂

borkdude20:11:40

Emacs highlighting tip for a babashka shebang script: https://twitter.com/borkdude/status/1461060105722552321

vlad_poh20:11:43

Trying to use Babashka on a server at work

(require '[babashka.pods :as pods])
(pods/load-pod 'org.babashka/mssql "0.0.8")
(require '[pod.babashka.mssql :as sql])
(def db {:dbtype "mssql" :host "localhost" :dbname "widgets" :integratedSecurity true})
(sql/execute! db "select * from dbo.users")
and i get the following error
; clojure.lang.ExceptionInfo: Resource bundle not found com.microsoft.sqlserver.jdbc.SQLServerResource, locale en_US. Register the resource bundle using the option -H:IncludeResourceBundles=com.microsoft.sqlserver.jdbc.SQLServerResource.
Not sure how to proceed. Any tips?

borkdude20:11:36

I'm not an expert on mssql, but perhaps @U08JKUHA9 can weigh in here?

borkdude20:11:00

We could try to add the resource bundle like the error suggests

vlad_poh20:11:39

to add some more clarity. It's a windows server 2016 box with 4GB of ram and no jdk or jre installed.

isak20:11:30

Oh I think I remember trying this and it worked on windows via WSL, but not otherwise

borkdude21:11:00

in your case the integrated security didn't work, right?

isak21:11:03

Otherwise, I didn't really expect JDBC to work without a lot of caveats/effort on windows, especially with integrated authentication, so I just made a pod in C# to make it work more easily for scripting: https://github.com/xledger/pod_sql_server

isak21:11:54

You may be right, it was a while ago I tried the official pod

borkdude21:11:40

@U06GMV0B0 The SQL pod is built in this repo: https://github.com/babashka/babashka-sql-pods I'd be happy to receive PRs but I'm not able to test properly I think the edge case you run into.

👍 1
borkdude21:11:32

The builds for Windows are done in appveyor.yml

borkdude22:11:16

If you want to share all top level libraries from deps.edn in bb.edn , you can put this in bb.edn:

{:deps {current/project {:local/root "."}}}