notify-api-412 use black to enforce python coding style

This commit is contained in:
Kenneth Kehl
2023-08-25 09:12:23 -07:00
parent c6eb007386
commit 8c9721d8e2
201 changed files with 31660 additions and 28105 deletions

View File

@@ -10,29 +10,25 @@ cache = RequestCache(redis_client)
def _attach_current_user(data):
return dict(
created_by=current_user.id,
**data
)
return dict(created_by=current_user.id, **data)
class NotifyAdminAPIClient(BaseAPIClient):
def __init__(self):
super().__init__("a" * 73, "b")
def init_app(self, app):
self.base_url = app.config['API_HOST_NAME']
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
self.api_key = app.config['ADMIN_CLIENT_SECRET']
self.route_secret = app.config['ROUTE_SECRET_KEY_1']
self.base_url = app.config["API_HOST_NAME"]
self.service_id = app.config["ADMIN_CLIENT_USER_NAME"]
self.api_key = app.config["ADMIN_CLIENT_SECRET"]
self.route_secret = app.config["ROUTE_SECRET_KEY_1"]
def generate_headers(self, api_token):
headers = {
"Content-type": "application/json",
"Authorization": "Bearer {}".format(api_token),
"X-Custom-Forwarder": self.route_secret,
"User-agent": "NOTIFY-API-PYTHON-CLIENT/{}".format(__version__)
"User-agent": "NOTIFY-API-PYTHON-CLIENT/{}".format(__version__),
}
return self._add_request_id_header(headers)
@@ -40,8 +36,8 @@ class NotifyAdminAPIClient(BaseAPIClient):
def _add_request_id_header(headers):
if not has_request_context():
return headers
headers['X-B3-TraceId'] = request.request_id
headers['X-B3-SpanId'] = request.span_id
headers["X-B3-TraceId"] = request.request_id
headers["X-B3-SpanId"] = request.span_id
return headers
def check_inactive_service(self):
@@ -51,7 +47,11 @@ class NotifyAdminAPIClient(BaseAPIClient):
# if the current service is inactive and the user isn't a platform admin, we should block them from making any
# stateful modifications to that service
if current_service and not current_service.active and not current_user.platform_admin:
if (
current_service
and not current_service.active
and not current_user.platform_admin
):
abort(403)
def post(self, *args, **kwargs):