Closed matclab closed 2 years ago
So something similar to the aiohttp Client auth example?
My initial thoughts are to add a auth
keyword argument to the Pusher.__init__
method allowing a user to pass a BasicAuth object that would then be passed to the aiohttp.ClientSession
in the add
, replace
and delete
methods.
Yes, it would fulfill the need for me.
kwargs
to be passed on to the aiohttp.ClientSession
used within the Pusher. This means you can now supply auth parameters which should resolve this issue.The example code below shows how you can achieve it.
import aiohttp
from aioprometheus import REGISTRY, Counter
from aioprometheus.pusher import Pusher
auth = aiohttp.BasicAuth(username, password=password)
p = Pusher("my-job", push_gateway_url)
c = Counter("total_requests", "Total requests.", {})
c.inc({"url": "/p/user"})
# Push to the pushgateway
resp = await p.replace(REGISTRY, auth=auth)
assert resp.status == 200
The push gateway is often used with an authentication. It would be nice to have an
auth
parameter that would be passed to theaiohttp.ClientSession
.