Skip to content

Commit f717413

Browse files
authoredNov 3, 2021
fix(Context-Based Restrictions): add support for the X-Correlation-Id header (#130)
1 parent e6876d2 commit f717413

28 files changed

+504
-67
lines changed
 

‎modules/context-based-restrictions/src/main/java/com/ibm/cloud/platform_services/context_based_restrictions/v1/ContextBasedRestrictions.java

+60-19
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050

5151
/**
5252
* With the Context Based Restrictions API, you can:
53-
* * Create, list, get, update, and delete network zones
54-
* * Create, list, get, update, and delete context-based restriction rules
53+
* * Create, list, get, replace, and delete network zones
54+
* * Create, list, get, replace, and delete context-based restriction rules
5555
* * Get account settings
5656
* .
5757
*
@@ -100,7 +100,7 @@ public ContextBasedRestrictions(String serviceName, Authenticator authenticator)
100100
}
101101

102102
/**
103-
* Create a zone.
103+
* Create a network zone.
104104
*
105105
* This operation creates a network zone for the specified account.
106106
*
@@ -119,6 +119,9 @@ public ServiceCall<Zone> createZone(CreateZoneOptions createZoneOptions) {
119119
builder.header(header.getKey(), header.getValue());
120120
}
121121
builder.header("Accept", "application/json");
122+
if (createZoneOptions.xCorrelationId() != null) {
123+
builder.header("X-Correlation-Id", createZoneOptions.xCorrelationId());
124+
}
122125
if (createZoneOptions.transactionId() != null) {
123126
builder.header("Transaction-Id", createZoneOptions.transactionId());
124127
}
@@ -147,7 +150,7 @@ public ServiceCall<Zone> createZone(CreateZoneOptions createZoneOptions) {
147150
}
148151

149152
/**
150-
* Create a zone.
153+
* Create a network zone.
151154
*
152155
* This operation creates a network zone for the specified account.
153156
*
@@ -174,6 +177,9 @@ public ServiceCall<ZoneList> listZones(ListZonesOptions listZonesOptions) {
174177
builder.header(header.getKey(), header.getValue());
175178
}
176179
builder.header("Accept", "application/json");
180+
if (listZonesOptions.xCorrelationId() != null) {
181+
builder.header("X-Correlation-Id", listZonesOptions.xCorrelationId());
182+
}
177183
if (listZonesOptions.transactionId() != null) {
178184
builder.header("Transaction-Id", listZonesOptions.transactionId());
179185
}
@@ -190,9 +196,9 @@ public ServiceCall<ZoneList> listZones(ListZonesOptions listZonesOptions) {
190196
}
191197

192198
/**
193-
* Get the specified network zone.
199+
* Get a network zone.
194200
*
195-
* This operation returns the network zone for the specified ID.
201+
* This operation retrieves the network zone identified by the specified zone ID.
196202
*
197203
* @param getZoneOptions the {@link GetZoneOptions} containing the options for the call
198204
* @return a {@link ServiceCall} with a result of type {@link Zone}
@@ -208,6 +214,9 @@ public ServiceCall<Zone> getZone(GetZoneOptions getZoneOptions) {
208214
builder.header(header.getKey(), header.getValue());
209215
}
210216
builder.header("Accept", "application/json");
217+
if (getZoneOptions.xCorrelationId() != null) {
218+
builder.header("X-Correlation-Id", getZoneOptions.xCorrelationId());
219+
}
211220
if (getZoneOptions.transactionId() != null) {
212221
builder.header("Transaction-Id", getZoneOptions.transactionId());
213222
}
@@ -217,9 +226,10 @@ public ServiceCall<Zone> getZone(GetZoneOptions getZoneOptions) {
217226
}
218227

219228
/**
220-
* Update the specified network zone.
229+
* Replace a network zone.
221230
*
222-
* This operation updates the network zone with the specified ID.
231+
* This operation replaces the network zone identified by the specified zone ID. Partial updates are not supported.
232+
* The entire network zone object must be replaced.
223233
*
224234
* @param replaceZoneOptions the {@link ReplaceZoneOptions} containing the options for the call
225235
* @return a {@link ServiceCall} with a result of type {@link Zone}
@@ -236,6 +246,9 @@ public ServiceCall<Zone> replaceZone(ReplaceZoneOptions replaceZoneOptions) {
236246
}
237247
builder.header("Accept", "application/json");
238248
builder.header("If-Match", replaceZoneOptions.ifMatch());
249+
if (replaceZoneOptions.xCorrelationId() != null) {
250+
builder.header("X-Correlation-Id", replaceZoneOptions.xCorrelationId());
251+
}
239252
if (replaceZoneOptions.transactionId() != null) {
240253
builder.header("Transaction-Id", replaceZoneOptions.transactionId());
241254
}
@@ -262,9 +275,9 @@ public ServiceCall<Zone> replaceZone(ReplaceZoneOptions replaceZoneOptions) {
262275
}
263276

264277
/**
265-
* Delete the specified network zone.
278+
* Delete a network zone.
266279
*
267-
* This operation deletes the network zone with the specified home ID.
280+
* This operation deletes the network zone identified by the specified zone ID.
268281
*
269282
* @param deleteZoneOptions the {@link DeleteZoneOptions} containing the options for the call
270283
* @return a {@link ServiceCall} with a void result
@@ -279,6 +292,9 @@ public ServiceCall<Void> deleteZone(DeleteZoneOptions deleteZoneOptions) {
279292
for (Entry<String, String> header : sdkHeaders.entrySet()) {
280293
builder.header(header.getKey(), header.getValue());
281294
}
295+
if (deleteZoneOptions.xCorrelationId() != null) {
296+
builder.header("X-Correlation-Id", deleteZoneOptions.xCorrelationId());
297+
}
282298
if (deleteZoneOptions.transactionId() != null) {
283299
builder.header("Transaction-Id", deleteZoneOptions.transactionId());
284300
}
@@ -304,6 +320,12 @@ public ServiceCall<ServiceRefTargetList> listAvailableServicerefTargets(ListAvai
304320
builder.header(header.getKey(), header.getValue());
305321
}
306322
builder.header("Accept", "application/json");
323+
if (listAvailableServicerefTargetsOptions.xCorrelationId() != null) {
324+
builder.header("X-Correlation-Id", listAvailableServicerefTargetsOptions.xCorrelationId());
325+
}
326+
if (listAvailableServicerefTargetsOptions.transactionId() != null) {
327+
builder.header("Transaction-Id", listAvailableServicerefTargetsOptions.transactionId());
328+
}
307329
if (listAvailableServicerefTargetsOptions.type() != null) {
308330
builder.query("type", String.valueOf(listAvailableServicerefTargetsOptions.type()));
309331
}
@@ -343,6 +365,9 @@ public ServiceCall<Rule> createRule(CreateRuleOptions createRuleOptions) {
343365
builder.header(header.getKey(), header.getValue());
344366
}
345367
builder.header("Accept", "application/json");
368+
if (createRuleOptions.xCorrelationId() != null) {
369+
builder.header("X-Correlation-Id", createRuleOptions.xCorrelationId());
370+
}
346371
if (createRuleOptions.transactionId() != null) {
347372
builder.header("Transaction-Id", createRuleOptions.transactionId());
348373
}
@@ -378,7 +403,7 @@ public ServiceCall<Rule> createRule() {
378403
/**
379404
* List rules.
380405
*
381-
* This operation lists rules for the specified account.
406+
* This operation lists rules in the specified account.
382407
*
383408
* @param listRulesOptions the {@link ListRulesOptions} containing the options for the call
384409
* @return a {@link ServiceCall} with a result of type {@link RuleList}
@@ -392,6 +417,9 @@ public ServiceCall<RuleList> listRules(ListRulesOptions listRulesOptions) {
392417
builder.header(header.getKey(), header.getValue());
393418
}
394419
builder.header("Accept", "application/json");
420+
if (listRulesOptions.xCorrelationId() != null) {
421+
builder.header("X-Correlation-Id", listRulesOptions.xCorrelationId());
422+
}
395423
if (listRulesOptions.transactionId() != null) {
396424
builder.header("Transaction-Id", listRulesOptions.transactionId());
397425
}
@@ -426,9 +454,9 @@ public ServiceCall<RuleList> listRules(ListRulesOptions listRulesOptions) {
426454
}
427455

428456
/**
429-
* Get the specified rule.
457+
* Get a rule.
430458
*
431-
* This operation gets the rule for the specified ID.
459+
* This operation retrieves the rule identified by the specified rule ID.
432460
*
433461
* @param getRuleOptions the {@link GetRuleOptions} containing the options for the call
434462
* @return a {@link ServiceCall} with a result of type {@link Rule}
@@ -444,6 +472,9 @@ public ServiceCall<Rule> getRule(GetRuleOptions getRuleOptions) {
444472
builder.header(header.getKey(), header.getValue());
445473
}
446474
builder.header("Accept", "application/json");
475+
if (getRuleOptions.xCorrelationId() != null) {
476+
builder.header("X-Correlation-Id", getRuleOptions.xCorrelationId());
477+
}
447478
if (getRuleOptions.transactionId() != null) {
448479
builder.header("Transaction-Id", getRuleOptions.transactionId());
449480
}
@@ -453,9 +484,10 @@ public ServiceCall<Rule> getRule(GetRuleOptions getRuleOptions) {
453484
}
454485

455486
/**
456-
* Update the specified rule.
487+
* Replace a rule.
457488
*
458-
* This operation updates the rule for the specified ID.
489+
* This operation replaces the rule identified by the specified rule ID. Partial updates are not supported. The entire
490+
* rule object must be replaced.
459491
*
460492
* @param replaceRuleOptions the {@link ReplaceRuleOptions} containing the options for the call
461493
* @return a {@link ServiceCall} with a result of type {@link Rule}
@@ -472,6 +504,9 @@ public ServiceCall<Rule> replaceRule(ReplaceRuleOptions replaceRuleOptions) {
472504
}
473505
builder.header("Accept", "application/json");
474506
builder.header("If-Match", replaceRuleOptions.ifMatch());
507+
if (replaceRuleOptions.xCorrelationId() != null) {
508+
builder.header("X-Correlation-Id", replaceRuleOptions.xCorrelationId());
509+
}
475510
if (replaceRuleOptions.transactionId() != null) {
476511
builder.header("Transaction-Id", replaceRuleOptions.transactionId());
477512
}
@@ -492,9 +527,9 @@ public ServiceCall<Rule> replaceRule(ReplaceRuleOptions replaceRuleOptions) {
492527
}
493528

494529
/**
495-
* Delete the specified rule.
530+
* Delete a rule.
496531
*
497-
* This operation deletes the rule for the specified home ID.
532+
* This operation deletes the rule identified by the specified rule ID.
498533
*
499534
* @param deleteRuleOptions the {@link DeleteRuleOptions} containing the options for the call
500535
* @return a {@link ServiceCall} with a void result
@@ -509,6 +544,9 @@ public ServiceCall<Void> deleteRule(DeleteRuleOptions deleteRuleOptions) {
509544
for (Entry<String, String> header : sdkHeaders.entrySet()) {
510545
builder.header(header.getKey(), header.getValue());
511546
}
547+
if (deleteRuleOptions.xCorrelationId() != null) {
548+
builder.header("X-Correlation-Id", deleteRuleOptions.xCorrelationId());
549+
}
512550
if (deleteRuleOptions.transactionId() != null) {
513551
builder.header("Transaction-Id", deleteRuleOptions.transactionId());
514552
}
@@ -517,9 +555,9 @@ public ServiceCall<Void> deleteRule(DeleteRuleOptions deleteRuleOptions) {
517555
}
518556

519557
/**
520-
* Get the specified account settings.
558+
* Get account settings.
521559
*
522-
* This operation gets the settings for the specified account ID.
560+
* This operation retrieves the settings for the specified account ID.
523561
*
524562
* @param getAccountSettingsOptions the {@link GetAccountSettingsOptions} containing the options for the call
525563
* @return a {@link ServiceCall} with a result of type {@link AccountSettings}
@@ -535,6 +573,9 @@ public ServiceCall<AccountSettings> getAccountSettings(GetAccountSettingsOptions
535573
builder.header(header.getKey(), header.getValue());
536574
}
537575
builder.header("Accept", "application/json");
576+
if (getAccountSettingsOptions.xCorrelationId() != null) {
577+
builder.header("X-Correlation-Id", getAccountSettingsOptions.xCorrelationId());
578+
}
538579
if (getAccountSettingsOptions.transactionId() != null) {
539580
builder.header("Transaction-Id", getAccountSettingsOptions.transactionId());
540581
}

‎modules/context-based-restrictions/src/main/java/com/ibm/cloud/platform_services/context_based_restrictions/v1/model/CreateRuleOptions.java

+31-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class CreateRuleOptions extends GenericModel {
2525
protected String description;
2626
protected List<RuleContext> contexts;
2727
protected List<Resource> resources;
28+
protected String xCorrelationId;
2829
protected String transactionId;
2930

3031
/**
@@ -34,12 +35,14 @@ public static class Builder {
3435
private String description;
3536
private List<RuleContext> contexts;
3637
private List<Resource> resources;
38+
private String xCorrelationId;
3739
private String transactionId;
3840

3941
private Builder(CreateRuleOptions createRuleOptions) {
4042
this.description = createRuleOptions.description;
4143
this.contexts = createRuleOptions.contexts;
4244
this.resources = createRuleOptions.resources;
45+
this.xCorrelationId = createRuleOptions.xCorrelationId;
4346
this.transactionId = createRuleOptions.transactionId;
4447
}
4548

@@ -125,6 +128,17 @@ public Builder resources(List<Resource> resources) {
125128
return this;
126129
}
127130

131+
/**
132+
* Set the xCorrelationId.
133+
*
134+
* @param xCorrelationId the xCorrelationId
135+
* @return the CreateRuleOptions builder
136+
*/
137+
public Builder xCorrelationId(String xCorrelationId) {
138+
this.xCorrelationId = xCorrelationId;
139+
return this;
140+
}
141+
128142
/**
129143
* Set the transactionId.
130144
*
@@ -141,6 +155,7 @@ protected CreateRuleOptions(Builder builder) {
141155
description = builder.description;
142156
contexts = builder.contexts;
143157
resources = builder.resources;
158+
xCorrelationId = builder.xCorrelationId;
144159
transactionId = builder.transactionId;
145160
}
146161

@@ -186,13 +201,25 @@ public List<Resource> resources() {
186201
return resources;
187202
}
188203

204+
/**
205+
* Gets the xCorrelationId.
206+
*
207+
* The supplied or generated value of this header is logged for a request and repeated in a response header for the
208+
* corresponding response. The same value is used for downstream requests and retries of those requests. If a value of
209+
* this headers is not supplied in a request, the service generates a random (version 4) UUID.
210+
*
211+
* @return the xCorrelationId
212+
*/
213+
public String xCorrelationId() {
214+
return xCorrelationId;
215+
}
216+
189217
/**
190218
* Gets the transactionId.
191219
*
192-
* The UUID that is used to correlate and track transactions. If you omit this field, the service generates and sends
193-
* a transaction ID in the response.
194-
* **Note:** To help with debugging, we strongly recommend that you generate and supply a `Transaction-Id` with each
195-
* request.
220+
* The `Transaction-Id` header behaves as the `X-Correlation-Id` header. It is supported for backward compatibility
221+
* with other IBM platform services that support the `Transaction-Id` header only. If both `X-Correlation-Id` and
222+
* `Transaction-Id` are provided, `X-Correlation-Id` has the precedence over `Transaction-Id`.
196223
*
197224
* @return the transactionId
198225
*/

0 commit comments

Comments
 (0)
Please sign in to comment.