feature: add so_linger option to settings.

This commit is contained in:
UpstreamData
2023-11-27 09:24:28 -07:00
parent 2b443497ea
commit 3f1183a4f9
10 changed files with 68 additions and 46 deletions

View File

@@ -38,10 +38,13 @@ class AntminerModernWebAPI(BaseWebAPI):
url = f"http://{self.ip}/cgi-bin/{command}.cgi"
auth = httpx.DigestAuth(self.username, self.pwd)
try:
async with httpx.AsyncClient(verify=settings.ssl_cxt) as client:
async with httpx.AsyncClient(transport=settings.transport()) as client:
if parameters:
data = await client.post(
url, data=json.dumps(parameters), auth=auth, timeout=settings.get("api_function_timeout", 3) # noqa
url,
data=json.dumps(parameters),
auth=auth,
timeout=settings.get("api_function_timeout", 3), # noqa
)
else:
data = await client.get(url, auth=auth)
@@ -57,7 +60,7 @@ class AntminerModernWebAPI(BaseWebAPI):
async def multicommand(
self, *commands: str, ignore_errors: bool = False, allow_warning: bool = True
) -> dict:
async with httpx.AsyncClient(verify=settings.ssl_cxt) as client:
async with httpx.AsyncClient(transport=settings.transport()) as client:
tasks = [
asyncio.create_task(self._handle_multicommand(client, command))
for command in commands
@@ -149,10 +152,13 @@ class AntminerOldWebAPI(BaseWebAPI):
url = f"http://{self.ip}/cgi-bin/{command}.cgi"
auth = httpx.DigestAuth(self.username, self.pwd)
try:
async with httpx.AsyncClient(verify=settings.ssl_cxt) as client:
async with httpx.AsyncClient(transport=settings.transport()) as client:
if parameters:
data = await client.post(
url, data=parameters, auth=auth, timeout=settings.get("api_function_timeout", 3)
url,
data=parameters,
auth=auth,
timeout=settings.get("api_function_timeout", 3),
)
else:
data = await client.get(url, auth=auth)
@@ -170,7 +176,7 @@ class AntminerOldWebAPI(BaseWebAPI):
) -> dict:
data = {k: None for k in commands}
auth = httpx.DigestAuth(self.username, self.pwd)
async with httpx.AsyncClient(verify=settings.ssl_cxt) as client:
async with httpx.AsyncClient(transport=settings.transport()) as client:
for command in commands:
try:
url = f"http://{self.ip}/cgi-bin/{command}.cgi"

View File

@@ -186,7 +186,7 @@ class BOSMinerGQLAPI:
if command.get("query") is None:
query = {"query": self.parse_command(command)}
try:
async with httpx.AsyncClient(verify=settings.ssl_cxt) as client:
async with httpx.AsyncClient(transport=settings.transport()) as client:
await self.auth(client)
data = await client.post(url, json=query)
except httpx.HTTPError:
@@ -239,7 +239,7 @@ class BOSMinerLuCIAPI:
async def send_command(self, path: str, ignore_errors: bool = False) -> dict:
try:
async with httpx.AsyncClient(verify=settings.ssl_cxt) as client:
async with httpx.AsyncClient(transport=settings.transport()) as client:
await self.auth(client)
data = await client.get(
f"http://{self.ip}{path}", headers={"User-Agent": "BTC Tools v0.1"}

View File

@@ -31,7 +31,7 @@ class GoldshellWebAPI(BaseWebAPI):
self.jwt = None
async def auth(self):
async with httpx.AsyncClient(verify=settings.ssl_cxt) as client:
async with httpx.AsyncClient(transport=settings.transport()) as client:
try:
await client.get(f"http://{self.ip}/user/logout")
auth = (
@@ -71,7 +71,7 @@ class GoldshellWebAPI(BaseWebAPI):
parameters.pop("pool_pwd")
if not self.jwt:
await self.auth()
async with httpx.AsyncClient(verify=settings.ssl_cxt) as client:
async with httpx.AsyncClient(transport=settings.transport()) as client:
for i in range(settings.get("get_data_retries", 1)):
try:
if parameters:
@@ -102,7 +102,7 @@ class GoldshellWebAPI(BaseWebAPI):
data = {k: None for k in commands}
data["multicommand"] = True
await self.auth()
async with httpx.AsyncClient(verify=settings.ssl_cxt) as client:
async with httpx.AsyncClient(transport=settings.transport()) as client:
for command in commands:
try:
response = await client.get(

View File

@@ -32,7 +32,7 @@ class InnosiliconWebAPI(BaseWebAPI):
self.jwt = None
async def auth(self):
async with httpx.AsyncClient(verify=settings.ssl_cxt) as client:
async with httpx.AsyncClient(transport=settings.transport()) as client:
try:
auth = await client.post(
f"http://{self.ip}/api/auth",
@@ -54,7 +54,7 @@ class InnosiliconWebAPI(BaseWebAPI):
) -> dict:
if not self.jwt:
await self.auth()
async with httpx.AsyncClient(verify=settings.ssl_cxt) as client:
async with httpx.AsyncClient(transport=settings.transport()) as client:
for i in range(settings.get("get_data_retries", 1)):
try:
response = await client.post(
@@ -90,7 +90,7 @@ class InnosiliconWebAPI(BaseWebAPI):
data = {k: None for k in commands}
data["multicommand"] = True
await self.auth()
async with httpx.AsyncClient(verify=settings.ssl_cxt) as client:
async with httpx.AsyncClient(transport=settings.transport()) as client:
for command in commands:
try:
response = await client.post(

View File

@@ -31,7 +31,7 @@ class VNishWebAPI(BaseWebAPI):
self.token = None
async def auth(self):
async with httpx.AsyncClient(verify=settings.ssl_cxt) as client:
async with httpx.AsyncClient(transport=settings.transport()) as client:
try:
auth = await client.post(
f"http://{self.ip}/api/v1/unlock",
@@ -58,7 +58,7 @@ class VNishWebAPI(BaseWebAPI):
) -> dict:
if not self.token:
await self.auth()
async with httpx.AsyncClient(verify=settings.ssl_cxt) as client:
async with httpx.AsyncClient(transport=settings.transport()) as client:
for i in range(settings.get("get_data_retries", 1)):
try:
auth = self.token