Skip to content

Commit 6d7aeb5

Browse files
committed
Add example and readme
1 parent 71c50da commit 6d7aeb5

5 files changed

Lines changed: 223 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
- **Feature:** Add new `ConflictError` model for responses with 409 status code
3434
- `v1betaapi`:
3535
- **Feature:** Add new `ConflictError` model for responses with 409 status code
36+
- `vpn`:
37+
- [v0.1.0](services/vpn/CHANGELOG.md#v010)
38+
- Initial onboarding of STACKIT Java SDK for STACKIT VPN service
39+
3640

3741
## Release (2026-10-16)
3842

@@ -369,4 +373,3 @@
369373
- Initial onboarding of STACKIT Java SDK for IaaS service
370374
- `resourcemanger`: [v0.1.0](services/resourcemanager/CHANGELOG.md#v010)
371375
- Initial onboarding of STACKIT Java SDK for Resourcemanager service
372-

‎examples/vpn/build.gradle‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dependencies {
2+
implementation project (':services:vpn')
3+
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
4+
}
5+
6+
ext.mainClassName = 'cloud.stackit.sdk.vpn.examples.VpnExample'
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
package cloud.stackit.sdk.vpn.examples;
2+
3+
import cloud.stackit.sdk.core.exception.ApiException;
4+
import cloud.stackit.sdk.vpn.v1api.api.VpnApi;
5+
import cloud.stackit.sdk.vpn.v1api.model.ConnectionList;
6+
import cloud.stackit.sdk.vpn.v1api.model.ConnectionResponse;
7+
import cloud.stackit.sdk.vpn.v1api.model.CreateGatewayPayload;
8+
import cloud.stackit.sdk.vpn.v1api.model.CreateGatewayPayloadAvailabilityZones;
9+
import cloud.stackit.sdk.vpn.v1api.model.GatewayList;
10+
import cloud.stackit.sdk.vpn.v1api.model.RoutingType;
11+
import cloud.stackit.sdk.vpn.v1api.model.TunnelConfiguration;
12+
import cloud.stackit.sdk.vpn.v1api.model.TunnelConfigurationPhase1;
13+
import cloud.stackit.sdk.vpn.v1api.model.TunnelConfigurationPhase2;
14+
import cloud.stackit.sdk.vpn.v1api.model.UpdateGatewayPayload;
15+
import cloud.stackit.sdk.vpn.v1api.model.UpdateGatewayPayloadAvailabilityZones;
16+
import cloud.stackit.sdk.vpn.v1api.model.UpdateGatewayConnectionPayload;
17+
import cloud.stackit.sdk.vpn.v1api.model.CreateGatewayConnectionPayload;
18+
import cloud.stackit.sdk.vpn.v1api.model.GatewayResponse;
19+
import cloud.stackit.sdk.vpn.v1api.model.GatewayStatus;
20+
import cloud.stackit.sdk.vpn.v1api.model.Region;
21+
import java.io.IOException;
22+
import java.net.HttpURLConnection;
23+
import java.util.Collections;
24+
import java.util.Objects;
25+
import java.util.UUID;
26+
import java.util.concurrent.TimeUnit;
27+
28+
public final class VpnExample {
29+
private static final String REGION = "eu01";
30+
31+
private VpnExample() {}
32+
33+
@SuppressWarnings({
34+
"PMD.CyclomaticComplexity",
35+
"PMD.AvoidUsingHardCodedIP",
36+
"PMD.SystemPrintln",
37+
"PMD.AvoidThrowingRawExceptionTypes"
38+
})
39+
public static void main(String[] args) throws IOException, ApiException, InterruptedException {
40+
/*
41+
* Credentials are read from the credentialsFile in `~/.stackit/credentials.json` or the env
42+
* STACKIT_SERVICE_ACCOUNT_KEY_PATH / STACKIT_SERVICE_ACCOUNT_KEY
43+
* */
44+
45+
VpnApi vpnApi = new VpnApi();
46+
47+
// the id of your STACKIT project, read from env var for this example
48+
String projectId = System.getenv("STACKIT_PROJECT_ID");
49+
if (projectId == null || projectId.isEmpty()) {
50+
System.err.println("Environment variable 'STACKIT_PROJECT_ID' not found.");
51+
return;
52+
}
53+
Region region = Region.fromValue(REGION);
54+
55+
56+
try {
57+
/*
58+
* ///////////////////////////////////////////////////////
59+
* // G A T E W A Y S //
60+
* ///////////////////////////////////////////////////////
61+
* */
62+
63+
/* create a gateway in the project */
64+
GatewayResponse gatewayResponse =
65+
vpnApi.createGateway(
66+
projectId,
67+
region,
68+
new CreateGatewayPayload()
69+
.displayName("example-vpn-gateway")
70+
.planId("p500")
71+
.routingType(RoutingType.ROUTE_BASED)
72+
.availabilityZones(
73+
new CreateGatewayPayloadAvailabilityZones().tunnel1("eu01-1").tunnel2("eu01-2")));
74+
75+
Objects.requireNonNull(gatewayResponse.getId());
76+
77+
/* wait for the gateway creation to complete */
78+
UUID gatewayId = gatewayResponse.getId();
79+
Objects.requireNonNull(gatewayId);
80+
System.out.println(vpnApi.getGateway(projectId, region, gatewayId).getState());
81+
while (Objects.equals(
82+
vpnApi.getGateway(projectId, region, gatewayId).getState(),
83+
GatewayStatus.PENDING)) {
84+
System.out.println("Waiting for gateway creation to complete ...");
85+
TimeUnit.SECONDS.sleep(5);
86+
}
87+
System.out.println("Gateway created with the ID: " + gatewayId.toString());
88+
89+
// Delay because of API service: If the Gateway is updated directly after the creation, it will throw
90+
// an Error 409 "Internal conflict - please retry again later or contact support if the issue persists"
91+
TimeUnit.SECONDS.sleep(10);
92+
93+
/* update the gateway we just created (send complete resource because of the PUT endpoint) */
94+
vpnApi.updateGateway(projectId, region, gatewayId,
95+
new UpdateGatewayPayload().displayName("example-vpn-gateway-updated")
96+
.planId("p500")
97+
.routingType(RoutingType.ROUTE_BASED)
98+
.availabilityZones(
99+
new UpdateGatewayPayloadAvailabilityZones().tunnel1("eu01-1").tunnel2("eu01-2"))
100+
.labels(Collections.singletonMap("some-gateway-label", "updated")));
101+
102+
/* fetch the gateway we just created */
103+
GatewayResponse fetchedGateway = vpnApi.getGateway(projectId, region, gatewayId);
104+
System.out.println("\nFetched gateway: ");
105+
System.out.println("* Gateway name: " + fetchedGateway.getDisplayName());
106+
System.out.println("* Id: " + fetchedGateway.getId());
107+
108+
/* list all available gateways in the project */
109+
GatewayList gateways = vpnApi.listGateways(projectId, region, null);
110+
System.out.println("\nAvailable gateways: ");
111+
for (GatewayResponse gateway : gateways.getGateways()) {
112+
System.out.println("* " + gateway.getDisplayName());
113+
}
114+
115+
/*
116+
* ///////////////////////////////////////////////////////
117+
* // C O N N E C T I O N S //
118+
* ///////////////////////////////////////////////////////
119+
* */
120+
121+
/* create a connection in the gateway */
122+
TunnelConfiguration tunnelConfiguration =
123+
new TunnelConfiguration()
124+
.remoteAddress("198.51.100.10")
125+
.preSharedKey("Example-super-secret-key-tunnel-0123")
126+
.phase1(
127+
new TunnelConfigurationPhase1()
128+
.dhGroups(Collections.singletonList(TunnelConfigurationPhase1.DhGroupsEnum.ECP384))
129+
.encryptionAlgorithms(Collections.singletonList(TunnelConfigurationPhase1.EncryptionAlgorithmsEnum.AES256))
130+
.integrityAlgorithms(Collections.singletonList(TunnelConfigurationPhase1.IntegrityAlgorithmsEnum.SHA2_384)))
131+
.phase2(
132+
new TunnelConfigurationPhase2()
133+
.dhGroups(Collections.singletonList(TunnelConfigurationPhase2.DhGroupsEnum.ECP384))
134+
.encryptionAlgorithms(Collections.singletonList(TunnelConfigurationPhase2.EncryptionAlgorithmsEnum.AES256))
135+
.integrityAlgorithms(Collections.singletonList(TunnelConfigurationPhase2.IntegrityAlgorithmsEnum.SHA2_384)));
136+
137+
ConnectionResponse connectionResponse =
138+
vpnApi.createGatewayConnection(
139+
projectId,
140+
region,
141+
gatewayId,
142+
new CreateGatewayConnectionPayload()
143+
.displayName("example-vpn-connection")
144+
.tunnel1(tunnelConfiguration)
145+
.tunnel2(tunnelConfiguration)
146+
.localSubnets(Collections.singletonList("172.16.0.0/24"))
147+
.remoteSubnets(Collections.singletonList("172.17.0.0/24")));
148+
149+
Objects.requireNonNull(connectionResponse.getId());
150+
151+
UUID connectionId = connectionResponse.getId();
152+
Objects.requireNonNull(connectionId);
153+
System.out.println("Gateway created with the ID:" + connectionId.toString());
154+
155+
/* update the connection we just created */
156+
vpnApi.updateGatewayConnection(projectId, region, gatewayId, connectionId.toString(),
157+
new UpdateGatewayConnectionPayload()
158+
.displayName("example-vpn-connection-updated")
159+
.tunnel1(tunnelConfiguration)
160+
.tunnel2(tunnelConfiguration)
161+
.localSubnets(Collections.singletonList("172.16.0.0/24"))
162+
.remoteSubnets(Collections.singletonList("172.17.0.0/24")));
163+
164+
/* fetch the connection we just created */
165+
ConnectionResponse fetchedConnection = vpnApi.getGatewayConnection(projectId, region, gatewayId, connectionId.toString());
166+
System.out.println("\nFetched connection: ");
167+
System.out.println("* Connection name: " + fetchedConnection.getDisplayName());
168+
System.out.println("* Id: " + fetchedConnection.getId());
169+
170+
/* list all available connection in the project */
171+
ConnectionList connections = vpnApi.listGatewayConnections(projectId, region, gatewayId, null);
172+
System.out.println("\nAvailable connections: ");
173+
for (ConnectionResponse connection : connections.getConnections()) {
174+
System.out.println("* " + connection.getDisplayName());
175+
}
176+
177+
/* delete the connection */
178+
vpnApi.deleteGatewayConnection(projectId, region, gatewayId, connectionId.toString());
179+
System.out.println("Deleted connection: " + connectionId.toString());
180+
181+
/*
182+
* ///////////////////////////////////////////////////////
183+
* // D E L E T I O N //
184+
* ///////////////////////////////////////////////////////
185+
* */
186+
187+
/* delete the gateway we created */
188+
vpnApi.deleteGateway(projectId, region, gatewayId);
189+
System.out.println("Started gateway deletion: " + gatewayId);
190+
191+
/* wait for gateway deletion to complete */
192+
while (true) {
193+
try {
194+
vpnApi.getGateway(projectId, region, gatewayId);
195+
System.out.println("Waiting for gateway deletion to complete...");
196+
TimeUnit.SECONDS.sleep(5);
197+
} catch (ApiException e) {
198+
if (e.getCode() == HttpURLConnection.HTTP_NOT_FOUND) {
199+
System.out.println("Successfully deleted");
200+
break;
201+
}
202+
}
203+
}
204+
205+
} catch (ApiException | InterruptedException e) {
206+
throw new RuntimeException(e);
207+
}
208+
}
209+
}

‎services/vpn/CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
## v0.1.0
3+
- Initial onboarding of STACKIT Java SDK for STACKIT VPN service

‎services/vpn/VERSION‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

0 commit comments

Comments
 (0)