def _get_agent_state(self, name):
     try:
         state = self._provider.status(name)['state']
         return {'state': state}
     except InstanceNotFoundError as error:
             logger.warn(error.message)
             response.status = '404 Not Found - %s' % error.message
 def _get_agent(self, name):
     try:
         self._provider.status(name)
         return self._agent_to_json(name)
     except InstanceNotFoundError as error:
             logger.warn(error.message)
             response.status = '404 Not Found - %s' % error.message
Beispiel #3
0
    def serve_forever(self):
        try:
            provider = self._download_api_ca_bundle()
            users = Users(self._root_path)
            authenticator = Authenticator(users, provider)
            provider = self._create_provider()

            Thread(target=provider.initialize).start()

            logger.info('Starting REST api')
            self._server = RESTfulServer(self._ssl_config,
                                         users,
                                         authenticator,
                                         provider,
                                         bindaddr=self._bindaddr,
                                         port=DEFAULT_PORT)
            if self._ssl_config:
                logger.info('Using SSL certfile %s and keyfile %s' %
                            (self._ssl_config.ssl_certfile,
                             self._ssl_config.ssl_keyfile))
            else:
                logger.warn('No SSL configured')
            logger.info('Listening on %s:%d' % ('localhost', DEFAULT_PORT))
            self._server.serve_forever()
        except Exception, e:
            logger.exception("Error while running manager: %s" % e)
            raise  # re-raise
Beispiel #4
0
 def _get_agent_state(self, name):
     try:
         state = self._provider.status(name)['state']
         return {'state': state}
     except InstanceNotFoundError as error:
         logger.warn(error.message)
         response.status = '404 Not Found - %s' % error.message
Beispiel #5
0
 def _get_agent(self, name):
     try:
         self._provider.status(name)
         return self._agent_to_json(name)
     except InstanceNotFoundError as error:
         logger.warn(error.message)
         response.status = '404 Not Found - %s' % error.message
 def _delete_agent(self, name):
     try:
         self._provider.remove(name)
         logger.info('Removed agent of user %s' % name)
         response.status = "200 OK"
     except InstanceNotFoundError as error:
             logger.warn(error.message)
             response.status = '404 Not Found - %s' % error.message
 def _authenticate_agent(self, name):
     password = request.json['password']
     result = self._provider.authenticate(name, password)
     if result:
         response.status = '200 Ok'
         logger.info('User %s logged in successfully' % name)
     else:
         response.status = '403 Forbidden'
         logger.warn('Authentication failed for user %s!' % name)
     return {}
Beispiel #8
0
 def _reset_agent_data(self, name):
     try:
         user_config = self._users.config(name)
         self._provider.reset_data(user_config)
         return self._get_agent_state(name)
     except UserNotExistError as error:
         logger.warn(error.message)
         response.status = '404 Not Found - %s' % error.message
     except InstanceAlreadyRunningError as error:
         logger.warn(error.message)
         response.status = '409 Conflict - %s' % error.message
 def _reset_agent_data(self, name):
     try:
         user_config = self._users.config(name)
         self._provider.reset_data(user_config)
         return self._get_agent_state(name)
     except UserNotExistError as error:
         logger.warn(error.message)
         response.status = '404 Not Found - %s' % error.message
     except InstanceAlreadyRunningError as error:
         logger.warn(error.message)
         response.status = '409 Conflict - %s' % error.message
Beispiel #10
0
 def _authenticate_agent(self, name):
     password = request.json['password']
     result = self._authenticator.authenticate(name, password)
     if result:
         self._provider.pass_credentials_to_agent(self._users.config(name),
                                                  password)
         response.status = '200 Ok'
         logger.info('User %s logged in successfully' % name)
     else:
         response.status = '403 Forbidden'
         logger.warn('Authentication failed for user %s!' % name)
     return {}
 def _add_agent(self):
     name = request.json['name']
     password = request.json['password']
     try:
         self._provider.add(name, password)
         logger.info('Added agent for user %s' % name)
         response.status = '201 Created'
         response.headers['Location'] = self._agent_uri(name)
         return self._agent_to_json(name)
     except InstanceAlreadyExistsError as error:
             logger.warn(error.message)
             response.status = '409 Conflict - %s' % error.message
