Skip to content

Conversation

@dmuhs
Copy link
Contributor

@dmuhs dmuhs commented Mar 20, 2019

Add a middleware that automatically fills in the clientToolName field of analysis submission requests so people on the API side know PythX was used.

@dmuhs dmuhs self-assigned this Mar 20, 2019
@dmuhs dmuhs requested a review from cache-monet March 20, 2019 17:48
@dmuhs dmuhs added this to the v1.0 milestone Mar 20, 2019
class ClientToolNameMiddleware(BaseMiddleware):
def __init__(self, name="pythx"):
LOGGER.debug("Initializing")
self.name = name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we planning to add additional middleware or allow devs to build custom ones off of PythX?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Developers can add their own middlewares, simply by adding them to the APIHandler, like

from foo import MyMiddleware
from pythx.api.handler import APIHandler
mw = MyMiddleware()
handler = APIHandler(middlewares=[mw])

and then passing that to the Client class. I'm also hacking up a passthrough so you can do something like

c = Client(middlewares=[mw])

to completely abstract from the API handler class.

(CUSTOM_CTN_MIDDLEWARE, generate_request_dict(testdata.LOGOUT_REQUEST_OBJECT), False),
(CUSTOM_CTN_MIDDLEWARE, generate_request_dict(testdata.REFRESH_REQUEST_OBJECT), False),
],
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests passed for me!

cache-monet
cache-monet previously approved these changes Mar 21, 2019
Copy link
Contributor

@cache-monet cache-monet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good stuff, I'm learning a lot just by reviewing the code 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants