mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
Add get_object_tagging and put_object_tagging Storage requests
This commit is contained in:
parent
ab288f29a0
commit
17a9206a8a
4 changed files with 118 additions and 0 deletions
33
lib/fog/aws/parsers/storage/get_object_tagging.rb
Normal file
33
lib/fog/aws/parsers/storage/get_object_tagging.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module Storage
|
||||
class GetObjectTagging < Fog::Parsers::Base
|
||||
def reset
|
||||
@in_tag = {}
|
||||
@response = {'ObjectTagging' => {}}
|
||||
end
|
||||
|
||||
def start_element(name, *args)
|
||||
super
|
||||
if name == 'Tag'
|
||||
@in_tag = {}
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'Tag'
|
||||
@response['ObjectTagging'].merge!(@in_tag)
|
||||
@in_tag = {}
|
||||
when 'Key'
|
||||
@in_tag[value] = nil
|
||||
when 'Value'
|
||||
@in_tag = {@in_tag.keys.first => value}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
41
lib/fog/aws/requests/storage/get_object_tagging.rb
Normal file
41
lib/fog/aws/requests/storage/get_object_tagging.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class Storage
|
||||
class Real
|
||||
require 'fog/aws/parsers/storage/get_object_tagging'
|
||||
|
||||
# Get tags for an S3 object
|
||||
#
|
||||
# @param bucket_name [String] Name of bucket to read from
|
||||
# @param object_name [String] Name of object to get tags for
|
||||
#
|
||||
# @return [Excon::Response] response:
|
||||
# * body [Hash]:
|
||||
# * ObjectTagging [Hash]:
|
||||
# * Key [String] - tag key
|
||||
# * Value [String] - tag value
|
||||
# @see https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectTagging.html
|
||||
|
||||
def get_object_tagging(bucket_name, object_name)
|
||||
unless bucket_name
|
||||
raise ArgumentError.new('bucket_name is required')
|
||||
end
|
||||
unless object_name
|
||||
raise ArgumentError.new('object_name is required')
|
||||
end
|
||||
|
||||
request({
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:bucket_name => bucket_name,
|
||||
:object_name => object_name,
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::AWS::Storage::GetObjectTagging.new,
|
||||
:query => {'tagging' => nil}
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
42
lib/fog/aws/requests/storage/put_object_tagging.rb
Normal file
42
lib/fog/aws/requests/storage/put_object_tagging.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class Storage
|
||||
class Real
|
||||
# Change tag set for an S3 object
|
||||
#
|
||||
# @param bucket_name [String] Name of bucket to modify object in
|
||||
# @param object_name [String] Name of object to modify
|
||||
#
|
||||
# @param tags [Hash]:
|
||||
# * Key [String]: tag key
|
||||
# * Value [String]: tag value
|
||||
#
|
||||
# @see https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectTagging.html
|
||||
|
||||
def put_object_tagging(bucket_name, object_name, tags)
|
||||
tagging = tags.map do |k,v|
|
||||
"<Tag><Key>#{k}</Key><Value>#{v}</Value></Tag>"
|
||||
end.join("\n")
|
||||
data =
|
||||
<<-DATA
|
||||
<Tagging xmlns="http://doc.s3.amazonaws.com/2006-03-01" >
|
||||
<TagSet>
|
||||
#{tagging}
|
||||
</TagSet>
|
||||
</Tagging>
|
||||
DATA
|
||||
|
||||
request({
|
||||
:body => data,
|
||||
:expects => 200,
|
||||
:headers => {'Content-MD5' => Base64.encode64(OpenSSL::Digest::MD5.digest(data)).chomp!, 'Content-Type' => 'application/xml'},
|
||||
:bucket_name => bucket_name,
|
||||
:object_name => object_name,
|
||||
:method => 'PUT',
|
||||
:query => {'tagging' => nil}
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -84,6 +84,7 @@ module Fog
|
|||
request :get_object_http_url
|
||||
request :get_object_https_url
|
||||
request :get_object_url
|
||||
request :get_object_tagging
|
||||
request :get_request_payment
|
||||
request :get_service
|
||||
request :head_bucket
|
||||
|
@ -107,6 +108,7 @@ module Fog
|
|||
request :put_object
|
||||
request :put_object_acl
|
||||
request :put_object_url
|
||||
request :put_object_tagging
|
||||
request :put_request_payment
|
||||
request :sync_clock
|
||||
request :upload_part
|
||||
|
|
Loading…
Reference in a new issue