Beispiel #12
0
    def post(self):
        username = self.get_argument("username", "")
        password = self.get_argument("password", "")
        try:
            agent = self._client.get_agent(username)

            # now authenticate with server...
            self._client.authenticate(username, password)
            self.set_current_user(username)

            logger.info('Successful login of user %s' % username)
            logger.info('Starting agent for %s' % username)
            runtime = self._client.get_agent_runtime(username)
            if runtime['state'] != 'running':
                self._client.start(username)

                # wait til agent is running
                runtime = self._client.get_agent_runtime(username)
                max_wait_seconds = TIMEOUT_WAIT_FOR_AGENT_TO_BE_UP
                waited = 0
                while runtime[
                        'state'] != 'running' and waited < max_wait_seconds:
                    yield gen.Task(tornado.ioloop.IOLoop.current().add_timeout,
                                   time.time() + TIMEOUT_WAIT_STEP)
                    runtime = self._client.get_agent_runtime(username)
                    waited += TIMEOUT_WAIT_STEP

                # wait till agent is up and serving
                if runtime['state'] == 'running':
                    yield gen.Task(self._wait_til_agent_is_up, runtime)
                    port = runtime['port']
                    self.redirect(u'/')
                else:
                    logger.warn(
                        'Agent not running, redirecting user to login page')
                    self.redirect(u'/auth/login')
            else:
                self.redirect(u'/')
        except PixelatedNotAvailableHTTPError:
            logger.error(
                'Login attempt while service not available by user: %s' %
                username)
            self.set_cookie(
                'error_msg',
                tornado.escape.url_escape('Service currently not available'))
            self.redirect(u'/auth/login')
        except PixelatedHTTPError, e:
            logger.warn('Login attempt with invalid credentials by user %s' %
                        username)
            self.set_cookie('error_msg',
                            tornado.escape.url_escape('Invalid credentials'))
            self.redirect(u'/auth/login')
Beispiel #13
0
 def _add_agent(self):
     name = request.json['name']
     password = request.json['password']
     try:
         self._users.add(name)
         self._authenticator.add_credentials(name, password)
         logger.info('Added agent for user %s' % name)
         response.status = '201 Created'
         response.headers['Location'] = self._agent_uri(name)
         return self._agent_to_json(name)
     except UserAlreadyExistsError as error:
         logger.warn(error.message)
         response.status = '409 Conflict - %s' % error.message
 def serve_forever(self):
     app = self.create_app()
     # app.listen(port=self._port, address=self._bindaddr, ssl_options=self.ssl_options)
     if self.ssl_options:
         logger.info('Using SSL certfile %s and keyfile %s' % (self.ssl_options['certfile'], self.ssl_options['keyfile']))
     else:
         logger.warn('No SSL configured!')
     logger.info('Listening on %s:%d' % (self._bindaddr, self._port))
     self._server = HTTPServer(app, ssl_options=self.ssl_options)
     self._server.listen(port=self._port, address=self._bindaddr)
     self._ioloop = tornado.ioloop.IOLoop.instance()
     self._ioloop.start()  # this is a blocking call, server has stopped on next line
     self._ioloop = None
 def validate_connection(self, timeout_in_s=DEFAULT_TIMEOUT_IN_S):
     try:
         start = time.time()
         ok = False
         while not ok and (time.time() - start < timeout_in_s):
             try:
                 self.list()
                 ok = True
             except ConnectionError, e:
                 logger.warn(e.message)
             time.sleep(0.5)
         if not ok:
             raise ConnectionError('Failed to connect to manager (%s) within %d seconds' % (self._hostname, timeout_in_s))
 def validate_connection(self, timeout_in_s=DEFAULT_TIMEOUT_IN_S):
     try:
         start = time.time()
         ok = False
         while not ok and (time.time() - start < timeout_in_s):
             try:
                 self.list()
                 ok = True
             except ConnectionError, e:
                 logger.warn(e.message)
             time.sleep(0.5)
         if not ok:
             raise ConnectionError('Failed to connect to manager (%s) within %d seconds' % (self._hostname, timeout_in_s))
    def serve_forever(self):
        provider = self._create_provider()

        Thread(target=provider.initialize).start()

        logger.info('Starting REST api')
        self._server = RESTfulServer(self._ssl_config, provider, bindaddr=self._bindaddr, port=DEFAULT_PORT)
        if self._ssl_config:
            logger.info('Using SSL certfile %s and keyfile %s' % (self._ssl_config.ssl_certfile, self._ssl_config.ssl_keyfile))
        else:
            logger.warn('No SSL configured')
        logger.info('Listening on %s:%d' % ('localhost', DEFAULT_PORT))
        self._server.serve_forever()
    def serve_forever(self):
        users = Users(self._root_path)
        authenticator = Authenticator(users, self._leap_provider_hostname, self._leap_provider_ca)
        provider = self._create_provider()

        Thread(target=provider.initialize).start()

        logger.info('Starting REST api')
        self._server = RESTfulServer(self._ssl_config, users, authenticator, provider, bindaddr=self._bindaddr, port=DEFAULT_PORT)
        if self._ssl_config:
            logger.info('Using SSL certfile %s and keyfile %s' % (self._ssl_config.ssl_certfile, self._ssl_config.ssl_keyfile))
        else:
            logger.warn('No SSL configured')
        logger.info('Listening on %s:%d' % ('localhost', DEFAULT_PORT))
        self._server.serve_forever()
    def post(self):
        username = self.get_argument("username", "")
        password = self.get_argument("password", "")
        try:
            agent = self._client.get_agent(username)

            # now authenticate with server...
            self._client.authenticate(username, password)
            self.set_current_user(username)

            logger.info('Successful login of user %s' % username)
            logger.info('Starting agent for %s' % username)
            runtime = self._client.get_agent_runtime(username)
            if runtime['state'] != 'running':
                self._client.start(username)

                # wait til agent is running
                runtime = self._client.get_agent_runtime(username)
                max_wait_seconds = TIMEOUT_WAIT_FOR_AGENT_TO_BE_UP
                waited = 0
                while runtime['state'] != 'running' and waited < max_wait_seconds:
                    yield gen.Task(tornado.ioloop.IOLoop.current().add_timeout, time.time() + TIMEOUT_WAIT_STEP)
                    runtime = self._client.get_agent_runtime(username)
                    waited += TIMEOUT_WAIT_STEP

                # wait till agent is up and serving
                if runtime['state'] == 'running':
                    yield gen.Task(self._wait_til_agent_is_up, runtime)
                    port = runtime['port']
                    self.redirect(u'/')
                else:
                    logger.warn('Agent not running, redirecting user to login page')
                    self.redirect(u'/auth/login')
            else:
                self.redirect(u'/')
        except PixelatedNotAvailableHTTPError:
            logger.error('Login attempt while service not available by user: %s' % username)
            self.set_cookie('error_msg', tornado.escape.url_escape('Service currently not available'))
            self.redirect(u'/auth/login')
        except PixelatedHTTPError, e:
            logger.warn('Login attempt with invalid credentials by user %s' % username)
            self.set_cookie('error_msg', tornado.escape.url_escape('Invalid credentials'))
            self.redirect(u'/auth/login')
    def serve_forever(self):
        try:
            provider = self._download_api_ca_bundle()
            users = Users(self._root_path)
            authenticator = Authenticator(users, provider)
            provider = self._create_provider()

            Thread(target=provider.initialize).start()

            logger.info('Starting REST api')
            self._server = RESTfulServer(self._ssl_config, users, authenticator, provider, bindaddr=self._bindaddr, port=DEFAULT_PORT)
            if self._ssl_config:
                logger.info('Using SSL certfile %s and keyfile %s' % (self._ssl_config.ssl_certfile, self._ssl_config.ssl_keyfile))
            else:
                logger.warn('No SSL configured')
            logger.info('Listening on %s:%d' % ('localhost', DEFAULT_PORT))
            self._server.serve_forever()
        except Exception, e:
            logger.exception("Error while running manager: %s" % e)
            raise  # re-raise
