Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Dec 15, 2016
2 parents 331625e + a5583c5 commit a7ee24e
Show file tree
Hide file tree
Showing 39 changed files with 262 additions and 392 deletions.
1 change: 0 additions & 1 deletion goodtablesio/VERSION

This file was deleted.

4 changes: 2 additions & 2 deletions goodtablesio/app.py
@@ -1,6 +1,6 @@
from flask import Flask, render_template

from . import config
from . import settings
from .auth import oauth, login_manager
from .blueprints.api import api
from .blueprints.site import site
Expand All @@ -13,7 +13,7 @@
# Create instance
app = Flask(__name__)

app.secret_key = config.FLASK_SECRET_KEY
app.secret_key = settings.FLASK_SECRET_KEY

app.config['JSONIFY_MIMETYPE'] = 'application/json; charset=utf-8'

Expand Down
6 changes: 3 additions & 3 deletions goodtablesio/auth.py
Expand Up @@ -2,7 +2,7 @@
from flask_oauthlib.client import OAuth
from flask_login import LoginManager

from goodtablesio import config, models
from goodtablesio import settings, models

GITHUB_OAUTH_SCOPES = ['user', 'repo', 'admin:repo_hook']

Expand All @@ -14,8 +14,8 @@

github_auth = oauth.remote_app(
'github_auth',
consumer_key=config.GITHUB_CLIENT_ID,
consumer_secret=config.GITHUB_CLIENT_SECRET,
consumer_key=settings.GITHUB_CLIENT_ID,
consumer_secret=settings.GITHUB_CLIENT_SECRET,
request_token_params={'scope': ' '.join(GITHUB_OAUTH_SCOPES)},
base_url='https://api.github.com/',
request_token_url=None,
Expand Down
4 changes: 2 additions & 2 deletions goodtablesio/blueprints/api.py
Expand Up @@ -5,9 +5,9 @@
from flask.json import jsonify

from goodtablesio import exceptions
from goodtablesio import helpers
from goodtablesio import models
from goodtablesio import tasks
from goodtablesio.utils.jobconf import verify_validation_conf

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -60,7 +60,7 @@ def create_job():
# Validate validation configuration

try:
helpers.validate_validation_conf(validation_conf)
verify_validation_conf(validation_conf)
except exceptions.InvalidValidationConfiguration:
raise APIError(400, 'Invalid configuration')

Expand Down
18 changes: 0 additions & 18 deletions goodtablesio/commands.py

This file was deleted.

2 changes: 0 additions & 2 deletions goodtablesio/helpers/__init__.py

This file was deleted.

49 changes: 0 additions & 49 deletions goodtablesio/helpers/validate.py

This file was deleted.

13 changes: 0 additions & 13 deletions goodtablesio/models/base.py
@@ -1,11 +1,8 @@
from functools import wraps
import uuid

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import class_mapper

from goodtablesio.services import db_session as default_db_session


Base = declarative_base()

Expand All @@ -29,13 +26,3 @@ def to_dict(self):

def make_uuid():
return str(uuid.uuid4())


def auto_db_session(func):
@wraps(func)
def wrapper(*args, **kwargs):
db_session = kwargs.pop('db_session', default_db_session)

args = args + (db_session,)
return func(*args, **kwargs)
return wrapper
49 changes: 15 additions & 34 deletions goodtablesio/models/job.py
Expand Up @@ -4,8 +4,8 @@
from sqlalchemy import Column, Unicode, DateTime, update as db_update
from sqlalchemy.dialects.postgresql import JSONB

from goodtablesio.models.base import (Base, BaseModelMixin, make_uuid,
auto_db_session)
from goodtablesio.services import database
from goodtablesio.models.base import Base, BaseModelMixin, make_uuid


log = logging.getLogger(__name__)
Expand All @@ -25,39 +25,33 @@ class Job(Base, BaseModelMixin):
error = Column(JSONB)


@auto_db_session
def create(params, db_session):
def create(params):
"""
Creates a job object in the database.
Arguments:
params (dict): A dictionary with the values for the new job.
db_session (Session): The session to use, pre-filled if using
the default one.
Returns:
job (dict): The newly created job as a dict
"""

job = Job(**params)

db_session.add(job)
db_session.commit()
database['session'].add(job)
database['session'].commit()

log.debug('Created job "%s" on the database', job.id)
return job.to_dict()


@auto_db_session
def update(params, db_session):
def update(params):
"""
Updates a job object in the database.
Arguments:
params (dict): A dictionary with the fields to be updated. It must
contain a valid `job_id` key.
db_session (Session): The session to use, pre-filled if using
the default one.
Returns:
job (dict): The updated job as a dict
Expand All @@ -70,74 +64,61 @@ def update(params, db_session):
if not job_id:
raise ValueError('You must provide a id in the params dict')

job = db_session.query(Job).get(job_id)
job = database['session'].query(Job).get(job_id)
if not job:
raise ValueError('Job not found: %s', job_id)

job_table = Job.__table__
u = db_update(job_table).where(job_table.c.id == job_id).values(**params)

db_session.execute(u)
db_session.commit()
database['session'].execute(u)
database['session'].commit()

log.debug('Updated job "%s" on the database', job_id)
return job.to_dict()


@auto_db_session
def get(job_id, db_session):
def get(job_id):
"""
Get a job object in the database and return it as a dict.
Arguments:
job_id (str): The job id.
db_session (Session): The session to use, pre-filled if using
the default one.
Returns:
job (dict): A dictionary with the job details, or None if the job was
not found.
"""

job = db_session.query(Job).get(job_id)
job = database['session'].query(Job).get(job_id)

if not job:
return None

return job.to_dict()


@auto_db_session
def get_ids(db_session):
def get_ids():
"""Get all job ids from the database.
Arguments:
db_session (Session): The session to use, pre-filled if using
the default one.
Returns:
job_ids (str[]): A list of job ids, sorted by descending creation date.
"""

job_ids = db_session.query(Job.id).order_by(Job.created.desc()).all()
job_ids = database['session'].query(Job.id).order_by(Job.created.desc()).all()
return [j.id for j in job_ids]


@auto_db_session
def get_all(db_session):
def get_all():
"""Get all jobs in the database as dict.
Warning: Use with caution, this should probably only be used in tests
Arguments:
db_session (Session): The session to use, pre-filled if using
the default one.
Returns:
jobs (dict[]): A list of job dicts, sorted by descending creation date.
"""

jobs = db_session.query(Job).order_by(Job.created.desc()).all()
jobs = database['session'].query(Job).order_by(Job.created.desc()).all()
return [j.to_dict() for j in jobs]

0 comments on commit a7ee24e

Please sign in to comment.