Coder Social home page Coder Social logo

module.ataraxy's People

Contributors

scottlowe avatar weavejester avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

module.ataraxy's Issues

Some example with middleware.buddy?

I can't seem to get it to work.

{:duct.core/project-ns   foo
 :duct.module/ataraxy    {"/" ^:auth/basic[:index]}
 :foo.handler/index      {}
 :duct.middleware.buddy/authentication
 {:backend :basic
  :realm   "Example"
  :authfn  #ig/ref :example.auth/basic}
 :example.auth/basic {}}

Thanks in advance.

Instrumenting coercer specs raises an exception when running reset

If you define a coercer and put a spec on it, then instrumenting the specs in your project with a call to (clojure.spec.test.alpha/instrument) and then calling (reset) causes duct's ataraxy router to blow up with the following exception:

It appears this might be due to compile and clojure.tools.namespace.repl/refresh.

A workaround is to run (instrument) after the (reset), though this isn't a fully general solution as it will for example mean instrumentation doesn't happen during system init... though integrants spec support may reduce the need for that.

3. Unhandled clojure.lang.ExceptionInfo
   Error on key :duct.router/ataraxy when building system
   { ,,, ,,,}
                 core.cljc:  285  integrant.core$build_exception/invokeStatic
                 core.cljc:  284  integrant.core$build_exception/invoke
                 core.cljc:  296  integrant.core$try_build_action/invokeStatic
                 core.cljc:  293  integrant.core$try_build_action/invoke
                 core.cljc:  302  integrant.core$build_key/invokeStatic
                 core.cljc:  298  integrant.core$build_key/invoke
                  core.clj: 2639  clojure.core/partial/fn
             protocols.clj:  168  clojure.core.protocols/fn
             protocols.clj:  124  clojure.core.protocols/fn
             protocols.clj:   19  clojure.core.protocols/fn/G
             protocols.clj:   31  clojure.core.protocols/seq-reduce
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   13  clojure.core.protocols/fn/G
                  core.clj: 6808  clojure.core/reduce
                  core.clj: 6790  clojure.core/reduce
                 core.cljc:  325  integrant.core$build/invokeStatic
                 core.cljc:  305  integrant.core$build/invoke
                 core.cljc:  460  integrant.core$resume/invokeStatic
                 core.cljc:  450  integrant.core$resume/invoke
                 core.cljc:  456  integrant.core$resume/invokeStatic
                 core.cljc:  450  integrant.core$resume/invoke
                  repl.clj:   42  integrant.repl/resume-system/fn
                  repl.clj:   24  integrant.repl/build-system
                  repl.clj:   22  integrant.repl/build-system
                  repl.clj:   41  integrant.repl/resume-system
                  repl.clj:   40  integrant.repl/resume-system
                  repl.clj:   77  integrant.repl/resume/fn
                  AFn.java:  154  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  Var.java:  308  clojure.lang.Var/alterRoot
                  core.clj: 5510  clojure.core/alter-var-root
                  core.clj: 5505  clojure.core/alter-var-root
               RestFn.java:  425  clojure.lang.RestFn/invoke
                  repl.clj:   75  integrant.repl/resume
                  repl.clj:   71  integrant.repl/resume
                  Var.java:  380  clojure.lang.Var/invoke
                  repl.clj:  100  clojure.tools.namespace.repl/do-refresh
                  repl.clj:   82  clojure.tools.namespace.repl/do-refresh
                  repl.clj:  145  clojure.tools.namespace.repl/refresh
                  repl.clj:  128  clojure.tools.namespace.repl/refresh
               RestFn.java:  421  clojure.lang.RestFn/invoke
                  repl.clj:   84  integrant.repl/reset
                  repl.clj:   82  integrant.repl/reset
                   dev.clj:  128  zib.dev/reset
                   dev.clj:  121  zib.dev/reset
                   dev.clj:  122  zib.dev/reset
                   dev.clj:  121  zib.dev/reset
                      REPL: 1179  zib.dev/eval83157
                      REPL: 1179  zib.dev/eval83157
             Compiler.java: 7178  clojure.lang.Compiler/eval
             Compiler.java: 7133  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
                  main.clj:  390  clojure.main/repl/read-eval-print/fn
                  main.clj:  390  clojure.main/repl/read-eval-print
                  main.clj:  413  clojure.main/repl/fn
                  main.clj:  413  clojure.main/repl
                  main.clj:  316  clojure.main/repl
               RestFn.java:  137  clojure.lang.RestFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj:  660  clojure.core/apply
                regrow.clj:   18  refactor-nrepl.ns.slam.hound.regrow/wrap-clojure-repl/fn
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87  clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj: 1973  clojure.core/with-bindings*
                  core.clj: 1973  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   85  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   55  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  222  clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
    interruptible_eval.clj:  190  clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
                  AFn.java:   22  clojure.lang.AFn/run
   ThreadPoolExecutor.java: 1149  java.util.concurrent.ThreadPoolExecutor/runWorker
   ThreadPoolExecutor.java:  624  java.util.concurrent.ThreadPoolExecutor$Worker/run
               Thread.java:  748  java.lang.Thread/run
2. Caused by java.lang.ExceptionInInitializerError
   (No message)
NativeConstructorAccessorImpl.java:   -2  sun.reflect.NativeConstructorAccessorImpl/newInstance0
NativeConstructorAccessorImpl.java:   62  sun.reflect.NativeConstructorAccessorImpl/newInstance
DelegatingConstructorAccessorImpl.java:   45  sun.reflect.DelegatingConstructorAccessorImpl/newInstance
          Constructor.java:  423  java.lang.reflect.Constructor/newInstance
                Class.java:  442  java.lang.Class/newInstance
             Compiler.java: 4996  clojure.lang.Compiler$ObjExpr/eval
             Compiler.java: 7177  clojure.lang.Compiler/eval
             Compiler.java: 7133  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
                  core.clj:  269  ataraxy.core/compile
                  core.clj:  263  ataraxy.core/compile
                  core.clj:  335  ataraxy.core/handler
                  core.clj:  319  ataraxy.core/handler
               ataraxy.clj:   33  duct.router.ataraxy/eval68787/fn
              MultiFn.java:  234  clojure.lang.MultiFn/invoke
                 core.cljc:  377  integrant.core$eval15710$fn__15711/invoke
              MultiFn.java:  244  clojure.lang.MultiFn/invoke
                 core.cljc:  463  integrant.core$resume$fn__15753/invoke
                 core.cljc:  294  integrant.core$try_build_action/invokeStatic
                 core.cljc:  293  integrant.core$try_build_action/invoke
                 core.cljc:  302  integrant.core$build_key/invokeStatic
                 core.cljc:  298  integrant.core$build_key/invoke
                  core.clj: 2639  clojure.core/partial/fn
             protocols.clj:  168  clojure.core.protocols/fn
             protocols.clj:  124  clojure.core.protocols/fn
             protocols.clj:   19  clojure.core.protocols/fn/G
             protocols.clj:   31  clojure.core.protocols/seq-reduce
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   13  clojure.core.protocols/fn/G
                  core.clj: 6808  clojure.core/reduce
                  core.clj: 6790  clojure.core/reduce
                 core.cljc:  325  integrant.core$build/invokeStatic
                 core.cljc:  305  integrant.core$build/invoke
                 core.cljc:  460  integrant.core$resume/invokeStatic
                 core.cljc:  450  integrant.core$resume/invoke
                 core.cljc:  456  integrant.core$resume/invokeStatic
                 core.cljc:  450  integrant.core$resume/invoke
                  repl.clj:   42  integrant.repl/resume-system/fn
                  repl.clj:   24  integrant.repl/build-system
                  repl.clj:   22  integrant.repl/build-system
                  repl.clj:   41  integrant.repl/resume-system
                  repl.clj:   40  integrant.repl/resume-system
                  repl.clj:   77  integrant.repl/resume/fn
                  AFn.java:  154  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  Var.java:  308  clojure.lang.Var/alterRoot
                  core.clj: 5510  clojure.core/alter-var-root
                  core.clj: 5505  clojure.core/alter-var-root
               RestFn.java:  425  clojure.lang.RestFn/invoke
                  repl.clj:   75  integrant.repl/resume
                  repl.clj:   71  integrant.repl/resume
                  Var.java:  380  clojure.lang.Var/invoke
                  repl.clj:  100  clojure.tools.namespace.repl/do-refresh
                  repl.clj:   82  clojure.tools.namespace.repl/do-refresh
                  repl.clj:  145  clojure.tools.namespace.repl/refresh
                  repl.clj:  128  clojure.tools.namespace.repl/refresh
               RestFn.java:  421  clojure.lang.RestFn/invoke
                  repl.clj:   84  integrant.repl/reset
                  repl.clj:   82  integrant.repl/reset
                   dev.clj:  128  zib.dev/reset
                   dev.clj:  121  zib.dev/reset
                   dev.clj:  122  zib.dev/reset
                   dev.clj:  121  zib.dev/reset
                      REPL: 1179  zib.dev/eval83157
                      REPL: 1179  zib.dev/eval83157
             Compiler.java: 7178  clojure.lang.Compiler/eval
             Compiler.java: 7133  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
                  main.clj:  390  clojure.main/repl/read-eval-print/fn
                  main.clj:  390  clojure.main/repl/read-eval-print
                  main.clj:  413  clojure.main/repl/fn
                  main.clj:  413  clojure.main/repl
                  main.clj:  316  clojure.main/repl
               RestFn.java:  137  clojure.lang.RestFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj:  660  clojure.core/apply
                regrow.clj:   18  refactor-nrepl.ns.slam.hound.regrow/wrap-clojure-repl/fn
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87  clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj: 1973  clojure.core/with-bindings*
                  core.clj: 1973  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   85  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   55  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  222  clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
    interruptible_eval.clj:  190  clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
                  AFn.java:   22  clojure.lang.AFn/run
   ThreadPoolExecutor.java: 1149  java.util.concurrent.ThreadPoolExecutor/runWorker
   ThreadPoolExecutor.java:  624  java.util.concurrent.ThreadPoolExecutor$Worker/run
               Thread.java:  748  java.lang.Thread/run
1. Caused by java.lang.IllegalArgumentException
   No matching ctor found for class
   clojure.spec.test.alpha$spec_checking_fn$fn__3026
            Reflector.java:  237  clojure.lang.Reflector/invokeConstructor
           LispReader.java: 1307  clojure.lang.LispReader$EvalReader/invoke
           LispReader.java:  843  clojure.lang.LispReader$DispatchReader/invoke
           LispReader.java:  275  clojure.lang.LispReader/read
           LispReader.java:  206  clojure.lang.LispReader/read
           LispReader.java:  195  clojure.lang.LispReader/read
                   RT.java: 1873  clojure.lang.RT/readString
                   RT.java: 1868  clojure.lang.RT/readString
                      REPL: 1179  zib.dev/eval83246
NativeConstructorAccessorImpl.java:   -2  sun.reflect.NativeConstructorAccessorImpl/newInstance0
NativeConstructorAccessorImpl.java:   62  sun.reflect.NativeConstructorAccessorImpl/newInstance
DelegatingConstructorAccessorImpl.java:   45  sun.reflect.DelegatingConstructorAccessorImpl/newInstance
          Constructor.java:  423  java.lang.reflect.Constructor/newInstance
                Class.java:  442  java.lang.Class/newInstance
             Compiler.java: 4996  clojure.lang.Compiler$ObjExpr/eval
             Compiler.java: 7177  clojure.lang.Compiler/eval
             Compiler.java: 7133  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
                  core.clj:  269  ataraxy.core/compile
                  core.clj:  263  ataraxy.core/compile
                  core.clj:  335  ataraxy.core/handler
                  core.clj:  319  ataraxy.core/handler
               ataraxy.clj:   33  duct.router.ataraxy/eval68787/fn
              MultiFn.java:  234  clojure.lang.MultiFn/invoke
                 core.cljc:  377  integrant.core$eval15710$fn__15711/invoke
              MultiFn.java:  244  clojure.lang.MultiFn/invoke
                 core.cljc:  463  integrant.core$resume$fn__15753/invoke
                 core.cljc:  294  integrant.core$try_build_action/invokeStatic
                 core.cljc:  293  integrant.core$try_build_action/invoke
                 core.cljc:  302  integrant.core$build_key/invokeStatic
                 core.cljc:  298  integrant.core$build_key/invoke
                  core.clj: 2639  clojure.core/partial/fn
             protocols.clj:  168  clojure.core.protocols/fn
             protocols.clj:  124  clojure.core.protocols/fn
             protocols.clj:   19  clojure.core.protocols/fn/G
             protocols.clj:   31  clojure.core.protocols/seq-reduce
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   13  clojure.core.protocols/fn/G
                  core.clj: 6808  clojure.core/reduce
                  core.clj: 6790  clojure.core/reduce
                 core.cljc:  325  integrant.core$build/invokeStatic
                 core.cljc:  305  integrant.core$build/invoke
                 core.cljc:  460  integrant.core$resume/invokeStatic
                 core.cljc:  450  integrant.core$resume/invoke
                 core.cljc:  456  integrant.core$resume/invokeStatic
                 core.cljc:  450  integrant.core$resume/invoke
                  repl.clj:   42  integrant.repl/resume-system/fn
                  repl.clj:   24  integrant.repl/build-system
                  repl.clj:   22  integrant.repl/build-system
                  repl.clj:   41  integrant.repl/resume-system
                  repl.clj:   40  integrant.repl/resume-system
                  repl.clj:   77  integrant.repl/resume/fn
                  AFn.java:  154  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  Var.java:  308  clojure.lang.Var/alterRoot
                  core.clj: 5510  clojure.core/alter-var-root
                  core.clj: 5505  clojure.core/alter-var-root
               RestFn.java:  425  clojure.lang.RestFn/invoke
                  repl.clj:   75  integrant.repl/resume
                  repl.clj:   71  integrant.repl/resume
                  Var.java:  380  clojure.lang.Var/invoke
                  repl.clj:  100  clojure.tools.namespace.repl/do-refresh
                  repl.clj:   82  clojure.tools.namespace.repl/do-refresh
                  repl.clj:  145  clojure.tools.namespace.repl/refresh
                  repl.clj:  128  clojure.tools.namespace.repl/refresh
               RestFn.java:  421  clojure.lang.RestFn/invoke
                  repl.clj:   84  integrant.repl/reset
                  repl.clj:   82  integrant.repl/reset
                   dev.clj:  128  zib.dev/reset
                   dev.clj:  121  zib.dev/reset
                   dev.clj:  122  zib.dev/reset
                   dev.clj:  121  zib.dev/reset
                      REPL: 1179  zib.dev/eval83157
                      REPL: 1179  zib.dev/eval83157
             Compiler.java: 7178  clojure.lang.Compiler/eval
             Compiler.java: 7133  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
                  main.clj:  390  clojure.main/repl/read-eval-print/fn
                  main.clj:  390  clojure.main/repl/read-eval-print
                  main.clj:  413  clojure.main/repl/fn
                  main.clj:  413  clojure.main/repl
                  main.clj:  316  clojure.main/repl
               RestFn.java:  137  clojure.lang.RestFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj:  660  clojure.core/apply
                regrow.clj:   18  refactor-nrepl.ns.slam.hound.regrow/wrap-clojure-repl/fn
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87  clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj: 1973  clojure.core/with-bindings*
                  core.clj: 1973  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   85  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   55  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  222  clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
    interruptible_eval.clj:  190  clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
                  AFn.java:   22  clojure.lang.AFn/run
   ThreadPoolExecutor.java: 1149  java.util.concurrent.ThreadPoolExecutor/runWorker
   ThreadPoolExecutor.java:  624  java.util.concurrent.ThreadPoolExecutor$Worker/run
               Thread.java:  748  java.lang.Thread/run

Buddy authentication middleware not working

I am not able to get authentication to work with the example below. Basically when I hithttp :3000 it returns 200

Full config.edn below:

{:duct.core/project-ns duct-service
 :duct.core/environment :production

 :duct.module/logging {}
 :duct.module.web/api {}

 :duct-service.middleware/jws-auth
 {:backend :jws
  :secret "somesecret"}

 :duct.module/ataraxy
 {[:get "/"]
  ^:jws-auth [:entries/list]}

 [:duct.handler.static/ok :duct-service.handler.entries/list]
 {:body {:entries "hello"}}
 }

jws-auth middleware is a direct copy of the buddy middleware with some println added:

(ns duct-service.middleware
  (:require [buddy.auth.middleware :as buddy]
            [buddy.auth.backends :as backend]
            [integrant.core :as ig]))

(def backends
  {:basic   backend/basic
   :session (fn [_] (backend/session))
   :token   backend/token
   :jws     backend/jws
   :jwe     backend/jwe})

(defn wrap-debugger [handler]
  (fn [request]
    (println "identity:" (:identity request))
    (handler request)))

(defmethod ig/init-key ::jws-auth
  [_ {:keys [backend] :as config}]
  (let [backend-fn (backends backend)
        config     (dissoc config :backend)
        _ (println config backend-fn)]
    (fn [handler]
      (-> handler
          wrap-debugger
          (buddy/wrap-authentication (backend-fn config))))))

correct usage of `:ataraxy.error/failed-spec`

Here is a working example start from [module.ataraxy 0.17]. May I know using :example instead of :my.handler/example is intentional or not?

config.edn

{:duct.module/ataraxy
 {[:get "/example" {body :params}] [:example body]}
 :duct.router/ataraxy
 {:handlers {:ataraxy.error/failed-spec #ig/ref :my.handler/error}}
 :my.handler/error {}}

my.handler/example.clj

(defmethod ig/init-key :my.handler/example [_ options]
  (fn [{[_ body] :ataraxy/result}]
    [::response/ok (io/resource "my/handler/example/example.html")]))

(defmethod ataraxy/result-spec :example [_]
  (s/tuple any? :my.spec/example))

my.handler/error.clj

(defmethod ig/init-key :my.handler/error [_ options]
  (fn [{[_ error] :ataraxy/result}]
    (let [messages (map f/format
                        (-> error :clojure.spec.alpha/problems))]
      [::response/bad-request {:messages messages}])))

Being explicit & switching off infering keys for handlers/middlewares

I wonder if it might be possible to add an option e.g. :fully-qualified-keys true to turn key inference off in the ataraxy router config.

The reason I'd like this is when refactoring things you want to do a find/replace on the keys throughout the project, but because the keys in the router config are aliased, they get missed. Recently I was helping a new developer get up to speed and they'd done this, but this key got missed, and I found myself having to explain this, as an extra unintuitive convention, in addition to clojure's :: prefix and aliases via :as, as things to watch out for.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.