Skip to content

Is200/auth business logic #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 83 commits into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
2741834
Fixes typos in client after bad merge
Jul 6, 2018
9646035
Merge remote-tracking branch 'upstream/master'
Jul 6, 2018
c3ad81c
Merge remote-tracking branch 'upstream/master'
Jul 6, 2018
d7b91f7
Merge remote-tracking branch 'upstream/master'
Jul 10, 2018
a65aa8e
Merge remote-tracking branch 'upstream/master'
Jul 11, 2018
4edc12a
Merge remote-tracking branch 'upstream/master'
Jul 16, 2018
460bdea
Merge remote-tracking branch 'upstream/master'
Jul 16, 2018
408990d
Merge remote-tracking branch 'upstream/master'
Jul 18, 2018
ee1b91b
Merge remote-tracking branch 'upstream/master'
Jul 20, 2018
cf7b3f4
Merge remote-tracking branch 'upstream/master'
Aug 9, 2018
3f4eed8
Merge remote-tracking branch 'upstream/master'
Aug 22, 2018
14cbec2
Merge remote-tracking branch 'upstream/master'
Aug 23, 2018
b57188b
Merge remote-tracking branch 'upstream/master'
Sep 3, 2018
66e5cdc
Merge remote-tracking branch 'upstream/master'
Sep 4, 2018
31aeb8f
Merge remote-tracking branch 'upstream/master'
Sep 13, 2018
c0dbe36
Merge remote-tracking branch 'upstream/master'
Sep 18, 2018
81111e0
Merge remote-tracking branch 'upstream/master'
Sep 19, 2018
6b4c1bf
Merge remote-tracking branch 'upstream/master'
Sep 24, 2018
bbe7558
Merge remote-tracking branch 'upstream/master'
Sep 25, 2018
fd2befe
Merge remote-tracking branch 'upstream/master'
Oct 10, 2018
6b0dd8f
Merge remote-tracking branch 'upstream/master'
Oct 12, 2018
b706243
Merge remote-tracking branch 'upstream/master'
Oct 17, 2018
0bf32b8
Merge remote-tracking branch 'upstream/master'
Oct 17, 2018
d0664c9
Merge remote-tracking branch 'upstream/master'
Oct 19, 2018
5e895e0
Merge remote-tracking branch 'upstream/master'
Oct 19, 2018
90eb8f4
Merge remote-tracking branch 'upstream/master'
Oct 19, 2018
dc90291
Merge remote-tracking branch 'upstream/master'
Oct 19, 2018
726c5f6
Removed old db module and replaced by a new one
Oct 20, 2018
bc08cf8
Added new db tables
Oct 20, 2018
660f616
Minor cleanup of service library
Oct 20, 2018
076bc32
Cleanup setup session/security as well as models
Oct 20, 2018
78fb231
Split tests in unit and dev subfolders
Oct 20, 2018
1e71cad
WIP: Fixes after running test_security (still not fully working)
Oct 20, 2018
9c40933
Fixes after running test_security
Oct 20, 2018
a7f2370
WIP: Adding login submodule
Oct 22, 2018
b85391d
Moved old auth_handlers into login/fake_handlers and routed using new…
Oct 22, 2018
28285da
WIP: testing login
Oct 22, 2018
38d60c1
Merge branch 'is200/auth-business-logic' of github.com:pcrespov/ospar…
pcrespov Oct 22, 2018
152d2cc
Merge remote-tracking branch 'upstream/master'
pcrespov Oct 22, 2018
3dc0c6d
Merge branch 'master' into is200/auth-business-logic
pcrespov Oct 22, 2018
c05d086
WIP: adding test/login
pcrespov Oct 22, 2018
060d490
Modified app's config to accomodate options for smtp server
pcrespov Oct 22, 2018
ce01554
Login:
pcrespov Oct 22, 2018
c01efa6
Cleanup testing. Disabled old tests and modifying testing configuration
pcrespov Oct 22, 2018
050f636
Fixes makefile to run three separte tests
pcrespov Oct 22, 2018
d92262b
WIP: fixing dependencies
pcrespov Oct 22, 2018
f93736c
Fixes configuration errors
Oct 23, 2018
f804c75
servicelib: flattening submodules
Oct 23, 2018
879669c
Fixes tests/unit
Oct 23, 2018
dcb6cda
Fixes tests/dev
Oct 23, 2018
a1e8ff1
WIP: fixing tests/login
Oct 23, 2018
e690b32
tests/login/test_login passes
Oct 23, 2018
4dc919a
WIP: test_registration passes
Oct 24, 2018
b7d149f
servicelib: created response_utils
Oct 24, 2018
ff3d6db
test_registration passes
Oct 24, 2018
b72aa4f
test_logout
Oct 24, 2018
b0622e6
Replacing cfg.STORAGE singleton by application storage
Oct 24, 2018
226006d
test_login runs
Oct 24, 2018
e1f0190
servicelib new utils
Oct 24, 2018
451da54
Adds postgres service to login tests
Oct 24, 2018
d1e4eed
Merge branch 'is200/auth-business-logic' of github.com:pcrespov/ospar…
Oct 24, 2018
f0ead81
Merge branch 'master' into is200/auth-business-logic
pcrespov Oct 24, 2018
ddbd842
Removed dev tests
Oct 24, 2018
e6553fa
Removed disabled tests
Oct 24, 2018
7d36f7a
Added missing requirements
Oct 24, 2018
752c882
Fixes linter errors
Oct 24, 2018
2786484
Adding infrastructure to create/drop all tables using an aiopg Engine…
Oct 24, 2018
631224c
Getting ownership for servicelib
Oct 24, 2018
e5cd610
Added option to create/initialize db tables
Oct 25, 2018
794ee2a
Fixes sidecar: boot.sh +x
Oct 25, 2018
1370ee8
Fixing db tables definition and creation
Oct 25, 2018
5b90d16
Merge branch 'master' into is200/auth-business-logic
pcrespov Oct 26, 2018
a053649
- Fixes server specs setup
Oct 29, 2018
fafc572
Fixes linter error
Oct 29, 2018
9369cf1
Merge branch 'is200/auth-business-logic' of github.com:pcrespov/ospar…
Oct 29, 2018
cacee1f
Cleanup
Oct 29, 2018
e74ab0a
Fixes null parameters in configuration
Oct 29, 2018
6a00fd7
Fixes pylint error and test_configs.py
Oct 29, 2018
40a6210
Added email setup and hides renderer setup
Oct 29, 2018
94400a2
Fixes lit errors
pcrespov Oct 29, 2018
12a8dd1
Merge branch 'master' into is200/auth-business-logic
pcrespov Oct 29, 2018
a89f8ac
Started deploy tools (prototype)
Oct 30, 2018
350f26e
Fixes linter
Oct 30, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env-devel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# NOTE: write here host gid and docker gid.
# TODO: keep hierarchy
HOST_GID=1000
DOCKER_GID=1001
RUN_DOCKER_ENGINE_ROOT=0
Expand All @@ -18,4 +19,5 @@ S3_ENDPOINT=minio:9000
S3_ACCESS_KEY=12345678
S3_SECRET_KEY=12345678
S3_BUCKET_NAME=simcore

SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
17 changes: 9 additions & 8 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Order is important. The last matching pattern has the most precedence.

# files and folders recursively
/api/ @sanderegg, @pcrespov
/docs/ @pcrespov
/services/computation @mguidon
/services/dy* @sanderegg
/services/sidecar @pcrespov, @mguidon
/services/web/client @odeimaiz, @oetiker
/services/web/server @pcrespov
/services/storage @mguidon
/api/ @sanderegg, @pcrespov
/docs/ @pcrespov
/packages/service-library @pcrespov
/services/computation @mguidon
/services/dy* @sanderegg
/services/sidecar @pcrespov, @mguidon
/services/web/client @odeimaiz, @oetiker
/services/web/server @pcrespov
/services/storage @mguidon

# any change in travis
/.travis.yml @odeimaiz
6 changes: 4 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- **WIP-** prefix in title if still work in progress -->

## What do these changes do?

<!-- Please give a short brief about these changes. -->
Expand All @@ -6,9 +8,8 @@
## Related issue number

<!--
- Add **WIP-** prefix in title if it is still work in progress (i.e. should not be merged but is ready to start reviewing it)
Use [waffle.io] keywords in title/descriptions to trigger bot actions:

- Use [waffle.io] keywords in title/descriptions to trigger bot actions:
- close, closes, close, closes, closed, fix, fixes, fixed, resolve, resolves, resolved #[issueNumber]
- connect to, connects to, connected to, connect, connects, connected #[issueNumber]
-->
Expand All @@ -19,6 +20,7 @@
- [ ] I think the code is well written
- [ ] Unit tests for the changes exist
- [ ] Documentation reflects the changes
- [ ] **Runs in the swarm**
- [ ] If you design a new module, add your user to .github/CODEOWNERS

