Example #1
0
def add(config_or_file, default=False):
    """
    Add an endpoint to the registry.

    ``config_or_file`` can be the path to a yaml definition file or a dictionary of arguments to pass to
    ``endpoints.api``. See also Google's documentation on `endpoints.api <https://cloud.google.com/appengine/docs/python/endpoints/create_api#defining_the_api_endpointsapi>`__.

    Typically, this is called in an application's ``main.py`` before any services are loaded.

    Examples::

        ferris3.endpoints.add('app/default-endpoint.yaml', default=True)
        ferris3.endpoints.add({
            name: 'test',
            version: 'v1'
        })
    """
    global _endpoints, _default_endpoint_name

    if isinstance(config_or_file, (str, unicode)):
        config = load_config_file(config_or_file)
    else:
        config = config_or_file

    api = endpoints.api(**config)
    _endpoints[config['name']] = api

    if default:
        _default_endpoint_name = config['name']

    return api
Example #2
0
def add(config_or_file, default=False):
    """
    Add an endpoint to the registry.

    ``config_or_file`` can be the path to a yaml definition file or a dictionary of arguments to pass to
    ``endpoints.api``. See also Google's documentation on `endpoints.api <https://developers.google.com/appengine/docs/python/endpoints/create_api#defining_the_api_endpointsapi>`__.

    Tpyically, this is called in an application's ``main.py`` before any services are loaded.

    Examples::

        ferris3.endpoints.add('app/default-endpoint.yaml', default=True)
        ferris3.endpoints.add({
            name: 'test',
            version: 'v1'
        })
    """
    global _endpoints, _default_endpoint_name

    if isinstance(config_or_file, (str, unicode)):
        config = load_config_file(config_or_file)
    else:
        config = config_or_file

    api = endpoints.api(**config)
    _endpoints[config['name']] = api

    if default:
        _default_endpoint_name = config['name']

    return api
Example #3
0
 def build(self, api_name, **kwargs):
     return endpoints.api(**kwargs)(
         type(
             api_name,
             (remote.Service, ),
             self._methods
         )
     )
Example #4
0
def add(config_file, default=False):
    global _apis, _default_api_name

    config = load_config_file(config_file)
    api = endpoints.api(**config)
    _apis[config['name']] = api

    if default:
        _default_api_name = config['name']

    return api
Example #5
0
def add(config_file, default=False):
    global _apis, _default_api_name

    config = load_config_file(config_file)
    api = endpoints.api(**config)
    _apis[config['name']] = api

    if default:
        _default_api_name = config['name']

    return api
Example #6
0
def endpoints_api(
    name, version,
    auth_level=endpoints.AUTH_LEVEL.OPTIONAL,
    allowed_client_ids=None,
    **kwargs):
  """Same as @endpoints.api but tweaks default auth related properties.

  By default API marked with this decorator will use same authentication scheme
  as non-endpoints request handlers (i.e. fetch a whitelist of OAuth client_id's
  from the datastore, recognize service accounts, etc.), disabling client_id
  checks performed by Cloud Endpoints frontend (and doing them on the backend,
  see 'initialize_auth' below).

  Using service accounts with vanilla Cloud Endpoints auth is somewhat painful:
  every service account should be whitelisted in the 'allowed_client_ids' list
  in the source code of the application (when calling @endpoints.api). By moving
  client_id checks to the backend we can support saner logic.
  """
  # 'audiences' is used with id_token auth, it's not supported yet.
  assert 'audiences' not in kwargs, 'Not supported'

  # We love authentication.
  if auth_level == endpoints.AUTH_LEVEL.NONE:
    raise ValueError('Authentication is required')

  # We love API Explorer.
  if allowed_client_ids is None:
    allowed_client_ids = endpoints.SKIP_CLIENT_ID_CHECK
  if allowed_client_ids != endpoints.SKIP_CLIENT_ID_CHECK:
    allowed_client_ids = sorted(
        set(allowed_client_ids) | set([endpoints.API_EXPLORER_CLIENT_ID]))

  return endpoints.api(
      name, version,
      auth_level=auth_level,
      allowed_client_ids=allowed_client_ids,
      **kwargs)
Example #7
0
def endpoints_api(name,
                  version,
                  auth_level=endpoints.AUTH_LEVEL.OPTIONAL,
                  allowed_client_ids=None,
                  **kwargs):
    """Same as @endpoints.api but tweaks default auth related properties.

  By default API marked with this decorator will use same authentication scheme
  as non-endpoints request handlers (i.e. fetch a whitelist of OAuth client_id's
  from the datastore, recognize service accounts, etc.), disabling client_id
  checks performed by Cloud Endpoints frontend (and doing them on the backend,
  see 'initialize_auth' below).

  Using service accounts with vanilla Cloud Endpoints auth is somewhat painful:
  every service account should be whitelisted in the 'allowed_client_ids' list
  in the source code of the application (when calling @endpoints.api). By moving
  client_id checks to the backend we can support saner logic.
  """
    # 'audiences' is used with id_token auth, it's not supported yet.
    assert 'audiences' not in kwargs, 'Not supported'

    # We love authentication.
    if auth_level == endpoints.AUTH_LEVEL.NONE:
        raise ValueError('Authentication is required')

    # We love API Explorer.
    if allowed_client_ids is None:
        allowed_client_ids = endpoints.SKIP_CLIENT_ID_CHECK
    if allowed_client_ids != endpoints.SKIP_CLIENT_ID_CHECK:
        allowed_client_ids = sorted(
            set(allowed_client_ids) | set([endpoints.API_EXPLORER_CLIENT_ID]))

    return endpoints.api(name,
                         version,
                         auth_level=auth_level,
                         allowed_client_ids=allowed_client_ids,
                         **kwargs)
Example #8
0
import endpoints
from protorpc import messages
from protorpc import message_types
from protorpc import remote

from models.article import Article
from models.article_collection import ArticleCollection

# STORED_ARTICLES = ArticleCollection(items=[
#     Article(title='article 1!'),
#     Article(title='article 2!'),
# ])

article_api = endpoints.api(name='article', version='v1')

@article_api.api_class(resource_name='article')
class ArticleAPI(remote.Service):
  @endpoints.method(message_types.VoidMessage, ArticleCollection,
                    path='articles', http_method='GET',
                    name='articles.listArticles')
  def article_list(self, unused_request):
    query = Article.query()
    articles = []
    for article_model in query.fetch():
      article = Aticle(title=article_model.title,author=article_model.author)
      articles.append(article)

    return ArticleCollection(items=articles)

  ID_RESOURCE = endpoints.ResourceContainer(
      message_types.VoidMessage,
Example #9
0
"""Stock API implemented using Google Cloud Endpoints.

Defined here are the ProtoRPC messages needed to define Schemas for methods
as well as those methods defined in an API.
"""

import endpoints


stock_api = endpoints.api(
    name='stockApi',
    version='v1',
    description='API for the stock web scraper'
)
import endpoints


eagle_api = endpoints.api(
    name='eagleApi',
    version='v1',
    description='API for the egale-credits manager'
)
Example #11
0
else:
    DEBUG = False

logging.info("Starting application in DEBUG mode: %s", DEBUG)

# endpoint api
if DEBUG:
    API_ROOT = 'http://*****:*****@gmail.com"
]

books_api = endpoints.api(
    name='dummy',
    version='v1',
    description='dummy API',
    allowed_client_ids=[CLIENT_ID, endpoints.API_EXPLORER_CLIENT_ID],
    scopes=[endpoints.EMAIL_SCOPE])
Example #12
0
from loaner.web_app.backend.lib import xsrf

__all__ = ['ROOT_API']


class Service(remote.Service):
    """Remote Service subclass."""
    def check_xsrf_token(self, request_state):
        """Examine a request and raise an exception for an invalid XSRF token.

    Args:
      request_state: a protorpc.remote.HttpRequestState object from Endpoints
          API request.

    Raises:
      endpoints.ForbiddenException: if the call to xsrf.validate_request returns
          False.
    """
        if not xsrf.validate_request(request_state):
            raise endpoints.ForbiddenException(
                'Refresh page to obtain a valid XSRF token.')


ROOT_API = endpoints.api(allowed_client_ids=constants.ALLOWED_CLIENT_IDS,
                         auth_level=endpoints.AUTH_LEVEL.REQUIRED,
                         description='Loaner Root API',
                         name='loaner',
                         scopes=constants.ROOT_SCOPES,
                         title='Loaner API',
                         version='v1')
Example #13
0
class TestIntegers(messages.Message):
  """Simple ProtoRPC request/response with a few integer types."""
  var_int32 = messages.IntegerField(1, variant=messages.Variant.INT32)
  var_int64 = messages.IntegerField(2, variant=messages.Variant.INT64)
  var_repeated_int64 = messages.IntegerField(3, variant=messages.Variant.INT64,
                                             repeated=True)
  var_sint64 = messages.IntegerField(4, variant=messages.Variant.SINT64)
  var_uint64 = messages.IntegerField(5, variant=messages.Variant.UINT64)


class TestBytes(messages.Message):
  """Simple ProtoRPC request/response with a bytes field."""
  bytes_value = messages.BytesField(1)


my_api = endpoints.api(name='test_service', version='v1')


@my_api.api_class()
class TestService(remote.Service):
  """ProtoRPC test class for Cloud Endpoints."""

  @endpoints.method(message_types.VoidMessage, TestResponse,
                    http_method='GET', scopes=[])
  def test(self, unused_request):
    return TestResponse(text='Test response')

  @endpoints.method(message_types.VoidMessage, TestResponse,
                    http_method='GET', scopes=[])
  def empty_test(self, unused_request):
    return TestResponse()
Example #14
0
import endpoints


pmm_api = endpoints.api(
    name='pmmApi',
    version='v1',
    description='API for the Policy Mapping Matrix'
)
Example #15
0
from . import models
from . import run_info

import endpoints
from protorpc import message_types
from protorpc import messages
from protorpc import remote

package = "com.appspot.ng-dash"


class Error(Exception):
    pass


api = endpoints.api(name="ngdash", version="v0.1")

run_info_handler = run_info.run_info_handler


@api.api_class(resource_name="run", path="run")
class RunInfoApi(remote.Service):
    @endpoints.method(
        message_types.VoidMessage,
        models.RunInfoCollection,
        path="",
        http_method="GET",
        name="listRuns",
    )
    def list_runs(self, unused_request):
        return models.RunInfoCollection(items=run_info_handler.Get())
Example #16
0
import endpoints

teachme_api = endpoints.api(name='teachme',
                            version='v1',
                            description='API for TeachMe')
Example #17
0
import endpoints

