def create(self, request, *args, **kwargs): """Create a source.""" response = super().create(request, args, kwargs) # Modify json for response json_source = response.data format_source(json_source) # check to see if a connection scan was requested # through query parameter scan = request.query_params.get('scan', False) # If the scan was requested, create a connection scan if scan: if is_boolean(scan): if convert_to_boolean(scan): # Grab the source id source_id = response.data['id'] # Create the scan job scan_job = ScanJob(scan_type=ScanTask.SCAN_TYPE_CONNECT) scan_job.save() # Add the source scan_job.sources.add(source_id) scan_job.save() # Start the scan start_scan.send(sender=self.__class__, instance=scan_job) else: error = { 'scan': [_(messages.SOURCE_CONNECTION_SCAN)] } raise ValidationError(error) return response
def create(self, request, *args, **kwargs): """Create a source.""" response = super().create(request, args, kwargs) # Modify json for response json_source = response.data source_id = json_source.get('id') if not source_id or (source_id and not isinstance(source_id, int)): error = {'id': [_(messages.COMMON_ID_INV)]} raise ValidationError(error) get_object_or_404(self.queryset, pk=source_id) # Create expanded host cred JSON expand_credential(json_source) # check to see if a connection scan was requested # through query parameter scan = request.query_params.get('scan', False) # If the scan was requested, create a connection scan if scan: if is_boolean(scan): if convert_to_boolean(scan): # Grab the source id source_id = response.data['id'] # Define the scan options object scan_options = ScanOptions() scan_options.save() # Create the scan job scan_job = ScanJob(scan_type=ScanTask.SCAN_TYPE_CONNECT, options=scan_options) scan_job.save() # Add the source scan_job.sources.add(source_id) scan_job.save() # Start the scan start_scan.send(sender=self.__class__, instance=scan_job) else: error = {'scan': [_(messages.SOURCE_CONNECTION_SCAN)]} raise ValidationError(error) return response