Skip to content

Commit 891f289

Browse files
committed
Fix formatting
1 parent 6d7aeb5 commit 891f289

1 file changed

Lines changed: 99 additions & 62 deletions

File tree

‎examples/vpn/src/main/java/cloud/stackit/sdk/vpn/examples/VpnExample.java‎

Lines changed: 99 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
import cloud.stackit.sdk.vpn.v1api.api.VpnApi;
55
import cloud.stackit.sdk.vpn.v1api.model.ConnectionList;
66
import cloud.stackit.sdk.vpn.v1api.model.ConnectionResponse;
7+
import cloud.stackit.sdk.vpn.v1api.model.CreateGatewayConnectionPayload;
78
import cloud.stackit.sdk.vpn.v1api.model.CreateGatewayPayload;
89
import cloud.stackit.sdk.vpn.v1api.model.CreateGatewayPayloadAvailabilityZones;
910
import cloud.stackit.sdk.vpn.v1api.model.GatewayList;
11+
import cloud.stackit.sdk.vpn.v1api.model.GatewayResponse;
12+
import cloud.stackit.sdk.vpn.v1api.model.GatewayStatus;
13+
import cloud.stackit.sdk.vpn.v1api.model.Region;
1014
import cloud.stackit.sdk.vpn.v1api.model.RoutingType;
1115
import cloud.stackit.sdk.vpn.v1api.model.TunnelConfiguration;
1216
import cloud.stackit.sdk.vpn.v1api.model.TunnelConfigurationPhase1;
1317
import cloud.stackit.sdk.vpn.v1api.model.TunnelConfigurationPhase2;
18+
import cloud.stackit.sdk.vpn.v1api.model.UpdateGatewayConnectionPayload;
1419
import cloud.stackit.sdk.vpn.v1api.model.UpdateGatewayPayload;
1520
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;
2121
import java.io.IOException;
2222
import java.net.HttpURLConnection;
2323
import java.util.Collections;
@@ -37,21 +37,20 @@ private VpnExample() {}
3737
"PMD.AvoidThrowingRawExceptionTypes"
3838
})
3939
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-
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);
5554

5655
try {
5756
/*
@@ -66,11 +65,13 @@ public static void main(String[] args) throws IOException, ApiException, Interru
6665
projectId,
6766
region,
6867
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")));
68+
.displayName("example-vpn-gateway")
69+
.planId("p500")
70+
.routingType(RoutingType.ROUTE_BASED)
71+
.availabilityZones(
72+
new CreateGatewayPayloadAvailabilityZones()
73+
.tunnel1("eu01-1")
74+
.tunnel2("eu01-2")));
7475

7576
Objects.requireNonNull(gatewayResponse.getId());
7677

@@ -86,18 +87,25 @@ public static void main(String[] args) throws IOException, ApiException, Interru
8687
}
8788
System.out.println("Gateway created with the ID: " + gatewayId.toString());
8889

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"
90+
// Delay because of API service: If the Gateway is updated directly after the creation,
91+
// it will throw an Error 409 "Internal conflict - please retry again later or contact
92+
// support if the issue persists"
9193
TimeUnit.SECONDS.sleep(10);
9294

9395
/* 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")));
96+
vpnApi.updateGateway(
97+
projectId,
98+
region,
99+
gatewayId,
100+
new UpdateGatewayPayload()
101+
.displayName("example-vpn-gateway-updated")
102+
.planId("p500")
103+
.routingType(RoutingType.ROUTE_BASED)
104+
.availabilityZones(
105+
new UpdateGatewayPayloadAvailabilityZones()
106+
.tunnel1("eu01-1")
107+
.tunnel2("eu01-2"))
108+
.labels(Collections.singletonMap("some-gateway-label", "updated")));
101109

102110
/* fetch the gateway we just created */
103111
GatewayResponse fetchedGateway = vpnApi.getGateway(projectId, region, gatewayId);
@@ -120,31 +128,53 @@ public static void main(String[] args) throws IOException, ApiException, Interru
120128

121129
/* create a connection in the gateway */
122130
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)));
131+
new TunnelConfiguration()
132+
.remoteAddress("198.51.100.10")
133+
.preSharedKey("Example-super-secret-key-tunnel-0123")
134+
.phase1(
135+
new TunnelConfigurationPhase1()
136+
.dhGroups(
137+
Collections.singletonList(
138+
TunnelConfigurationPhase1.DhGroupsEnum
139+
.ECP384))
140+
.encryptionAlgorithms(
141+
Collections.singletonList(
142+
TunnelConfigurationPhase1
143+
.EncryptionAlgorithmsEnum
144+
.AES256))
145+
.integrityAlgorithms(
146+
Collections.singletonList(
147+
TunnelConfigurationPhase1
148+
.IntegrityAlgorithmsEnum
149+
.SHA2_384)))
150+
.phase2(
151+
new TunnelConfigurationPhase2()
152+
.dhGroups(
153+
Collections.singletonList(
154+
TunnelConfigurationPhase2.DhGroupsEnum
155+
.ECP384))
156+
.encryptionAlgorithms(
157+
Collections.singletonList(
158+
TunnelConfigurationPhase2
159+
.EncryptionAlgorithmsEnum
160+
.AES256))
161+
.integrityAlgorithms(
162+
Collections.singletonList(
163+
TunnelConfigurationPhase2
164+
.IntegrityAlgorithmsEnum
165+
.SHA2_384)));
136166

