Skip to content

Commit 6d1f957

Browse files
Transparent proxy: Simplify transparent proxy builders naming (#904)
Co-authored-by: Alexander Dümont <[email protected]>
1 parent c11e010 commit 6d1f957

File tree

2 files changed

+49
-46
lines changed

2 files changed

+49
-46
lines changed

cloudplatform/connectivity-destination-service/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/TransparentProxyDestination.java

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* https://help.sap.com/docs/connectivity/sap-btp-connectivity-cf/transparent-proxy-for-kubernetes
3131
*/
3232
@Slf4j
33+
@com.google.common.annotations.Beta
3334
public class TransparentProxyDestination implements HttpDestination
3435
{
3536
static final String DESTINATION_NAME_HEADER_KEY = "x-destination-name";
@@ -227,33 +228,35 @@ public int hashCode()
227228
}
228229

229230
/**
230-
* Creates a new builder for a "static" destination.
231+
* Creates a new builder for a destination.
231232
* <p>
232-
* A static destination connects directly to a specified URL and does not use the destination-gateway. It allows
233-
* setting generic headers but does not support gateway-specific properties like destination name or fragments.
233+
* A destination connects directly to a specified URL and does not use the destination-gateway. It allows setting
234+
* generic headers but does not support gateway-specific properties like destination name or fragments.
234235
*
235-
* @return A new {@link StaticBuilder} instance.
236+
* @return A new {@link Builder} instance.
236237
*/
237238
@Nonnull
238-
public static StaticBuilder staticDestination( @Nonnull final String uri )
239+
public static Builder destination( @Nonnull final String uri )
239240
{
240-
return new StaticBuilder(uri);
241+
return new Builder(uri);
241242
}
242243

243244
/**
244-
* Creates a new builder for a "dynamic" destination that is resolved via the destination-gateway.
245+
* Creates a new builder for a destination-gateway.
245246
* <p>
246-
* A dynamic destination requires a destination name and will be routed through the central destination-gateway. It
247+
* A destination-gateway requires a destination name and will be routed through the central destination-gateway. It
247248
* supports all gateway-specific properties like fragments, tenant context, and authentication flows.
248249
*
249250
* @param destinationName
250251
* The name of the destination to be resolved by the gateway.
251-
* @return A new {@link DynamicBuilder} instance.
252+
* @return A new {@link DestinationGatewayBuilder} instance.
252253
*/
253254
@Nonnull
254-
public static DynamicBuilder dynamicDestination( @Nonnull final String destinationName, @Nonnull final String uri )
255+
public static
256+
DestinationGatewayBuilder
257+
destinationGateway( @Nonnull final String destinationName, @Nonnull final String uri )
255258
{
256-
return new DynamicBuilder(destinationName, uri);
259+
return new DestinationGatewayBuilder(destinationName, uri);
257260
}
258261

259262
/**
@@ -619,70 +622,70 @@ public TransparentProxyDestination build()
619622
}
620623

621624
/**
622-
* Builder for creating a "static" {@link TransparentProxyDestination}. See
625+
* Builder for creating a destination {@link TransparentProxyDestination}. See
623626
* https://help.sap.com/docs/connectivity/sap-btp-connectivity-cf/destination-custom-resource
624627
*/
625-
public static final class StaticBuilder extends AbstractBuilder<StaticBuilder>
628+
public static final class Builder extends AbstractBuilder<Builder>
626629
{
627-
private StaticBuilder( @Nonnull final String uri )
630+
private Builder( @Nonnull final String uri )
628631
{
629632
property(DestinationProperty.URI, uri);
630633
}
631634

632635
@Override
633-
protected StaticBuilder getThis()
636+
protected Builder getThis()
634637
{
635638
return this;
636639
}
637640
}
638641

639642
/**
640-
* Builder for creating a "dynamic" {@link TransparentProxyDestination}. See
643+
* Builder for creating a destination-gateway {@link TransparentProxyDestination}. See
641644
* https://help.sap.com/docs/connectivity/sap-btp-connectivity-cf/dynamic-lookup-of-destinations
642645
*/
643-
public static final class DynamicBuilder extends AbstractBuilder<DynamicBuilder>
646+
public static final class DestinationGatewayBuilder extends AbstractBuilder<DestinationGatewayBuilder>
644647
{
645-
private DynamicBuilder( @Nonnull final String destinationName, @Nonnull final String uri )
648+
private DestinationGatewayBuilder( @Nonnull final String destinationName, @Nonnull final String uri )
646649
{
647650
if( destinationName.isEmpty() ) {
648651
throw new IllegalArgumentException(
649-
"The 'destinationName' property is required for dynamic destinations but was not set.");
652+
"The 'destinationName' property is required for destination-gateway but was not set.");
650653
}
651654

652655
this.header(DESTINATION_NAME_HEADER_KEY, destinationName);
653656
property(DestinationProperty.URI, uri);
654657
}
655658

656659
@Override
657-
protected DynamicBuilder getThis()
660+
protected DestinationGatewayBuilder getThis()
658661
{
659662
return this;
660663
}
661664

662665
/**
663-
* Sets the fragment name for the dynamic destination. See
666+
* Sets the fragment name for the destination-gateway. See
664667
* https://help.sap.com/docs/connectivity/sap-btp-connectivity-cf/dynamic-lookup-of-destinations
665668
*
666669
* @param fragmentName
667670
* The name of the fragment to use.
668671
* @return This builder instance for method chaining.
669672
*/
670673
@Nonnull
671-
public DynamicBuilder fragmentName( @Nonnull final String fragmentName )
674+
public DestinationGatewayBuilder fragmentName( @Nonnull final String fragmentName )
672675
{
673676
return header(new Header(FRAGMENT_NAME_HEADER_KEY, fragmentName));
674677
}
675678

676679
/**
677-
* Sets the fragment optional flag for the dynamic destination. See
680+
* Sets the fragment optional flag for the destination-gateway. See
678681
* https://help.sap.com/docs/connectivity/sap-btp-connectivity-cf/dynamic-lookup-of-destinations
679682
*
680683
* @param fragmentOptional
681684
* The value indicating if the fragment is optional.
682685
* @return This builder instance for method chaining.
683686
*/
684687
@Nonnull
685-
public DynamicBuilder fragmentOptional( final boolean fragmentOptional )
688+
public DestinationGatewayBuilder fragmentOptional( final boolean fragmentOptional )
686689
{
687690
return header(new Header(FRAGMENT_OPTIONAL_HEADER_KEY, Boolean.toString(fragmentOptional)));
688691
}

cloudplatform/connectivity-destination-service/src/test/java/com/sap/cloud/sdk/cloudplatform/connectivity/TransparentProxyDestinationTest.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void testGetDelegationDestination()
3535
{
3636
final TransparentProxyDestination destination =
3737
TransparentProxyDestination
38-
.dynamicDestination(TEST_DEST_NAME, VALID_URI.toString())
38+
.destinationGateway(TEST_DEST_NAME, VALID_URI.toString())
3939
.property(TEST_KEY, TEST_VALUE)
4040
.build();
4141

@@ -46,7 +46,7 @@ void testGetDelegationDestination()
4646
void testGetUriSuccessfully()
4747
{
4848
final TransparentProxyDestination destination =
49-
TransparentProxyDestination.dynamicDestination(TEST_DEST_NAME, VALID_URI.toString()).build();
49+
TransparentProxyDestination.destinationGateway(TEST_DEST_NAME, VALID_URI.toString()).build();
5050

5151
Assertions.assertThat(destination.getUri()).isEqualTo(VALID_URI);
5252
}
@@ -60,7 +60,7 @@ void testHeaders()
6060

6161
final TransparentProxyDestination destination =
6262
TransparentProxyDestination
63-
.dynamicDestination(TEST_DEST_NAME, VALID_URI.toString())
63+
.destinationGateway(TEST_DEST_NAME, VALID_URI.toString())
6464
.header(header1)
6565
.header(header2)
6666
.build();
@@ -70,11 +70,11 @@ void testHeaders()
7070
}
7171

7272
@Test
73-
void testDynamicDestinationHeaders()
73+
void testDestinationGatewayHeaders()
7474
{
7575
final TransparentProxyDestination destination =
7676
TransparentProxyDestination
77-
.dynamicDestination(TEST_DEST_NAME, VALID_URI.toString())
77+
.destinationGateway(TEST_DEST_NAME, VALID_URI.toString())
7878
.fragmentName("fragName")
7979
.fragmentOptional(true)
8080
.build();
@@ -90,13 +90,13 @@ void testDynamicDestinationHeaders()
9090
void testTenantHeaders()
9191
{
9292
final TransparentProxyDestination destWithTenantId =
93-
TransparentProxyDestination.staticDestination(VALID_URI.toString()).tenantId("tenantId").build();
93+
TransparentProxyDestination.destination(VALID_URI.toString()).tenantId("tenantId").build();
9494

9595
assertThat(destWithTenantId.getHeaders(VALID_URI))
9696
.contains(new Header(TransparentProxyDestination.TENANT_ID_HEADER_KEY, "tenantId"));
9797

9898
final TransparentProxyDestination destWithSubdomain =
99-
TransparentProxyDestination.staticDestination(VALID_URI.toString()).tenantSubdomain("subdomain").build();
99+
TransparentProxyDestination.destination(VALID_URI.toString()).tenantSubdomain("subdomain").build();
100100

101101
assertThat(destWithSubdomain.getHeaders(VALID_URI))
102102
.contains(new Header(TransparentProxyDestination.TENANT_SUBDOMAIN_HEADER_KEY, "subdomain"));
@@ -107,7 +107,7 @@ void testCommonHeaders()
107107
{
108108
final TransparentProxyDestination destination =
109109
TransparentProxyDestination
110-
.staticDestination(VALID_URI.toString())
110+
.destination(VALID_URI.toString())
111111
.tokenServiceTenant("tokenTenant")
112112
.clientAssertion("clientAssert")
113113
.clientAssertionType("clientAssertType")
@@ -153,7 +153,7 @@ void testTenantIdIsAddedPerRequest()
153153
{
154154
Tenant tenant = new DefaultTenant(TEST_TENANT_ID, TEST_TENANT_SUBDOMAIN);
155155
TransparentProxyDestination destination =
156-
TransparentProxyDestination.dynamicDestination(TEST_DEST_NAME, TRANSPARENT_PROXY_GATEWAY).build();
156+
TransparentProxyDestination.destinationGateway(TEST_DEST_NAME, TRANSPARENT_PROXY_GATEWAY).build();
157157
TenantAccessor.executeWithTenant(tenant, () -> {
158158
assertThat(destination.getHeaders(URI.create(TRANSPARENT_PROXY_GATEWAY)))
159159
.contains(new Header(TransparentProxyDestination.TENANT_ID_HEADER_KEY, TEST_TENANT_ID));
@@ -168,7 +168,7 @@ void testAuthorizationHeaderIsAddedPerRequest()
168168
AuthToken token = new AuthToken(mockJwt);
169169

170170
TransparentProxyDestination destination =
171-
TransparentProxyDestination.dynamicDestination(TEST_DEST_NAME, TRANSPARENT_PROXY_GATEWAY).build();
171+
TransparentProxyDestination.destinationGateway(TEST_DEST_NAME, TRANSPARENT_PROXY_GATEWAY).build();
172172
assertNotNull(destination);
173173
AuthTokenAccessor.executeWithAuthToken(token, () -> {
174174
assertThat(destination.getHeaders(URI.create(TRANSPARENT_PROXY_GATEWAY)))
@@ -181,31 +181,31 @@ void testBuildThrowsExceptionWhenDestinationNameMissing()
181181
{
182182
Assertions
183183
.assertThatThrownBy(
184-
() -> TransparentProxyDestination.dynamicDestination("", TRANSPARENT_PROXY_GATEWAY).build())
184+
() -> TransparentProxyDestination.destinationGateway("", TRANSPARENT_PROXY_GATEWAY).build())
185185
.isInstanceOf(IllegalArgumentException.class)
186186
.hasMessageContaining(
187-
"The 'destinationName' property is required for dynamic destinations but was not set.");
187+
"The 'destinationName' property is required for destination-gateway but was not set.");
188188
}
189189

190190
@Test
191-
void testEqualDynamicDestinations()
191+
void testEqualDestinationGateway()
192192
{
193193
final TransparentProxyDestination destination1 =
194-
TransparentProxyDestination.dynamicDestination(TEST_DEST_NAME, VALID_URI.toString()).build();
194+
TransparentProxyDestination.destinationGateway(TEST_DEST_NAME, VALID_URI.toString()).build();
195195

196196
final TransparentProxyDestination destination2 =
197-
TransparentProxyDestination.dynamicDestination(TEST_DEST_NAME, VALID_URI.toString()).build();
197+
TransparentProxyDestination.destinationGateway(TEST_DEST_NAME, VALID_URI.toString()).build();
198198
assertThat(destination1).isEqualTo(destination2);
199199
}
200200

201201
@Test
202-
void testEqualStaticDestinations()
202+
void testEqualDestination()
203203
{
204204
final TransparentProxyDestination destination1 =
205-
TransparentProxyDestination.staticDestination(VALID_URI.toString()).build();
205+
TransparentProxyDestination.destination(VALID_URI.toString()).build();
206206

207207
final TransparentProxyDestination destination2 =
208-
TransparentProxyDestination.staticDestination(VALID_URI.toString()).build();
208+
TransparentProxyDestination.destination(VALID_URI.toString()).build();
209209

210210
assertThat(destination1).isEqualTo(destination2);
211211
}
@@ -216,7 +216,7 @@ void testTenantIdAndTenantSubdomainCannotBePassedTogether()
216216
Assertions
217217
.assertThatThrownBy(
218218
() -> TransparentProxyDestination
219-
.staticDestination(VALID_URI.toString())
219+
.destination(VALID_URI.toString())
220220
.tenantId("tenantId")
221221
.tenantSubdomain("tenantSubdomain")
222222
.build())
@@ -226,7 +226,7 @@ void testTenantIdAndTenantSubdomainCannotBePassedTogether()
226226
Assertions
227227
.assertThatThrownBy(
228228
() -> TransparentProxyDestination
229-
.staticDestination(VALID_URI.toString())
229+
.destination(VALID_URI.toString())
230230
.tenantSubdomain("tenantSubdomain")
231231
.tenantId("tenantId")
232232
.build())
@@ -238,7 +238,7 @@ void testTenantIdAndTenantSubdomainCannotBePassedTogether()
238238
void testNoTenantHeaderWhenNoTenantPresent()
239239
{
240240
TransparentProxyDestination destination =
241-
TransparentProxyDestination.dynamicDestination(TEST_DEST_NAME, TRANSPARENT_PROXY_GATEWAY).build();
241+
TransparentProxyDestination.destinationGateway(TEST_DEST_NAME, TRANSPARENT_PROXY_GATEWAY).build();
242242
Collection<Header> headers = destination.getHeaders(URI.create(TRANSPARENT_PROXY_GATEWAY));
243243
assertThat(
244244
headers
@@ -252,7 +252,7 @@ void testNoTenantHeaderWhenNoTenantPresent()
252252
void testNoAuthorizationHeaderWhenNoAuthTokenPresent()
253253
{
254254
TransparentProxyDestination destination =
255-
TransparentProxyDestination.dynamicDestination(TEST_DEST_NAME, TRANSPARENT_PROXY_GATEWAY).build();
255+
TransparentProxyDestination.destinationGateway(TEST_DEST_NAME, TRANSPARENT_PROXY_GATEWAY).build();
256256
Collection<Header> headers = destination.getHeaders(URI.create(TRANSPARENT_PROXY_GATEWAY));
257257
assertThat(
258258
headers

0 commit comments

Comments
 (0)