Python aiohttp.BasicAuth() Examples

The following are 30 code examples of aiohttp.BasicAuth(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module aiohttp , or try the search function .
Example #1
Source File: badfish.py    From badfish with GNU General Public License v3.0 7 votes vote down vote up
def post_request(self, uri, payload, headers):
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession() as session:
                    async with session.post(
                        uri,
                        data=json.dumps(payload),
                        headers=headers,
                        auth=aiohttp.BasicAuth(self.username, self.password),
                        verify_ssl=False,
                    ) as _response:
                        if _response.status != 204:
                            await _response.read()
                        else:
                            return _response
        except (Exception, TimeoutError):
            self.logger.exception("Failed to communicate with server.")
            raise BadfishException
        return _response 
Example #2
Source File: __init__.py    From atomicpuppy with MIT License 7 votes vote down vote up
def __init__(self, cfg_file, callback, loop=None, username=None, password=None):
        """
        cfg_file: dictionary or filename or yaml text
        """
        self.config = StreamConfigReader().read(cfg_file)
        self.callback = callback
        self._loop = loop or asyncio.get_event_loop()
        self._queue = asyncio.Queue(maxsize=20, loop=self._loop)

        auth = None
        if username != None and password != None:
            auth = aiohttp.BasicAuth(login=username, password=password, encoding='utf-8')

        self.session = aiohttp.ClientSession(
                read_timeout=self.config.timeout,
                conn_timeout=self.config.timeout,
                raise_for_status=True,
                loop=self._loop,
                auth=auth) 
Example #3
Source File: api.py    From mkctf with GNU General Public License v3.0 7 votes vote down vote up
def push(self, host, port=443, tags=[], categories=[],
                   username='', password='', no_verify_ssl=False):
        '''Push challenge configuration to a scoreboard
        '''
        self.__assert_valid_repo()
        challenges = []
        for challenge in self._repo.scan(tags, categories):
                challenges.append(challenge.conf.raw)
        url = f'https://{host}:{port}/mkctf-api/push'
        ssl = False if no_verify_ssl else None
        auth = BasicAuth(username, password)
        timeout = ClientTimeout(total=2*60)
        async with ClientSession(auth=auth, timeout=timeout) as session:
            async with session.post(url, ssl=ssl, json={'challenges': challenges}) as resp:
                if resp.status < 400:
                    app_log.info("push succeeded.")
                    return {'pushed': True}
        app_log.error("push failed.")
        return {'pushed': False} 
Example #4
Source File: monitor.py    From mkctf with GNU General Public License v3.0 7 votes vote down vote up
def __init__(self, api, host, port, username, password,
                 iter_cnt=-1, iter_delay=600,
                 task_timeout=120, worker_cnt=4,
                 post_timeout=60, no_verify_ssl=False):
        '''[summary]
        '''
        self._api = api
        self._workers = []
        self._iter_cnt = iter_cnt
        self._iter_delay = iter_delay
        self._worker_cnt = worker_cnt
        self._task_queue = Queue()
        self._task_timeout = task_timeout
        self._output_lock = Lock()
        self._url = f'https://{host}:{port}/mkctf-api/healthcheck'
        self._ssl = False if no_verify_ssl else None
        self._auth = BasicAuth(username, password)
        self._post_timeout = ClientTimeout(total=post_timeout) 
Example #5
Source File: badfish.py    From quads with GNU General Public License v3.0 6 votes vote down vote up
def patch_request(self, uri, payload, headers, _continue=False):
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession(loop=self.loop) as session:
                    async with session.patch(
                        uri,
                        data=json.dumps(payload),
                        headers=headers,
                        auth=BasicAuth(self.username, self.password),
                        verify_ssl=False,
                    ) as _response:
                        await _response.text("utf-8", "ignore")
        except Exception as ex:
            if _continue:
                return
            else:
                logger.debug(ex)
                logger.error("Failed to communicate with server.")
                raise BadfishException
        return _response 
Example #6
Source File: badfish.py    From badfish with GNU General Public License v3.0 6 votes vote down vote up
def patch_request(self, uri, payload, headers, _continue=False):
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession() as session:
                    async with session.patch(
                        uri,
                        data=json.dumps(payload),
                        headers=headers,
                        auth=aiohttp.BasicAuth(self.username, self.password),
                        verify_ssl=False,
                    ) as _response:
                        await _response.read()
        except Exception as ex:
            if _continue:
                return
            else:
                self.logger.debug(ex)
                self.logger.error("Failed to communicate with server.")
                raise BadfishException
        return _response 
Example #7
Source File: foreman.py    From quads with GNU General Public License v3.0 6 votes vote down vote up
def get(self, endpoint):
        logger.debug("GET: %s" % endpoint)
        try:
            async with aiohttp.ClientSession(
                loop=self.loop
            ) as session:
                async with session.get(
                    self.url + endpoint,
                    auth=BasicAuth(self.username, self.password),
                    verify_ssl=False,
                ) as response:
                    result = await response.json(content_type="application/json")
        except Exception as ex:
            logger.debug(ex)
            logger.error("There was something wrong with your request.")
            return {}
        return result 
Example #8
Source File: foreman.py    From quads with GNU General Public License v3.0 6 votes vote down vote up
def put_host_parameter(self, host_id, parameter_id, value):
        logger.debug("PUT param: {%s:%s}" % (parameter_id, value))
        endpoint = "/hosts/%s/parameters/%s" % (host_id, parameter_id)
        data = {'parameter': {"value": value}}
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession(
                    loop=self.loop
                ) as session:
                    async with session.put(
                        self.url + endpoint,
                        json=data,
                        auth=BasicAuth(self.username, self.password),
                        verify_ssl=False,
                    ) as response:
                        await response.json(content_type="application/json")
        except Exception as ex:
            logger.debug(ex)
            logger.error("There was something wrong with your request.")
            return False
        if response.status in [200, 204]:
            logger.info("Host parameter updated successfully.")
            return True
        return False 
Example #9
Source File: foreman.py    From quads with GNU General Public License v3.0 6 votes vote down vote up
def post_host_parameter(self, host_id, name, value):
        logger.debug("PUT param: {%s:%s}" % (name, value))
        endpoint = "/hosts/%s/parameters" % host_id
        data = {"parameter": {"name": name, "value": value}}
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession(
                    loop=self.loop
                ) as session:
                    async with session.post(
                        self.url + endpoint,
                        json=data,
                        auth=BasicAuth(self.username, self.password),
                        verify_ssl=False,
                    ) as response:
                        await response.json(content_type="application/json")
        except Exception as ex:
            logger.debug(ex)
            logger.error("There was something wrong with your request.")
            return False
        if response.status in [200, 201, 204]:
            logger.info("Host parameter updated successfully.")
            return True
        return False 
Example #10
Source File: foreman.py    From quads with GNU General Public License v3.0 6 votes vote down vote up
def update_user_password(self, login, password):
        logger.debug("PUT login pass: {%s}" % login)
        _host_id = await self.get_user_id(login)
        endpoint = "/users/%s" % _host_id
        data = {"user": {"login": login, "password": password}}
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession(
                    loop=self.loop
                ) as session:
                    async with session.put(
                        self.url + endpoint,
                        json=data,
                        auth=BasicAuth(self.username, self.password),
                        verify_ssl=False,
                    ) as response:
                        await response.json(content_type="application/json")
        except Exception as ex:
            logger.debug(ex)
            logger.error("There was something wrong with your request.")
            return False
        if response.status in [200, 204]:
            logger.info("User password updated successfully.")
            return True
        return False 
Example #11
Source File: badfish.py    From badfish with GNU General Public License v3.0 6 votes vote down vote up
def get_request(self, uri, _continue=False):
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession() as session:
                    async with session.get(
                        uri,
                        auth=aiohttp.BasicAuth(self.username, self.password),
                        verify_ssl=False,
                        timeout=60,
                    ) as _response:
                        await _response.read()
        except (Exception, TimeoutError) as ex:
            if _continue:
                return
            else:
                self.logger.debug(ex)
                self.logger.error("Failed to communicate with server.")
                raise BadfishException
        return _response 
Example #12
Source File: badfish.py    From quads with GNU General Public License v3.0 6 votes vote down vote up
def get_request(self, uri, _continue=False):
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession(loop=self.loop) as session:
                    async with session.get(
                        uri,
                        auth=BasicAuth(self.username, self.password),
                        verify_ssl=False,
                        timeout=60,
                    ) as _response:
                        await _response.text("utf-8", "ignore")
        except (Exception, TimeoutError) as ex:
            if _continue:
                return
            else:
                logger.debug(ex)
                logger.error("Failed to communicate with server.")
                raise BadfishException
        return _response 
Example #13
Source File: animu.py    From mee6 with MIT License 6 votes vote down vote up
def get_xml(self, nature, name):
        auth = aiohttp.BasicAuth(login = MAL_USERNAME, password = MAL_PASSWORD)
        url = 'http://myanimelist.net/api/{}/search.xml'.format(nature)
        params = {
            'q': name
        }
        with aiohttp.ClientSession(auth=auth) as session:
            async with session.get(url, params=params) as response:
                data = await response.text()
                return data 
Example #14
Source File: badfish.py    From quads with GNU General Public License v3.0 6 votes vote down vote up
def post_request(self, uri, payload, headers):
        try:
            async with self.semaphore:
                async with aiohttp.ClientSession(loop=self.loop) as session:
                    async with session.post(
                        uri,
                        data=json.dumps(payload),
                        headers=headers,
                        auth=BasicAuth(self.username, self.password),
                        verify_ssl=False,
                    ) as _response:
                        if _response.status != 204:
                            await _response.text("utf-8", "ignore")
                        else:
                            return _response
        except (Exception, TimeoutError):
            logger.exception("Failed to communicate with server.")
            raise BadfishException
        return _response 
Example #15
Source File: sensor.py    From SmartHouse with MIT License 6 votes vote down vote up
def async_update(self):
    try:
      auth = aiohttp.BasicAuth(self.username, self.password)
      with async_timeout.timeout(TIMEOUT, loop=self.hass.loop):
        response = await self.websession.get(ENDPOINT, auth=auth)
        data = await response.json(content_type=None)
        if len(data) > 0:
          _LOGGER.debug("Updating sensor: {}".format(data))
          entry = data[0]
          self._meal = entry['meal']
          self.extract_deilver_date(entry['deliveryDate'])
        else:
          _LOGGER.debug("No data to update: {}".format(data))
          self._deliver_from = None
          self._deliver_to = None
          self._time_left = None
          self._meal = None
    except (asyncio.TimeoutError, aiohttp.ClientError, IndexError) as error:
      _LOGGER.error("Failed getting devices: %s", error) 
Example #16
Source File: remote_api_order_book_data_source.py    From hummingbot with Apache License 2.0 6 votes vote down vote up
def get_tracking_pairs(self) -> Dict[str, OrderBookTrackerEntry]:
        auth: aiohttp.BasicAuth = aiohttp.BasicAuth(login=conf.coinalpha_order_book_api_username,
                                                    password=conf.coinalpha_order_book_api_password)
        client_session: aiohttp.ClientSession = await self.get_client_session()
        response: aiohttp.ClientResponse = await client_session.get(self.SNAPSHOT_REST_URL, auth=auth)
        timestamp: float = time.time()
        if response.status != 200:
            raise EnvironmentError(f"Error fetching order book tracker snapshot from {self.SNAPSHOT_REST_URL}.")

        binary_data: bytes = await response.read()
        order_book_tracker_data: Dict[str, Tuple[pd.DataFrame, pd.DataFrame]] = pickle.loads(binary_data)
        retval: Dict[str, OrderBookTrackerEntry] = {}

        for trading_pair, (bids_df, asks_df) in order_book_tracker_data.items():
            order_book: BinanceOrderBook = BinanceOrderBook()
            order_book.apply_numpy_snapshot(bids_df.values, asks_df.values)
            retval[trading_pair] = OrderBookTrackerEntry(trading_pair, timestamp, order_book)

        return retval 
Example #17
Source File: connector.py    From aiosocks with Apache License 2.0 6 votes vote down vote up
def update_proxy(self, proxy, proxy_auth, proxy_headers):
        if proxy and proxy.scheme not in ['http', 'socks4', 'socks5']:
            raise ValueError(
                "Only http, socks4 and socks5 proxies are supported")
        if proxy and proxy_auth:
            if proxy.scheme == 'http' and \
                    not isinstance(proxy_auth, aiohttp.BasicAuth):
                raise ValueError("proxy_auth must be None or "
                                 "BasicAuth() tuple for http proxy")
            if proxy.scheme == 'socks4' and \
                    not isinstance(proxy_auth, Socks4Auth):
                raise ValueError("proxy_auth must be None or Socks4Auth() "
                                 "tuple for socks4 proxy")
            if proxy.scheme == 'socks5' and \
                    not isinstance(proxy_auth, Socks5Auth):
                raise ValueError("proxy_auth must be None or Socks5Auth() "
                                 "tuple for socks5 proxy")
        self.proxy = proxy
        self.proxy_auth = proxy_auth
        self.proxy_headers = proxy_headers 
Example #18
Source File: RedditSource.py    From Dozer with GNU General Public License v3.0 6 votes vote down vote up
def get_token(self):
        """Using OAuth2, get a reddit bearer token. If this fails, fallback to non-oauth API"""
        client_id = self.bot.config['news']['reddit']['client_id']
        client_secret = self.bot.config['news']['reddit']['client_secret']
        params = {
            'grant_type': 'client_credentials'
        }
        auth = aiohttp.BasicAuth(client_id, client_secret)
        response = await self.http_session.post(self.token_url, params=params, auth=auth)
        response = await response.json()
        try:
            self.access_token = response['access_token']
        except KeyError:
            DOZER_LOGGER.critical(f"Error in {self.full_name} Token Get: {response['message']}. Switching to "
                                  f"non-OAuth API")
            self.oauth_disabled = True
            return

        expiry_seconds = response['expires_in']
        time_delta = datetime.timedelta(seconds=expiry_seconds)
        self.expiry_time = datetime.datetime.now() + time_delta 
Example #19
Source File: http_request.py    From gd.py with MIT License 6 votes vote down vote up
def __init__(
        self,
        *,
        url: Union[str, URL] = BASE,
        use_user_agent: bool = False,
        forwarded_for: Optional[str] = None,
        proxy: Optional[str] = None,
        proxy_auth: Optional[aiohttp.BasicAuth] = None,
        timeout: Union[float, int] = 150,
        max_requests: int = 250,
        debug: bool = False,
        **kwargs,
    ) -> None:
        self.semaphore = asyncio.Semaphore(max_requests)
        self.url = URL(url)
        self.use_agent = use_user_agent
        self.forwarded_for = forwarded_for
        self.proxy = proxy
        self.proxy_auth = proxy_auth
        self.timeout = timeout
        self.debug = debug
        self.last_result = None  # for testing 
Example #20
Source File: async_http.py    From BTG with GNU General Public License v3.0 5 votes vote down vote up
def filler(request):
    url = request['url']
    module_name = request['module']
    ioc = request['ioc']
    verbose = request['verbose']
    headers = request['headers']

    if request['proxy']['https'] == '':
        if request['proxy']['http'] == '':
            proxy = None
        else:
            proxy = request['proxy']['http']
    else:
        proxy = request['proxy']['https']

    if 'auth' in request:
        type = request['auth'][0]
        # TODO
        # add other condition if any
        if type == "BASIC":
            auth = BasicAuth(request['auth'][1][0], request['auth'][1][1])
        else:
            auth = None
    else:
        auth = None

    if module_name in ['cuckoosandbox', 'viper', 'misp']:
        server_id = request['server_id']
    else:
        server_id = None

    if 'verify' in request:
        verify = request['verify']
    else:
        verify = None

    return url, module_name, ioc, verbose, headers, proxy, auth, server_id, verify 
Example #21
Source File: hashdump.py    From domi-owned with MIT License 5 votes vote down vote up
def get_hashes(self, urls):
		"""
		Create client session based on authentication type.
		"""
		loop = asyncio.get_event_loop()
		loop.add_signal_handler(signal.SIGINT, self.signal_handler)

		if self.username and self.auth_type == 'basic':
			client = aiohttp.ClientSession(headers=self.utilities.HEADERS, auth=aiohttp.BasicAuth(self.username, self.password), loop=loop)

		elif self.auth_type == 'form':
			# Check if cookies or SSO are being used for authentication
			if 'DomAuthSessId' in self.session.cookies:
				session_id = dict(DomAuthSessId=self.session.cookies['DomAuthSessId'])
			elif 'LtpaToken' in self.session.cookies:
				session_id = dict(LtpaToken=self.session.cookies['LtpaToken'])
			else:
				session_id = None

			client = aiohttp.ClientSession(headers=self.utilities.HEADERS, cookies=session_id, loop=loop)

		else:
			client = aiohttp.ClientSession(headers=self.utilities.HEADERS, loop=loop)

		with client as session:
			try:
				loop.run_until_complete(self.query(session, urls))
			except asyncio.CancelledError:
				sys.exit()
			except Exception as error:
				self.logger.error('An error occurred while dumping Domino account hashes')
				sys.exit() 
Example #22
Source File: socks_http.py    From nowallet with MIT License 5 votes vote down vote up
def urlopen(url: str, bauth_tuple=None, loop=None) -> str:
    bauth = None
    if bauth_tuple:
        login, password = bauth_tuple
        bauth = aiohttp.BasicAuth(login, password=password, encoding='latin1')
    auth5 = aiosocks.Socks5Auth(
        'proxyuser1', password='pwd')  # type: aiosocks.Socks5Auth
    conn = ProxyConnector(
        remote_resolve=True, loop=loop)  # type: ProxyConnector

    try:
        with aiohttp.ClientSession(
            connector=conn,
            auth=bauth,
            request_class=ProxyClientRequest
        ) as session:
            async with session.get(
                url,
                proxy='socks5://127.0.0.1:9050',
                proxy_auth=auth5
            ) as resp:

                if resp.status == 200:
                    return await resp.text()
                else:
                    message = "HTTP response not OK: {}".format(resp.status)
                    raise SocksHTTPError(message)

    except aiohttp.ClientProxyConnectionError:
        # connection problem
        pass
    except aiosocks.SocksError:
        # communication problem
        pass
    return ""  # Should never happen 
Example #23
Source File: enumerate.py    From domi-owned with MIT License 5 votes vote down vote up
def enum_dirs(self, urls):
		"""
		Create client session based on authentication type.
		"""
		loop = asyncio.get_event_loop()
		loop.add_signal_handler(signal.SIGINT, self.signal_handler)

		if self.username and self.auth_type == 'basic':
			client = aiohttp.ClientSession(headers=self.utilities.HEADERS, auth=aiohttp.BasicAuth(self.username, self.password), loop=loop)

		elif self.auth_type == 'form':
			# Check if cookies or SSO are being used for authentication
			if 'DomAuthSessId' in self.session.cookies:
				session_id = dict(DomAuthSessId=self.session.cookies['DomAuthSessId'])
			elif 'LtpaToken' in self.session.cookies:
				session_id = dict(LtpaToken=self.session.cookies['LtpaToken'])
			else:
				session_id = None

			client = aiohttp.ClientSession(headers=self.utilities.HEADERS, cookies=session_id, loop=loop)

		else:
			client = aiohttp.ClientSession(headers=self.utilities.HEADERS, loop=loop)

		with client as session:
			try:
				loop.run_until_complete(self.query(session, urls))
			except asyncio.CancelledError:
				sys.exit()
			except Exception as error:
				self.logger.error('An error occurred while enumerating Domino URLs')
				sys.exit() 
Example #24
Source File: api.py    From PyPlanet with GNU General Public License v3.0 5 votes vote down vote up
def create_session(self):
		self.session = await aiohttp.ClientSession(
			# TODO: Remove when TMNext Exchange is live
			auth=aiohttp.BasicAuth('alphatester', 'mX!tR4ckbu1lDinG'),

			cookie_jar=self.cookie_jar,
			headers={
				'User-Agent': 'PyPlanet/{}'.format(pyplanet_version),
				'X-ManiaPlanet-ServerLogin': self.server_login
			}
		).__aenter__() 
Example #25
Source File: foreman.py    From quads with GNU General Public License v3.0 5 votes vote down vote up
def remove_extraneous_interfaces(self, host):
        _host_id = await self.get_host_id(host)
        success = True
        extraneous_interfaces = await self.get_host_extraneous_interfaces(_host_id)
        for interface in extraneous_interfaces:
            endpoint = self.url + "/hosts/%s/interfaces/%s" % (_host_id, interface["id"])
            try:
                async with self.semaphore:
                    async with aiohttp.ClientSession(
                        loop=self.loop
                    ) as session:
                        async with session.delete(
                            endpoint,
                            auth=BasicAuth(self.username, self.password),
                            verify_ssl=False,
                        ) as response:
                            await response.json(content_type="application/json")
            except Exception as ex:
                logger.debug(ex)
                logger.error("There was something wrong with your request.")
                success = False
                continue
            if response.status != 200:
                logger.info("Interface removed successfully.")
                success = False
        return success 
Example #26
Source File: endpoints.py    From rasa-for-botfront with Apache License 2.0 5 votes vote down vote up
def session(self) -> aiohttp.ClientSession:
        # create authentication parameters
        if self.basic_auth:
            auth = aiohttp.BasicAuth(
                self.basic_auth["username"], self.basic_auth["password"]
            )
        else:
            auth = None

        return aiohttp.ClientSession(
            headers=self.headers,
            auth=auth,
            timeout=aiohttp.ClientTimeout(total=DEFAULT_REQUEST_TIMEOUT),
        ) 
Example #27
Source File: test_connection.py    From elasticsearch-py-async with Apache License 2.0 5 votes vote down vote up
def test_auth_is_set_correctly(event_loop):
    connection = AIOHttpConnection(http_auth=('user', 'secret'), loop=event_loop)
    assert connection.session._default_auth == aiohttp.BasicAuth('user', 'secret')

    connection = AIOHttpConnection(http_auth='user:secret', loop=event_loop)
    assert connection.session._default_auth == aiohttp.BasicAuth('user', 'secret') 
Example #28
Source File: test_client.py    From dask-gateway with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_http_client_proxy_explicit(monkeypatch):
    http_proxy = "http://alice:password@host:80/path"
    proxy_sol = yarl.URL("http://host:80/path")
    proxy_auth_sol = aiohttp.BasicAuth("alice", "password")

    with dask.config.set(gateway__http_client__proxy=http_proxy):
        with monkeypatch.context() as m:
            m.setenv("http_proxy", "http://bob:foobar@otherhost:90/path")

            # Loaded from config, not environment variables
            for scheme in ["http", "https"]:
                g = Gateway(f"{scheme}://myhost:80")
                assert g._request_kwargs["proxy"] == proxy_sol
                assert g._request_kwargs["proxy_auth"] == proxy_auth_sol 
Example #29
Source File: test_client.py    From dask-gateway with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_http_client_proxy_true(monkeypatch):
    http_proxy = "http://alice:password@host:80/path"
    proxy_sol = yarl.URL("http://host:80/path")
    proxy_auth_sol = aiohttp.BasicAuth("alice", "password")

    with dask.config.set(gateway__http_client__proxy=True):
        with monkeypatch.context() as m:
            for k in ["http_proxy", "https_proxy"]:
                m.delenv(k, raising=False)
                m.delenv(k.upper(), raising=False)

            with m.context() as m2:
                m2.setenv("http_proxy", http_proxy)

                # Properly inferred from environment
                g = Gateway("http://myhost:80")
                assert g._request_kwargs["proxy"] == proxy_sol
                assert g._request_kwargs["proxy_auth"] == proxy_auth_sol

                # No HTTPS proxy set
                g = Gateway("https://myhost:80")
                assert g._request_kwargs == {"proxy": None, "proxy_auth": None}

            # No HTTP proxy set
            g = Gateway("http://myhost:80")
            assert g._request_kwargs == {"proxy": None, "proxy_auth": None} 
Example #30
Source File: test_client.py    From dask-gateway with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_config_auth_kwargs_template_environment_vars(monkeypatch):
    monkeypatch.setenv("TEST_USER", "bruce")
    config = {
        "gateway": {"auth": {"type": "basic", "kwargs": {"username": "{TEST_USER}"}}}
    }
    with dask.config.set(config):
        auth = get_auth()
        assert isinstance(auth, BasicAuth)
        assert auth.username == "bruce"