Skip to content

Commit

Permalink
Cleanup rest. test_rest running
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Crespo committed Nov 12, 2018
1 parent 4597c24 commit 984c9b8
Show file tree
Hide file tree
Showing 25 changed files with 158 additions and 202 deletions.
8 changes: 7 additions & 1 deletion packages/service-library/src/servicelib/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ async def create_openapi_specs(location: str) -> OpenApiSpec:
if URL(location).host:
spec_dict, spec_url = await load_from_url(URL(location))
else:
spec_dict, spec_url = load_from_path(Path(location))
path = Path(location).expanduser().resolve()
spec_dict, spec_url = load_from_path(path)

return openapi_core.create_spec(spec_dict, spec_url)

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


def get_base_path(specs: OpenApiSpec) ->str :
# TODO: guarantee this convention is true
return '/v' + specs.info.version.split('.')[0]


__all__ = (
'create_specs',
'OAI_VERSION',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ def create_application(config: dict):
log.debug("Config:\n%s",
json.dumps(config, indent=2, sort_keys=True))

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

# TODO: create dependency mechanism and compute setup order
setup_statics(app)
setup_db(app)
setup_session(app)
setup_security(app)
setup_rest(app, debug=testing)
setup_email(app)
setup_computation(app)
setup_statics(app)
setup_sockets(app)
setup_rest(app)
setup_login(app)
setup_director(app)
setup_s3(app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def create_schema():
"main": T.Dict({
"host": T.IP,
"port": T.Int(),
T.Key("public_url", optional=True): T.Or(T.String(), T.List(T.String)), # full url seen by front-end
"client_outdir": T.String(),
"log_level": T.Enum(*logging._nameToLevel.keys()), # pylint: disable=protected-access
"testing": T.Bool(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from .director import director_sdk
from .application_keys import APP_CONFIG_KEY
from .db_config import CONFIG_SECTION_NAME as CONFIG_DB_SECTION
from .computation_worker import celery

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

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

db_engine = create_engine(endpoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ main:
host: 127.0.0.1
log_level: INFO
port: 8080
public_url: http://localhost:8080
testing: true
disable_services: []
db:
Expand Down Expand Up @@ -40,7 +39,8 @@ smtp:
# endpoint: play.minio.io:9000
# secret_key: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG'
rest:
oas:
version: v0
location: ../../../../../../api/specs/webserver/v0
#location: http://localhost:8043/api/specs/webserver/v0
version: v0
location: ~/devp/osparc-simcore/api/specs/webserver/v0/openapi.yaml
#location: http://localhost:8043/api/specs/webserver/v0/openapi.yaml
extra_urls:
- http://localhost:8080
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ main:
host: 127.0.0.1
log_level: DEBUG
port: 8080
public_url: http://localhost:9081
testing: true
disable_services: []
director:
Expand Down Expand Up @@ -40,6 +39,7 @@ smtp:
username: Null
password: Null
rest:
oas:
version: v0
location: http://localhost:8043/api/specs/webserver/v0
version: v0
location: http://localhost:8043/api/specs/webserver/v0/openapi.yaml
extra_urls:
- http://localhost:9081
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ version: "1.0"
main:
host: 0.0.0.0
port: 8080
public_url: ${OSPARC_PUBLIC_URL}
client_outdir: ${SIMCORE_WEB_OUTDIR}
log_level: DEBUG
testing: True
# disable_services: [director, postgres, rabbit, s3]
director:
host: ${DIRECTOR_HOST}
port: ${DIRECTOR_PORT}
Expand Down Expand Up @@ -40,7 +38,8 @@ smtp:
username: Null
password: Null
rest:
oas:
version: v0
location: http://${APIHUB_HOST}:${APIHUB_PORT}/api/specs/webserver/v0
version: v0
location: http://${APIHUB_HOST}:${APIHUB_PORT}/api/specs/webserver/v0/openapi.yaml
extra_urls:
- ${OSPARC_PUBLIC_URL}
...
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version: "1.0"
main:
host: 0.0.0.0
port: 8080
public_url: ${OSPARC_PUBLIC_URL}
client_outdir: ${SIMCORE_WEB_OUTDIR}
log_level: INFO
testing: False
Expand Down Expand Up @@ -39,7 +38,8 @@ smtp:
username: Null
password: Null
rest:
oas:
version: v0
location: http://${APIHUB_HOST}:${APIHUB_PORT}/api/specs/webserver/v0
version: v0
location: http://${APIHUB_HOST}:${APIHUB_PORT}/api/specs/webserver/v0/openapi.yaml
extra_urls:
- ${OSPARC_PUBLIC_URL}
...
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ smtp:
username: Null
password: Null
rest:
oas:
version: v0
location: http://${APIHUB_HOST}:${APIHUB_PORT}/api/specs/webserver/v0
version: v0
location: http://${APIHUB_HOST}:${APIHUB_PORT}/api/specs/webserver/v0/openapi.yaml
extra_urls:
- ${OSPARC_PUBLIC_URL}
...
28 changes: 16 additions & 12 deletions services/web/server/src/simcore_service_webserver/login/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@

from ..application_keys import APP_CONFIG_KEY, APP_DB_POOL_KEY
from ..db import DSN
from ..email_config import CONFIG_SECTION_NAME
from .cfg import cfg
from ..email_config import CONFIG_SECTION_NAME as CONFIG_STMP_SECTION
from ..rest_config import APP_OPENAPI_SPECS_KEY
from .cfg import cfg, APP_LOGIN_CONFIG
from .storage import AsyncpgStorage
from .routes import create_routes

log = logging.getLogger(__name__)

APP_LOGIN_CONFIG = __name__ + ".config"
CFG_LOGIN_STORAGE = __name__ + ".storage"


async def pg_pool(app: web.Application):

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

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

# TODO: requires rest ready!
assert CONFIG_STMP_SECTION in app[APP_CONFIG_KEY]

# routes
specs = app[APP_OPENAPI_SPECS_KEY]
routes = create_routes(specs)
app.router.add_routes(routes)

# signals
app.on_startup.append(pg_pool)

def get_storage(app: web.Application):
return app[APP_LOGIN_CONFIG]['STORAGE']

# alias
setup_login = setup

__all__ = (
'setup_login',
'get_storage'
'setup_login'
)
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from aiohttp import web

REQUIRED = object()
DEFAULTS = {
'COMMON_THEME': 'templates/common',
Expand Down Expand Up @@ -48,6 +50,12 @@
'STORAGE': REQUIRED,
}

APP_LOGIN_CONFIG = __name__ + ".config"
CFG_LOGIN_STORAGE = __name__ + ".storage"

def get_storage(app: web.Application):
return app[APP_LOGIN_CONFIG]['STORAGE']


# pylint: disable=W0231
class Cfg(dict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from servicelib.rest_models import LogMessageType
from servicelib.rest_utils import extract_and_validate

from ..db_models import UserRole, UserStatus, ConfirmationAction
from ..db_models import ConfirmationAction, UserRole, UserStatus
from ..security import (authorized_userid, check_password, encrypt_password,
forget, login_required, remember)
from .cfg import cfg # FIXME: do not use singletons!
from . import get_storage
from .cfg import cfg, get_storage # FIXME: do not use singletons!
from .storage import AsyncpgStorage
from .utils import (common_themed, get_client_ip, is_confirmation_allowed,
is_confirmation_expired, make_confirmation_link,
Expand Down
20 changes: 14 additions & 6 deletions services/web/server/src/simcore_service_webserver/login/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
def create(specs: openapi.Spec) -> List[web.RouteDef]:
# TODO: consider the case in which server creates routes for both v0 and v1!!!
# TODO: should this be taken from servers instead?
BASEPATH = '/v' + specs.info.version.split('.')[0]
base_path = openapi.get_base_path(specs)

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

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

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

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

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

return routes


# alias
create_routes = create

__all__ = (
'create_routes'
)
Loading

0 comments on commit 984c9b8

Please sign in to comment.