Giter Club home page Giter Club logo

Comments (4)

shtlrs avatar shtlrs commented on August 10, 2024

I have no knowledge whatsoever with Blackbox, but I'd be interested to tackle this.

from blackbox.

lemonsaurus avatar lemonsaurus commented on August 10, 2024

Hi @shtlrs! I'm happy to let you take a crack at it if you'd like.

If you get stuck, poke me on Discord in https://discord.gg/hc5pDWNNzx in the #blackbox channel and I'll try to help.

from blackbox.

shtlrs avatar shtlrs commented on August 10, 2024

Alright sir, i'd happily take this then!

from blackbox.

shtlrs avatar shtlrs commented on August 10, 2024

@lemonsaurus Very sorry, I had completely forgotten about this, it got filtered out because i've set the org to pydis.

So I was running through the code to see how it all works and I was wondering how we'd want to handle auth for this.

The subscriber should be lambda API but the problem is that we don't know how auth is implemented for this api, it could be thourgh HTTP headers, in the request's body under a specific key, in the query parameters or maybe it doesn't even have auth for all that we know.

This got me thinking into how we'd want to implement this in the most simple way, so how about this

notifiers:
  json:
    my-api:
      url: https://mydomain.com/api/v1/database-updates/
      auth:
        type: headers
        key: key
        value: value
        method: 'POST'

The type can either be header, body or query-params (The naming can be discussed obviously)
Then depending on that type, we'll know where we can put the credentials.

For example

from requests import Request, Session
    class Json(BlackboxNotifier):
        ....
        def notify(self) -> None:
            """Send a webhook to Slack with a blackbox report."""
            request = Request(
                method=self.config["method"],
                url=self.config["url"],
            )
            auth = self.config.get("auth", {"type": "none", "key": "none", "value": "none"})
            auth_key = auth["key"]
            auth_value = auth["value"]
            auth_type = auth["type"]
            payload = self.method_to_construct_request_payload()
            request.json = payload

            if auth_type == "headers":
                request.headers = {auth_key: auth_value}
            if auth_type == "body":
                payload[auth_key] = auth_value
            if auth_type == "query-params":
                request.params[auth_key] = auth_value

            with Session() as session:
                session.send(request=request.prepare())

As I'm writing this, it also occured to me that we cannot even guarantee that the endpoint would solely take POST requests, so maybe that should be held into account as well ?

I know that auth for webhooks usually doesn't take place like this and that the end sending the event/request would include some sort of signature in the headers that needs to be validated by combining the request's body and some secret then hashing them etc etc, but I also don't believe that we can achieve that here.

from blackbox.

Related Issues (20)

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.