Skip to content

Commit ace32d6

Browse files
authoredSep 30, 2020
fix(Global Tagging): re-gen service with latest API definition (#47)
1 parent b650e64 commit ace32d6

File tree

18 files changed

+780
-204
lines changed

18 files changed

+780
-204
lines changed
 

‎modules/examples/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
<artifactId>configuration-governance</artifactId>
2929
<version>${project.version}</version>
3030
</dependency>
31+
<dependency>
32+
<groupId>${project.groupId}</groupId>
33+
<artifactId>global-tagging</artifactId>
34+
<version>${project.version}</version>
35+
</dependency>
3136
<dependency>
3237
<groupId>org.slf4j</groupId>
3338
<artifactId>slf4j-jdk14</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
* (C) Copyright IBM Corp. 2020.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package com.ibm.cloud.platform_services.global_tagging.v1;
15+
16+
import com.ibm.cloud.platform_services.global_tagging.v1.model.AttachTagOptions;
17+
import com.ibm.cloud.platform_services.global_tagging.v1.model.DeleteTagAllOptions;
18+
import com.ibm.cloud.platform_services.global_tagging.v1.model.DeleteTagOptions;
19+
import com.ibm.cloud.platform_services.global_tagging.v1.model.DeleteTagResults;
20+
import com.ibm.cloud.platform_services.global_tagging.v1.model.DeleteTagsResult;
21+
import com.ibm.cloud.platform_services.global_tagging.v1.model.DetachTagOptions;
22+
import com.ibm.cloud.platform_services.global_tagging.v1.model.ListTagsOptions;
23+
import com.ibm.cloud.platform_services.global_tagging.v1.model.Resource;
24+
import com.ibm.cloud.platform_services.global_tagging.v1.model.TagList;
25+
import com.ibm.cloud.platform_services.global_tagging.v1.model.TagResults;
26+
import com.ibm.cloud.sdk.core.http.Response;
27+
import com.ibm.cloud.sdk.core.service.exception.ServiceResponseException;
28+
import com.ibm.cloud.sdk.core.util.CredentialUtils;
29+
import java.util.Map;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
32+
33+
//
34+
// This file provides an example of how to use the Global Tagging service.
35+
//
36+
// The following configuration properties are assumed to be defined in the external configuration file:
37+
// GLOBAL_TAGGING_URL=<service url>
38+
// GLOBAL_TAGGING_AUTHTYPE=iam
39+
// GLOBAL_TAGGING_APIKEY=<IAM api key>
40+
// GLOBAL_TAGGING_AUTH_URL=<IAM token service URL - omit this if using the production environment>
41+
// GLOBAL_TAGGING_RESOURCE_CRN=<the crn of the resource to be used in the examples>
42+
//
43+
public class GlobalTaggingExamples {
44+
private static final Logger logger = LoggerFactory.getLogger(GlobalTaggingExamples.class);
45+
46+
protected GlobalTaggingExamples() {
47+
}
48+
49+
static {
50+
System.setProperty("IBM_CREDENTIALS_FILE", "../../global_tagging.env");
51+
}
52+
53+
public static void main(String[] args) throws Exception {
54+
GlobalTagging service = GlobalTagging.newInstance();
55+
56+
// Load up our test-specific config properties.
57+
Map<String, String> config = CredentialUtils.getServiceProperties(GlobalTagging.DEFAULT_SERVICE_NAME);
58+
String resourceCRN = config.get("RESOURCE_CRN");
59+
60+
try {
61+
// begin-list_tags
62+
ListTagsOptions listTagsOptions = new ListTagsOptions.Builder()
63+
.attachedOnly(true)
64+
.build();
65+
66+
Response<TagList> response = service.listTags(listTagsOptions).execute();
67+
TagList tagList = response.getResult();
68+
System.out.println(tagList.toString());
69+
// end-list_tags
70+
} catch (ServiceResponseException e) {
71+
logger.error(String.format("Service returned status code %s: %s\nError details: %s", e.getStatusCode(),
72+
e.getMessage(), e.getDebuggingInfo()), e);
73+
}
74+
75+
try {
76+
// begin-attach_tag
77+
Resource resourceModel = new Resource.Builder()
78+
.resourceId(resourceCRN)
79+
.build();
80+
AttachTagOptions attachTagOptions = new AttachTagOptions.Builder()
81+
.addResources(resourceModel)
82+
.addTagNames("tag_test_1")
83+
.addTagNames("tag_test_2")
84+
.build();
85+
86+
Response<TagResults> response = service.attachTag(attachTagOptions).execute();
87+
TagResults tagResults = response.getResult();
88+
System.out.println(tagResults.toString());
89+
// end-attach_tag
90+
} catch (ServiceResponseException e) {
91+
logger.error(String.format("Service returned status code %s: %s\nError details: %s", e.getStatusCode(),
92+
e.getMessage(), e.getDebuggingInfo()), e);
93+
}
94+
95+
try {
96+
// begin-detach_tag
97+
Resource resourceModel = new Resource.Builder()
98+
.resourceId(resourceCRN)
99+
.build();
100+
DetachTagOptions detachTagOptions = new DetachTagOptions.Builder()
101+
.addResources(resourceModel)
102+
.addTagNames("tag_test_1")
103+
.addTagNames("tag_test_2")
104+
.build();
105+
106+
Response<TagResults> response = service.detachTag(detachTagOptions).execute();
107+
TagResults tagResults = response.getResult();
108+
System.out.println(tagResults.toString());
109+
// end-detach_tag
110+
} catch (ServiceResponseException e) {
111+
logger.error(String.format("Service returned status code %s: %s\nError details: %s", e.getStatusCode(),
112+
e.getMessage(), e.getDebuggingInfo()), e);
113+
}
114+
115+
try {
116+
// begin-delete_tag
117+
DeleteTagOptions deleteTagOptions = new DeleteTagOptions.Builder()
118+
.tagName("tag_test_1")
119+
.build();
120+
121+
Response<DeleteTagResults> response = service.deleteTag(deleteTagOptions).execute();
122+
DeleteTagResults deleteTagResults = response.getResult();
123+
System.out.println(deleteTagResults.toString());
124+
// end-delete_tag
125+
} catch (ServiceResponseException e) {
126+
logger.error(String.format("Service returned status code %s: %s\nError details: %s", e.getStatusCode(),
127+
e.getMessage(), e.getDebuggingInfo()), e);
128+
}
129+
130+
try {
131+
// begin-delete_tag_all
132+
DeleteTagAllOptions deleteTagAllOptions = new DeleteTagAllOptions.Builder().build();
133+
134+
Response<DeleteTagsResult> response = service.deleteTagAll(deleteTagAllOptions).execute();
135+
DeleteTagsResult deleteTagsResult = response.getResult();
136+
137+
System.out.println(deleteTagsResult.toString());
138+
// end-delete_tag_all
139+
} catch (ServiceResponseException e) {
140+
logger.error(String.format("Service returned status code %s: %s\nError details: %s", e.getStatusCode(),
141+
e.getMessage(), e.getDebuggingInfo()), e);
142+
}
143+
}
144+
}

‎modules/global-tagging/src/main/java/com/ibm/cloud/platform_services/global_tagging/v1/GlobalTagging.java

+57-24
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
/*
15-
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-cfe3553a-20200914-135527
15+
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-9b0d887a-20200923-132457
1616
*/
1717

1818
package com.ibm.cloud.platform_services.global_tagging.v1;
@@ -43,7 +43,9 @@
4343
/**
4444
* Manage your tags with the Tagging API in IBM Cloud. You can attach, detach, delete a tag or list all tags in your
4545
* billing account with the Tagging API. The tag name must be unique within a billing account. You can create tags in
46-
* two formats: `key:value` or `label`.
46+
* two formats: `key:value` or `label`. The tagging API supports two types of tag: `user` and `service`. `service` tags
47+
* cannot be attached to IMS resources (see `providers=ims` query parameter). `service` tags must be in the form
48+
* `service_prefix:tag_label` where `service_prefix` identifies the Service owning the tag.
4749
*
4850
* @version v1
4951
*/
@@ -108,27 +110,33 @@ public ServiceCall<TagList> listTags(ListTagsOptions listTagsOptions) {
108110
builder.header(header.getKey(), header.getValue());
109111
}
110112
builder.header("Accept", "application/json");
113+
if (listTagsOptions.accountId() != null) {
114+
builder.query("account_id", String.valueOf(listTagsOptions.accountId()));
115+
}
116+
if (listTagsOptions.tagType() != null) {
117+
builder.query("tag_type", String.valueOf(listTagsOptions.tagType()));
118+
}
119+
if (listTagsOptions.fullData() != null) {
120+
builder.query("full_data", String.valueOf(listTagsOptions.fullData()));
121+
}
111122
if (listTagsOptions.providers() != null) {
112123
builder.query("providers", RequestUtils.join(listTagsOptions.providers(), ","));
113124
}
114125
if (listTagsOptions.attachedTo() != null) {
115126
builder.query("attached_to", String.valueOf(listTagsOptions.attachedTo()));
116127
}
117-
if (listTagsOptions.fullData() != null) {
118-
builder.query("full_data", String.valueOf(listTagsOptions.fullData()));
119-
}
120128
if (listTagsOptions.offset() != null) {
121129
builder.query("offset", String.valueOf(listTagsOptions.offset()));
122130
}
123131
if (listTagsOptions.limit() != null) {
124132
builder.query("limit", String.valueOf(listTagsOptions.limit()));
125133
}
126-
if (listTagsOptions.orderByName() != null) {
127-
builder.query("order_by_name", String.valueOf(listTagsOptions.orderByName()));
128-
}
129134
if (listTagsOptions.timeout() != null) {
130135
builder.query("timeout", String.valueOf(listTagsOptions.timeout()));
131136
}
137+
if (listTagsOptions.orderByName() != null) {
138+
builder.query("order_by_name", String.valueOf(listTagsOptions.orderByName()));
139+
}
132140
if (listTagsOptions.attachedOnly() != null) {
133141
builder.query("attached_only", String.valueOf(listTagsOptions.attachedOnly()));
134142
}
@@ -150,9 +158,9 @@ public ServiceCall<TagList> listTags() {
150158
}
151159

152160
/**
153-
* Delete unused tags.
161+
* Delete all unused tags.
154162
*
155-
* Delete the tags that are not attatched to any resource.
163+
* Delete the tags that are not attached to any resource.
156164
*
157165
* @param deleteTagAllOptions the {@link DeleteTagAllOptions} containing the options for the call
158166
* @return a {@link ServiceCall} with a result of type {@link DeleteTagsResult}
@@ -170,15 +178,21 @@ public ServiceCall<DeleteTagsResult> deleteTagAll(DeleteTagAllOptions deleteTagA
170178
if (deleteTagAllOptions.providers() != null) {
171179
builder.query("providers", String.valueOf(deleteTagAllOptions.providers()));
172180
}
181+
if (deleteTagAllOptions.accountId() != null) {
182+
builder.query("account_id", String.valueOf(deleteTagAllOptions.accountId()));
183+
}
184+
if (deleteTagAllOptions.tagType() != null) {
185+
builder.query("tag_type", String.valueOf(deleteTagAllOptions.tagType()));
186+
}
173187
ResponseConverter<DeleteTagsResult> responseConverter =
174188
ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DeleteTagsResult>() { }.getType());
175189
return createServiceCall(builder.build(), responseConverter);
176190
}
177191

178192
/**
179-
* Delete unused tags.
193+
* Delete all unused tags.
180194
*
181-
* Delete the tags that are not attatched to any resource.
195+
* Delete the tags that are not attached to any resource.
182196
*
183197
* @return a {@link ServiceCall} with a result of type {@link DeleteTagsResult}
184198
*/
@@ -187,7 +201,7 @@ public ServiceCall<DeleteTagsResult> deleteTagAll() {
187201
}
188202

189203
/**
190-
* Delete a tag.
204+
* Delete an unused tag.
191205
*
192206
* Delete an existing tag. A tag can be deleted only if it is not attached to any resource.
193207
*
@@ -208,18 +222,25 @@ public ServiceCall<DeleteTagResults> deleteTag(DeleteTagOptions deleteTagOptions
208222
if (deleteTagOptions.providers() != null) {
209223
builder.query("providers", RequestUtils.join(deleteTagOptions.providers(), ","));
210224
}
225+
if (deleteTagOptions.accountId() != null) {
226+
builder.query("account_id", String.valueOf(deleteTagOptions.accountId()));
227+
}
228+
if (deleteTagOptions.tagType() != null) {
229+
builder.query("tag_type", String.valueOf(deleteTagOptions.tagType()));
230+
}
211231
ResponseConverter<DeleteTagResults> responseConverter =
212232
ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DeleteTagResults>() { }.getType());
213233
return createServiceCall(builder.build(), responseConverter);
214234
}
215235

216236
/**
217-
* Attach one or more tags.
237+
* Attach tags.
218238
*
219-
* Attaches one or more tags to one or more resources. To attach a tag to a resource managed by the Resource
220-
* Controller, you must be an editor on the resource. To attach a tag to a Cloud Foundry resource, you must have space
221-
* developer role. To attach a tag to IMS resources, depending on the resource, you need either `view hardware
222-
* details`, `view virtual server details` or `manage storage` permission.
239+
* Attaches one or more tags to one or more resources. To attach a `user` tag on a resource, you must have the access
240+
* listed in the [Granting users access to tag resources](https://cloud.ibm.com/docs/account?topic=account-access)
241+
* documentation. To attach a `service` tag, you must be an authorized service. If that is the case, then you can
242+
* attach a `service` tag with your registered `prefix` to any resource in any account. The account ID must be set
243+
* through the `account_id` query parameter.
223244
*
224245
* @param attachTagOptions the {@link AttachTagOptions} containing the options for the call
225246
* @return a {@link ServiceCall} with a result of type {@link TagResults}
@@ -233,6 +254,12 @@ public ServiceCall<TagResults> attachTag(AttachTagOptions attachTagOptions) {
233254
builder.header(header.getKey(), header.getValue());
234255
}
235256
builder.header("Accept", "application/json");
257+
if (attachTagOptions.accountId() != null) {
258+
builder.query("account_id", String.valueOf(attachTagOptions.accountId()));
259+
}
260+
if (attachTagOptions.tagType() != null) {
261+
builder.query("tag_type", String.valueOf(attachTagOptions.tagType()));
262+
}
236263
final JsonObject contentJson = new JsonObject();
237264
contentJson.add("resources", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(attachTagOptions.resources()));
238265
if (attachTagOptions.tagName() != null) {
@@ -248,13 +275,13 @@ public ServiceCall<TagResults> attachTag(AttachTagOptions attachTagOptions) {
248275
}
249276

250277
/**
251-
* Detach one or more tags.
278+
* Detach tags.
252279
*
253-
* Detach one or more tags from one or more resources. To detach a tag from a Resource Controller managed resource,
254-
* you must be an editor on the resource. To detach a tag to a Cloud Foundry resource, you must have `space developer`
255-
* role.
256-
* To detach a tag to IMS resources, depending on the resource, you need either `view hardware details`, `view
257-
* virtual server details` or `storage manage` permission.
280+
* Detaches one or more tags from one or more resources. To detach a `user` tag on a resource you must have the
281+
* permissions listed in the [Granting users access to tag
282+
* resources](https://cloud.ibm.com/docs/account?topic=account-access) documentation. To detach a `service` tag you
283+
* must be an authorized Service. If that is the case, then you can detach a `service` tag with your registered
284+
* `prefix` from any resource in any account. The account ID must be set through the `account_id` query parameter.
258285
*
259286
* @param detachTagOptions the {@link DetachTagOptions} containing the options for the call
260287
* @return a {@link ServiceCall} with a result of type {@link TagResults}
@@ -268,6 +295,12 @@ public ServiceCall<TagResults> detachTag(DetachTagOptions detachTagOptions) {
268295
builder.header(header.getKey(), header.getValue());
269296
}
270297
builder.header("Accept", "application/json");
298+
if (detachTagOptions.accountId() != null) {
299+
builder.query("account_id", String.valueOf(detachTagOptions.accountId()));
300+
}
301+
if (detachTagOptions.tagType() != null) {
302+
builder.query("tag_type", String.valueOf(detachTagOptions.tagType()));
303+
}
271304
final JsonObject contentJson = new JsonObject();
272305
contentJson.add("resources", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(detachTagOptions.resources()));
273306
if (detachTagOptions.tagName() != null) {

0 commit comments

Comments
 (0)
Please sign in to comment.