Fork me on GitHub
#yada
<
2017-01-17
>
stijn09:01:26

@malcolmsparks: did something change between 1.1.45 and 1.2.0 that creates the interceptor-chain for resources?

stijn09:01:52

all my resources that work under 1.1.45 do not get an interceptor-chain under 1.2.0 (and also 1.1.46)

stijn09:01:38

ok, I see the difference

stijn09:01:01

yada 1.2.0 doesn't set an interceptor-chain on resource creation.

stijn09:01:04

but, how is this supposed to work with manipulating the interceptor chain for a set of resources (I walk the bidi routes to update everything that is e.g. under the "/api" endpoint)

malcolmsparks09:01:36

hi @stijn - the rationale for the change is that interceptor chains are part of the processing of a web request with respect to a resource - in upcoming versions of yada resources-as-data will be used for other purposes, so the idea of a single interceptor chain doesn't fit with that model

malcolmsparks09:01:58

But, the logic still allows you to explicitly add an interceptor chain which the handler will respect.

malcolmsparks09:01:34

You'll just have to start with the interceptor chain of your choice (call yada.yada/interceptor-chain with a nil arg), the modify it as you want, then add it to the resource.

malcolmsparks09:01:46

If you look in the code in handler.clj, you'll see how interceptor chains are constructed

malcolmsparks09:01:06

Point is, they're now part of handler logic rather than resource logic

malcolmsparks09:01:48

Sorry about this, it's part of a wider refactoring/refurbishment effort which I've tried hard to keep existing users immune from, but it's not always been easy

malcolmsparks09:01:35

(at least I'm trying to improve yada whilst keeping backward compatibility, in the 0.4.3 -> 1.1 transition it was much more 'move fast and break things')

stijn09:01:15

ok, I see

stijn09:01:07

well, then instead of (yada.resource/insert-interceptor yada.security/authenticate (verify-app-existence apps)) when walking the resources, I should just construct the interceptor chain there?

stijn09:01:59

I need some set of resources to manipulate the context before authentication

stijn09:01:29

or is this no longer the preferred way then?

stijn09:01:50

oh, but I can create a ring handler for that entire set of resources (they fall into one bidi path) and give that handler the interceptor-chain it needs?

stijn09:01:42

that doesn't make sense, what I just said 😛

naartjie12:01:56

1.2.0 doesn't seem to report the body schema validation messages anymore. Is this bug/intentional or something specific to my setup maybe? Let me explain: The resource:

:produces     "application/json"
:methods {:post {:parameters {:body {:field s/Bool}}}
                 ...
                 }
If I make a request with accept: application/json, I just get an empty body 400, if I set accept: text/plain, I get (`Content-Type: text/plain;charset=utf-8`):
Malformed body

{:status 400,
 :error
 {:field (not (instance? java.lang.Boolean "True"))}}

malcolmsparks13:01:51

hi @naartjie - I've had a couple of people point this out - the problem is that yada 1.2.0 only declares text/plain as a format it will render errors in. We've had so many issues with application/json errors (when Cheshire can't render something in the error, so generates its own error instead).

malcolmsparks13:01:47

I think the best course of action would be to restore the original behaviour, but I don't know what we should do when Cheshire fails

naartjie13:01:20

@malcolmsparks I actually prefer the new 1.2.0 way - it makes sense, if you want a JSON response, make it explicit, i.e. in responses. I guess I was just noting it to compare notes and check if I didn't make a mistake with the migration somewhere.

naartjie13:01:54

^^^ but I'm not sure how to code that yet, would need to watch for schema validation errors in :responses 400 I guess.

malcolmsparks13:01:28

yes, for now. Are you thinking of adopting clojure.spec any time soon?

naartjie14:01:16

I would like to yes, but all in due time. I am getting on a bit now, and bleeding edge hurts a lot more than it used to 😜

naartjie14:01:58

What is the plan for yada + spec?

malcolmsparks14:01:01

I've done a proof-of-concept and considering the move to clojure.spec prior to adding more major features - I'll preserve backward compatibility though

mccraigmccraig15:01:18

@malcolmsparks if/when you move to clojure.spec will you do something extra to deal with spec's inability to disallow keys ?

mccraigmccraig15:01:20

i can kinda sorta see why spec doesn't want to deal with disallowing keys, but for validating messages received from the internet i would like to be able to strictly check the schema and forbid anything off piste

dominicm15:01:35

@mccraigmccraig is it not enough to do something like: (s/and (s/keys …) #(= (select-keys % [:a :b :c]) %)) ?

mccraigmccraig15:01:35

looks like https://github.com/metosin/spec-tools aims to support disallowing extra keys

dominicm15:01:39

Yeah, they're doing some crazy stuff in there. I personally feel like this is a problem for the spec community to solve at large.

malcolmsparks15:01:09

There are 2 aspects to a possible clojure.spec migration - the first is :parameters, which is where spec-tools is likely to be the library we'll use. The second aspect is the spec of the yada resource (and possibly handler) to help alert to errors by the yada resource author

malcolmsparks15:01:09

I think the :parameters section could list a flat list of parameters, each with their own specs, rather than the whole parameters structure having a single spec.

malcolmsparks15:01:33

@mccraigmccraig it's a good point you're raising, glad you did

malcolmsparks15:01:16

It's the second aspect (validating yada resources) where the clojure.spec policy of allowing unknown keys is quite useful

stijn15:01:26

@malcolmsparks what about a response spec? to communicate the shape of data to the user

malcolmsparks15:01:12

@stijn isn't that captured in the Content-Type (and generally media-types)

malcolmsparks15:01:17

and JSON Schema

stijn15:01:49

oh, and is there a way to add that to the swagger documentation from yada?

mccraigmccraig15:01:00

agree @malcolmsparks - allowing unknown keys can be nice for fn/handler/resources... i've done similar with spec quite profitably in the past - although i know of at least one place in my code where not having the ability to disallow extra fn args could lead to some nasty subtle bugs, so i'm a bit ambivalent about the feature/lack-thereof

geek-draven19:01:54

@malcolmsparks I've got the pages displaying correctly now - it was a rookie error of an incorrect indent! Now, I just need to sort out the consumer on the post and the project will be updated, then I can start on the fun stuff of Swagger and authentication 🙂

danielcompton19:01:57

Is there a common pattern for making csrf tokens?

malcolmsparks20:01:58

@danielcompton Nothing explicit in yada to help you

malcolmsparks20:01:12

Possibly use :properties, and generate the same value to put in your GET response and check in your POST. Same resource.

malcolmsparks20:01:08

You could use buddy.jwt to generate a value you can verify.

malcolmsparks20:01:24

Without revealing secrets