Skip to content

Commit

Permalink
Merge 8b731da into 77a700b
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinos Kousidis committed May 2, 2018
2 parents 77a700b + 8b731da commit 1b8f365
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 288 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ services:
- docker

before_install:
- pip install -r requirements-dev.txt
- travis_retry pip install --upgrade pip setuptools py
- travis_retry pip install twine wheel coveralls

Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ FROM python:3.6

ENV TERM=xterm
RUN apt-get update && \
apt-get install -y vim-tiny
apt-get install -y vim-tiny && \
pip install --upgrade pip

RUN pip install -e git://github.com/dinosk/reana-commons.git@models#egg=reana-commons

ADD . /code
WORKDIR /code
Expand All @@ -35,4 +38,4 @@ RUN if [ "${DEBUG}" = "true" ]; then pip install -r requirements-dev.txt; pip in
EXPOSE 5000
ENV FLASK_APP reana_workflow_controller/app.py
CMD flask users create info@reana.io &&\
flask run --host=0.0.0.0
flask run --host=0.0.0.0
34 changes: 24 additions & 10 deletions reana_workflow_controller/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

import click
from flask.cli import with_appcontext
from reana_commons.database import Session
from reana_commons.models import Organization, User, UserOrganization

from reana_workflow_controller import config
from reana_workflow_controller.factory import db
from reana_workflow_controller.models import User
from reana_workflow_controller.utils import create_user_space


Expand All @@ -38,26 +38,40 @@ def users():

@users.command('create')
@click.argument('email')
@click.option('-o', '--organization', 'organization',
@click.option('-o', '--organization', 'organization_name',
type=click.Choice(config.ORGANIZATIONS),
default='default')
@click.option('-i', '--id', 'id_',
default='00000000-0000-0000-0000-000000000000')
@click.option('-k', '--key', 'key', default='secretkey')
@with_appcontext
def users_create_default(email, organization, id_, key):
def users_create_default(email, organization_name, id_, key):
"""Create new user."""
user_characteristics = {"id_": id_,
"email": email,
"api_key": key}
"api_key": key
}
user_organization_characteristics = {"user_id": id_,
"name": organization_name}
organization_characteristics = {"name": organization_name}
try:
db.choose_organization(organization)
user = db.session.query(User).filter_by(**user_characteristics).first()
user = User.query.filter_by(**user_characteristics).first()
organization = Organization.query.filter_by(
**organization_characteristics).first()
user_organization = UserOrganization.query.filter_by(
**user_organization_characteristics).first()
if not organization:
organization = Organization(**organization_characteristics)
Session.add(organization)
if not user:
user = User(**user_characteristics)
db.session.add(user)
db.session.commit()
create_user_space(id_, organization)
create_user_space(id_, organization_name)
Session.add(user)
if not user_organization:
user_organization = UserOrganization(
**user_organization_characteristics)
Session.add(user_organization)
Session.commit()
click.echo(user.id_)
except Exception as e:
click.echo('Something went wrong: {0}'.format(e))
10 changes: 2 additions & 8 deletions reana_workflow_controller/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,7 @@
'message-broker.default.svc.cluster.local//')

SHARED_VOLUME_PATH = os.getenv('SHARED_VOLUME_PATH', '/reana')
"""Path to the mounted REANA shared volume."""

SQLALCHEMY_DATABASE_URI_TEMPLATE = 'sqlite:///{path}'.format(
path=os.path.join(SHARED_VOLUME_PATH, 'default/reana.db'))
"""SQLAlchemy database location"""

ORGANIZATIONS = os.getenv('ORGANIZATIONS').split(',') \
if os.getenv('ORGANIZATIONS') else []
"""Organizations."""

SQLALCHEMY_TRACK_MODIFICATIONS = False
"""Track modifications flag."""
Expand All @@ -63,3 +55,5 @@
"""The default prefix used to name workflow(s): e.g. reana-1, reana-2, etc.
If workflow is manually named by the user that prefix will used instead.
"""

ORGANIZATIONS = ['atlas', 'alice', 'cms', 'default', 'lhcb']
15 changes: 2 additions & 13 deletions reana_workflow_controller/factory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2017 CERN.
# Copyright (C) 2017, 2018 CERN.
#
# REANA is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
Expand All @@ -26,12 +26,7 @@

from flask import Flask

from .multiorganization import MultiOrganizationSQLAlchemy

# Initialize DB
db = MultiOrganizationSQLAlchemy()

from .models import User, Workflow # isort:skip # noqa
from reana_commons.models import Base # isort:skip # noqa


def create_app(config_mapping=None):
Expand All @@ -42,13 +37,7 @@ def create_app(config_mapping=None):
app.config.from_mapping(config_mapping)

app.secret_key = "super secret key"

# Initialize flask extensions
db.init_app(app)
# Register API routes
from .rest import restapi_blueprint # noqa
app.register_blueprint(restapi_blueprint, url_prefix='/api')
with app.app_context():
db.initialize_dbs()

return app
105 changes: 0 additions & 105 deletions reana_workflow_controller/models.py

This file was deleted.

70 changes: 0 additions & 70 deletions reana_workflow_controller/multiorganization.py

This file was deleted.

Loading

0 comments on commit 1b8f365

Please sign in to comment.