api_holder = endpoints.api(
    name="user_n_teamsystem",
    version="v1.0",
    title="User and Team System",
)
Example #18
0
"""

import endpoints
from protorpc import messages
from protorpc import message_types
from protorpc import remote

from models.greeting import Greeting
from models.greeting_collection import GreetingCollection

STORED_GREETINGS = GreetingCollection(items=[
    Greeting(message='hello world!'),
    Greeting(message='goodbye world!'),
])

hw_api = endpoints.api(name='helloworld', version='v1')

@hw_api.api_class(resource_name='helloworld')
class HelloWorldApi(remote.Service):
  """Helloworld API v1."""

  @endpoints.method(message_types.VoidMessage, GreetingCollection,
                    path='hellogreeting', http_method='GET',
                    name='greetings.listGreeting')
  def greetings_list(self, unused_request):
    return STORED_GREETINGS

  MULTIPLY_METHOD_RESOURCE = endpoints.ResourceContainer(
    Greeting,
    times=messages.IntegerField(2, variant=messages.Variant.INT32,
                                required=True))
Example #19
0
else:
    API_ROOT = 'https://cage-20160705-edm.appspot.com/_ah/api'

CLIENT_SECRETS = os.path.join(os.path.dirname(__file__), 'client_secret.json')

WEB_CLIENT_ID = '591130412399-rj4b59imkhhpei2kgirq9frklfplnpec.apps.googleusercontent.com'

DEVELOPER_KEY = 'AIzaSyCe1PxvzGZYMkqlCOaClwM2V5MJfmvh7zg'

SERVICE_ACCOUNT_EMAIL = '*****@*****.**'

ADMINS = [
    '*****@*****.**',
]

SENDGRID = {'USERNAME': '******', 'PASSWORD': '******'}

SITE_NAME = 'cheerspoint'
BASIC_SITE_URL = 'https://cage-20160705-edm.appspot.com/'
SITE_OWNER = 'KAI CHU CHUNG'
DISQUS_SHORTNAME = 'cheerspoint'

# recipient upload bucket
BUCKET = 'cage-20160705-edm.appspot.com'

cheerspoint_api = endpoints.api(
    name='cheerspoint',
    version='v1',
    description='cheerspoint',
    allowed_client_ids=[WEB_CLIENT_ID, endpoints.API_EXPLORER_CLIENT_ID],
    scopes=[endpoints.EMAIL_SCOPE])
Example #20
0
import endpoints
import logging

from protorpc import messages
from protorpc import message_types
from protorpc import remote

from models import CourseEntity

rateCourse_api = endpoints.api(
    name='rateCourse',
    version='v1',
    description='A rest API for rate course applicaiton')


class CourseMessage(messages.Message):
    course_name = messages.StringField(1)
    course_code = messages.StringField(2)
    course_department = messages.StringField(3)


class CourseNameMessage(messages.Message):
    course_name = messages.StringField(1)


class DepartmentMessage(messages.Message):
    department = messages.StringField(1)


class ListCourseMessage(messages.Message):
    courses = messages.MessageField(CourseMessage, 1, repeated=True)
Example #21
0
import endpoints
from protorpc import messages
from protorpc import message_types
from protorpc import remote
import httplib2
import hashlib
import json
import urllib
# cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile(inspect.currentframe() ))[0],"apiClass")))
# if cmd_subfolder not in sys.path:
#    sys.path.insert(0, cmd_subfolder)

from operator import attrgetter

import pprint

SODA_APP_TOKEN = 'CI8NkwQLjR5fbNjRwUrtbZz52'
SALT = 'U2ltYmE0UHJlc2lkZW50'
TOMATO_KEY = 'wefqm3hwnmjmvje8v4nmbsdv'
MOVIEDB_KEY = '7bfb5aa6abb2c2a47d4bba0e1ff36ccc'
UBER_SERV_TOK = '4ErmvJdtVQXx2I6XpdAPSL_AI_kgq2DeigkFHnub'

moviepins = endpoints.api(
    name='moviepins',
    version='v1.0',
    description='API for managing Users and related medical data')


class Response(messages.Message):
    resp = messages.StringField(1)
Example #22
0
          message_types.VoidMessage,
          string=messages.StringField(1, repeated=True)),
      Message, http_method='GET')
  def query_string_method(self, _):
    """An HTTP GET method supporting query strings."""
    return Message()

  @endpoints.method(
      endpoints.ResourceContainer(Message, path=messages.StringField(1)),
      Message, path='{path}/method')
  def path_parameter_method(self, _):
    """An HTTP POST method supporting path parameters."""
    return Message()


SplitService = endpoints.api(
    'split', 'v1', description='A split service to test with.')


@SplitService.api_class(resource_name='sa', path='a')
class ServiceA(remote.Service):
  """Part A of a split service to test with."""

  @endpoints.method(message_types.VoidMessage, Message)
  def post_method(self, _):
    """An HTTP POST method."""
    return Message()


@SplitService.api_class(resource_name='sb', path='b')
class ServiceB(remote.Service):
  """Part B of a split service to test with."""
Example #23
0
    """Greeting that stores a message."""
    message = proto_messages.StringField(1)


class GreetingCollection(proto_messages.Message):
    """Collection of Greetings."""
    items = proto_messages.MessageField(Greeting, 1, repeated=True)


STORED_GREETINGS = GreetingCollection(items=[
    Greeting(message='hello world!'),
    Greeting(message='goodbye world!'),
])


mb_api = endpoints.api(name='mbapi', version='v1')

@mb_api.api_class(resource_name='helloworld')
class HelloWorldApi(remote.Service):
    """Helloworld API v1."""

    MULTIPLY_METHOD_RESOURCE = endpoints.ResourceContainer(
            Greeting,
            times=proto_messages.IntegerField(2, variant=proto_messages.Variant.INT32,
                                        required=True))

    @endpoints.method(MULTIPLY_METHOD_RESOURCE, Greeting,
                      path='hellogreeting/{times}', http_method='POST',
                      name='greetings.multiply')
    def greetings_multiply(self, request):
        return Greeting(message=request.message * request.times)
class TestIntegers(messages.Message):
  """Simple ProtoRPC request/response with a few integer types."""
  var_int32 = messages.IntegerField(1, variant=messages.Variant.INT32)
  var_int64 = messages.IntegerField(2, variant=messages.Variant.INT64)
  var_repeated_int64 = messages.IntegerField(3, variant=messages.Variant.INT64,
                                             repeated=True)
  var_sint64 = messages.IntegerField(4, variant=messages.Variant.SINT64)
  var_uint64 = messages.IntegerField(5, variant=messages.Variant.UINT64)


class TestBytes(messages.Message):
  """Simple ProtoRPC request/response with a bytes field."""
  bytes_value = messages.BytesField(1)


my_api = endpoints.api(name='test_service', version='v1')


@my_api.api_class()
class TestService(remote.Service):
  """ProtoRPC test class for Cloud Endpoints."""

  @endpoints.method(message_types.VoidMessage, TestResponse,
                    http_method='GET', scopes=[])
  def test(self, unused_request):
    return TestResponse(text='Test response')

  @endpoints.method(message_types.VoidMessage, TestResponse,
                    http_method='GET', scopes=[])
  def empty_test(self, unused_request):
    return TestResponse()
Example #25
0
import endpoints
from protorpc import remote
from models_classes import *
from messages_classes import *
from protorpc import message_types
import datetime

api_collection = endpoints.api(name='mobile', version='v1.0')


@api_collection.api_class(resource_name='UserTransactions')
class UserPut(remote.Service):
    @endpoints.method(UserMessage, message_types.VoidMessage,
                      name='user_put',
                      path='user_put',
                      http_method='POST')
    def user_put(self, request):


        UserModel(
                  auth_id=request.auth_id,
                  name=request.name,
                  email=request.email,
                  phone=request.phone,
                  city=request.city,
                  birthday=datetime.datetime.strptime(request.birthday, '%Y-%m-%d'),
                  rank=request.rank
                  ).put()
        return message_types.VoidMessage()

def endpoints_api(
    name, version,
    auth_level=endpoints.AUTH_LEVEL.OPTIONAL,
    allowed_client_ids=None,
    **kwargs):
  """Same as @endpoints.api but tweaks default auth related properties.

  By default API marked with this decorator will use same authentication scheme
  as non-endpoints request handlers (i.e. fetch a whitelist of OAuth client_id's
  from the datastore, recognize service accounts, etc.), disabling client_id
  checks performed by Cloud Endpoints frontend (and doing them on the backend,
  see 'initialize_auth' below).

  Using service accounts with vanilla Cloud Endpoints auth is somewhat painful:
  every service account should be whitelisted in the 'allowed_client_ids' list
  in the source code of the application (when calling @endpoints.api). By moving
  client_id checks to the backend we can support saner logic.
  """
  # 'audiences' is used with id_token auth, it's not supported yet.
  assert 'audiences' not in kwargs, 'Not supported'

  # We love authentication.
  if auth_level == endpoints.AUTH_LEVEL.NONE:
    raise ValueError('Authentication is required')

  # We love API Explorer.
  if allowed_client_ids is None:
    allowed_client_ids = endpoints.SKIP_CLIENT_ID_CHECK
  if allowed_client_ids != endpoints.SKIP_CLIENT_ID_CHECK:
    allowed_client_ids = sorted(
        set(allowed_client_ids) | set([endpoints.API_EXPLORER_CLIENT_ID]))

  # Someone was looking for job security here:
  # - api() returns _ApiDecorator class instance.
  # - One of the following is done:
  #   - _ApiDecorator.__call__() is called with the remote.Service class as
  #     argument.
  #   - api_class() is explicitly called which returns a function, which is then
  #     called with the  remote.Service class as argument.
  api_decorator = endpoints.api(
      name, version,
      auth_level=auth_level,
      allowed_client_ids=allowed_client_ids,
      **kwargs)

  def fn(cls):
    if not cls.all_remote_methods():
      raise TypeError(
          'Service %s must have at least one auth.endpoints_method method' %
          name)
    for method, func in cls.all_remote_methods().iteritems():
      if func and not api.is_decorated(func.remote._RemoteMethodInfo__method):
        raise TypeError(
            'Method \'%s\' of \'%s\' is not protected by @require or @public '
            'decorator' % (method, name))
    return cls

  # Monkey patch api_decorator to make 'api_class' to return wrapped decorator.
  orig = api_decorator.api_class
  def patched_api_class(*args, **kwargs):
    wrapper = orig(*args, **kwargs)
    return lambda cls: fn(wrapper(cls))
  api_decorator.api_class = patched_api_class

  return api_decorator
Example #27
0
class DateLocationsMessage(messages.Message):
    """ Message with many locations, timezone and day data and number of locations variable """
    locations = messages.MessageField(LocationMessage, 1, repeated=True)
    timeZone = messages.MessageField(TimeZoneMessage, 2, repeated=False)
    date = messages.MessageField(DateMessage, 3, repeated=False)
    totalLocations = messages.IntegerField(4, variant=messages.Variant.INT32)

# Resource to hold the GET request information to the history endpoint
DATE_RESOURCE_CONTAINER = endpoints.ResourceContainer(
    message_types.VoidMessage,
    year=messages.IntegerField(2, variant=messages.Variant.INT32, required=True),
    month=messages.IntegerField(3, variant=messages.Variant.INT32, required=True),
    day=messages.IntegerField(4, variant=messages.Variant.INT32, required=True))

# myLatitude API backend
myLatAPI = endpoints.api(name='mylatitude', version='v2', description='Rest API to your location data',
                         allowed_client_ids=ALLOWED_CLIENT_IDS)


@myLatAPI.api_class(resource_name='locations', path='locations')
class LocationsEndPoint(remote.Service):
    """ Endpoints for location services of the API """

    @staticmethod
    def create_location_message(location_obj):
        """ Create a location message from a location database object

        @rtype : LocationMessage
        @param location_obj: ndb Location Class object
        @return: LocationMessage Class object
        """
        return LocationMessage(timestampMs=location_obj.timestampMs,
Example #28
0
    l = []
    for p in obj.parent:
      l.append(PersonMessageFromPerson(t))
    obj.parent = l
  return o


def RecordCollectionMessageFromRecord(objs):
  container = []
  for o in objs:
    container.append(RecordMessageFromRecord(o))
  return RecordCollectionMessage(items=container)


parentd_api = endpoints.api(
  name='parentd', version='v1.0',
  allowed_client_ids=[WEB_CLIENT_ID, endpoints.API_EXPLORER_CLIENT_ID],
  audiences=[ANDROID_AUDIENCE], scopes=[endpoints.EMAIL_SCOPE])

@parentd_api.api_class(resource_name='district')
class DistrictService(remote.Service):
  @endpoints.method(message_types.VoidMessage, DistrictCollectionMessage,
                    path='district/list', http_method='GET', name='list')
  def DistrictList(self, unused_request):
    q = District.query()
    districts = q.fetch()
    return DistrictCollectionMessageFromDistrict(districts)

  @endpoints.method(DistrictMessage, DistrictMessage,
                    path='district/add', http_method='POST', name='add')
  def DistrictAdd(self, request):
    def _AddTransaction():
Example #29
0
def endpoints_api(name,
                  version,
                  auth_level=None,
                  allowed_client_ids=None,
                  **kwargs):
    """Same as @endpoints.api but tweaks default auth related properties.

  By default API marked with this decorator will use same authentication scheme
  as non-endpoints request handlers (i.e. fetch a whitelist of OAuth client_id's
  from the datastore, recognize service accounts, etc.), disabling client_id
  checks performed by Cloud Endpoints frontend (and doing them on the backend,
  see 'initialize_auth' below).

  Using service accounts with vanilla Cloud Endpoints auth is somewhat painful:
  every service account should be whitelisted in the 'allowed_client_ids' list
  in the source code of the application (when calling @endpoints.api). By moving
  client_id checks to the backend we can support saner logic.
  """
    # 'audiences' is used with id_token auth, it's not supported yet.
    assert 'audiences' not in kwargs, 'Not supported'

    # On prod, make sure Cloud Endpoints frontend validates OAuth tokens for us.
    # On dev instances we will validate them ourselves to support custom token
    # validation endpoint.
    if auth_level is not None:
        if utils.is_local_dev_server() or utils.is_dev():
            # AUTH_LEVEL.NONE: Frontend authentication will be skipped. If
            # authentication is desired, it will need to be performed by the backend.
            auth_level = endpoints.AUTH_LEVEL.NONE
        else:
            # AUTH_LEVEL.OPTIONAL: Authentication is optional. If authentication
            # credentials are supplied they must be valid. Backend will be called if
            # the request contains valid authentication credentials or no
            # authentication credentials.
            auth_level = endpoints.AUTH_LEVEL.OPTIONAL

    # We love API Explorer.
    if allowed_client_ids is None:
        allowed_client_ids = endpoints.SKIP_CLIENT_ID_CHECK
    if allowed_client_ids != endpoints.SKIP_CLIENT_ID_CHECK:
        allowed_client_ids = sorted(
            set(allowed_client_ids) | set([endpoints.API_EXPLORER_CLIENT_ID]))

    # Someone was looking for job security here:
    # - api() returns _ApiDecorator class instance.
    # - One of the following is done:
    #   - _ApiDecorator.__call__() is called with the remote.Service class as
    #     argument.
    #   - api_class() is explicitly called which returns a function, which is then
    #     called with the  remote.Service class as argument.
    api_decorator = endpoints.api(name,
                                  version,
                                  auth_level=auth_level,
                                  allowed_client_ids=allowed_client_ids,
                                  **kwargs)

    def fn(cls):
        if not cls.all_remote_methods():
            raise TypeError(
                'Service %s must have at least one auth.endpoints_method method'
                % name)
        for method, func in cls.all_remote_methods().items():
            if func and not api.is_decorated(
                    func.remote._RemoteMethodInfo__method):
                raise TypeError(
                    'Method \'%s\' of \'%s\' is not protected by @require or @public '
                    'decorator' % (method, name))
        return cls

    # Monkey patch api_decorator to make 'api_class' to return wrapped decorator.
    orig = api_decorator.api_class

    def patched_api_class(*args, **kwargs):
        wrapper = orig(*args, **kwargs)
        return lambda cls: fn(wrapper(cls))

    api_decorator.api_class = patched_api_class

    return api_decorator
Example #30
0
from endpoints_proto_datastore.ndb import EndpointsModel


class Address(EndpointsModel):
    street = ndb.StringProperty()
    house_no = ndb.StringProperty()
    city = ndb.StringProperty()
    type = ndb.StringProperty()


class User(EndpointsModel):
    email = ndb.StringProperty()
    addresses = ndb.StructuredProperty(Address, repeated=True)


MyServer = endpoints.api(name='test', version='v1', description='Test API')


@MyServer.api_class(resource_name='user')
class UserService(endpoints.remote.Service):
    @User.method(path='user', http_method='POST', request_fields=('email', 'addresses'),
                 response_fields=('entityKey', 'email', 'addresses'), name='create_user')
    def create_user(self, user):
        """creates user"""

        user.put()
        return user

    @User.method(path='user/{entityKey}', http_method='GET', response_fields=('entityKey', 'email', 'addresses'),
                 name='get_user')
    def get_user(self, user):
Example #31
0
import endpoints
kenix_wms_api = endpoints.api(name='kenix_wms', version='v1.0', description='Kenix Warehouse Management System API')
Example #32
0
import endpoints
from protorpc import messages
from protorpc import message_types
from protorpc import remote
from google.appengine.ext import ndb
from operator import itemgetter
import password as pwd
import json
import module_factory
import logging
import time


ayn_api = endpoints.api(name='ayn', version='v1')



class Token(messages.Message):
	source = messages.StringField(1, required=True)
	token = messages.StringField(2, required=True)


class TokenCollection(messages.Message):
	sources = messages.MessageField(Token, 1, repeated=True)


class TokenMessage(messages.Message):
	token = messages.MessageField(Token, 1)

class News(messages.Message):
	source = messages.StringField(1)
Example #33
0
import endpoints

# TODO: Replace the following lines with client IDs obtained from the APIs
# Console or Cloud Console.
WEB_CLIENT_ID = 'replace this with your web client application ID'
ANDROID_CLIENT_ID = 'replace this with your Android client ID'
IOS_CLIENT_ID = 'replace this with your iOS client ID'
ANDROID_AUDIENCE = WEB_CLIENT_ID

api_root = endpoints.api(
  name='musubio',
  version='v1',
  description='Musubio API',
  allowed_client_ids=[WEB_CLIENT_ID, ANDROID_CLIENT_ID, IOS_CLIENT_ID],
  audiences=[ANDROID_AUDIENCE])
Example #34
0
from endpoints.api_config import (_MethodInfo, _CheckEnum, _CheckType)
import endpoints.util as endpoints_util
from django.conf import settings

from greenday_core.api_exceptions import (ForbiddenException,
                                          UnauthorizedException)
from .utils import get_current_user

# Valid client IDs from the Google API Console
CLIENT_IDS = [
    settings.OAUTH_SETTINGS['client_id'], endpoints.API_EXPLORER_CLIENT_ID
]

greenday_api = endpoints.api(name='greenday',
                             version='v1',
                             description='Montage API',
                             allowed_client_ids=CLIENT_IDS,
                             audiences=[settings.OAUTH_SETTINGS['client_id']])


def auth_required(api_instance, request):
    """
        API method middleware to enforce that a user is authed
    """
    if not api_instance.current_user:
        raise UnauthorizedException


def auth_superuser(api_instance, request):
    """
        API method middleware to ensure that the current user is a
