def find_hosts(org: str, space: str, appname: str, configuration: Configuration) -> Dict[str, Any]: """ Find all hosts of this application in Cloud Foundry. :param org: String; Cloud Foundry organization containing the application. :param space: String; Cloud Foundry space containing the application. :param appname: String; Application in Cloud Foundry which is to be targeted. :param configuration: Configuration; Configuration details, see `README.md`. :return: A JSON Object representing the application which was targeted. """ def f(): app = App(org, space, appname) app.find_hosts(configuration) return app return _run(f, "Finding all application hosts...")
def block_traffic(org: str, space: str, appname: str, configuration: Configuration) -> Dict[str, Any]: """ Block all traffic to the application. :param org: String; Cloud Foundry organization containing the application. :param space: String; Cloud Foundry space containing the application. :param appname: String; Application in Cloud Foundry which is to be targeted. :param configuration: Configuration; Configuration details, see `README.md`. :return: A JSON Object representing the application which was targeted. """ def f(): app = App(org, space, appname) app.find_hosts(configuration) app.block(configuration) if configuration.get('database'): # TODO: Implement writing to a DB what we targeted assert False return app return _run(f, "Blocking all traffic to {}...".format(appname))
def block_services(org: str, space: str, appname: str, configuration: Configuration, services=None) -> Dict[str, Any]: """ Block the application from reaching all its services. :param org: String; Cloud Foundry organization containing the application. :param space: String; Cloud Foundry space containing the application. :param appname: String; Application in Cloud Foundry which is to be targeted. :param services: List[String]; List of service names to block, will target all if unset. :param configuration: Configuration; Configuration details, see `README.md`. :return: A JSON Object representing the application which was targeted. """ def f(): app = App(org, space, appname) app.find_hosts(configuration) app.find_services(configuration) if configuration.get('database'): # TODO: Implement writing to a DB what we targeted assert False app.block_services(configuration, services=services) return app msg = "Blocking traffic to {} bound to {}...".format(services, appname) if services \ else "Blocking traffic to all services bound to {}...".format(appname) return _run(f, msg)