From a35b07a7bc031701631f3313757910a2d09d8feb Mon Sep 17 00:00:00 2001 From: Fabrizio Leoni Date: Fri, 21 Jun 2024 10:32:35 +0200 Subject: [PATCH] fix(Global Tagging): add 'update' option to attach_tag operation Signed-off-by: Fabrizio Leoni --- .../global_tagging/v1/GlobalTagging.java | 7 +++- .../v1/model/AttachTagOptions.java | 34 +++++++++++++++++-- .../global_tagging/v1/GlobalTaggingTest.java | 2 ++ .../v1/model/AttachTagOptionsTest.java | 2 ++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/modules/global-tagging/src/main/java/com/ibm/cloud/platform_services/global_tagging/v1/GlobalTagging.java b/modules/global-tagging/src/main/java/com/ibm/cloud/platform_services/global_tagging/v1/GlobalTagging.java index af3393a8c9..53691cfda9 100644 --- a/modules/global-tagging/src/main/java/com/ibm/cloud/platform_services/global_tagging/v1/GlobalTagging.java +++ b/modules/global-tagging/src/main/java/com/ibm/cloud/platform_services/global_tagging/v1/GlobalTagging.java @@ -48,7 +48,9 @@ * two formats: `key:value` or `label`. The tagging API supports three types of tag: `user` `service`, and `access` * tags. `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`. + * attached to IMS and Cloud Foundry resources. They must be in the 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 */ @@ -332,6 +334,9 @@ public ServiceCall attachTag(AttachTagOptions attachTagOptions) { if (attachTagOptions.replace() != null) { builder.query("replace", String.valueOf(attachTagOptions.replace())); } + if (attachTagOptions.update() != null) { + builder.query("update", String.valueOf(attachTagOptions.update())); + } final JsonObject contentJson = new JsonObject(); contentJson.add("resources", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(attachTagOptions.resources())); if (attachTagOptions.tagName() != null) { diff --git a/modules/global-tagging/src/main/java/com/ibm/cloud/platform_services/global_tagging/v1/model/AttachTagOptions.java b/modules/global-tagging/src/main/java/com/ibm/cloud/platform_services/global_tagging/v1/model/AttachTagOptions.java index 504cfdb70d..63c642d804 100644 --- a/modules/global-tagging/src/main/java/com/ibm/cloud/platform_services/global_tagging/v1/model/AttachTagOptions.java +++ b/modules/global-tagging/src/main/java/com/ibm/cloud/platform_services/global_tagging/v1/model/AttachTagOptions.java @@ -43,6 +43,7 @@ public interface TagType { protected String accountId; protected String tagType; protected Boolean replace; + protected Boolean update; /** * Builder. @@ -56,6 +57,7 @@ public static class Builder { private String accountId; private String tagType; private Boolean replace; + private Boolean update; /** * Instantiates a new Builder from an existing AttachTagOptions instance. @@ -71,6 +73,7 @@ private Builder(AttachTagOptions attachTagOptions) { this.accountId = attachTagOptions.accountId; this.tagType = attachTagOptions.tagType; this.replace = attachTagOptions.replace; + this.update = attachTagOptions.update; } /** @@ -218,6 +221,17 @@ public Builder replace(Boolean replace) { this.replace = replace; return this; } + + /** + * Set the update. + * + * @param update the update + * @return the AttachTagOptions builder + */ + public Builder update(Boolean update) { + this.update = update; + return this; + } } protected AttachTagOptions() { } @@ -233,6 +247,7 @@ protected AttachTagOptions(Builder builder) { accountId = builder.accountId; tagType = builder.tagType; replace = builder.replace; + update = builder.update; } /** @@ -335,13 +350,28 @@ public String tagType() { /** * Gets the replace. * - * 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. + * Flag to request replacement of all attached tags. Set `true` if you want to replace all tags attached to the + * resource with the current ones. Default value is false. * * @return the replace */ public Boolean replace() { return replace; } + + /** + * Gets the update. + * + * 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. + * + * @return the update + */ + public Boolean update() { + return update; + } } diff --git a/modules/global-tagging/src/test/java/com/ibm/cloud/platform_services/global_tagging/v1/GlobalTaggingTest.java b/modules/global-tagging/src/test/java/com/ibm/cloud/platform_services/global_tagging/v1/GlobalTaggingTest.java index 1a747a13cc..31bd59dc83 100644 --- a/modules/global-tagging/src/test/java/com/ibm/cloud/platform_services/global_tagging/v1/GlobalTaggingTest.java +++ b/modules/global-tagging/src/test/java/com/ibm/cloud/platform_services/global_tagging/v1/GlobalTaggingTest.java @@ -326,6 +326,7 @@ public void testAttachTagWOptions() throws Throwable { .accountId("testString") .tagType("user") .replace(false) + .update(false) .build(); // Invoke attachTag() with a valid options model and verify the result @@ -347,6 +348,7 @@ public void testAttachTagWOptions() throws Throwable { assertEquals(query.get("account_id"), "testString"); assertEquals(query.get("tag_type"), "user"); assertEquals(Boolean.valueOf(query.get("replace")), Boolean.valueOf(false)); + assertEquals(Boolean.valueOf(query.get("update")), Boolean.valueOf(false)); } // Test the attachTag operation with and without retries enabled diff --git a/modules/global-tagging/src/test/java/com/ibm/cloud/platform_services/global_tagging/v1/model/AttachTagOptionsTest.java b/modules/global-tagging/src/test/java/com/ibm/cloud/platform_services/global_tagging/v1/model/AttachTagOptionsTest.java index f8c07e0e90..ceae456003 100644 --- a/modules/global-tagging/src/test/java/com/ibm/cloud/platform_services/global_tagging/v1/model/AttachTagOptionsTest.java +++ b/modules/global-tagging/src/test/java/com/ibm/cloud/platform_services/global_tagging/v1/model/AttachTagOptionsTest.java @@ -48,6 +48,7 @@ public void testAttachTagOptions() throws Throwable { .accountId("testString") .tagType("user") .replace(false) + .update(false) .build(); assertEquals(attachTagOptionsModel.resources(), java.util.Arrays.asList(resourceModel)); assertEquals(attachTagOptionsModel.tagName(), "testString"); @@ -57,6 +58,7 @@ public void testAttachTagOptions() throws Throwable { assertEquals(attachTagOptionsModel.accountId(), "testString"); assertEquals(attachTagOptionsModel.tagType(), "user"); assertEquals(attachTagOptionsModel.replace(), Boolean.valueOf(false)); + assertEquals(attachTagOptionsModel.update(), Boolean.valueOf(false)); } @Test(expectedExceptions = IllegalArgumentException.class)