Example #35
0
"""Main API definition."""
import endpoints

from settings import WEB_CLIENT_ID

ALLOWED_CLIENT_IDS = [endpoints.API_EXPLORER_CLIENT_ID, WEB_CLIENT_ID]

api_definition = endpoints.api(name='scaffold',
                               version='v1',
                               description='Scaffold API',
                               allowed_client_ids=ALLOWED_CLIENT_IDS,
                               auth_level=endpoints.AUTH_LEVEL.REQUIRED)
Example #36
0
# -*- coding: utf8 -*-

import sys
sys.path.insert(0, 'lib/')

import endpoints
from protorpc import messages
from protorpc import message_types
from protorpc import remote

from utils.utils import SolutionRenderer, get_translation

an_api = endpoints.api(name='libvertix',
                       version='v1.0',
                       description="Vertix API")

#Definig the API default types of messages

#testEcho


class EchoRequest(messages.Message):
    message = messages.StringField(1)


class EchoResponse(messages.Message):
    message = messages.StringField(1)


@an_api.api_class(resource_name="echo", path="echo")
class Echo(remote.Service):
Example #37
0
from django.core.signals import request_finished


from api_helpers import *

logger = logging.getLogger(__name__)

CONTROLLED_ACL_GOOGLE_GROUP = settings.ACL_GOOGLE_GROUP
INSTALLED_APP_CLIENT_ID = settings.INSTALLED_APP_CLIENT_ID


