def post(self): ldap_config = self._validate_set_ldap_request() from cloudify_premium.multi_tenancy.ldap_authentication \ import LdapAuthentication # update current configuration for key, value in ldap_config.iteritems(): setattr(config.instance, key, value) # assert LDAP configuration is valid. authenticator = LdapAuthentication() authenticator.configure_ldap() try: authenticator.authenticate_user(ldap_config.get('ldap_username'), ldap_config.get('ldap_password')) except UnauthorizedError: # reload previous configuration. config.instance.load_configuration() raise BadParametersError( 'Failed setting LDAP authenticator: Invalid parameters ' 'provided.') config.reset(config.instance, write=True) # Restart the rest service so that each the LDAP configuration # be loaded to all flask processes. rest_utils.set_restart_task() ldap_config.pop('ldap_password') return ldap_config
def reset_state(configuration=None): global app # print "resetting state in server" config.reset(configuration) # this doesn't really do anything # blueprints_manager.reset() storage_manager.reset() app = setup_app()
def reset_state(configuration=None): global app # print "resetting state in server" config.reset(configuration) # this doesn't really do anything # blueprints_manager.reset() storage_manager.reset() app = setup_app()
def get_storage_manager_instance(): """Configure and yield a storage_manager instance. This is to be used only OUTSIDE of the context of the REST API. """ try: with _get_flask_app().app_context(): sm = get_storage_manager() yield sm finally: config.reset(config.Config())
def _get_storage_manager(): """Configure and yield a storage_manager instance. This is to be used only OUTSIDE of the context of the REST API. """ config.instance.load_from_file(RESTSERVICE_CONFIG_PATH) app = server.CloudifyFlaskApp() try: with app.app_context(): sm = get_storage_manager() yield sm finally: config.reset(config.Config())
def _collect_cloudify_config(data): config.instance.load_from_file(RESTSERVICE_CONFIG_PATH) app = server.CloudifyFlaskApp() try: with app.app_context(): ldap = bool(app.ldap) data['cloudify_config'] = { 'ldap_enabled': ldap, 'ha_enabled': _is_clustered() } finally: config.reset(config.Config())
def generate_auth_token(): config.instance.load_from_file(RESTSERVICE_CONFIG_PATH) config.instance.rest_service_log_path = '/dev/null' app = server.CloudifyFlaskApp() try: with app.app_context(): sm = storage.get_storage_manager() enc_uid = storage.idencoder.get_encoder().encode(0) admin_user = sm.get(storage.models.User, 0) token_key = admin_user.api_token_key return enc_uid + token_key finally: config.reset(config.Config())
def reset_app(configuration=None): global app config.reset(configuration) app = CloudifyFlaskApp(False)
def reset_app(configuration=None): global app config.reset(configuration) app = CloudifyFlaskApp(False)