|
10 | 10 | parse_request_body_as, |
11 | 11 | parse_request_path_parameters_as, |
12 | 12 | ) |
13 | | -from servicelib.mimetype_constants import MIMETYPE_APPLICATION_JSON |
14 | | -from simcore_postgres_database.errors import DatabaseError |
15 | 13 | from simcore_service_webserver.api_keys._exceptions_handlers import ( |
16 | 14 | handle_plugin_requests_exceptions, |
17 | 15 | ) |
@@ -41,22 +39,17 @@ class ApiKeysPathParams(StrictRequestParameters): |
41 | 39 | async def create_api_key(request: web.Request): |
42 | 40 | req_ctx = RequestContext.model_validate(request) |
43 | 41 | new_api_key = await parse_request_body_as(ApiKeyCreate, request) |
44 | | - try: |
45 | | - created_api_key: ApiKey = await _api.create_api_key( |
46 | | - request.app, |
47 | | - display_name=new_api_key.display_name, |
48 | | - expiration=new_api_key.expiration, |
49 | | - user_id=req_ctx.user_id, |
50 | | - product_name=req_ctx.product_name, |
51 | | - ) |
52 | | - |
53 | | - api_key = ApiKeyGet.model_validate(created_api_key) |
54 | | - # api_key.api_base_url = TODO: https://github.com/ITISFoundation/osparc-simcore/issues/6340 |
55 | | - except DatabaseError as err: |
56 | | - raise web.HTTPBadRequest( |
57 | | - reason="Invalid API key name: already exists", |
58 | | - content_type=MIMETYPE_APPLICATION_JSON, |
59 | | - ) from err |
| 42 | + |
| 43 | + created_api_key: ApiKey = await _api.create_api_key( |
| 44 | + request.app, |
| 45 | + display_name=new_api_key.display_name, |
| 46 | + expiration=new_api_key.expiration, |
| 47 | + user_id=req_ctx.user_id, |
| 48 | + product_name=req_ctx.product_name, |
| 49 | + ) |
| 50 | + |
| 51 | + api_key = ApiKeyGet.model_validate(created_api_key) |
| 52 | + # api_key.api_base_url = TODO: https://github.com/ITISFoundation/osparc-simcore/issues/6340 # @pcrespov |
60 | 53 |
|
61 | 54 | return envelope_json_response(api_key) |
62 | 55 |
|
@@ -101,18 +94,11 @@ async def delete_api_key(request: web.Request): |
101 | 94 | req_ctx = RequestContext.model_validate(request) |
102 | 95 | path_params = parse_request_path_parameters_as(ApiKeysPathParams, request) |
103 | 96 |
|
104 | | - try: |
105 | | - await _api.delete_api_key( |
106 | | - request.app, |
107 | | - api_key_id=path_params.api_key_id, |
108 | | - user_id=req_ctx.user_id, |
109 | | - product_name=req_ctx.product_name, |
110 | | - ) |
111 | | - except DatabaseError as err: |
112 | | - _logger.warning( |
113 | | - "Failed to delete API key with ID: %s. Ignoring error", |
114 | | - path_params.api_key_id, |
115 | | - exc_info=err, |
116 | | - ) |
| 97 | + await _api.delete_api_key( |
| 98 | + request.app, |
| 99 | + api_key_id=path_params.api_key_id, |
| 100 | + user_id=req_ctx.user_id, |
| 101 | + product_name=req_ctx.product_name, |
| 102 | + ) |
117 | 103 |
|
118 | 104 | return web.json_response(status=status.HTTP_204_NO_CONTENT) |
0 commit comments