class ReturnJSON(messages.Message):
    msg = messages.StringField(1)


User_Endpoints = endpoints.api(name='user_api', version='v1', description='Get information about users.',
                               allowed_client_ids=[INSTALLED_APP_CLIENT_ID, endpoints.API_EXPLORER_CLIENT_ID])

@User_Endpoints.api_class(resource_name='user_endpoints')
class User_Endpoints_API(remote.Service):

    GET_RESOURCE = endpoints.ResourceContainer(token=messages.StringField(1, required=False))
    @endpoints.method(GET_RESOURCE, ReturnJSON,
                      path='am_i_dbgap_authorized', http_method='GET', name='user.amiauthorized')
    def am_i_dbgap_authorized(self, request):
        '''
        Returns information about the user.
        :param token: Optional. Access token with email scope to verify user's google identity.
        :return: ReturnJSON with msg string indicating presence or absence on the controlled-access list.
        '''
        print >> sys.stderr,'Called '+sys._getframe().f_code.co_name
        user_email = None
Example #38
0
from protorpc import remote
from messages import UserMessageCollection, UserMessage, ItemMessage, ItemMessageCollection, \
    BaseMessage, CommMessage, CommMessageCollection
from models import User, Item, Comm
from backend.messages import SearchMessage, FeedbackMessage, FeedbackMessageCollection

