예제 #1
0
def run_hub_app(celery, worker, https):
    app = Flask(__name__)
    app.config['PUBLISH_SUPPORTED'] = True

    hub = Hub(SQLite3HubStorage('hub.db'), celery, **app.config)
    worker.reload()

    app.register_blueprint(hub.build_blueprint(url_prefix='/hub'))
    with serve_app(app, port=5001, https=https):
        yield hub

    os.remove('hub.db')
예제 #2
0
def test_default_hub(app):
    # mess with the internals so it looks like no hub has been created yet -
    # even if it has been by another test.
    import flask_websub.hub.blueprint
    flask_websub.hub.blueprint.first_time = True
    # we don't need celery & storage to just construct the blueprint & find
    # the URL. So we just pass in None.
    hub = Hub(None, None, **app.config)
    app.register_blueprint(hub.build_blueprint(url_prefix='/hub'))

    @app.route('/resource')
    @publisher()
    def resource():
        return 'Hello World!'
    resp = app.test_client().get('/resource')
    assert '<http://localhost/hub>; rel="hub"' in resp.headers['Link']
    assert '<http://localhost/resource>; rel="self"' in resp.headers['Link']
예제 #3
0
# app & celery
app = Flask(__name__)
app.config['SERVER_NAME'] = 'localhost:8080'
celery = Celery('sever_example', broker='redis://localhost:6379')

# initialise publisher
init_publisher(app)

# initialise hub
#
# PUBLISH_SUPPORTED is not recommended in production, as it just accepts any
# link without validation, but it's but nice for testing.
app.config['PUBLISH_SUPPORTED'] = True
# we could also have passed in just PUBLISH_SUPPORTED, but this is probably a
# nice pattern for your app:
hub = Hub(SQLite3HubStorage('server_data.sqlite3'), celery, **app.config)
app.register_blueprint(hub.build_blueprint(url_prefix='/hub'))


def validate_topic_existence(callback_url, topic_url, *args):
    with app.app_context():
        if topic_url.startswith('https://websub.rocks/'):
            return  # pass validation
        if topic_url != url_for('topic', _external=True):
            return "Topic not allowed"


hub.register_validator(validate_topic_existence)
hub.schedule_cleanup()  # cleanup expired subscriptions once a day, by default

예제 #4
0
from flask import Flask, render_template, url_for
from flask_websub.hub import Hub, SQLite3HubStorage
from celery import Celery

# app & celery
app = Flask(__name__)
app.config['SERVER_NAME'] = 'vanl0057336.online-vm.com'

broker_url = 'sqs://*****:*****@'
celery = Celery('server_example', broker='redis://localhost:6379')

app.config['PUBLISH_SUPPORTED'] = True
# we could also have passed in just PUBLISH_SUPPORTED, but this is probably a
# nice pattern for your app:
hub = Hub(SQLite3HubStorage('/root/Hub/server_data.sqlite3'), celery,
          **app.config)
app.register_blueprint(hub.build_blueprint(url_prefix='/'))

hub.schedule_cleanup()  # cleanup expired subscriptions once a day, by default


@app.before_first_request
def cleanup():
    # or just cleanup manually at some point
    hub.cleanup_expired_subscriptions.delay()


@app.route('/welcome')
def topic():
    return render_template('server_example.html')