Skip to content

Commit 32caa44

Browse files
Merge branch 'is7930/refactor-async-jobs-rpc-routes' of github.com:giancarloromeo/osparc-simcore into is7930/refactor-async-jobs-rpc-routes
2 parents 377f6b8 + 321f218 commit 32caa44

File tree

28 files changed

+407
-179
lines changed

28 files changed

+407
-179
lines changed

api/specs/web-server/_auth.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,15 @@ async def logout(_body: LogoutBody):
153153

154154
@router.get(
155155
"/auth:check",
156-
operation_id="check_authentication",
157156
status_code=status.HTTP_204_NO_CONTENT,
158157
responses={
159158
status.HTTP_401_UNAUTHORIZED: {
160159
"model": EnvelopedError,
161-
"description": "unauthorized reset due to invalid token code",
162160
}
163161
},
164162
)
165163
async def check_auth():
166-
"""checks if user is authenticated in the platform"""
164+
"""checks whether user request is authenticated"""
167165

168166

169167
@router.post(

services/static-webserver/client/source/class/osparc/dashboard/ResourceDetails.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
890890
return;
891891
}
892892

893-
if (!osparc.study.Utils.canCreateFunction(this.__resourceData["workbench"])) {
893+
if (!osparc.study.Utils.isPotentialFunction(this.__resourceData["workbench"])) {
894894
return;
895895
}
896896

services/static-webserver/client/source/class/osparc/study/Utils.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,22 @@ qx.Class.define("osparc.study.Utils", {
250250
return Array.from(services);
251251
},
252252

253+
extractComputationalServices: function(workbench) {
254+
const computationals = Object.values(workbench).filter(node => {
255+
const metadata = osparc.store.Services.getMetadata(node["key"], node["version"]);
256+
return metadata && osparc.data.model.Node.isComputational(metadata);
257+
});
258+
return computationals;
259+
},
260+
261+
extractDynamicServices: function(workbench) {
262+
const dynamics = Object.values(workbench).filter(node => {
263+
const metadata = osparc.store.Services.getMetadata(node["key"], node["version"]);
264+
return metadata && osparc.data.model.Node.isDynamic(metadata);
265+
});
266+
return dynamics;
267+
},
268+
253269
extractFilePickers: function(workbench) {
254270
const parameters = Object.values(workbench).filter(srv => srv["key"].includes("simcore/services/frontend/file-picker"));
255271
return parameters;
@@ -277,20 +293,28 @@ qx.Class.define("osparc.study.Utils", {
277293
return parameters;
278294
},
279295

280-
canCreateFunction: function(workbench) {
296+
isPotentialFunction: function(workbench) {
281297
// in order to create a function, the pipeline needs:
282-
// - at least one parameter (or file-picker (file type parameter))
283-
// - at least one probe
298+
// - at least one parameter or one probe
299+
// - for now, only float types are allowed
300+
// - at least one computational service
301+
// - no dynamic services
284302

285303
// const filePickers = osparc.study.Utils.extractFilePickers(workbench);
286304
// const parameters = osparc.study.Utils.extractParameters(workbench);
287305
// const probes = osparc.study.Utils.extractProbes(workbench);
288306
// return (filePickers.length + parameters.length) && probes.length;
289307

290-
// - for now, only float types are allowed
291308
const parameters = osparc.study.Utils.extractFunctionableParameters(workbench);
292309
const probes = osparc.study.Utils.extractFunctionableProbes(workbench);
293-
return parameters.length && probes.length;
310+
const computationals = osparc.study.Utils.extractComputationalServices(workbench);
311+
const dynamics = osparc.study.Utils.extractDynamicServices(workbench);
312+
313+
return (
314+
(parameters.length || probes.length) &&
315+
computationals.length > 0 &&
316+
dynamics.length === 0
317+
);
294318
},
295319

296320
getCantReadServices: function(studyServices = []) {

services/web/server/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.69.0
1+
0.69.1

services/web/server/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.69.0
2+
current_version = 0.69.1
33
commit = True
44
message = services/webserver api version: {current_version} → {new_version}
55
tag = False

services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ openapi: 3.1.0
22
info:
33
title: simcore-service-webserver
44
description: Main service with an interface (http-API & websockets) to the web front-end
5-
version: 0.69.0
5+
version: 0.69.1
66
servers:
77
- url: ''
88
description: webserver
@@ -238,13 +238,13 @@ paths:
238238
tags:
239239
- auth
240240
summary: Check Auth
241-
description: checks if user is authenticated in the platform
242-
operationId: check_authentication
241+
description: checks whether user request is authenticated
242+
operationId: check_auth
243243
responses:
244244
'204':
245245
description: Successful Response
246246
'401':
247-
description: unauthorized reset due to invalid token code
247+
description: Unauthorized
248248
content:
249249
application/json:
250250
schema:

services/web/server/src/simcore_service_webserver/application.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from .invitations.plugin import setup_invitations
3030
from .licenses.plugin import setup_licenses
3131
from .login.plugin import setup_login
32+
from .login_auth.plugin import setup_login_auth
3233
from .long_running_tasks import setup_long_running_tasks
3334
from .notifications.plugin import setup_notifications
3435
from .payments.plugin import setup_payments
@@ -169,6 +170,25 @@ def create_application() -> web.Application:
169170
return app
170171

171172

173+
def create_application_auth() -> web.Application:
174+
app = create_safe_application()
175+
setup_settings(app)
176+
setup_rest(app)
177+
setup_db(app)
178+
179+
setup_login_auth(app)
180+
181+
# NOTE: *last* events
182+
app.on_startup.append(_welcome_banner)
183+
app.on_shutdown.append(_finished_banner)
184+
185+
_logger.debug(
186+
"Routes in application-auth: \n %s", pformat(app.router.named_resources())
187+
)
188+
189+
return app
190+
191+
172192
def run_service(app: web.Application, config: dict[str, Any]):
173193
web.run_app(
174194
app,
@@ -177,9 +197,3 @@ def run_service(app: web.Application, config: dict[str, Any]):
177197
# this gets overriden by the gunicorn config in /docker/boot.sh
178198
access_log_format='%a %t "%r" %s %b --- [%Dus] "%{Referer}i" "%{User-Agent}i"',
179199
)
180-
181-
182-
__all__: tuple[str, ...] = (
183-
"create_application",
184-
"run_service",
185-
)

services/web/server/src/simcore_service_webserver/application_settings.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from functools import cached_property
3-
from typing import Annotated, Any, Final
3+
from typing import Annotated, Any, Final, Literal
44

55
from aiohttp import web
66
from common_library.basic_types import DEFAULT_FACTORY
@@ -95,6 +95,13 @@ class ApplicationSettings(BaseApplicationSettings, MixinLoggingSettings):
9595
Field(None, description="Stack name defined upon deploy (see main Makefile)"),
9696
]
9797

98+
WEBSERVER_APP_FACTORY_NAME: Annotated[
99+
Literal["WEBSERVER_FULL_APP_FACTORY", "WEBSERVER_AUTHZ_APP_FACTORY"],
100+
Field(
101+
description="Application factory to be lauched by the gunicorn server",
102+
),
103+
] = "WEBSERVER_FULL_APP_FACTORY"
104+
98105
WEBSERVER_DEV_FEATURES_ENABLED: Annotated[
99106
bool,
100107
Field(

services/web/server/src/simcore_service_webserver/cli.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Application's command line .
1+
"""Application's command line .
22
33
Why does this file exist, and why not put this in __main__?
44
@@ -15,13 +15,12 @@
1515

1616
import logging
1717
import os
18-
from typing import Final
18+
from typing import Annotated, Final
1919

2020
import typer
2121
from aiohttp import web
2222
from common_library.json_serialization import json_dumps
2323
from settings_library.utils_cli import create_settings_command
24-
from typing_extensions import Annotated
2524

2625
from .application_settings import ApplicationSettings
2726
from .login import cli as login_cli
@@ -42,7 +41,6 @@ def _setup_app_from_settings(
4241
# NOTE: keeping imports here to reduce CLI load time
4342
from .application import create_application
4443
from .application_settings_utils import convert_to_app_config
45-
from .log import setup_logging
4644

4745
# NOTE: By having an equivalent config allows us
4846
# to keep some of the code from the previous
@@ -51,30 +49,39 @@ def _setup_app_from_settings(
5149
# given configs and changing those would not have
5250
# a meaningful RoI.
5351
config = convert_to_app_config(settings)
54-
55-
setup_logging(
56-
level=settings.log_level,
57-
slow_duration=settings.AIODEBUG_SLOW_DURATION_SECS,
58-
log_format_local_dev_enabled=settings.WEBSERVER_LOG_FORMAT_LOCAL_DEV_ENABLED,
59-
logger_filter_mapping=settings.WEBSERVER_LOG_FILTER_MAPPING,
60-
tracing_settings=settings.WEBSERVER_TRACING,
61-
)
62-
6352
app = create_application()
6453
return (app, config)
6554

6655

6756
async def app_factory() -> web.Application:
6857
"""Created to launch app from gunicorn (see docker/boot.sh)"""
58+
from .application import create_application_auth
59+
from .log import setup_logging
60+
6961
app_settings = ApplicationSettings.create_from_envs()
70-
assert app_settings.SC_BUILD_TARGET # nosec
7162

7263
_logger.info(
7364
"Application settings: %s",
7465
json_dumps(app_settings, indent=2, sort_keys=True),
7566
)
7667

77-
app, _ = _setup_app_from_settings(app_settings)
68+
_logger.info(
69+
"Using application factory: %s", app_settings.WEBSERVER_APP_FACTORY_NAME
70+
)
71+
72+
setup_logging(
73+
level=app_settings.log_level,
74+
slow_duration=app_settings.AIODEBUG_SLOW_DURATION_SECS,
75+
log_format_local_dev_enabled=app_settings.WEBSERVER_LOG_FORMAT_LOCAL_DEV_ENABLED,
76+
logger_filter_mapping=app_settings.WEBSERVER_LOG_FILTER_MAPPING,
77+
tracing_settings=app_settings.WEBSERVER_TRACING,
78+
)
79+
80+
if app_settings.WEBSERVER_APP_FACTORY_NAME == "WEBSERVER_AUTHZ_APP_FACTORY":
81+
82+
app = create_application_auth()
83+
else:
84+
app, _ = _setup_app_from_settings(app_settings)
7885

7986
return app
8087

services/web/server/src/simcore_service_webserver/login/_controller/rest/auth.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -287,19 +287,3 @@ async def logout(request: web.Request) -> web.Response:
287287
await security_web.forget_identity(request, response)
288288

289289
return response
290-
291-
292-
@routes.get(f"/{API_VTAG}/auth:check", name="check_authentication")
293-
@login_required
294-
async def check_auth(request: web.Request) -> web.Response:
295-
# lightweight endpoint for checking if users are authenticated
296-
# used primarily by Traefik auth middleware to verify session cookies
297-
298-
# NOTE: for future development
299-
# if database access is added here, services like jupyter-math
300-
# which load a lot of resources will have a big performance hit
301-
# consider caching some properties required by this endpoint or rely on Redis
302-
303-
assert request # nosec
304-
305-
return web.json_response(status=status.HTTP_204_NO_CONTENT)

0 commit comments

Comments
 (0)