Skip to content

Commit 47324d5

Browse files
fix(Global Tagging): add 'update' option to attach_tag operation (#259)
Signed-off-by: Fabrizio Leoni <[email protected]>
1 parent 00e8cc3 commit 47324d5

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

ibm_platform_services/global_tagging_v1.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
`service` tags cannot be attached to IMS resources. `service` tags must be in the form
2525
`service_prefix:tag_label` where `service_prefix` identifies the Service owning the tag.
2626
`access` tags cannot be attached to IMS and Cloud Foundry resources. They must be in the
27-
form `key:value`.
27+
form `key:value`. You can replace all resource's tags using the `replace` query parameter
28+
in the attach operation. You can update the `value` of a resource's tag in the format
29+
`key:value`, using the `update` query parameter in the attach operation.
2830
2931
API Version: 1.2.0
3032
"""
@@ -460,6 +462,7 @@ def attach_tag(
460462
account_id: Optional[str] = None,
461463
tag_type: Optional[str] = None,
462464
replace: Optional[bool] = None,
465+
update: Optional[bool] = None,
463466
**kwargs,
464467
) -> DetailedResponse:
465468
"""
@@ -497,8 +500,17 @@ def attach_tag(
497500
`user`, `service` and `access`. `service` and `access` are not supported
498501
for IMS resources.
499502
:param bool replace: (optional) Flag to request replacement of all attached
500-
tags. Set 'true' if you want to replace all the list of tags attached to
501-
the resource. Default value is false.
503+
tags. Set `true` if you want to replace all tags attached to the resource
504+
with the current ones. Default value is false.
505+
:param bool update: (optional) Flag to request update of attached tags in
506+
the format `key:value`. Here's how it works for each tag in the request
507+
body: If the tag to attach is in the format `key:value`, the System will
508+
atomically detach all existing tags starting with `key:` and attach the new
509+
`key:value` tag. If no such tags exist, a new `key:value` tag will be
510+
attached. If the tag is not in the `key:value` format (e.g., a simple
511+
label), the System will attach the label as usual. The update query
512+
parameter is available for user and access management tags, but not for
513+
service tags.
502514
:param dict headers: A `dict` containing the request headers
503515
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
504516
:rtype: DetailedResponse with `dict` result representing a `TagResults` object
@@ -522,6 +534,7 @@ def attach_tag(
522534
'account_id': account_id,
523535
'tag_type': tag_type,
524536
'replace': replace,
537+
'update': update,
525538
}
526539

527540
data = {

test/unit/test_global_tagging_v1.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ def test_attach_tag_all_params(self):
603603
account_id = 'testString'
604604
tag_type = 'user'
605605
replace = False
606+
update = False
606607

607608
# Invoke method
608609
response = _service.attach_tag(
@@ -614,6 +615,7 @@ def test_attach_tag_all_params(self):
614615
account_id=account_id,
615616
tag_type=tag_type,
616617
replace=replace,
618+
update=update,
617619
headers={},
618620
)
619621

@@ -626,6 +628,7 @@ def test_attach_tag_all_params(self):
626628
assert 'account_id={}'.format(account_id) in query_string
627629
assert 'tag_type={}'.format(tag_type) in query_string
628630
assert 'replace={}'.format('true' if replace else 'false') in query_string
631+
assert 'update={}'.format('true' if update else 'false') in query_string
629632
# Validate body params
630633
req_body = json.loads(str(responses.calls[0].request.body, 'utf-8'))
631634
assert req_body['resources'] == [resource_model]

0 commit comments

Comments
 (0)