Esempio n. 1
0
def run_serve_starts_with_single_instance():
    broker = Mock()
    broker.catalog.return_value = Service('id', 'name', 'description', False,
                                          [])
    api.serve(broker, [
        api.BrokerCredentials("cfy-login", "cfy-pwd"),
        api.BrokerCredentials("k8s-login", "k8s-pwd")
    ])
Esempio n. 2
0
def create_app():
    app = Flask(__name__)
    logger = basic_config()

    openbroker_bp = api.get_blueprint([
        TuFilesServiceBroker(),
        TuCloudServiceBroker(),
        TuHostServiceBroker()
    ], api.BrokerCredentials("", ""), logger)
    app.register_blueprint(openbroker_bp)

    return app
Esempio n. 3
0
def create_app():
    app = Flask(__name__)
    cf_logging._SETUP_DONE = False
    flask_logging.init(app)
    logger = logging.getLogger(__name__)
    app.config.from_object(config)

    db.init_app(app)
    migrate.init_app(app, db)

    credentials = openbrokerapi.BrokerCredentials(
        app.config["BROKER_USERNAME"], app.config["BROKER_PASSWORD"]
    )

    app.register_blueprint(openbrokerapi.get_blueprint(API(), credentials, logger))

    # drop the upstream's error-handlers, because they dump error messages to the cient
    del app.error_handler_spec["open_broker"][None][Exception]
    del app.error_handler_spec["open_broker"][None][NotImplementedError]

    # Endpoint to test if server comes up
    @app.route("/ping")
    def ping():
        return "PONG"

    @app.errorhandler(Exception)
    def handle_base_exception(e):
        logger.exception(e)
        if config.TESTING:
            response = ErrorResponse(description=str(e))
        else:
            response = ErrorResponse(description="Unhandled error during request")
        return (to_json_response(response), HTTPStatus.INTERNAL_SERVER_ERROR)

    @app.errorhandler(ClientError)
    def handle_not_implemented(e):
        logger.exception(e)
        return (
            to_json_response(ErrorResponse(description=str(e))),
            HTTPStatus.NOT_IMPLEMENTED,
        )

    @app.errorhandler(NotImplementedError)
    def handle_not_implemented(e):
        logger.exception(e)
        return (
            to_json_response(ErrorResponse(description="Not Implemented")),
            HTTPStatus.NOT_IMPLEMENTED,
        )

    return app
Esempio n. 4
0
def create_app():
    app = Flask(__name__)
    cf_logging._SETUP_DONE = False
    flask_logging.init(app)
    logger = logging.getLogger(__name__)
    app.config.from_object(config)

    db.init_app(app)
    migrate.init_app(app, db)

    credentials = openbrokerapi.BrokerCredentials(
        app.config["BROKER_USERNAME"], app.config["BROKER_PASSWORD"])

    app.register_blueprint(
        openbrokerapi.get_blueprint(API(), credentials, logger))

    # Endpoint to test if server comes up
    @app.route("/ping")
    def ping():
        return "PONG"

    return app
Esempio n. 5
0
def run_serve_starts_server():
    broker = Mock()
    broker.catalog.return_value = []
    api.serve(broker, api.BrokerCredentials("", ""))
 def run_server():
     api.serve_multiple([self.broker_1, self.broker_2],
                        api.BrokerCredentials(broker_username,
                                              broker_passsword),
                        port=5002,
                        debug=True)
    return api.get_blueprint(MongoDBOpenServiceBroker(), credentials, logger)

app = Flask(__name__)

logger = basic_config()  

# If we're running inside a kubernetes cluster, then we expect the credentials for
# the broker to be in a file mounted from a secret.
if os.environ.get('KUBERNETES_SERVICE_HOST'):
  k8s_host = os.environ.get('KUBERNETES_SERVICE_HOST')
  print("Detected running in a Kubernetes cluster. KUBERNETES_SERVICE_HOST=%s" % k8s_host)
  config_path = "/broker/broker-config"
  with open( ("%s/username" % config_path), 'r') as secret:
    username = secret.read()
  with open( ("%s/password" % config_path), 'r') as secret:
    password = secret.read()
else:
  print("Did not detect Kubernetes cluster. Running with default 'test/test' credentials")
  username = "******"
  password = "******"
openbroker_bp = api.get_blueprint(MongoDBOpenServiceBroker(), api.BrokerCredentials(username,password), logger)
#@openbroker_bp.app_errorhandler(HTTPException)
#def handle_http_error(error):
#  response = jsonify(error.to_dict())
#  response.status_code = error.status_code
#  print("app.errorhandler: response: %s" % response)
#  return response
app.register_blueprint(openbroker_bp)
#app.register_error_handler(handle_http_error)
app.run("0.0.0.0")
Esempio n. 8
0
        def run_server():
            class TestBroker(service_broker.ServiceBroker):
                def catalog(self) -> List[api.Service]:
                    return []

            api.serve(TestBroker(), api.BrokerCredentials("", ""))
Esempio n. 9
0
 def run_server():
     api.serve([], api.BrokerCredentials("", ""))
Esempio n. 10
0
 def run_server():
     api.serve(self.broker,
               api.BrokerCredentials(broker_username, broker_passsword),
               port=5001)
Esempio n. 11
0
# If we're running inside a kubernetes cluster, then we expect the credentials for
# the broker to be in a file mounted from a secret.
if os.environ.get('KUBERNETES_SERVICE_HOST'):
    k8s_host = os.environ.get('KUBERNETES_SERVICE_HOST')
    logger.debug(
        f'Running in a Kubernetes cluster. KUBERNETES_SERVICE_HOST={k8s_host}')
    with open("/mdb-osb/credentials/username", 'r') as secret:
        username = secret.read()
    with open("/mdb-osb/credentials/password", 'r') as secret:
        password = secret.read()
else:
    logger.debug("Did not detect Kubernetes cluster")
    logger.debug(
        f'Running with default {DEFAULT_USERNAME}:{DEFAULT_PWD} credentials')
    username = DEFAULT_USERNAME
    password = DEFAULT_PWD

openbroker_bp = api.get_blueprint(
    MongoDBEnterpriseOSB(template_folder=template_folder, logger=logger),
    api.BrokerCredentials(username, password), logger)

app.register_blueprint(openbroker_bp)

import pprint
pprint.pprint(app)
if __name__ == "__main__":
    # Only for debugging while developing
    app.template_folder = '../templates'
    app.run(host="0.0.0.0", debug=True, port=BROKER_PORT)