Process the requests for S3 bucket deletions
330772
def process_delete_records(delete_records):
    """"""
    for rec in delete_records:
        arn = f"arn:aws:s3:::{rec['detail']['requestParameters']['bucketName']}"

        # Need to check if the event is NEWER than the previous event in case
        # events are out of order. This could *possibly* happen if something
        # was deleted, and then quickly re-created. It could be *possible* for the
        # deletion event to arrive after the creation event. Thus, this will check
        # if the current event timestamp is newer and will only delete if the deletion
        # event is newer.
        try:
            LOG.debug(f'[-] Deleting bucket: {arn}')
            model = create_delete_model(rec)
            model.save(condition=(CurrentS3Model.eventTime <= rec['detail']['eventTime']))
            model.delete()

        except PynamoDBConnectionError as pdce:
            LOG.warning(f"[?] Unable to delete bucket: {arn}. Either it doesn't exist, or this deletion event is stale "
                        f"(arrived before a NEWER creation/update). The specific exception is: {pdce}")
1259577
function(buckets) {
    var bucketRegionCache = this.bucketRegionCache;
    if (!buckets) {
      buckets = Object.keys(bucketRegionCache);
    } else if (typeof buckets === 'string') {
      buckets = [buckets];
    }
    for (var i = 0; i < buckets.length; i++) {
      delete bucketRegionCache[buckets[i]];
    }
    return bucketRegionCache;
   }
1149273
private function deleteDailyBackups()
    {
        try {
            $date = strtotime('-2 months');

            // leave first day of the month
            if ((int) date('j', $date) !== 1) {
                $this->filesystem->deleteDir(date("Y/m/d", $date));
            }
        } catch (\Exception $e) {
            $this->event->fire('MonasheeBackupError', 'Error trying to delete directory on AWS S3');
        }
    }
869199
def process_request(self, req, resp):  # pylint: disable=unused-argument
        

        try:
            creds = self._get_creds(req)
            self.auth_creds(*creds)
        except (AuthRejected, AuthRequired, InvalidAuthSyntax) as exc:
            exc.headers = self._error_headers
            if not self.optional:
                abort(exc)
607835
def purge_files(self, exclude_files=["index.html", "error.html"]):
        
        for chunk in utils.chunk_list(self._get_manifest_data(), 1000):
            try:
                self.s3.delete_objects(
                    Bucket=self.sitename,
                    Delete={
                        'Objects': [{"Key": f} for f in chunk
                                    if f not in exclude_files]
                    }
                )
            except Exception as ex:
                pass
51743
def process_request(self, request, client_address):
        """"""
        self.collect_children()
        pid = os.fork()  # @UndefinedVariable
        if pid:
            # Parent process
            if self.active_children is None:
                self.active_children = []
            self.active_children.append(pid)
            self.close_request(request) #close handle in parent process
            return
        else:
            # Child process.
            # This must never return, hence os._exit()!
            try:
                self.finish_request(request, client_address)
                self.shutdown_request(request)
                os._exit(0)
            except:
                try:
                    self.handle_error(request, client_address)
                    self.shutdown_request(request)
                finally:
                    os._exit(1)
620395
def process_update_records(update_records):
    """"""
    events = sorted(update_records, key=lambda x: x['account'])

    # Group records by account for more efficient processing
    for account_id, events in groupby(events, lambda x: x['account']):
        events = list(events)

        # Grab the bucket names (de-dupe events):
        buckets = {}
        for event in events:
            # If the creation date is present, then use it:
            bucket_event = buckets.get(event['detail']['requestParameters']['bucketName'], {
                'creationDate': event['detail']['requestParameters'].get('creationDate')
            })
            bucket_event.update(event['detail']['requestParameters'])

            buckets[event['detail']['requestParameters']['bucketName']] = bucket_event
            buckets[event['detail']['requestParameters']['bucketName']]['eventDetails'] = event

        # Query AWS for current configuration
        for b_name, item in buckets.items():
            LOG.debug(f'[~] Processing Create/Update for: {b_name}')
            # If the bucket does not exist, then simply drop the request --
            # If this happens, there is likely a Delete event that has occurred and will be processed soon.
            try:
                bucket_details = get_bucket(b_name,
                                            account_number=account_id,
                                            include_created=(item.get('creationDate') is None),
                                            assume_role=HISTORICAL_ROLE,
                                            region=CURRENT_REGION)
                if bucket_details.get('Error'):
                    LOG.error(f"[X] Unable to fetch details about bucket: {b_name}. "
                              f"The error details are: {bucket_details['Error']}")
                    continue

            except ClientError as cerr:
                if cerr.response['Error']['Code'] == 'NoSuchBucket':
                    LOG.warning(f'[?] Received update request for bucket: {b_name} that does not '
                                'currently exist. Skipping.')
                    continue

                # Catch Access Denied exceptions as well:
                if cerr.response['Error']['Code'] == 'AccessDenied':
                    LOG.error(f'[X] Unable to fetch details for S3 Bucket: {b_name} in {account_id}. Access is Denied. '
                              'Skipping...')
                    continue
                raise Exception(cerr)

            # Pull out the fields we want:
            data = {
                'arn': f'arn:aws:s3:::{b_name}',
                'principalId': cloudwatch.get_principal(item['eventDetails']),
                'userIdentity': cloudwatch.get_user_identity(item['eventDetails']),
                'userAgent': item['eventDetails']['detail'].get('userAgent'),
                'sourceIpAddress': item['eventDetails']['detail'].get('sourceIPAddress'),
                'requestParameters': item['eventDetails']['detail'].get('requestParameters'),
                'accountId': account_id,
                'eventTime': item['eventDetails']['detail']['eventTime'],
                'BucketName': b_name,
                'Region': bucket_details.pop('Region'),
                # Duplicated in top level and configuration for secondary index
                'Tags': bucket_details.pop('Tags', {}) or {},
                'eventSource': item['eventDetails']['detail']['eventSource'],
                'eventName': item['eventDetails']['detail']['eventName'],
                'version': VERSION
            }

            # Remove the fields we don't care about:
            del bucket_details['Arn']
            del bucket_details['GrantReferences']
            del bucket_details['_version']
            del bucket_details['Name']

            if not bucket_details.get('CreationDate'):
                bucket_details['CreationDate'] = item['creationDate']

            data['configuration'] = bucket_details

            current_revision = CurrentS3Model(**data)
            current_revision.save()
