예제 #1
0
def register_service(config, name, service, path):
    """Register a diecutter service in Pyramid routing."""
    hello = cornice.Service(name='{name}_hello'.format(name=name),
                            path=path,
                            description="The template API",
                            cors_origins=('*', ))
    template = cornice.Service(name='{name}_template'.format(name=name),
                               path='%s{template_path:.+}' % path,
                               description="Return the template render or raw")
    hello.add_view('GET', service.hello)
    template.add_view('PUT',
                      service.put,
                      validators=(diecutter.validators.token_validator, ))
    template.add_view('GET', service.get)
    template.add_view('POST', service.post)
    cornice.register_service_views(config, hello)
    cornice.register_service_views(config, template)
    # Deprecate 'template_engine' and 'filename_template_engine' settings.
    deprecated_settings = [
        'diecutter.filename_template_engine', 'diecutter.template_engine'
    ]
    for deprecated_key in deprecated_settings:
        if deprecated_key in config.registry.settings:
            raise DeprecationWarning(
                'Setting {deprecated} is deprecated, use {new} instead'.format(
                    deprecated=deprecated_key,
                    new=deprecated_key.replace('template_', '')))
예제 #2
0
import cornice
import tractdb.server.accounts

service_role = cornice.Service(
    name='role',
    path='/account/{id_account}/role/{id_role}',
    description='TractDB Account Role',
    cors_origins=('*',),
    cors_credentials=True
)

service_role_collection = cornice.Service(
    name='roles',
    path='/account/{id_account}/roles',
    description='TractDB Account Roles Collection',
    cors_origins=('*',),
    cors_credentials=True
)


def _get_admin(request):
    # Create our admin object
    admin = tractdb.server.accounts.AccountsAdmin(
        couchdb_url=request.registry.settings.tractdb_couchdb,
        couchdb_admin=request.registry.settings.tractdb_couchdb_secrets['admin']['user'],
        couchdb_admin_password=request.registry.settings.tractdb_couchdb_secrets['admin']['password']
    )

    return admin

""" A temporary class containing views for Daniel's storytelling project.
"""

import cornice
import tractdb.server.documents
from stravalib.client import Client as StravaClient
from stravalib import unithelper
from forecastiopy import *
import time

service_runs = cornice.Service(
    name='storytelling_strava_runs',
    path='/storytelling/strava/runs',
    description=
    'Get all runs associated with the logged in user, provided they have a Strava access token',
    cors_origins=('*', ),
    cors_credentials=True)

service_n_runs = cornice.Service(
    name='storytelling_strava_n_runs',
    path='/storytelling/strava/runs/{num_runs}',
    description=
    'Get most recent n runs associated with the logged in user, provided they have a Strava access token',
    cors_origins=('*', ),
    cors_credentials=True)

