thp / urlwatch

Watch (parts of) webpages and get notified when something changes via e-mail, on your phone or via other means. Highly configurable.
https://thp.io/2008/urlwatch/
Other
2.81k stars 352 forks source link

Feature request: Custom AWS (requests) Authentication #716

Open batandwa opened 2 years ago

batandwa commented 2 years ago

I would like create a custom hook that sets custom authentication that is compatible request module.

For context... I thought this would be useful when I was doing AWS v4 signing using the aws_request_auth module.

batandwa commented 2 years ago

I am willing to contribute to this...

thp commented 2 years ago

Custom authentication here means special HTTP headers sent with the request? Or something more sophisticated?

batandwa commented 2 years ago

Whatever the request module allows in the auth parameter when executing request()

batandwa commented 2 years ago

On the other hand... That may lead to the request module being an irreplaceable dependency.

thp commented 1 year ago

On the other hand... That may lead to the request module being an irreplaceable dependency.

That's fine, it is already a required dependency.

Whatever the request module allows in the auth parameter when executing request()

The docs say:

auth – (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.

So I guess this means you get a tuple like (username, password) passed there and requests takes care of creating the right header. Should be easy to allow for this. However, for "custom" authentication, you can anyway just set a HTTP header. Granted, for Basic auth, username/password is convenient, and for Digest auth it's essential.

thp commented 1 year ago

..and i read your request again -- in this case, you probably would like to have a way of adding all the AWS settings and then pass the AWSRequestsAuth() object to the auth, so just configuring username/password in the YAML is not enough.

thp commented 1 year ago

One way to do it would be to subclass jobs.UrlJob as done in share/urlwatch/examples/hooks.py.example:

class CustomLoginJob(jobs.UrlJob):
    """Custom login for my webpage"""

    __kind__ = 'aws-login'
    __required__ = ('aws_access_key', 'aws_secret_access_key', ...)

    def retrieve(self, job_state):
        ... # TODO: Make request, return response, use self.aws_access_key, etc...