Example #1
0
    def delete(self):
        active_user = self.get_current_user()
        uri = self.request.uri
        method = self.request.method
        try:
            customer_names = (self.arguments.get(ApiArguments.CUSTOMER_NAMES))

            if not isinstance(customer_names, list):
                customer_names = customer_names.split(',')

            results = (remove_customers(customer_names, active_user, uri,
                                        method))
            self.set_status(results['http_status'])
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(results, indent=4))

            if (results[ApiResultKeys.VFENSE_STATUS_CODE] ==
                    CustomerCodes.CustomerDeleted):

                remove_all_agents_for_customer(customer_name)
                remove_all_apps_for_customer(customer_name)

        except Exception as e:
            results = (GenericResults(active_user, uri,
                                      method).something_broke(
                                          active_user, 'User', e))
            logger.exception(e)
            self.set_status(results['http_status'])
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(results, indent=4))
Example #2
0
    def delete(self):
        active_user = self.get_current_user()
        uri = self.request.uri
        method = self.request.method
        try:
            customer_names = (
                self.arguments.get(ApiArguments.CUSTOMER_NAMES)
            )

            if not isinstance(customer_names, list):
                customer_names = customer_names.split(',')

            results = (
                remove_customers(
                    customer_names,
                    active_user, uri, method
                )
            )
            self.set_status(results['http_status'])
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(results, indent=4))

            if (results[ApiResultKeys.VFENSE_STATUS_CODE] ==
                    CustomerCodes.CustomerDeleted):

                remove_all_agents_for_customer(customer_name)
                remove_all_apps_for_customer(customer_name)

        except Exception as e:
            results = (
                GenericResults(
                    active_user, uri, method
                ).something_broke(active_user, 'User', e)
            )
            logger.exception(e)
            self.set_status(results['http_status'])
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(results, indent=4))
Example #3
0
    def delete(self, customer_name):
        active_user = self.get_current_user()
        uri = self.request.uri
        method = self.request.method
        try:
            deleted_agents = (
                self.arguments.get(
                    ApiArguments.DELETE_ALL_AGENTS
                )
            )
            move_agents_to_customer = (
                self.arguments.get(
                    ApiArguments.MOVE_AGENTS_TO_CUSTOMER, None
                )
            )

            sched = self.application.scheduler
            jobs = sched.get_jobs(name=customer_name)

            if move_agents_to_customer:
                customer_exist = get_customer(move_agents_to_customer)
                if not customer_exist:
                    msg = 'customer %s does not exist' % (move_agents_to_customer)
                    data = {
                        ApiResultKeys.INVALID_ID: move_agents_to_customer,
                        ApiResultKeys.MESSAGE: msg,
                        ApiResultKeys.VFENSE_STATUS_CODE: CustomerFailureCodes.CustomerDoesNotExist
                    }
                    results = (
                        Results(
                            active_user, uri, method
                        ).invalid_id(**data)
                    ) 
                    self.set_status(results['http_status'])
                    self.set_header('Content-Type', 'application/json')
                    self.write(json.dumps(results, indent=4))

                else:
                    results = (
                        remove_customer(
                            customer_name,
                            active_user, uri, method
                        )
                    )
                    self.set_status(results['http_status'])
                    self.set_header('Content-Type', 'application/json')
                    self.write(json.dumps(results, indent=4))
                    if (results[ApiResultKeys.VFENSE_STATUS_CODE] ==
                            CustomerCodes.CustomerDeleted):

                        change_customer_for_all_agents_in_customer(
                            customer_name, move_agents_to_customer
                        )
                        change_customer_for_apps_in_customer(
                            customer_name, move_agents_to_customer
                        )

                        for job in jobs:
                            sched.unschedule_job(job)

            elif deleted_agents == ApiValues.YES:
                results = (
                    remove_customer(
                        customer_name,
                        active_user, uri, method
                    )
                )
                self.set_status(results['http_status'])
                self.set_header('Content-Type', 'application/json')
                self.write(json.dumps(results, indent=4))
                if (results[ApiResultKeys.VFENSE_STATUS_CODE] ==
                        CustomerCodes.CustomerDeleted):

                    remove_all_agents_for_customer(customer_name)
                    remove_all_apps_for_customer(customer_name)

                    for job in jobs:
                        sched.unschedule_job(job)

            elif deleted_agents == ApiValues.NO:
                results = (
                    remove_customer(
                        customer_name,
                        active_user, uri, method
                    )
                )

                for job in jobs:
                    sched.unschedule_job(job)
                    
                self.set_status(results['http_status'])
                self.set_header('Content-Type', 'application/json')
                self.write(json.dumps(results, indent=4))

            else:
                results = (
                    GenericResults(
                        active_user, uri, method
                    ).incorrect_arguments()
                )
                self.set_status(results['http_status'])
                self.set_header('Content-Type', 'application/json')
                self.write(json.dumps(results, indent=4))

        except Exception as e:
            results = (
                GenericResults(
                    active_user, uri, method
                ).something_broke(active_user, 'User', e)
            )
            logger.exception(e)
            self.set_status(results['http_status'])
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(results, indent=4))
Example #4
0
    def delete(self, customer_name):
        active_user = self.get_current_user()
        uri = self.request.uri
        method = self.request.method
        try:
            deleted_agents = (self.arguments.get(
                ApiArguments.DELETE_ALL_AGENTS))
            move_agents_to_customer = (self.arguments.get(
                ApiArguments.MOVE_AGENTS_TO_CUSTOMER, None))

            sched = self.application.scheduler
            jobs = sched.get_jobs(name=customer_name)

            if move_agents_to_customer:
                customer_exist = get_customer(move_agents_to_customer)
                if not customer_exist:
                    msg = 'customer %s does not exist' % (
                        move_agents_to_customer)
                    data = {
                        ApiResultKeys.INVALID_ID:
                        move_agents_to_customer,
                        ApiResultKeys.MESSAGE:
                        msg,
                        ApiResultKeys.VFENSE_STATUS_CODE:
                        CustomerFailureCodes.CustomerDoesNotExist
                    }
                    results = (Results(active_user, uri,
                                       method).invalid_id(**data))
                    self.set_status(results['http_status'])
                    self.set_header('Content-Type', 'application/json')
                    self.write(json.dumps(results, indent=4))

                else:
                    results = (remove_customer(customer_name, active_user, uri,
                                               method))
                    self.set_status(results['http_status'])
                    self.set_header('Content-Type', 'application/json')
                    self.write(json.dumps(results, indent=4))
                    if (results[ApiResultKeys.VFENSE_STATUS_CODE] ==
                            CustomerCodes.CustomerDeleted):

                        change_customer_for_all_agents_in_customer(
                            customer_name, move_agents_to_customer)
                        change_customer_for_apps_in_customer(
                            customer_name, move_agents_to_customer)

                        for job in jobs:
                            sched.unschedule_job(job)

            elif deleted_agents == ApiValues.YES:
                results = (remove_customer(customer_name, active_user, uri,
                                           method))
                self.set_status(results['http_status'])
                self.set_header('Content-Type', 'application/json')
                self.write(json.dumps(results, indent=4))
                if (results[ApiResultKeys.VFENSE_STATUS_CODE] ==
                        CustomerCodes.CustomerDeleted):

                    remove_all_agents_for_customer(customer_name)
                    remove_all_apps_for_customer(customer_name)

                    for job in jobs:
                        sched.unschedule_job(job)

            elif deleted_agents == ApiValues.NO:
                results = (remove_customer(customer_name, active_user, uri,
                                           method))

                for job in jobs:
                    sched.unschedule_job(job)

                self.set_status(results['http_status'])
                self.set_header('Content-Type', 'application/json')
                self.write(json.dumps(results, indent=4))

            else:
                results = (GenericResults(active_user, uri,
                                          method).incorrect_arguments())
                self.set_status(results['http_status'])
                self.set_header('Content-Type', 'application/json')
                self.write(json.dumps(results, indent=4))

        except Exception as e:
            results = (GenericResults(active_user, uri,
                                      method).something_broke(
                                          active_user, 'User', e))
            logger.exception(e)
            self.set_status(results['http_status'])
            self.set_header('Content-Type', 'application/json')
            self.write(json.dumps(results, indent=4))