this is a pallet (https://github.com/pallet) question. At the moment I try to use more specific group specs for my lift operations.
I try to lift just one specific node (e.g. a new one) in my group:
(api/lift
{jira-group #{meissa-jira-large}}
:user my-user
:compute provider
:phase [:init])
as described here: http://palletops.com/pallet/api/0.8/pallet.api.html#var-lift
But unfortunately I get
"group-spec error: Map did not contain expected path [:group-name]."
The more unspecific group spec is working fine:
(api/lift
jira-group
:user my-user
:compute provider
:phase [:init])
Any idea, what I'm doing wrong?
Best regards,
Michael
PS: jira-group is defined as follows:
(def ^:dynamic jira-group
(api/group-spec
"jira-group"
:extends [(config/with-config meissa-config/config)
init-pallet/with-init
hardening/with-hardening
hosteurope/with-hosteurope
jira/with-jira]
)
)
(api/lift
{:groups #{jira-group} :targets #{meissa-jira-large}}
:user my-user
:compute provider
:phase [:init])
works :-)
Related
How do I resolve a keyword to a schema from the default Malli registry? I seem unable to look up a value in the registry in order to walk it.
(def registry
(atom {}))
(defn register! [type ?schema]
(swap! registry assoc type ?schema))
;; Combine the default registry with our own mutable registry.
(mreg/set-default-registry!
(mreg/composite-registry
(mreg/fast-registry (malli/default-schemas))
(mreg/mutable-registry registry)))
(register! :db/kasse
[:map
[:id [:int {:primary-key true :db-generated true}]]
[:odlingsplats [:string {:foreign-key "odlingsplatser"}]]
[:diameter_m :int]
[:djup_m :int]
[:volym_m2 [:int {:db-generated true}]]])
(malli/walk
:db/kasse
(malli/schema-walker identity))
;; => :db/kasse
I've tried wrapping :db/kasse in different functions from malli but none seem to do the lookup and malli/-lookup is private. Just running (:db/kasse malli/default-registry) does not work either. Using malli/schema seems like the obvious choice but it seemingly has no effect.
(malli/walk
(malli/schema :db/kasse)
(malli/schema-walker identity))
;; => :db/kasse
Calling malli/deref was the answer:
(malli/walk
(malli/deref :db/kasse)
(malli/schema-walker identity))
;; => [:map [:id [:int {:primary-key true, :db-generated true}]] [:odlingsplats [:postgres/string {:foreign-key "odli\
ngsplatser"}]] [:diameter_m :int] [:djup_m :int] [:volym_m2 [:int {:db-generated true}]] [:namn {:optional true} [:po\
stgres/string {:db-generated true}]]]
Thank you to ikitommi at the Clojurians slack for providing the answer. He also provided an explanation as to why the library works this way:
The :db/kasse returned is a Malli Schema instance, it’s print output is just the form, so looks like keyword. It’s type is :malli.core/schema, which is the internal eager reference, like a Var in Clojure. If you want to get the schema behind it, you can m/deref it. But, calling m/validate on :db/kasse works too. the :malli.core/schema forwards the calls to the actual instance, like Var.
Most examples for JWT token use clj-time which is now deprecated in favor of native java.time. I'm trying to use java-time along with buddy to sign/verify tokens but I'm stuck trying to pass the exp claim to my token. Here's an example of what I have:
(ns test-app.test-ns
(:require
[buddy.sign.jwt :as jwt]
[buddy.auth.backends.token :as bat]
[java-time :as t]))
(def secret "myfishysecret")
(def auth-backend (bat/jws-backend {:secret secret
:options {:alg :hs512}}))
(def token (jwt/sign {:user "slacker"
:exp (t/plus (t/local-date-time) (t/seconds 60))
} secret {:alg :hs512}))
When tyring to test if I can unsign the token
(jwt/unsign token secret {:alg :hs512})
I get the following error:
Execution error (JsonGenerationException) at
cheshire.generate/generate (generate.clj:152). Cannot JSON encode
object of class: class java.time.LocalDateTime:
2021-01-22T12:37:52.206456
So, I tried to pass the same by encapsulating the call to (t/plus ...) inside a (str) but then I get this error:
class java.lang.String cannot be cast to class java.lang.Number
(java.lang.String and java.lang.Number are in module java.base of
loader 'bootstrap')
So, I'm stuck since I don't really know how to generate a valid exp number value using java-time (according to this question, format should be in seconds since the epoch). Older examples using clj-time just passed the exp claim value as
(clj-time.core/plus (clj-time.core/now) (clj-time.core/seconds 3600))
Any help is highly appreciated.
EDIT: Alan Thompson's answer works perfectly, for what's worth this would be the equivalent using the java-time wrapper:
(t/plus (t/instant) (t/seconds 60))
Here are 2 ways to do it:
(let [now+60 (-> (Instant/now)
(.plusSeconds 60))
now+60-unixsecs (.getEpochSecond now+60)]
(jwt/sign {:user "slacker" :exp now+60 } secret {:alg :hs512})
(jwt/sign {:user "slacker" :exp now+60-unixsecs} secret {:alg :hs512}))
and we have the now results:
now+60 => <#java.time.Instant #object[java.time.Instant 0x7ce0054c "2021-01-22T19:04:51.905586442Z"]>
now+60-unixsecs => <#java.lang.Long 1611342291>
So you have your choice of methods. It appears that buddy knows how to convert from a java.time.Instant, so going all the way to unix-seconds is unnecessary.
You may also be interested in this library of helper and convenience functions for working with java.time.
Here's my clojure data:
{:local/contacts-capability contacts-capability}
pr-str gives me this:
#:local{:contacts-capability #uuid "00000000-0000-4000-8000-000000000003"}
I pass this over to clojurescript and when I read it, I get:
Uncaught Error: Could not find tag parser for :local in ("simpleArk.arkRecord.Ark-record" "uuid/Timestamp" "inst" "js" "queue" "uuid" "miMap/MI-map" "tailrecursion.priority-map" "simpleArk.rolonRecord.Rolon-record")
at Function.cljs.reader.reader_error.cljs$core$IFn$_invoke$arity$variadic (reader.cljs:71)
at cljs$reader$reader_error (reader.cljs:69)
at cljs$reader$maybe_read_tagged_type (reader.cljs:613)
at cljs$reader$read_dispatch (reader.cljs:260)
at cljs$reader$read_delimited_list (reader.cljs:233)
at cljs$reader$read_vector (reader.cljs:280)
at cljs$reader$read (reader.cljs:464)
at cljs$reader$read_string (reader.cljs:477)
at console$client$display_property (client.cljs:366)
at console$client$explore_BANG_ (client.cljs:404)
Dependencies:
[org.clojure/clojure "1.9.0-alpha10" :scope "provided"]
[org.clojure/clojurescript "1.9.198"]
In Clojure 1.9, these two maps represent the same data:
#:foo{:bar 1 :baz 2}
{:foo/bar 1 :foo/baz 2}
If all the keys in the map are keywords and have the same namespace, the former is a shorter way to represent the latter. See here: http://dev.clojure.org/jira/browse/CLJ-1910
I suspect that this is currently not supported in ClojureScript.
The problem is with using such an old version of clojure script. Later versions do fix this. See https://github.com/ptaoussanis/sente/issues/241
This routes works in Luminus/Compojure/Ring app
(GET "/page/:id" [id] (home-page id))
but this doesn't and throws an error:
(GET ["/page/:id" :id #"^[1-9]\d{0,2}$"] [id] (home-page id))
The error is "Page not found", even when I go to the same url "page/2"
Remove the anchors ^ $, which are redundant: apparently the keyword (:id) specifies which part of the route string (":id") is to be matched by the regex, in entirety.
The answer to why this is so is likely found in the implementation of this logic, Clout.
I want to automatically generate the JavaDoc using buildr. I tried using the approach suggested in the official Guide PDF from the Homepage. However, it did not work.
define "SharedState_ebBP", :layout=>eclipse_layout do
project.version = VERSION_NUMBER
project.group = GROUP
doc :windowtitle => "Abandon All Hope, Ye Who Enter Here", :private => true
end
The error message is as follows:
RuntimeError: Don't know how to generate documentation from windowtitleAbandon ......
The correct syntax for setting the window title is
doc.using(:windowtitle => "Abandon All Hope", :private => true)
and with end on a line by itself. However that in and of itself does not cause the doc task to get run automatically.
To automatically build the JavaDoc when you run buildr simply add to the end of your buildfile:
task :default => [:build, :doc]
This redefines the default task to first build and then doc.