Skip to content
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

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

Merged
merged 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -332,6 +334,9 @@ public ServiceCall<TagResults> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public interface TagType {
protected String accountId;
protected String tagType;
protected Boolean replace;
protected Boolean update;

/**
* Builder.
Expand All @@ -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.
Expand All @@ -71,6 +73,7 @@ private Builder(AttachTagOptions attachTagOptions) {
this.accountId = attachTagOptions.accountId;
this.tagType = attachTagOptions.tagType;
this.replace = attachTagOptions.replace;
this.update = attachTagOptions.update;
}

/**
Expand Down Expand Up @@ -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() { }
Expand All @@ -233,6 +247,7 @@ protected AttachTagOptions(Builder builder) {
accountId = builder.accountId;
tagType = builder.tagType;
replace = builder.replace;
update = builder.update;
}

/**
Expand Down Expand Up @@ -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;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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)
Expand Down