Class: FakeS3::XmlAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/fakes3/xml_adapter.rb

Class Method Summary collapse

Class Method Details

.acl(object = nil) ⇒ Object

ACL xml



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/fakes3/xml_adapter.rb', line 157

def self.acl(object = nil)
  output = ""
  xml = Builder::XmlMarkup.new(:target => output)
  xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
  xml.AccessControlPolicy(:xmlns => "http://s3.amazonaws.com/doc/2006-03-01/") { |acp|
    acp.Owner do |owner|
      owner.ID("abc")
      owner.DisplayName("You")
    end
    acp.AccessControlList do |acl|
      acl.Grant do |grant|
        grant.Grantee("xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", "xsi:type" => "CanonicalUser") do |grantee|
          grantee.ID("abc")
          grantee.DisplayName("You")
        end
        grant.Permission("FULL_CONTROL")
      end
    end
  }
  output
end

.append_objects_to_list_bucket_result(lbr, objects) ⇒ Object

<LastModified>2006-01-01T12:00:00.000Z</LastModified>

<ETag>&quot;828ef3fdfa96f00ad9f27c383fc9ac7f&quot;</ETag>
<Size>5</Size>
<StorageClass>STANDARD</StorageClass>
<Owner>
  <ID>bcaf161ca5fb16fd081034f</ID>
  <DisplayName>webfile</DisplayName>
 </Owner>
</Contents>


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/fakes3/xml_adapter.rb', line 115

def self.append_objects_to_list_bucket_result(lbr,objects)
  return if objects.nil? or objects.size == 0

  if objects.index(nil)
    require 'ruby-debug'
    Debugger.start
    debugger
  end

  objects.each do |s3_object|
    lbr.Contents { |contents|
      contents.Key(s3_object.name)
      contents.LastModified(s3_object.modified_date)
      contents.ETag("\"#{s3_object.md5}\"")
      contents.Size(s3_object.size)
      contents.StorageClass("STANDARD")

      contents.Owner { |owner|
        owner.ID("abc")
        owner.DisplayName("You")
      }
    }
  end
end

.bucket(bucket) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/fakes3/xml_adapter.rb', line 88

def self.bucket(bucket)
  output = ""
  xml = Builder::XmlMarkup.new(:target => output)
  xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
  xml.ListBucketResult(:xmlns => "http://s3.amazonaws.com/doc/2006-03-01/") { |lbr|
    lbr.Name(bucket.name)
    lbr.Prefix
    lbr.Marker
    lbr.MaxKeys("1000")
    lbr.IsTruncated("false")
  }
  output
end

.bucket_query(bucket_query) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/fakes3/xml_adapter.rb', line 140

def self.bucket_query(bucket_query)
  output = ""
  bucket = bucket_query.bucket
  xml = Builder::XmlMarkup.new(:target => output)
  xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
  xml.ListBucketResult(:xmlns => "http://s3.amazonaws.com/doc/2006-03-01/") { |lbr|
    lbr.Name(bucket.name)
    lbr.Prefix(bucket_query.prefix)
    lbr.Marker(bucket_query.marker)
    lbr.MaxKeys(bucket_query.max_keys)
    lbr.IsTruncated(bucket_query.is_truncated?)
    append_objects_to_list_bucket_result(lbr,bucket_query.matches)
  }
  output
end

.buckets(bucket_objects) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fakes3/xml_adapter.rb', line 6

def self.buckets(bucket_objects)
  output = ""
  xml = Builder::XmlMarkup.new(:target => output)
  xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
  xml.ListAllMyBucketsResult(:xmlns => "http://s3.amazonaws.com/doc/2006-03-01/") { |lam|
    lam.Owner { |owner|
      owner.ID("123")
      owner.DisplayName("FakeS3")
    }
    lam.Buckets { |buckets|
      bucket_objects.each do |bucket|
        buckets.Bucket do |b|
          b.Name(bucket.name)
          b.CreationDate(bucket.creation_date.strftime("%Y-%m-%dT%H:%M:%S.000Z"))
        end
      end
    }
  }
  output
end

.error(error) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fakes3/xml_adapter.rb', line 27

def self.error(error)
  output = ""
  xml = Builder::XmlMarkup.new(:target => output)
  xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
  xml.Error { |err|
    err.Code(error.code)
    err.Message(error.message)
    err.Resource(error.resource)
    err.RequestId(1)
  }
  output
end

.error_bucket_not_empty(name) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fakes3/xml_adapter.rb', line 61

def self.error_bucket_not_empty(name)
  output = ""
  xml = Builder::XmlMarkup.new(:target => output)
  xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
  xml.Error { |err|
    err.Code("BucketNotEmpty")
    err.Message("The bucket you tried to delete is not empty.")
    err.Resource(name)
    err.RequestId(1)
  }
  output
end

.error_no_such_bucket(name) ⇒ Object

<?xml version=“1.0” encoding=“UTF-8”?> <Error>

<Code>NoSuchKey</Code>
<Message>The resource you requested does not exist</Message>
<Resource>/mybucket/myfoto.jpg</Resource>
<RequestId>4442587FB7D0A2F9</RequestId>

</Error>



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fakes3/xml_adapter.rb', line 48

def self.error_no_such_bucket(name)
  output = ""
  xml = Builder::XmlMarkup.new(:target => output)
  xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
  xml.Error { |err|
    err.Code("NoSuchBucket")
    err.Message("The resource you requested does not exist")
    err.Resource(name)
    err.RequestId(1)
  }
  output
end

.error_no_such_key(name) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/fakes3/xml_adapter.rb', line 74

def self.error_no_such_key(name)
  output = ""
  xml = Builder::XmlMarkup.new(:target => output)
  xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
  xml.Error { |err|
    err.Code("NoSuchKey")
    err.Message("The specified key does not exist")
    err.Key(name)
    err.RequestId(1)
    err.HostId(2)
  }
  output
end