[waffle.io]:https://waffle.io/marketing-assets/documents/waffleio_cheatsheet_v1.pdf?utm_source=blog&utm_medium=cheatsheet-ctabutton&utm_campaign=cheatsheet
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ run_test:
pytest --cov=pytest_docker -v packages/pytest_docker/tests
pytest --cov=s3wrapper -v packages/s3wrapper/tests
pytest --cov=simcore_sdk -v packages/simcore-sdk/tests
pytest --cov=simcore_service_webserver -v services/web/server/tests
pytest --cov=simcore_service_webserver -v services/web/server/tests/unit
pytest --cov=simcore_service_webserver -v services/web/server/tests/login
pytest --cov=simcore_service_director -v services/director/tests
pytest --cov=simcore_service_storage -v -m "not travis" services/storage/tests

Expand All @@ -116,7 +117,7 @@ test:
make run_test
make after_test

PLATFORM_VERSION=3.17
PLATFORM_VERSION=3.18

push_platform_images:
${DOCKER} login masu.speag.com
Expand Down
35 changes: 35 additions & 0 deletions packages/deploy-tools/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
SHELL = /bin/bash

##
# Definitions.

.SUFFIXES:

# Python virtual environment
VENV_DIR = $(CURDIR)/../../.venv
OUTPUT_DIR = $(CURDIR)/out


##
# Targets .

.PHONE: up-swarm
up-swarm:
docker swarm init
docker stack deploy -c "$(OUTPUT_DIR)/docker-compose.yml" services


.PHONE: down-swarm
down-swarm:
docker swarm leave -f


$(VENV_DIR):
@python3 -m venv "$(VENV_DIR)"
@"$(VENV_DIR)/bin/pip3" install --upgrade pip wheel setuptools
@"$(VENV_DIR)/bin/pip3" install pylint
@echo "To activate the virtual environment, execute 'source env/bin/activate'"

.PHONY: venv
# venv – Create the virtual environment into venv folder
venv: $(VENV_DIR)
8 changes: 8 additions & 0 deletions packages/deploy-tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Deploy tools [Under development]


### Features

- finds ``osparc-simcore/services/docker-compose`` files
- merges docker-compose files
- resolves services/docker-compose files and produces a docker-compose for deployment
2 changes: 2 additions & 0 deletions packages/deploy-tools/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
typing==3.6.6
PyYAML==3.13
58 changes: 58 additions & 0 deletions packages/deploy-tools/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""The setup script

"""
import sys
import re
from pathlib import Path
from setuptools import setup, find_packages
from typing import List

CURRENT_DIR = Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent
COMMENT = re.compile(r'^\s*#')

def list_packages(reqpath: Path) -> List[str]:
pkg_names = []
with reqpath.open() as f:
pkg_names = [line.strip() for line in f.readlines() if not COMMENT.match(line)]
return pkg_names


requirements = list_packages(CURRENT_DIR / 'requirements.txt')

setup_requirements = ['pytest-runner', ]

test_requirements = list_packages(CURRENT_DIR / 'tests' / 'requirements.txt')

setup(
name='simcore-deploy-tools',
version='0.1.0',
author="Pedro Crespo (pcrespov)",
description="Collection of deploy tools",
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 3.6'
],
license="MIT license",
install_requires=requirements,
packages=find_packages(where='src'),
package_dir={
'': 'src',
},
python_requires='>3.6, <3.7',
include_package_data=True,
setup_requires=setup_requirements,
test_suite='tests',
tests_require=test_requirements,
zip_safe=False,
entry_points={
'console_scripts': [
'simcore-deploy-tools = deploytools.cli:main',
],
}
)
Empty file.
13 changes: 13 additions & 0 deletions packages/deploy-tools/src/deploytools/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# TODO: redo with cookie-cutter
import sys

from .utils import output_dir
from .swarm_composer import create_deploy

def main(args=None):
if args is None:
args = sys.argv[1:]

# TODO: use click to create cli!
outdir = output_dir()
create_deploy(outdir)
42 changes: 42 additions & 0 deletions packages/deploy-tools/src/deploytools/merge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
""" Merges based on docker-compose tools
"""

from itertools import accumulate, chain
from typing import Dict, List, TypeVar

T = TypeVar('T')


def merge_lists(lhs: List[T], rhs: List[T]) -> List:
# NOTE assumes all elements in the list are of the same type!
# NOTE: does not respect order
res = list( set(lhs + rhs) )
return res


def merge_dicts(lhs: Dict, rhs: Dict) -> Dict:

merged_keys = set( chain(lhs.keys(), rhs.keys()) )
res = dict.fromkeys(merged_keys, None)
for key in merged_keys:
if key in lhs:
lhs_value = lhs[key]
if key not in rhs:
res[key] = lhs_value
else: # rhs overrides
assert key in rhs
rhs_value = rhs[key]
if isinstance(rhs_value, dict):
res[key] = merge_dicts(lhs_value, rhs_value)
elif isinstance(rhs_value, list):
res[key] = merge_lists(lhs_value, rhs_value)
else:
res[key] = rhs_value
else:
res[key] = rhs[key]

return res


def merge_docker_compose(*compose_dicts):
return list(accumulate(compose_dicts, merge_dicts))[-1]
34 changes: 34 additions & 0 deletions packages/deploy-tools/src/deploytools/readers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
""" File readers

