Skip to content

Commit c2ee16e

Browse files
committed
2 parents 725282e + a140cf5 commit c2ee16e

File tree

4 files changed

+41
-299
lines changed

4 files changed

+41
-299
lines changed
Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
from aiohttp import (
2-
web,
3-
ClientSession,
4-
ClientRequest,
52
ClientResponse,
63
ClientError,
7-
ClientTimeout,
84
)
95

10-
import asyncio
116
import logging
127

138
import json
149

15-
from ..helpers.utils import log_msg
1610

17-
EVENT_LOGGER = logging.getLogger("__name__")
11+
LOGGER = logging.getLogger("__name__")
1812

1913

2014
class repr_json:
@@ -34,24 +28,11 @@ def __init__(self, admin_url: str, client_session):
3428
self.color = None
3529
self.prefix = None
3630

37-
def log(self, *msg, **kwargs):
38-
self.handle_output(*msg, **kwargs)
39-
4031
@property
4132
def prefix_str(self):
4233
if self.prefix:
4334
return f"{self.prefix:10s} |"
4435

45-
def handle_output(self, *output, source: str = None, **kwargs):
46-
end = "" if source else "\n"
47-
if source == "stderr":
48-
color = "fg:ansired"
49-
elif not source:
50-
color = self.color or "fg:ansiblue"
51-
else:
52-
color = None
53-
log_msg(*output, color=color, prefix=self.prefix_str, end=end, **kwargs)
54-
5536
async def admin_request(
5637
self, method, path, json_data=None, text=False, params=None, data=None
5738
) -> ClientResponse:
@@ -72,91 +53,91 @@ async def admin_request(
7253

7354
async def admin_GET(self, path, text=False, params=None) -> ClientResponse:
7455
try:
75-
EVENT_LOGGER.debug("Controller GET %s request to Agent", path)
56+
LOGGER.debug("Controller GET %s request to Agent", path)
7657
response = await self.admin_request("GET", path, None, text, params)
77-
EVENT_LOGGER.debug(
58+
LOGGER.debug(
7859
"Response from GET %s received: \n%s",
7960
path,
8061
repr_json(response),
8162
)
8263
return response
8364
except ClientError as e:
84-
self.log(f"Error during GET {path}: {str(e)}")
65+
LOGGER.error(f"Error during GET {path}: {str(e)}")
8566
raise
8667

8768
async def admin_POST(
8869
self, path, json_data=None, text=False, params=None, data=None
8970
) -> ClientResponse:
9071
try:
91-
EVENT_LOGGER.debug(
72+
LOGGER.debug(
9273
"Controller POST %s request to Agent%s",
9374
path,
9475
(" with data: \n{}".format(repr_json(json_data)) if json_data else ""),
9576
)
9677
response = await self.admin_request(
9778
"POST", path, json_data, text, params, data
9879
)
99-
EVENT_LOGGER.debug(
80+
LOGGER.debug(
10081
"Response from POST %s received: \n%s",
10182
path,
10283
repr_json(response),
10384
)
10485
return response
10586
except ClientError as e:
106-
self.log(f"Error during POST {path}: {str(e)}")
87+
LOGGER.error(f"Error during POST {path}: {str(e)}")
10788
raise
10889

10990
async def admin_PATCH(
11091
self, path, json_data=None, text=False, params=None, data=None
11192
) -> ClientResponse:
11293
try:
113-
EVENT_LOGGER.debug(
94+
LOGGER.debug(
11495
"Controller PATCH %s request to Agent%s",
11596
path,
11697
(" with data: \n{}".format(repr_json(json_data)) if json_data else ""),
11798
)
11899
response = await self.admin_request(
119100
"PATCH", path, json_data, text, params, data
120101
)
121-
EVENT_LOGGER.debug(
102+
LOGGER.debug(
122103
"Response from PATCH %s received: \n%s", path, repr_json(response)
123104
)
124105
return response
125106
except ClientError as e:
126-
self.log(f"Error during PATCH {path}: {str(e)}")
107+
LOGGER.error(f"Error during PATCH {path}: {str(e)}")
127108
raise
128109

129110
async def admin_PUT(
130111
self, path, json_data=None, text=False, params=None, data=None
131112
) -> ClientResponse:
132113
try:
133-
EVENT_LOGGER.debug(
114+
LOGGER.debug(
134115
"Controller PUT %s request to Agent%s",
135116
path,
136117
(" with data: \n{}".format(repr_json(json_data)) if json_data else ""),
137118
)
138119
response = await self.admin_request(
139120
"PUT", path, json_data, text, params, data
140121
)
141-
EVENT_LOGGER.debug(
122+
LOGGER.debug(
142123
"Response from PUT %s received: \n%s", path, repr_json(response)
143124
)
144125
return response
145126
except ClientError as e:
146-
self.log(f"Error during PUT {path}: {str(e)}")
127+
LOGGER.error(f"Error during PUT {path}: {str(e)}")
147128
raise
148129

149130
async def admin_DELETE(self, path, text=False, params=None) -> ClientResponse:
150131
try:
151-
EVENT_LOGGER.debug("Controller DELETE %s request to Agent", path)
132+
LOGGER.debug("Controller DELETE %s request to Agent", path)
152133

153134
response = await self.admin_request("DELETE", path, None, text, params)
154-
EVENT_LOGGER.debug(
135+
LOGGER.debug(
155136
"Response from DELETE %s received: \n%s",
156137
path,
157138
repr_json(response),
158139
)
159140
return response
160141
except ClientError as e:
161-
self.log(f"Error during DELETE {path}: {str(e)}")
142+
LOGGER.error(f"Error during DELETE {path}: {str(e)}")
162143
raise

0 commit comments

Comments
 (0)