mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|compute] allow deleting all tags
This commit is contained in:
parent
9f1bf4de33
commit
cb4a9d0cd9
2 changed files with 17 additions and 14 deletions
|
@ -8,8 +8,8 @@ module Fog
|
|||
# Remove tags from resources
|
||||
#
|
||||
# ==== Parameters
|
||||
# * resources<~String> - One or more resources to tag
|
||||
# * tags<~String> - hash of key value tag pairs to assign
|
||||
# * resources<~String> - One or more resources to remove tags from
|
||||
# * tags<~String> - hash of key value tag pairs to remove
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
|
@ -18,15 +18,18 @@ module Fog
|
|||
# * 'return'<~Boolean> - success?
|
||||
def delete_tags(resources, tags)
|
||||
resources = [*resources]
|
||||
for key, value in tags
|
||||
if value.nil?
|
||||
tags[key] = ''
|
||||
end
|
||||
end
|
||||
params = {}
|
||||
params.merge!(AWS.indexed_param('ResourceId', resources))
|
||||
params.merge!(AWS.indexed_param('Tag.%d.Key', tags.keys))
|
||||
params.merge!(AWS.indexed_param('Tag.%d.Value', tags.values))
|
||||
|
||||
# can not rely on indexed_param because nil values should be omitted
|
||||
tags.keys.each_with_index do |key, index|
|
||||
index += 1 # should start at 1 instead of 0
|
||||
params.merge!("Tag.#{index}.Key" => key)
|
||||
unless tags[key].nil?
|
||||
params.merge("Tag.#{index}.Value" => tags[key])
|
||||
end
|
||||
end
|
||||
|
||||
request({
|
||||
'Action' => 'DeleteTags',
|
||||
:parser => Fog::Parsers::AWS::Compute::Basic.new
|
||||
|
|
|
@ -29,6 +29,11 @@ Shindo.tests('AWS::Compute | tag requests', ['aws']) do
|
|||
AWS[:compute].delete_tags(@volume.identity, 'foo' => 'bar').body
|
||||
end
|
||||
|
||||
tests("#delete_tags('vol-00000000', 'baz' => 'qux')").succeeds do
|
||||
pending if Fog.mocking?
|
||||
AWS[:compute].delete_tags('vol-00000000', 'baz' => 'qux')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failure') do
|
||||
|
@ -37,11 +42,6 @@ Shindo.tests('AWS::Compute | tag requests', ['aws']) do
|
|||
AWS[:compute].create_tags('vol-00000000', 'baz' => 'qux')
|
||||
end
|
||||
|
||||
tests("#delete_tags('vol-00000000', 'baz' => 'qux')").raises(Fog::Service::NotFound) do
|
||||
pending if Fog.mocking?
|
||||
AWS[:compute].delete_tags('vol-00000000', 'baz' => 'qux')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@volume.destroy
|
||||
|
|
Loading…
Reference in a new issue