"""

from typing import Dict, Optional

import yaml

from .utils import env_devel_file, osparc_simcore_root_dir


def load_docker_compose(suffix: Optional[str]=None) -> Dict:
name = "docker-compose"
if suffix:
name += suffix
name += ".yml"
dcpath = osparc_simcore_root_dir() / "services" / name
assert dcpath.exists(), dcpath

dc = dict()
with dcpath.open() as f:
dc = yaml.safe_load(f)
return dc


def load_devel_environ(name: Optional[str]=None):
environ = {}
with env_devel_file(name).open() as f:
for line in f:
line = line.strip()
if line and not line.startswith("#"):
key, value = line.split("=")
environ[key] = value
return environ
112 changes: 112 additions & 0 deletions packages/deploy-tools/src/deploytools/swarm_composer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import re
from collections import defaultdict
from copy import deepcopy
from functools import lru_cache
from typing import Dict, List, Optional
from pathlib import Path

from .merge import merge_docker_compose
from .readers import load_devel_environ, load_docker_compose
from .utils import dump_to_file, dump_to_stdout, output_dir


# SWARM OPTIONS ------------
@lru_cache(None)
def get_constraints() -> Dict:
# TODO: check that these constraints are correct
_constraints = defaultdict.fromkeys(["director", "webserver"],
['node.platform.os == linux', "node.role == manager"])
_constraints.default_factory = list

_constraints["apihub"].append('node.platform.os == linux')
return _constraints

#-------------------------------



def resolve_environs(service_environ: List[str]) -> Dict:
""" Creates a dict with the environment variables
inside of a webserver container
"""
host_environ = load_devel_environ()

container_environ = {
# 'SIMCORE_WEB_OUTDIR': 'home/scu/services/web/client' # defined in Dockerfile
}

MATCH = re.compile(r'\$\{(\w+)+')

for item in service_environ:
key, value = item.split("=")
m = MATCH.match(value)
if m:
envkey = m.groups()[0]
value = host_environ[envkey]
container_environ[key] = value

return container_environ



def resolve_deploy(dc_source: Dict, exclude: Optional[List[str]]=None) -> Dict:

constraints = get_constraints()
if exclude is None:
exclude = []

dc_deploy = deepcopy(dc_source)

for name in dc_source["services"]:
service = dc_deploy["services"][name]
if name in exclude:
dc_deploy["services"].pop(name)
continue

# remove builds
service.pop("build", None)

# replace by image
service.setdefault("image", "services_{}:latest".format(name))

# add deploy info
constraint = constraints.get(name, None)
if constraint is not None:
service["deploy"] = {
"placement": {
"constraints": list(constraint)
}
}

# resolve environs
if "environment" in service:
environs = resolve_environs(service["environment"])
service["environment"] = [ "{}={}".format(k,v) for k,v in environs.items()]

print("{:-^20}".format(name))
dump_to_stdout(service)

return dc_deploy


def create_deploy(outdir: Path):

prod = load_docker_compose()
tools = load_docker_compose(".tools")

merged = merge_docker_compose(prod, tools)

dc_deploy = resolve_deploy(merged, exclude=["webclient"])
fpath = outdir / "docker-compose.yml"
dump_to_file(dc_deploy, fpath)

# dc_devel = merge(dc_deploy, docker_compose(".devel"))
# fpath = here() / "out" / "docker-compose.devel.yml"
# yaml_dump(fpath, dc_deploy)





if __name__ == "__main__":
create_deploy(output_dir())
Loading