コード例 #1
0
def get_oauth():
    client_key = get_client_key(request)
    client_secret = Config().oauth_signature
    if not client_key or not client_secret:
        return None
    return OAuth1(client_key=client_key,
                  client_secret=client_secret)
コード例 #2
0
    def test_config_load(self):
        Config.load()
        config = InlineClass({
            'debug': True,
            'fallball_service_url': 'PUT_HERE_FALLBALL_SERVICE_URI',
            'fallball_service_authorization_token': 'PUT_HERE_FALLBALL_SERVICE_AUTHORIZATION_TOKEN',
            'oauth_key': 'PUT_HERE_OAUTH_KEY',
            'oauth_secret': 'PUT_HERE_OAUTH_SECRET',
            'diskspace_resource': 'DISKSPACE',
            'devices_resource': 'DEVICES',
        })

        for (key, value) in viewitems(config.__dict__):
            self.assertTrue(hasattr(Config, key))

        Config.conf_file = 'tests/fake_config_invalid.json'
        with self.assertRaises(RuntimeError):
            Config.load()

        Config.conf_file = 'not_exists'
        with self.assertRaises(IOError):
            Config.load()
コード例 #3
0
 def __init__(self):
     self.endpoint = oauth.SignatureOnlyEndpoint(self)
     self._config = Config()
     super(RequestValidator, self).__init__()
コード例 #4
0
import json

from flask_testing import TestCase

from connector.app import app

from connector.config import Config

from tests.utils import bypass_auth

config = Config()


class TestApp(TestCase):
    def create_app(self):
        app.config.update({'TESTING': True})
        self.client = app.test_client()
        self.new_app = json.dumps(
            {'aps': {
                'type': 'http://new.app',
                'id': '123-123-123'
            }})
        self.headers = {
            'Content-type': 'application/json',
            'aps-instance-id': '123-123-123',
            'aps-controller-uri': 'https://aps.com'
        }

        return app

    def test_healthcheck(self):
コード例 #5
0
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
stream = logging.StreamHandler(sys.stdout)
logger.addHandler(stream)

app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)

app.register_blueprint(api_v1, url_prefix='/v1')


@app.route('/')
def home():
    return jsonify({'service': 'box_connector', 'host': socket.gethostname()})


if __name__ == '__main__':
    logger.info(" * Using CONFIG_FILE=%s", Config().conf_file)

    if not check_configuration(Config()):
        raise RuntimeError("You can't run your connector with default "
                           "parameters, please update the JSON config "
                           "file and replace PUT_HERE_* values with real "
                           "ones")

    port = int(os.environ.get('PORT', 5000))

    app.run(debug=True if Config().loglevel == 'DEBUG' else False,
            host='0.0.0.0',
            port=port)
コード例 #6
0
import logging
import os
import sys
import socket

from flask import Flask, jsonify
from werkzeug.contrib.fixers import ProxyFix

from connector.config import Config, check_configuration
from connector.v1 import api_bp as api_v1

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

if not Config().debug:  # pragma: no cover
    logging.disable(logging.DEBUG)

stream = logging.StreamHandler(sys.stdout)
logger.addHandler(stream)

app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)

app.register_blueprint(api_v1, url_prefix='/connector/v1')

api_v1.name = 'latest'
app.register_blueprint(api_v1, url_prefix='/connector')


@app.route('/')
def home():