service_access_token = cornice.Service(
    name='storytelling_strava_access_token',
    path='/storytelling/strava/access_token',
    description=
    'Set the access token by exchanging the code provided by Strava',
""" A temporary class containing views for Daniel's storytelling project.
"""

import cornice
import tractdb.server.documents

service_chapters = cornice.Service(
    name='storytelling_chapters',
    path='/storytelling/{story_id}/chapters',
    description='Get all chapters associated with a story',
    cors_origins=('*',),
    cors_credentials=True
)


def _get_admin(request):
    # Create our admin object
    admin = tractdb.server.documents.DocumentsAdmin(
        couchdb_url=request.registry.settings['tractdb_couchdb'],
        couchdb_user=request.session['temp_couchdb_user'],
        couchdb_user_password=request.session['temp_couchdb_user_password']
    )

    return admin


@service_chapters.get()
def get_chapters(request):
    """ Get all chapters associated with a story.
    """
예제 #5
0
def simple_tween_factory(handler, registry):
    def simple_tween(request):
        return handler(request)

    return simple_tween


# CORNICE SECTION
try:
    import cornice
    import cornice.resource
except ImportError:
    cornice = None
else:
    service = cornice.Service(name="service", path="/service", description="Service")


    @service.get()
    def cornice_service_get_info(request):
        return {"Hello": "World"}


    @cornice.resource.resource(collection_path="/resource", path="/resource/{id}")
    class Resource(object):
        def __init__(self, request, context=None):
            self.request = request

        def collection_get(self):
            return {"resource": ["1", "2"]}
""" A temporary class containing views for Daniel's storytelling project.
"""

import cornice
import tractdb.server.documents

service_allchapters = cornice.Service(
    name='storytelling_allchapters',
    path='/storytelling/chapters',
    description='Get all chapters associated with the account',
    cors_origins=('*',),
    cors_credentials=True
)


def _get_admin(request):
    # Create our admin object
    admin = tractdb.server.documents.DocumentsAdmin(
        couchdb_url=request.registry.settings['tractdb_couchdb'],
        couchdb_user=request.session['temp_couchdb_user'],
        couchdb_user_password=request.session['temp_couchdb_user_password']
    )

    return admin


@service_allchapters.get()
def get_chapters(request):
    """ Get all chapters associated with an account.
    """
예제 #7
0
import cornice
import requests

service = cornice.Service(name='status',
                          path='/',
                          description='TractDB Status',
                          cors_origins=('*', ),
                          cors_credentials=True)


@service.get()
def get(request):
    return {
        'status':
        'ready',
        'couchdb':
        requests.get(request.registry.settings['tractdb_couchdb']).json()
    }
import pyramid.view
import requests

################################################################################
# A simple service that is accessible only when authenticated.
################################################################################


def acl_authenticated(request):
    return [(pyramid.security.Allow, pyramid.security.Authenticated,
             'authenticated'), pyramid.security.DENY_ALL]


service_authenticated = cornice.Service(name='authenticated',
                                        path='/authenticated',
                                        description='TractDB Authenticated',
                                        cors_origins=('*', ),
                                        cors_credentials=True,
                                        acl=acl_authenticated)


@service_authenticated.get(permission='authenticated')
def authenticated_get(request):
    return {'account': request.authenticated_userid}


################################################################################
# The login service.
################################################################################


def _get_couchdb_url(request):
예제 #9
0
import cornice
import pyramid.security
import tractdb.server.accounts


def acl_authenticated(request):
    return [
        (pyramid.security.Allow, pyramid.security.Authenticated, 'authenticated'),
        pyramid.security.DENY_ALL
    ]


service_account = cornice.Service(
    name='account',
    path='/account/{id_account}',
    description='TractDB Account',
    cors_origins=('*',),
    cors_credentials=True,
    acl=acl_authenticated
)

service_account_collection = cornice.Service(
    name='accounts',
    path='/accounts',
    description='TractDB Account Collection',
    cors_origins=('*',),
    cors_credentials=True,
    acl=acl_authenticated
)


def _get_admin(request):
예제 #10
0
import cornice
import couchdb.http
import pyramid.security
import tractdb.server.documents


def acl_authenticated(request):
    return [(pyramid.security.Allow, pyramid.security.Authenticated,
             'authenticated'), pyramid.security.DENY_ALL]


service_attachment = cornice.Service(
    name='attachment',
    path='/document/{id_document}/attachment/{id_attachment}',
    description='TractDB Attachment',
    cors_origins=('*', ),
    cors_credentials=True,
    acl=acl_authenticated)

service_attachment_collection = cornice.Service(
    name='attachments',
    path='/document/{id_document}/attachments',
    description='TractDB Attachments Collection',
    cors_origins=('*', ),
    cors_credentials=True,
    acl=acl_authenticated)


def _get_admin(request):
    # Create our admin object
    admin = tractdb.server.documents.DocumentsAdmin(
예제 #11
0
파일: views.py 프로젝트: jkoelker/newtonian
def _resource(name, collection_name=None):
    if collection_name is None:
        collection_name = name + 's'
    c = cornice.Service(name=collection_name, path='/%s' % collection_name)
    r = cornice.Service(name=name, path='/%s/{uuid}' % collection_name)
    return c, r
import pyramid.security
import requests
import tractdb.server.documents


def acl_authenticated(request):
    return [
        (pyramid.security.Allow, pyramid.security.Authenticated, 'authenticated'),
        pyramid.security.DENY_ALL
    ]


service_configure_fitbit = cornice.Service(
    name='configure fitbit',
    path='/configure/fitbit/callback_code',
    description='Configure Fitbit Callback Code',
    cors_origins=('*',),
    cors_credentials=True,
    acl=acl_authenticated
)


def _get_admin(request):
    # Create our admin object
    admin = tractdb.server.documents.DocumentsAdmin(
        couchdb_url=request.registry.settings['tractdb_couchdb'],
        couchdb_user=request.session['temp_couchdb_user'],
        couchdb_user_password=request.session['temp_couchdb_user_password']
    )

    return admin
예제 #13
0
파일: test.py 프로젝트: caliuf/bird-a
# -------------------------------------- #
# Enables python3-like strings handling
from __future__ import unicode_literals
str = unicode
# -------------------------------------- #

import cornice
import cornice.resource
import pprint
import colander

import __init__ as services

# ============================================================================ #

hello = cornice.Service(name='hello', path='/test/hello', description="Simplest app")

@hello.get()
def get_info(request):
	"""Returns Hello in JSON."""
	return {'Hello': 'World'}

# ============================================================================ #

params_test = cornice.Service(
		name='params',
		path='/test/params/{param}',
		description="Cornice params test")

# ---------------------------------------------------------------------------- #
예제 #14
0
import cornice
import datetime
import pyramid.security
import requests
import tractdb.server.documents


def acl_authenticated(request):
    return [(pyramid.security.Allow, pyramid.security.Authenticated,
             'authenticated'), pyramid.security.DENY_ALL]


service_fitbitquery = cornice.Service(
    name='familysleep_fitbitquery',
    path='/familysleep/fitbitquery',
    description='Get Fitbit sleep data for known devices',
    cors_origins=('*', ),
    cors_credentials=True,
    acl=acl_authenticated)

service_family_daily = cornice.Service(
    name='familysleep_familydaily',
    path='/familysleep/familydaily/{date}',
    description='Get data for a family for a single day',
    cors_origins=('*', ),
    cors_credentials=True,
    acl=acl_authenticated)

service_family_weekly = cornice.Service(
    name='familysleep_familyweekly',
    path='/familysleep/familyweekly/{date}',
예제 #15
0
import cornice
import tractdb.server.accounts

service_account = cornice.Service(name='account',
                                  path='/account/{id_account}',
                                  description='TractDB Account',
                                  cors_origins=('*', ),
                                  cors_credentials=True)

service_account_collection = cornice.Service(
    name='accounts',
    path='/accounts',
    description='TractDB Account Collection',
    cors_origins=('*', ),
    cors_credentials=True)

service_reset_password = cornice.Service(name='reset_password',
                                         path='/reset_password',
                                         description='TractDB Reset Password',
                                         cors_origins=('*', ),
                                         cors_credentials=True)


def _get_admin(request):
    # Create our admin object
    admin = tractdb.server.accounts.AccountsAdmin(
        couchdb_url=request.registry.settings.tractdb_couchdb,
        couchdb_admin=request.registry.settings.
        tractdb_couchdb_secrets['admin']['user'],
        couchdb_admin_password=request.registry.settings.
        tractdb_couchdb_secrets['admin']['password'])
예제 #16
0
파일: forms.py 프로젝트: caliuf/bird-a
# -*- coding: utf-8 -*-

# -------------------------------------- #
# Enables python3-like strings handling
from __future__ import unicode_literals
str = unicode
# -------------------------------------- #

import cornice
from __init__ import ServiceError
from jsons.forms import FormsSimple, FormsFull

# ============================================================================ #

forms = cornice.Service(name='forms',
                        path='/api/forms',
                        description="Forms list")

formsV1 = cornice.Service(name='formsV1',
                          path='/api/v1/forms',
                          description="Forms list")

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


@forms.get()
@formsV1.get()
def forms_get(request):

    lang = request.GET.get('lang', 'en').lower()