borgeby / jarl

Jarl is an Open Policy Agent (OPA) evaluator for the JVM and Javascript, written in Clojure(Script)
Apache License 2.0
41 stars 5 forks source link

Babashka: Unable to resolve classname: java.security.KeyFactory (java.security.Key) #176

Open srenatus opened 1 year ago

srenatus commented 1 year ago

I'd like to parse some plan JSON into the structures that Jarl provides -- without actually evaluating it. However, it fails:

bb.edn

{:deps {boregby/jarl 
         {:git/url "https://github.com/borgeby/jarl.git" 
          :deps/root "core" 
          :sha "f20a80c599e0a482900ea3889a0b2fa3eab39681"}}}

test

#!/usr/bin/env -S bb
(require '[babashka.process :refer [process shell]]
         '[jarl.parser :as parser])

(defn plan []
  (-> (apply shell {:out :string} "irdump" "-f" *command-line-args*)
      :out))

(let [plan-out (plan)
      p0 (parser/parse-json plan-out)]
  (prn p0))

I don't know if that script would actually work, because it fails early:

% ./test foo.rego x/p  
----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: java.security.KeyFactory
Location: /Users/stephan/.gitlibs/libs/boregby/jarl/f20a80c599e0a482900ea3889a0b2fa3eab39681/core/src/main/cljc/jarl/builtins/crypto.cljc:9:3

----- Context ------------------------------------------------------------------
 5:             #?(:clj  [clojure.string :as str])
 6:             #?(:cljs [goog.crypt :as crypt]))
 7:   #?(:cljs
 8:      (:import (goog.crypt Md5 Sha1 Sha256 Sha512 Hmac)))
 9:   #?(:clj
      ^--- Unable to resolve classname: java.security.KeyFactory
10:      (:import (javax.crypto.spec SecretKeySpec)
11:               (javax.crypto Mac)
12:               (java.security MessageDigest KeyFactory Key)
13:               (org.jose4j.jwk JsonWebKey$Factory JsonWebKey$OutputControlLevel)
14:               (java.security.spec PKCS8EncodedKeySpec)

----- Stack trace --------------------------------------------------------------
jarl.builtins.crypto   - /Users/stephan/.gitlibs/libs/boregby/jarl/f20a80c599e0a482900ea3889a0b2fa3eab39681/core/src/main/cljc/jarl/builtins/crypto.cljc:9:3
jarl.builtins.registry - /Users/stephan/.gitlibs/libs/boregby/jarl/f20a80c599e0a482900ea3889a0b2fa3eab39681/core/src/main/cljc/jarl/builtins/registry.cljc:2:3
jarl.parser            - /Users/stephan/.gitlibs/libs/boregby/jarl/f20a80c599e0a482900ea3889a0b2fa3eab39681/core/src/main/cljc/jarl/parser.cljc:2:3
user                   - /Users/stephan/Scratch/bb-diff/./test:2:1
srenatus commented 1 year ago

Running with the latest snapshot, which has

Add java.security.KeyFactory, java.security.spec.PKCS8EncodedKeySpec, java.net.URISyntaxException

in its CHANGELOG, I do get past that, but hit another error:

----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  Unable to resolve classname: java.security.Key
Location: /Users/stephan/.gitlibs/libs/boregby/jarl/f20a80c599e0a482900ea3889a0b2fa3eab39681/core/src/main/cljc/jarl/builtins/crypto.cljc:9:3

----- Context ------------------------------------------------------------------
 5:             #?(:clj  [clojure.string :as str])
 6:             #?(:cljs [goog.crypt :as crypt]))
 7:   #?(:cljs
 8:      (:import (goog.crypt Md5 Sha1 Sha256 Sha512 Hmac)))
 9:   #?(:clj
      ^--- Unable to resolve classname: java.security.Key
10:      (:import (javax.crypto.spec SecretKeySpec)
11:               (javax.crypto Mac)
12:               (java.security MessageDigest KeyFactory Key)
13:               (org.jose4j.jwk JsonWebKey$Factory JsonWebKey$OutputControlLevel)
14:               (java.security.spec PKCS8EncodedKeySpec)

----- Stack trace --------------------------------------------------------------
jarl.builtins.crypto   - /Users/stephan/.gitlibs/libs/boregby/jarl/f20a80c599e0a482900ea3889a0b2fa3eab39681/core/src/main/cljc/jarl/builtins/crypto.cljc:9:3
jarl.builtins.registry - /Users/stephan/.gitlibs/libs/boregby/jarl/f20a80c599e0a482900ea3889a0b2fa3eab39681/core/src/main/cljc/jarl/builtins/registry.cljc:2:3
jarl.parser            - /Users/stephan/.gitlibs/libs/boregby/jarl/f20a80c599e0a482900ea3889a0b2fa3eab39681/core/src/main/cljc/jarl/parser.cljc:2:3
srenatus commented 1 year ago

Looking into this a bit more, I think my premise was flawed. There's not much to operate on in jarl, as the plan is basically parsed into functions operating on state, am I right?

anderseknert commented 1 year ago

Correct!

srenatus commented 1 year ago

OK so while my original intention was misguided, I believe being able to run Jarl in Babashka would still be kinda cool. Let's keep this open for tracking, shall we?

anderseknert commented 1 year ago

Indeed, that sounds good to me 👍