493550
protected void process(Collection<R> requests) {
        for(;;) {
            while(!requests.isEmpty()) {
                removeAndProcess(requests); // remove matching requests and process them
            }
            lock.lock();
            try {
                if(requests.isEmpty()) {
                    setProcessing(false);
                    return;
                }
            }
            finally {
                lock.unlock();
            }
        }
    }
1035123
function requestBucketRegion(resp, done) {
    var error = resp.error;
    var req = resp.request;
    var bucket = req.params.Bucket || null;

    if (!error || !bucket || error.region || req.operation === 'listObjects' ||
        (AWS.util.isNode() && req.operation === 'headBucket') ||
        (error.statusCode === 400 && req.operation !== 'headObject') ||
        regionRedirectErrorCodes.indexOf(error.code) === -1) {
      return done();
    }
    var reqOperation = AWS.util.isNode() ? 'headBucket' : 'listObjects';
    var reqParams = {Bucket: bucket};
    if (reqOperation === 'listObjects') reqParams.MaxKeys = 0;
    var regionReq = req.service[reqOperation](reqParams);
    regionReq._requestRegionForBucket = bucket;
    regionReq.send(function() {
      var region = req.service.bucketRegionCache[bucket] || null;
      error.region = region;
      done();
    });
  }
1293870
def process_request(self, request_object):
        """"""

        # Delete the object by its identifier
        entity = request_object.entity_cls.get(request_object.identifier)
        entity.delete()

        # FIXME Check for return value of `delete()`

        # We have successfully deleted the object.
        # Sending a 204 Response code.
        return ResponseSuccessWithNoContent()
787156
def AckFlowProcessingRequests(self, requests, cursor=None):
    """"""
    if not requests:
      return

    query = "DELETE FROM flow_processing_requests WHERE "

    conditions = []
    args = []
    for r in requests:
      conditions.append(
          "(client_id=%s AND flow_id=%s AND timestamp=FROM_UNIXTIME(%s))")
      args.append(db_utils.ClientIDToInt(r.client_id))
      args.append(db_utils.FlowIDToInt(r.flow_id))
      args.append(mysql_utils.RDFDatetimeToTimestamp(r.timestamp))

    query += " OR ".join(conditions)
    cursor.execute(query, args)
166456
def delete(cls, bucket_id):
        
        bucket = cls.get(bucket_id)
        if not bucket or bucket.deleted:
            return False

        bucket.deleted = True
        return True
411864
def delete_bucket(bucket_name)
      begin
        s3 = AWS::S3.new
        bucket = s3.buckets[bucket_name]
        bucket.delete!

      rescue AWS::Errors::Base => s3e
        raise S3AccessError.new(s3e.http_response), s3e.message
      end
    end
242475
def delete_object(self, bucket, object_name):
        
        details = self._details(
            method=b"DELETE",
            url_context=self._url_context(bucket=bucket, object_name=object_name),
        )
        d = self._submit(self._query_factory(details))
        return d
434468
def remove_file_from_s3(awsclient, bucket, key):
    
    client_s3 = awsclient.get_client('s3')
    response = client_s3.delete_object(Bucket=bucket, Key=key)
605963
def prepare_bucket(self):
        
        self.logger.info('Deleting old bucket first')
        del_url = '{0}/buckets/{1}'.format(self.cluster_prefix, self.bucket)
        r = self._htsess.delete(del_url)

        try:
            r.raise_for_status()
        except:
            self.logger.exception("Couldn't delete bucket")

        cr_url = '{0}/buckets'.format(self.cluster_prefix)
        data = {
            'name': self.bucket,
            'ramQuotaMB': '{0}'.format(self.quota),
            'bucketType': 'couchbase',
            'authType': 'sasl',
            'saslPassword': '',
            'replicaNumber': '0'
        }
        r = self._htsess.post(cr_url, data)
        r.raise_for_status()
259007
def delete_sessions(self, uid):
        
        '''
            
        '''
    
        title = '%s.delete_session' % self.__class__.__name__
        
    # validate inputs
        input_fields = {
            'uid': uid
        }
        for key, value in input_fields.items():
            object_title = '%s(%s=%s)' % (title, key, str(value))
            self.fields.validate(value, '.%s' % key, object_title)
    
    # construct url
        url = self.bucket_url + '/_user/%s/_session' % uid
    
    # send request
        response = requests.delete(url)

        return response.status_code