def enable_logging(self, target_bucket, target_prefix='', grants=None, headers=None): """ Enable logging on a bucket. :type target_bucket: bucket or string :param target_bucket: The bucket to log to. :type target_prefix: string :param target_prefix: The prefix which should be prepended to the generated log files written to the target_bucket. :type grants: list of Grant objects :param grants: A list of extra permissions which will be granted on the log files which are created. :rtype: bool :return: True if ok or raises an exception. """ if isinstance(target_bucket, Bucket): target_bucket = target_bucket.name blogging = BucketLogging(target=target_bucket, prefix=target_prefix, grants=grants) return self.set_xml_logging(blogging.to_xml(), headers=headers)
def disable_logging(self, headers=None): """ Disable logging on a bucket. :rtype: bool :return: True if ok or raises an exception. """ blogging = BucketLogging() return self.set_xml_logging(blogging.to_xml(), headers=headers)
def test_set_bucket_logging(self): bucket = conn.get_bucket(test_bucket) # logging is kind of xml string. from ks3.bucketlogging import BucketLogging target = test_bucket prefix = "test_bucket_access_log" grants = [] logging = BucketLogging(target, prefix, grants).to_xml() bucket.set_xml_logging(logging, headers={'content-type': 'text/plain'})
def test_set_bucket_logging(self): bucket = conn.get_bucket(test_bucket) # logging is kind of xml string. from ks3.bucketlogging import BucketLogging target = test_bucket prefix = "test_bucket_access_log" grants = Grant() logging = BucketLogging(target, prefix, grants).to_xml() bucket.set_xml_logging(logging)
def get_logging_status(self, headers=None): """ Get the logging status for this bucket. :rtype: :class:`boto.s3.bucketlogging.BucketLogging` :return: A BucketLogging object for this bucket. """ response = self.connection.make_request('GET', self.name, query_args='logging', headers=headers) body = response.read() if response.status == 200: blogging = BucketLogging() h = handler.XmlHandler(blogging, self) if not isinstance(body, bytes): body = body.encode('utf-8') xml.sax.parseString(body, h) return blogging else: raise S3ResponseError(response.status, response.reason, body)