Beispiel #21
0
 def serve_forever(self):
     try:
         app = self.create_app()
         # app.listen(port=self._port, address=self._bindaddr, ssl_options=self.ssl_options)
         if self.ssl_options:
             logger.info('Using SSL certfile %s and keyfile %s' %
                         (self.ssl_options['certfile'],
                          self.ssl_options['keyfile']))
         else:
             logger.warn('No SSL configured!')
         logger.info('Listening on %s:%d' % (self._bindaddr, self._port))
         self._server = HTTPServer(app, ssl_options=self.ssl_options)
         self._server.listen(port=self._port, address=self._bindaddr)
         self._ioloop = tornado.ioloop.IOLoop.instance()
         self._ioloop.start(
         )  # this is a blocking call, server has stopped on next line
         self._ioloop = None
     except Exception, e:
         logger.exception("Error while running proxy: %s" % e)
         raise  # re-raise
    def _put_agent_state(self, name):
        state = request.json['state']

        if state == 'running':
            try:
                self._provider.start(name)
                logger.info('Started agent for user %s' % name)
                return self._get_agent_state(name)
            except InstanceNotFoundError as error:
                logger.warn(error.message)
                response.status = '404 Not Found - %s' % error.message
            except InstanceAlreadyRunningError as error:
                logger.warn(error.message)
                response.status = '409 Conflict - %s' % error.message
        else:
            try:
                self._provider.stop(name)
                logger.info('Stopped agent for user %s' % name)
                return self._get_agent_state(name)
            except InstanceNotRunningError as error:
                logger.warn(error.message)
                response.status = '409 Conflict - %s' % error.message
Beispiel #23
0
    def _put_agent_state(self, name):
        state = request.json['state']

        if state == 'running':
            try:
                user_cfg = self._users.config(name)
                self._provider.start(user_cfg)
                logger.info('Started agent for user %s' % name)
                return self._get_agent_state(name)
            except UserNotExistError as error:
                logger.warn(error.message)
                response.status = '404 Not Found - %s' % error.message
            except InstanceAlreadyRunningError as error:
                logger.warn(error.message)
                response.status = '409 Conflict - %s' % error.message
        else:
            try:
                self._provider.stop(name)
                logger.info('Stopped agent for user %s' % name)
                return self._get_agent_state(name)
            except InstanceNotRunningError as error:
                logger.warn(error.message)
                response.status = '409 Conflict - %s' % error.message