Skip to content

Commit 984c9b8

Browse files
author
Pedro Crespo
committed
Cleanup rest. test_rest running
1 parent 4597c24 commit 984c9b8

25 files changed

+158
-202
lines changed

packages/service-library/src/servicelib/openapi.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ async def create_openapi_specs(location: str) -> OpenApiSpec:
4343
if URL(location).host:
4444
spec_dict, spec_url = await load_from_url(URL(location))
4545
else:
46-
spec_dict, spec_url = load_from_path(Path(location))
46+
path = Path(location).expanduser().resolve()
47+
spec_dict, spec_url = load_from_path(path)
4748

4849
return openapi_core.create_spec(spec_dict, spec_url)
4950

@@ -62,6 +63,11 @@ def create_specs(openapi_path: Path) -> OpenApiSpec:
6263
return spec
6364

6465

66+
def get_base_path(specs: OpenApiSpec) ->str :
67+
# TODO: guarantee this convention is true
68+
return '/v' + specs.info.version.split('.')[0]
69+
70+
6571
__all__ = (
6672
'create_specs',
6773
'OAI_VERSION',

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@ def create_application(config: dict):
3535
log.debug("Config:\n%s",
3636
json.dumps(config, indent=2, sort_keys=True))
3737

38+
testing = config["main"].get("testing", False)
3839

3940
# TODO: create dependency mechanism and compute setup order
41+
setup_statics(app)
4042
setup_db(app)
4143
setup_session(app)
4244
setup_security(app)
45+
setup_rest(app, debug=testing)
4346
setup_email(app)
4447
setup_computation(app)
45-
setup_statics(app)
4648
setup_sockets(app)
47-
setup_rest(app)
4849
setup_login(app)
4950
setup_director(app)
5051
setup_s3(app)

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

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def create_schema():
3939
"main": T.Dict({
4040
"host": T.IP,
4141
"port": T.Int(),
42-
T.Key("public_url", optional=True): T.Or(T.String(), T.List(T.String)), # full url seen by front-end
4342
"client_outdir": T.String(),
4443
"log_level": T.Enum(*logging._nameToLevel.keys()), # pylint: disable=protected-access
4544
"testing": T.Bool(),

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from .director import director_sdk
2222
from .application_keys import APP_CONFIG_KEY
23+
from .db_config import CONFIG_SECTION_NAME as CONFIG_DB_SECTION
2324
from .computation_worker import celery
2425

2526
# TODO: this should be coordinated with postgres options from config/server.yaml
@@ -45,7 +46,7 @@ async def init_database(_app):
4546
RETRY_COUNT = 20
4647

4748
# db config
48-
db_config = _app[APP_CONFIG_KEY]["postgres"]
49+
db_config = _app[APP_CONFIG_KEY][CONFIG_DB_SECTION]["postgres"]
4950
endpoint = "postgresql+psycopg2://{user}:{password}@{host}:{port}/{database}".format(**db_config)
5051

5152
db_engine = create_engine(endpoint,

services/web/server/src/simcore_service_webserver/config/host-dev-config.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ main:
44
host: 127.0.0.1
55
log_level: INFO
66
port: 8080
7-
public_url: http://localhost:8080
87
testing: true
98
disable_services: []
109
db:
@@ -40,7 +39,8 @@ smtp:
4039
# endpoint: play.minio.io:9000
4140
# secret_key: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG'
4241
rest:
43-
oas:
44-
version: v0
45-
location: ../../../../../../api/specs/webserver/v0
46-
#location: http://localhost:8043/api/specs/webserver/v0
42+
version: v0
43+
location: ~/devp/osparc-simcore/api/specs/webserver/v0/openapi.yaml
44+
#location: http://localhost:8043/api/specs/webserver/v0/openapi.yaml
45+
extra_urls:
46+
- http://localhost:8080

services/web/server/src/simcore_service_webserver/config/server-defaults.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ main:
44
host: 127.0.0.1
55
log_level: DEBUG
66
port: 8080
7-
public_url: http://localhost:9081
87
testing: true
98
disable_services: []
109
director:
@@ -40,6 +39,7 @@ smtp:
4039
username: Null
4140
password: Null
4241
rest:
43-
oas:
44-
version: v0
45-
location: http://localhost:8043/api/specs/webserver/v0
42+
version: v0
43+
location: http://localhost:8043/api/specs/webserver/v0/openapi.yaml
44+
extra_urls:
45+
- http://localhost:9081

services/web/server/src/simcore_service_webserver/config/server-docker-dev.yaml

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ version: "1.0"
44
main:
55
host: 0.0.0.0
66
port: 8080
7-
public_url: ${OSPARC_PUBLIC_URL}
87
client_outdir: ${SIMCORE_WEB_OUTDIR}
98
log_level: DEBUG
109
testing: True
11-
# disable_services: [director, postgres, rabbit, s3]
1210
director:
1311
host: ${DIRECTOR_HOST}
1412
port: ${DIRECTOR_PORT}
@@ -40,7 +38,8 @@ smtp:
4038
username: Null
4139
password: Null
4240
rest:
43-
oas:
44-
version: v0
45-
location: http://${APIHUB_HOST}:${APIHUB_PORT}/api/specs/webserver/v0
41+
version: v0
42+
location: http://${APIHUB_HOST}:${APIHUB_PORT}/api/specs/webserver/v0/openapi.yaml
43+
extra_urls:
44+
- ${OSPARC_PUBLIC_URL}
4645
...

services/web/server/src/simcore_service_webserver/config/server-docker-prod.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ version: "1.0"
44
main:
55
host: 0.0.0.0
66
port: 8080
7-
public_url: ${OSPARC_PUBLIC_URL}
87
client_outdir: ${SIMCORE_WEB_OUTDIR}
98
log_level: INFO
109
testing: False
@@ -39,7 +38,8 @@ smtp:
3938
username: Null
4039
password: Null
4140
rest:
42-
oas:
43-
version: v0
44-
location: http://${APIHUB_HOST}:${APIHUB_PORT}/api/specs/webserver/v0
41+
version: v0
42+
location: http://${APIHUB_HOST}:${APIHUB_PORT}/api/specs/webserver/v0/openapi.yaml
43+
extra_urls:
44+
- ${OSPARC_PUBLIC_URL}
4545
...

services/web/server/src/simcore_service_webserver/config/server-template.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ smtp:
3838
username: Null
3939
password: Null
4040
rest:
41-
oas:
42-
version: v0
43-
location: http://${APIHUB_HOST}:${APIHUB_PORT}/api/specs/webserver/v0
41+
version: v0
42+
location: http://${APIHUB_HOST}:${APIHUB_PORT}/api/specs/webserver/v0/openapi.yaml
43+
extra_urls:
44+
- ${OSPARC_PUBLIC_URL}
4445
...

services/web/server/src/simcore_service_webserver/login/__init__.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,17 @@
1111

1212
from ..application_keys import APP_CONFIG_KEY, APP_DB_POOL_KEY
1313
from ..db import DSN
14-
from ..email_config import CONFIG_SECTION_NAME
15-
from .cfg import cfg
14+
from ..email_config import CONFIG_SECTION_NAME as CONFIG_STMP_SECTION
15+
from ..rest_config import APP_OPENAPI_SPECS_KEY
16+
from .cfg import cfg, APP_LOGIN_CONFIG
1617
from .storage import AsyncpgStorage
18+
from .routes import create_routes
1719

1820
log = logging.getLogger(__name__)
1921

20-
APP_LOGIN_CONFIG = __name__ + ".config"
21-
CFG_LOGIN_STORAGE = __name__ + ".storage"
22-
2322

2423
async def pg_pool(app: web.Application):
25-
26-
smtp_config = app[APP_CONFIG_KEY][CONFIG_SECTION_NAME]
24+
smtp_config = app[APP_CONFIG_KEY][CONFIG_STMP_SECTION]
2725
config = {"SMTP_{}".format(k.upper()): v for k, v in smtp_config.items()}
2826
#'SMTP_SENDER': None,
2927
#'SMTP_HOST': REQUIRED,
@@ -47,16 +45,22 @@ async def pg_pool(app: web.Application):
4745

4846
def setup(app: web.Application):
4947
log.debug("Setting up %s ...", __name__)
50-
app.on_startup.append(pg_pool)
5148

49+
# TODO: requires rest ready!
50+
assert CONFIG_STMP_SECTION in app[APP_CONFIG_KEY]
51+
52+
# routes
53+
specs = app[APP_OPENAPI_SPECS_KEY]
54+
routes = create_routes(specs)
55+
app.router.add_routes(routes)
56+
57+
# signals
58+
app.on_startup.append(pg_pool)
5259

53-
def get_storage(app: web.Application):
54-
return app[APP_LOGIN_CONFIG]['STORAGE']
5560

5661
# alias
5762
setup_login = setup
5863

5964
__all__ = (
60-
'setup_login',
61-
'get_storage'
65+
'setup_login'
6266
)

services/web/server/src/simcore_service_webserver/login/cfg.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from aiohttp import web
2+
13
REQUIRED = object()
24
DEFAULTS = {
35
'COMMON_THEME': 'templates/common',
@@ -48,6 +50,12 @@
4850
'STORAGE': REQUIRED,
4951
}
5052

53+
APP_LOGIN_CONFIG = __name__ + ".config"
54+
CFG_LOGIN_STORAGE = __name__ + ".storage"
55+
56+
def get_storage(app: web.Application):
57+
return app[APP_LOGIN_CONFIG]['STORAGE']
58+
5159

5260
# pylint: disable=W0231
5361
class Cfg(dict):

services/web/server/src/simcore_service_webserver/login/handlers.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
from servicelib.rest_models import LogMessageType
77
from servicelib.rest_utils import extract_and_validate
88

9-
from ..db_models import UserRole, UserStatus, ConfirmationAction
9+
from ..db_models import ConfirmationAction, UserRole, UserStatus
1010
from ..security import (authorized_userid, check_password, encrypt_password,
1111
forget, login_required, remember)
12-
from .cfg import cfg # FIXME: do not use singletons!
13-
from . import get_storage
12+
from .cfg import cfg, get_storage # FIXME: do not use singletons!
1413
from .storage import AsyncpgStorage
1514
from .utils import (common_themed, get_client_ip, is_confirmation_allowed,
1615
is_confirmation_expired, make_confirmation_link,

services/web/server/src/simcore_service_webserver/login/routes.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
def create(specs: openapi.Spec) -> List[web.RouteDef]:
2121
# TODO: consider the case in which server creates routes for both v0 and v1!!!
2222
# TODO: should this be taken from servers instead?
23-
BASEPATH = '/v' + specs.info.version.split('.')[0]
23+
base_path = openapi.get_base_path(specs)
2424

2525
log.debug("creating %s ", __name__)
2626
routes = []
@@ -30,22 +30,30 @@ def create(specs: openapi.Spec) -> List[web.RouteDef]:
3030
# auth --
3131
path, handler = '/auth/register', auth_handlers.register
3232
operation_id = specs.paths[path].operations['post'].operation_id
33-
routes.append( web.post(BASEPATH+path, handler, name=operation_id) )
33+
routes.append( web.post(base_path+path, handler, name=operation_id) )
3434

3535
path, handler = '/auth/login', auth_handlers.login
3636
operation_id = specs.paths[path].operations['post'].operation_id
37-
routes.append( web.post(BASEPATH+path, handler, name=operation_id) )
37+
routes.append( web.post(base_path+path, handler, name=operation_id) )
3838

3939
path, handler = '/auth/logout', auth_handlers.logout
4040
operation_id = specs.paths[path].operations['get'].operation_id
41-
routes.append( web.get(BASEPATH+path, handler, name=operation_id) )
41+
routes.append( web.get(base_path+path, handler, name=operation_id) )
4242

4343
path, handler = '/auth/confirmation/{code}', auth_handlers.email_confirmation
4444
operation_id = specs.paths[path].operations['get'].operation_id
45-
routes.append( web.get(BASEPATH+path, handler, name=operation_id) )
45+
routes.append( web.get(base_path+path, handler, name=operation_id) )
4646

4747
path, handler = '/auth/change-email', auth_handlers.change_email
4848
operation_id = specs.paths[path].operations['post'].operation_id
49-
routes.append( web.post(BASEPATH+path, handler, name=operation_id) )
49+
routes.append( web.post(base_path+path, handler, name=operation_id) )
5050

5151
return routes
52+
53+
54+
# alias
55+
create_routes = create
56+
57+
__all__ = (
58+
'create_routes'
59+
)

0 commit comments

Comments
 (0)