Skip to content

fix(Global Tagging): add 'update' option to attach_tag operation #259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions ibm_platform_services/global_tagging_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
`service` tags cannot be attached to IMS resources. `service` tags must be in the form
`service_prefix:tag_label` where `service_prefix` identifies the Service owning the tag.
`access` tags cannot be attached to IMS and Cloud Foundry resources. They must be in the
form `key:value`.
form `key:value`. You can replace all resource's tags using the `replace` query parameter
in the attach operation. You can update the `value` of a resource's tag in the format
`key:value`, using the `update` query parameter in the attach operation.

API Version: 1.2.0
"""
Expand Down Expand Up @@ -460,6 +462,7 @@ def attach_tag(
account_id: Optional[str] = None,
tag_type: Optional[str] = None,
replace: Optional[bool] = None,
update: Optional[bool] = None,
**kwargs,
) -> DetailedResponse:
"""
Expand Down Expand Up @@ -497,8 +500,17 @@ def attach_tag(
`user`, `service` and `access`. `service` and `access` are not supported
for IMS resources.
:param bool replace: (optional) Flag to request replacement of all attached
tags. Set 'true' if you want to replace all the list of tags attached to
the resource. Default value is false.
tags. Set `true` if you want to replace all tags attached to the resource
with the current ones. Default value is false.
:param bool update: (optional) Flag to request update of attached tags in
the format `key:value`. Here's how it works for each tag in the request
body: If the tag to attach is in the format `key:value`, the System will
atomically detach all existing tags starting with `key:` and attach the new
`key:value` tag. If no such tags exist, a new `key:value` tag will be
attached. If the tag is not in the `key:value` format (e.g., a simple
label), the System will attach the label as usual. The update query
parameter is available for user and access management tags, but not for
service tags.
:param dict headers: A `dict` containing the request headers
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
:rtype: DetailedResponse with `dict` result representing a `TagResults` object
Expand All @@ -522,6 +534,7 @@ def attach_tag(
'account_id': account_id,
'tag_type': tag_type,
'replace': replace,
'update': update,
}

data = {
Expand Down
3 changes: 3 additions & 0 deletions test/unit/test_global_tagging_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ def test_attach_tag_all_params(self):
account_id = 'testString'
tag_type = 'user'
replace = False
update = False

# Invoke method
response = _service.attach_tag(
Expand All @@ -614,6 +615,7 @@ def test_attach_tag_all_params(self):
account_id=account_id,
tag_type=tag_type,
replace=replace,
update=update,
headers={},
)

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