Class: S33r::S3Logging::LoggingResource

Inherits:
Object
  • Object
show all
Defined in:
lib/s33r/s3_logging.rb

Overview

For manipulating logging directives on resources (see docs.amazonwebservices.com/AmazonS3/2006-03-01/LoggingHowTo.html).

Creating a LoggingResource instance using new and no arguments will generate a “blank” instance; this can be put to the ?logging URL for a resource to remove logging from it.

To set a Bucket up for logging, create a LoggingResource with the correct log_target and log_prefix settings and put that to the ?logging URL for a bucket.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_target = nil, log_prefix = nil) ⇒ LoggingResource

log_target is the bucket to put logs into. log_prefix is the prefix for log files put into the log_target bucket.



17
18
19
20
# File 'lib/s33r/s3_logging.rb', line 17

def initialize(log_target=nil, log_prefix=nil)
  @log_target = log_target
  @log_prefix = log_prefix
end

Instance Attribute Details

#log_prefixObject (readonly)

Returns the value of attribute log_prefix.



13
14
15
# File 'lib/s33r/s3_logging.rb', line 13

def log_prefix
  @log_prefix
end

#log_targetObject (readonly)

Returns the value of attribute log_target.



13
14
15
# File 'lib/s33r/s3_logging.rb', line 13

def log_target
  @log_target
end

Class Method Details

.from_xml(logging_xml) ⇒ Object

Convert XML from S3 response into a LoggingResource

– TODO: tests



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/s33r/s3_logging.rb', line 46

def self.from_xml(logging_xml)
  return nil if logging_xml.nil?
  
  logging_xml = S33r.remove_namespace(logging_xml)
  doc = XML.get_xml_doc(logging_xml)
  
  log_target = doc.xget('//TargetBucket')
  log_prefix = doc.xget('//TargetPrefix')
  
  self.new(log_target, log_prefix)
end

Instance Method Details

#to_xmlObject

Generate a BucketLoggingStatus XML document for putting to the ?logging URL for a resource.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/s33r/s3_logging.rb', line 24

def to_xml
  xml_str = ""
  xml = Builder::XmlMarkup.new(:target => xml_str, :indent => 0)
  
  xml.instruct!
  
  # BucketLoggingStatus XML.
  xml.BucketLoggingStatus({"xmlns" => RESPONSE_NAMESPACE_URI}) {
    unless @log_target.nil? and @log_prefix.nil?
      xml.LoggingEnabled {
        xml.TargetBucket @log_target
        xml.TargetPrefix @log_prefix
      }
    end
  }
  
  xml_str
end