package = 'SecureCoding'

WEB_CLIENT_ID = '142521807042.apps.googleusercontent.com'
LOCAL_CLIENT_ID = '142521807042-f6qni9r0isipad8nldolobfvtdm64j58.apps.googleusercontent.com'
ANDROID_AUDIENCE = WEB_CLIENT_ID

hardcode = endpoints.api(name='hardcode',
                         version='v1',
                         allowed_client_ids=[
                             WEB_CLIENT_ID, LOCAL_CLIENT_ID,
                             endpoints.API_EXPLORER_CLIENT_ID
                         ],
                         audiences=[ANDROID_AUDIENCE],
                         scopes=[endpoints.EMAIL_SCOPE])


def check_signed_in():
    current_user = User.get_current_user()

    if not current_user:
        raise endpoints.UnauthorizedException('Invalid token.')
    else:
        return current_user


@hardcode.api_class(resource_name='items', path="items")
Example #39
0
import endpoints

api_collection = endpoints.api(name='library', version='v1.0')
Example #40
0
import logging
import sys
import traceback

import endpoints
import six
from six.moves import http_client as httplib
from tradefed_cluster import api_common

from multitest_transport.api import openapi

DEFAULT_MAX_RESULTS = 25  # The default number of max results per page.

MTT_API = endpoints.api(
    name='mtt',
    version='v1',
    description='Android Test Station API',
    allowed_client_ids=['anonymous', endpoints.API_EXPLORER_CLIENT_ID],
    scopes=[endpoints.EMAIL_SCOPE])