137167
ConnectionResponse connectionResponse =
138168
vpnApi.createGatewayConnection(
139169
projectId,
140170
region,
141171
gatewayId,
142172
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")));
173+
.displayName("example-vpn-connection")
174+
.tunnel1(tunnelConfiguration)
175+
.tunnel2(tunnelConfiguration)
176+
.localSubnets(Collections.singletonList("172.16.0.0/24"))
177+
.remoteSubnets(Collections.singletonList("172.17.0.0/24")));
148178

149179
Objects.requireNonNull(connectionResponse.getId());
150180

@@ -153,22 +183,29 @@ public static void main(String[] args) throws IOException, ApiException, Interru
153183
System.out.println("Gateway created with the ID:" + connectionId.toString());
154184

155185
/* 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")));
186+
vpnApi.updateGatewayConnection(
187+
projectId,
188+
region,
189+
gatewayId,
190+
connectionId.toString(),
191+
new UpdateGatewayConnectionPayload()
192+
.displayName("example-vpn-connection-updated")
193+
.tunnel1(tunnelConfiguration)
194+
.tunnel2(tunnelConfiguration)
195+
.localSubnets(Collections.singletonList("172.16.0.0/24"))
196+
.remoteSubnets(Collections.singletonList("172.17.0.0/24")));
163197

164198
/* fetch the connection we just created */
165-
ConnectionResponse fetchedConnection = vpnApi.getGatewayConnection(projectId, region, gatewayId, connectionId.toString());
199+
ConnectionResponse fetchedConnection =
200+
vpnApi.getGatewayConnection(
201+
projectId, region, gatewayId, connectionId.toString());
166202
System.out.println("\nFetched connection: ");
167203
System.out.println("* Connection name: " + fetchedConnection.getDisplayName());
168204
System.out.println("* Id: " + fetchedConnection.getId());
169205

170206
/* list all available connection in the project */
171-
ConnectionList connections = vpnApi.listGatewayConnections(projectId, region, gatewayId, null);
207+
ConnectionList connections =
208+
vpnApi.listGatewayConnections(projectId, region, gatewayId, null);
172209
System.out.println("\nAvailable connections: ");
173210
for (ConnectionResponse connection : connections.getConnections()) {
174211
System.out.println("* " + connection.getDisplayName());
@@ -196,7 +233,7 @@ public static void main(String[] args) throws IOException, ApiException, Interru
196233
TimeUnit.SECONDS.sleep(5);
197234
} catch (ApiException e) {
198235
if (e.getCode() == HttpURLConnection.HTTP_NOT_FOUND) {
199-
System.out.println("Successfully deleted");
236+
System.out.println("Successfully deleted");
200237
break;
201238
}
202239
}

0 commit comments

Comments
 (0)