def ApiMethod(request_type, response_type, **kwargs):
  """API method decorator."""
  endpoints_wrapper = endpoints.method(request_type, response_type, **kwargs)
  def _Decorator(method):
    # Wraps execution in an NDB context
    api_method = api_common.with_ndb_context(method)
    # Configures endpoint
    api_method = endpoints_wrapper(api_method)
    # Add method summary and description
    descriptor_wrapper = openapi.ApiMethodDescriptor(
        summary=method.__doc__.splitlines()[0] if method.__doc__ else None,
Example #41
0
def require_user(endpoints_method):
    """Method decorator enforcing authenticated user to enable multitenancy."""

    @functools.wraps(endpoints_method)
    def wrapped(*args, **kw):
        user = endpoints.get_current_user()
        if user is None:
            raise endpoints.UnauthorizedException('Invalid token.')
        namespace_manager.set_namespace(user.user_id())
        return endpoints_method(*args, **kw)

    return wrapped


bom_api = endpoints.api(allowed_client_ids=CLIENT_IDS,
                        description='Bank of Mom API',
                        name='bom',
                        version='v1')


@bom_api.api_class(resource_name='accounts')
class Accounts(remote.Service):

    @endpoints.method(
        request_message=messages.Account,
        response_message=messages.Account,
        path='accounts',
        http_method='POST')
    @require_user
    def insert(self, request):
        request.id = None
        account = models.Account.put_from_message(request)
Example #42
0
    tumor_seq_allele2 = StringField(10)
    match_norm_seq_allele1 = StringField(11)
    reference_allele = StringField(12)
    variant_type = StringField(13)
    ucsc_cons = StringField(14)


class MAFRecordList(Message):
    items = MessageField(MAFRecord, 1, repeated=True)


class MAFRequest(Message):
    gene = StringField(1, required=True)
    tumor = StringField(2, repeated=True)

MAFEndpointsAPI = endpoints.api(name='maf_api', version='v1')


@MAFEndpointsAPI .api_class(resource_name='maf_endpoints')
class MAFEndpointsAPI(remote.Service):
    @endpoints.method(MAFRequest, MAFRecordList,
                      path='maf_search', http_method='GET', name='maf.getMAF')
    def maf_search(self, request):
        gene = request.gene
        tumor_type_list = request.tumor
        tumor_set_template = ', '.join(['%s' for x in range(len(tumor_type_list))])
        query = 'SELECT * FROM maf WHERE hugo_symbol=%s AND tumor_type IN ({0})'.format(tumor_set_template)

        values = [gene]
        values.extend(tumor_type_list)
        try:
Example #43
0
from . import run_info

import endpoints
from protorpc import message_types
from protorpc import messages
from protorpc import remote

package = "com.appspot.ng-dash"


class Error(Exception):
  pass



api = endpoints.api(name="ngdash", version="v0.1")

run_info_handler = run_info.run_info_handler

@api.api_class(resource_name="run", path="run")
class RunInfoApi(remote.Service):
  @endpoints.method(message_types.VoidMessage, models.RunInfoCollection,
                    path="", http_method="GET",
                    name="listRuns",
                    )
  def list_runs(self, unused_request):
    return models.RunInfoCollection(items=run_info_handler.Get())

  SHA_PARAM_RESOURCE = endpoints.ResourceContainer(
      message_types.VoidMessage,
      commit_sha=messages.StringField(1))
Example #44
0
#!/usr/bin/env python

"""settings.py

Udacity conference server-side Python App Engine app user settings

$Id$

created/forked from conference.py by wesc on 2014 may 24

"""
import endpoints

# Replace the following lines with client IDs obtained from the APIs
# Console or Cloud Console.
WEB_CLIENT_ID = '423376222467-kaokhd2tqgmds8u47dgu8m4euph0h83f.apps.googleusercontent.com'
ANDROID_CLIENT_ID = 'replace with Android client ID'
IOS_CLIENT_ID = 'replace with iOS client ID'
ANDROID_AUDIENCE = WEB_CLIENT_ID
EMAIL_SCOPE = endpoints.EMAIL_SCOPE
API_EXPLORER_CLIENT_ID = endpoints.API_EXPLORER_CLIENT_ID

API = endpoints.api(name='conferenceCentral', version='v1', audiences=[ANDROID_AUDIENCE],
               allowed_client_ids=[WEB_CLIENT_ID, API_EXPLORER_CLIENT_ID, ANDROID_CLIENT_ID, IOS_CLIENT_ID],
               scopes=[EMAIL_SCOPE])
Example #45
0
import endpoints
from google.appengine.ext import ndb
from protorpc import messages
from protorpc import message_types
from protorpc import remote

package = 'myChannelEndpoint'

myChannel = endpoints.api(name='library', version='v1.0')

class chatRoom(ndb.Model):
  """Room class to maintain separate chat rooms"""
  roomID = ndb.StringProperty(required=True)
  participants = ndb.StringProperty(repeated=True)
  participantTokens = ndb.StringProperty(repeated=True)
  histChat = ndb.TextProperty(indexed=False)

class Greeting(messages.Message):
    """Greeting that stores a message."""
    message = messages.StringField(1)

class pktMsg(messages.Message):
    """Greeting that stores a message."""
    token = messages.StringField(1)
    clientID = messages.StringField(2)
    roomID = messages.StringField(3)
    message = messages.StringField(4)

class GreetingCollection(messages.Message):
    """Collection of Greetings."""
    items = messages.MessageField(Greeting, 1, repeated=True)
from models import ActivityType
from models import ProductGroup
from models import ActivityGroup

from google.appengine.ext import ndb

from .utils import check_auth

_CLIENT_IDs = [
    endpoints.API_EXPLORER_CLIENT_ID,
    '47242318878-dik3r14d8jc528h1ao35f8ehqa7tmpe1.apps.googleusercontent.com',
    '622745668355-rpeo1i7hjo4vj003dithtp1d71iniqqc.apps.googleusercontent.com',
    '66416776373-3k5goi8hn9d5rih68t8km57iliithohb.apps.googleusercontent.com'
]

api_root = endpoints.api(
    name='gdetracking', version='v1.0b2', allowed_client_ids=_CLIENT_IDs)
# name='expertstracking', version='v1.0b2', allowed_client_ids=_CLIENT_IDs)


@api_root.api_class(resource_name='activity_record', path='activityRecord')
class ActivityRecordService(remote.Service):

    @ActivityRecord.method(request_fields=('id',), path='/activityRecord/{id}',
                           http_method='GET', name='get')
    def get(self, activity_record):
        if not activity_record.from_datastore:
            raise endpoints.NotFoundException('ActivityRecord not found.')
        return activity_record

    @ActivityRecord.method(path='/activityRecord', http_method='POST',
                           name='insert')
)
NEW_GAME_REQUEST = endpoints.ResourceContainer(
    NewGameForm,
    user_name=messages.StringField(1, required=True)
)
GET_GAME_REQUEST = endpoints.ResourceContainer(
    user_name=messages.StringField(1, required=True),
    urlsafe_key=messages.StringField(2, required=True)
)
GUESS_CHAR_REQUEST = endpoints.ResourceContainer(
    GuessCharForm,
    user_name=messages.StringField(1, required=True),
    urlsafe_key=messages.StringField(2, required=True)
)

game_api = endpoints.api(name='game', version='v1')


@game_api.api_class(resource_name='game')
class GameApi(remote.Service):
    """Game APIs"""

    @endpoints.method(request_message=NEW_GAME_REQUEST,
                      response_message=NewGameResponse,
                      path='new_game',
                      name='new_game',
                      http_method='POST')
    def endpoint_new_game(self, request):
        """Create new game."""
        user = get_user(request.user_name)
Example #48
0
sys.path.insert(0, 'libs')
import tweepy
from datetime import datetime
from dateutil import parser
import endpoints
from protorpc import remote
from google.appengine.ext import ndb
from ayn_module import BaseModuleApi
import ayn_module
import ast
import json
import httplib
import logging


module_api = endpoints.api(name='module', version='v1')

class TokenDB(ndb.Model):
	token_key = ndb.StringProperty()
	token_secret = ndb.StringProperty()

class RawJsonParser(tweepy.parsers.Parser):
    def parse(self, method, payload):
        return payload


@module_api.api_class(resource_name='users')
class ModuleApi(BaseModuleApi):
	"""Module API v1"""

	CONSUMER_KEY = ''
Example #49
0
import endpoints

HangmanAPI = endpoints.api(name='hangman', version='v1.0')
Example #50
0
#!/usr/bin/env python
"""settings.py

Udacity conference server-side Python App Engine app user settings

$Id$

created/forked from conference.py by wesc on 2014 may 24

"""
import endpoints

# Replace the following lines with client IDs obtained from the APIs
# Console or Cloud Console.
WEB_CLIENT_ID = '423376222467-kaokhd2tqgmds8u47dgu8m4euph0h83f.apps.googleusercontent.com'
ANDROID_CLIENT_ID = 'replace with Android client ID'
IOS_CLIENT_ID = 'replace with iOS client ID'
ANDROID_AUDIENCE = WEB_CLIENT_ID
EMAIL_SCOPE = endpoints.EMAIL_SCOPE
API_EXPLORER_CLIENT_ID = endpoints.API_EXPLORER_CLIENT_ID

API = endpoints.api(name='conferenceCentral',
                    version='v1',
                    audiences=[ANDROID_AUDIENCE],
                    allowed_client_ids=[
                        WEB_CLIENT_ID, API_EXPLORER_CLIENT_ID,
                        ANDROID_CLIENT_ID, IOS_CLIENT_ID
                    ],
                    scopes=[EMAIL_SCOPE])
Example #51
0
import endpoints


yahtzee = endpoints.api("yahtzee", "v1", description="API for playing Yahtzee")
import endpoints


WEB_CLIENT_ID = 'replace this with your Android client ID'
ANDROID_CLIENT_ID = 'replace this with your Android client ID'
IOS_CLIENT_ID = 'replace this with your iOS client ID'
ANDROID_AUDIENCE = WEB_CLIENT_ID


capitolbells = endpoints.api(name='capitolbells', version='v1.0',
                             allowed_client_ids=[WEB_CLIENT_ID, ANDROID_CLIENT_ID, IOS_CLIENT_ID,
                                                 endpoints.API_EXPLORER_CLIENT_ID],
                             audiences=[ANDROID_AUDIENCE],
                             scopes=[endpoints.EMAIL_SCOPE])
    get_user,
    get_user_score_orderby_game_score
)

GET_GAME_REQUEST = endpoints.ResourceContainer(
    user_name=messages.StringField(1, required=True),
    urlsafe_key=messages.StringField(2, required=True)
)
GET_USER_REQUEST = endpoints.ResourceContainer(
    user_name=messages.StringField(1, required=True)
)
GET_ALL_SCORE_REQUEST = endpoints.ResourceContainer(
    fetch=messages.IntegerField(1)
)

score_api = endpoints.api(name='score', version='v1')


@score_api.api_class(resource_name='score')
class ScoreApi(remote.Service):
    """Score APIs"""

    @endpoints.method(request_message=GET_GAME_REQUEST,
                      response_message=GetScoreResponse,
                      path='get_game_score',
                      name='get_game_score',
                      http_method='GET')
    def endpoint_get_game_score(self, request):
        """Get score of the game"""
        game = get_game(request.urlsafe_key, request.user_name)
Example #54
0
import endpoints
from protorpc import remote

from models import Entity

api_root = endpoints.api(name='myApi', version='v1.0b')

@api_root.api_class(resource_name='entity', path='entity')
class EntityService(remote.Service):

    @Entity.method(path='/entity/{id}', http_method='POST', name='insert')
    def insert(self, entity):
        entity.put()
        return entity

    @Entity.method(path='/entity/{id}', http_method='GET', name='get')
    def get(self, entity):
        if not entity.from_datastore:
            raise endpoints.NotFoundException('Entity not found.')

        return entity

    @Entity.method(path='/entity/{id}', http_method='DELETE', name='delete')
    def delete(self, entity):
        if not entity.from_datastore:
            raise endpoints.NotFoundException('Entity not found.')

        entity.key.delete()
        return entity

    @Entity.query_method(query_fields=('limit', 'order', 'pageToken'),
Example #55
0
    label = messages.StringField(5)
    mutation_count = messages.IntegerField(6)
    source = messages.StringField(7)


class Association(messages.Message):
    node1 = messages.MessageField(Feature, 1)
    node2 = messages.MessageField(Feature, 2)
    logged_pvalue = messages.FloatField(3)


class CircvizOutput(messages.Message):
    items = messages.MessageField(Association, 1, repeated=True)


Pairwise_Endpoints = endpoints.api(name="pairwise", version="v1")


@Pairwise_Endpoints.api_class(resource_name="pairwise_api")
class PairwiseApi(remote.Service):
    """Pairwise API v1"""

    @endpoints.method(PairwiseJobRequest, PairwiseResults, name="run", http_method="POST")
    def run_job(self, request):
        """ Used by the web application."""
        features = []
        count = len(request.feature) - 1
        while count >= 0:
            features.append(str(request.feature[count]))
            count -= 1
Example #56
0
from google.appengine.ext import ndb
from protorpc import messages
from protorpc import message_types
from protorpc import remote
import endpoints

localhost = '737232045163-22rv82eod96bv46vphb63'\
            'pde23cm5t8m.apps.googleusercontent.com'
localhost8080 = '737232045163-5dmfng17mjmg32p01p35'\
                'restig325orb.apps.googleusercontent.com'

api = endpoints.api(name='gdgkobe20150429', version='v1',
                    allowed_client_ids=[localhost, localhost8080],
                    scopes=[endpoints.EMAIL_SCOPE])


class Article(ndb.Model):
    title = ndb.StringProperty(required=True)
    text = ndb.TextProperty(required=True)
    user = ndb.UserProperty(required=True)
    created = ndb.DateTimeProperty(auto_now_add=True)


class ArticleResponseMessage(messages.Message):
    key = messages.IntegerField(1)
    title = messages.StringField(2)
    text = messages.StringField(3)
    user = messages.StringField(4)
    created = messages.StringField(5)