Skip to content

Commit 99c83b1

Browse files
danielfbrightcopybara-github
authored andcommitted
feat: add validate lmfs roles within sample app
Committer: @danielfbright PiperOrigin-RevId: 435140471
1 parent df9ccdd commit 99c83b1

25 files changed

+1000
-42
lines changed

sample/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ dependencies {
4444
implementation 'com.google.api:gax:1.65.1'
4545
implementation 'com.google.api:gax-grpc:1.65.1'
4646

47-
implementation 'com.google.maps:gapic-google-maps-fleetengine-v1-java:0.0.197'
47+
implementation 'com.google.maps:gapic-google-maps-fleetengine-v1-java:0.0.348'
48+
implementation 'com.google.maps:gapic-google-maps-fleetengine-delivery-v1-java:0.0.348'
4849
implementation project(':fleetengine-auth')
4950

5051
testImplementation 'junit:junit:4.13.1'

sample/src/main/java/com/google/fleetengine/auth/sample/CommandsFactoryServiceClient.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616

1717
import com.google.fleetengine.auth.client.FleetEngineTokenProvider;
1818
import com.google.fleetengine.auth.sample.validation.CommandsFactory;
19+
import com.google.fleetengine.auth.sample.validation.DeliveryServiceCommands;
1920
import com.google.fleetengine.auth.sample.validation.TripCommands;
2021
import com.google.fleetengine.auth.sample.validation.TripStub;
2122
import com.google.fleetengine.auth.sample.validation.VehicleCommands;
2223
import com.google.fleetengine.auth.sample.validation.VehicleStub;
24+
import google.maps.fleetengine.delivery.v1.DeliveryServiceClient;
25+
import google.maps.fleetengine.delivery.v1.DeliveryServiceSettings;
2326
import google.maps.fleetengine.v1.TripServiceClient;
2427
import google.maps.fleetengine.v1.TripServiceSettings;
2528
import google.maps.fleetengine.v1.VehicleServiceClient;
@@ -58,4 +61,19 @@ public VehicleCommands createVehicleCommands(
5861
VehicleStub vehicleStub = new VehicleStubClient(client);
5962
return new VehicleCommands(vehicleStub, providerId);
6063
}
64+
65+
/** {@inheritDoc} */
66+
public DeliveryServiceCommands createDeliveryServiceCommands(
67+
String fleetEngineAddress, String providerId, FleetEngineTokenProvider tokenProvider)
68+
throws IOException {
69+
DeliveryServiceSettings settings =
70+
new com.google.fleetengine.auth.client.FleetEngineClientSettingsModifier<
71+
DeliveryServiceSettings, DeliveryServiceSettings.Builder>(tokenProvider)
72+
.updateBuilder(DeliveryServiceSettings.newBuilder())
73+
.setEndpoint(fleetEngineAddress)
74+
.build();
75+
76+
return new DeliveryServiceCommands(
77+
new DeliveryServiceStubClient(DeliveryServiceClient.create(settings)), providerId);
78+
}
6179
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.google.fleetengine.auth.sample;
2+
3+
import com.google.fleetengine.auth.sample.validation.DeliveryServiceStub;
4+
import google.maps.fleetengine.delivery.v1.CreateDeliveryVehicleRequest;
5+
import google.maps.fleetengine.delivery.v1.CreateTaskRequest;
6+
import google.maps.fleetengine.delivery.v1.DeliveryServiceClient;
7+
import google.maps.fleetengine.delivery.v1.DeliveryVehicle;
8+
import google.maps.fleetengine.delivery.v1.GetDeliveryVehicleRequest;
9+
import google.maps.fleetengine.delivery.v1.GetTaskRequest;
10+
import google.maps.fleetengine.delivery.v1.SearchTasksRequest;
11+
import google.maps.fleetengine.delivery.v1.Task;
12+
import google.maps.fleetengine.delivery.v1.UpdateTaskRequest;
13+
14+
public class DeliveryServiceStubClient implements DeliveryServiceStub {
15+
16+
private final DeliveryServiceClient client;
17+
18+
/** Constructor. */
19+
public DeliveryServiceStubClient(DeliveryServiceClient client) {
20+
this.client = client;
21+
}
22+
23+
@Override
24+
public Task createTask(CreateTaskRequest createTaskRequest) {
25+
return client.createTask(createTaskRequest);
26+
}
27+
28+
@Override
29+
public Task getTask(GetTaskRequest getTaskRequest) {
30+
return client.getTask(getTaskRequest);
31+
}
32+
33+
@Override
34+
public void searchTasks(SearchTasksRequest searchTripRequest) {
35+
client.searchTasks(searchTripRequest);
36+
}
37+
38+
@Override
39+
public Task updateTask(UpdateTaskRequest updateTaskRequest) {
40+
return client.updateTask(updateTaskRequest);
41+
}
42+
43+
@Override
44+
public DeliveryVehicle createDeliveryVehicle(
45+
CreateDeliveryVehicleRequest createDeliveryVehicleRequest) {
46+
return client.createDeliveryVehicle(createDeliveryVehicleRequest);
47+
}
48+
49+
@Override
50+
public DeliveryVehicle getDeliveryVehicle(GetDeliveryVehicleRequest getDeliveryVehicleRequest) {
51+
return client.getDeliveryVehicle(getDeliveryVehicleRequest);
52+
}
53+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.google.fleetengine.auth.sample;
2+
3+
public class LmfsConfiguration {
4+
// XXX_TOKEN_ACCOUNT are the names of the service accounts with the Fleet
5+
// Engine pre defined roles. The name is always in the format of:
6+
// <service account name>@<project id>.iam.gserviceaccount.com
7+
8+
// Set to service account with the Fleet Engine Delivery Super User SDK role.
9+
public static final String DELIVERY_SERVER_TOKEN_ACCOUNT =
10+
"<service account name>@<project id>.iam.gserviceaccount.com";
11+
12+
// Set to service account with the Fleet Engine Delivery Consumer User SDK role.
13+
public static final String DELIVERY_CONSUMER_TOKEN_ACCOUNT =
14+
"<service account name>@<project id>.iam.gserviceaccount.com";
15+
16+
// Set to service account with the Fleet Engine Delivery Untrusted Driver SDK role.
17+
public static final String DELIVERY_UNTRUSTED_DRIVER_TOKEN_ACCOUNT =
18+
"<service account name>@<project id>.iam.gserviceaccount.com";
19+
20+
// Set to service account with the Fleet Engine Delivery Trusted Driver SDK role.
21+
public static final String DELIVERY_TRUSTED_DRIVER_TOKEN_ACCOUNT =
22+
"<service account name>@<project id>.iam.gserviceaccount.com";
23+
24+
// Set to service account with the Fleet Engine Delivery Fleet Read SDK role.
25+
public static final String DELIVERY_FLEET_READER_TOKEN_ACCOUNT =
26+
"<service account name>@<project id>.iam.gserviceaccount.com";
27+
28+
// Provider Id is the same as your GCP Project Id.
29+
public static final String PROVIDER_ID = "<project id>";
30+
31+
// Endpoint of the Fleet Engine address.
32+
// In most cases, the default of fleetengine.googleapis.com:443 is correct
33+
public static final String FLEET_ENGINE_ADDRESS =
34+
"fleetengine.googleapis.com:443";
35+
36+
// Audience of the JWT token.
37+
// The address is the same as the FLEET_ENGINE_ADDRESS without the port number.
38+
public static final String FLEET_ENGINE_AUDIENCE =
39+
"https://fleetengine.googleapis.com/";
40+
41+
private LmfsConfiguration() {}
42+
}

sample/src/main/java/com/google/fleetengine/auth/sample/Configuration.java renamed to sample/src/main/java/com/google/fleetengine/auth/sample/OdrdConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
package com.google.fleetengine.auth.sample;
1616

17-
class Configuration {
17+
class OdrdConfiguration {
1818

1919
// XXX_TOKEN_ACCOUNT are the names of the service accounts with the Fleet
2020
// Engine pre defined roles. The name is always in the format of:
@@ -46,5 +46,5 @@ class Configuration {
4646
public static final String FLEET_ENGINE_AUDIENCE =
4747
"https://fleetengine.googleapis.com/";
4848

49-
private Configuration() {}
49+
private OdrdConfiguration() {}
5050
}

sample/src/main/java/com/google/fleetengine/auth/sample/SampleApp.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,20 @@ private SampleApp() {}
6565
public static void main(String[] args) throws Throwable {
6666
System.out.println(
6767
"\n\n\n=== Choose example: ===\n"
68-
+ "0. Validate Configured Roles\n"
68+
+ "0. Validate Configured ODRD Roles\n"
6969
+ "1. Create Vehicle\n"
7070
+ "2. Create Trip\n"
7171
+ "3. List Vehicles\n"
7272
+ "4. Search for Vehicles\n"
73-
+ "5. Search for Trips\n");
73+
+ "5. Search for Trips\n"
74+
+ "----------------------------------------\n"
75+
+ "10. Validate Configured LMFS Roles\n");
7476
Scanner scanner = new Scanner(System.in, UTF_8.name());
7577
int choice = scanner.nextInt();
7678

7779
switch (choice) {
7880
case 0:
79-
ValidateRoles.run();
81+
ValidateOdrdRoles.run();
8082
break;
8183
case 1:
8284
createVehicle();
@@ -93,7 +95,9 @@ public static void main(String[] args) throws Throwable {
9395
case 5:
9496
searchTrips();
9597
break;
96-
case 6:
98+
case 10:
99+
ValidateLmfsRoles.run();
100+
break;
97101
default:
98102
throw new IllegalArgumentException("Invalid choice provided.");
99103
}
@@ -109,7 +113,7 @@ private static void createVehicle() throws SignerInitializationException, IOExce
109113
// Set the vehicle name to the specified format
110114
.setName(
111115
String.format(
112-
"providers/%s/vehicles/%s", Configuration.PROVIDER_ID, randomVehicleId))
116+
"providers/%s/vehicles/%s", OdrdConfiguration.PROVIDER_ID, randomVehicleId))
113117

114118
// Set maximum capacity of vehicle to 1
115119
.setMaximumCapacity(1)
@@ -137,14 +141,14 @@ private static void createVehicle() throws SignerInitializationException, IOExce
137141
.setVehicle(vehicle)
138142

139143
// Set the parent to the specified format
140-
.setParent(String.format("providers/%s", Configuration.PROVIDER_ID))
144+
.setParent(String.format("providers/%s", OdrdConfiguration.PROVIDER_ID))
141145
.build();
142146

143147
VehicleServiceSettings settings =
144148
new FleetEngineClientSettingsModifier<
145149
VehicleServiceSettings, VehicleServiceSettings.Builder>(createMinter())
146150
.updateBuilder(VehicleServiceSettings.newBuilder())
147-
.setEndpoint(Configuration.FLEET_ENGINE_ADDRESS)
151+
.setEndpoint(OdrdConfiguration.FLEET_ENGINE_ADDRESS)
148152
.build();
149153

150154
VehicleServiceClient client = VehicleServiceClient.create(settings);
@@ -158,7 +162,7 @@ private static void createTrip() throws SignerInitializationException, IOExcepti
158162
Trip.newBuilder()
159163
// Set the trip name to the specified format
160164
.setName(
161-
String.format("providers/%s/trips/%s", Configuration.PROVIDER_ID, randomTripId))
165+
String.format("providers/%s/trips/%s", OdrdConfiguration.PROVIDER_ID, randomTripId))
162166

163167
// Set the trip type to be exclusive as opposed to SHARED
164168
.setTripType(TripType.EXCLUSIVE)
@@ -180,14 +184,14 @@ private static void createTrip() throws SignerInitializationException, IOExcepti
180184
.setTrip(trip)
181185

182186
// Set the parent to the specified format
183-
.setParent(String.format("providers/%s", Configuration.PROVIDER_ID))
187+
.setParent(String.format("providers/%s", OdrdConfiguration.PROVIDER_ID))
184188
.build();
185189

186190
TripServiceSettings settings =
187191
new FleetEngineClientSettingsModifier<TripServiceSettings, TripServiceSettings.Builder>(
188192
createMinter())
189193
.updateBuilder(TripServiceSettings.newBuilder())
190-
.setEndpoint(Configuration.FLEET_ENGINE_ADDRESS)
194+
.setEndpoint(OdrdConfiguration.FLEET_ENGINE_ADDRESS)
191195
.build();
192196

193197
TripServiceClient client = TripServiceClient.create(settings);
@@ -199,14 +203,14 @@ private static void listVehicles() throws SignerInitializationException, IOExcep
199203
ListVehiclesRequest request =
200204
ListVehiclesRequest.newBuilder()
201205
// Set the parent to the format providers/{providerId}
202-
.setParent(String.format("providers/%s", Configuration.PROVIDER_ID))
206+
.setParent(String.format("providers/%s", OdrdConfiguration.PROVIDER_ID))
203207
.build();
204208

205209
VehicleServiceSettings settings =
206210
new FleetEngineClientSettingsModifier<
207211
VehicleServiceSettings, VehicleServiceSettings.Builder>(createMinter())
208212
.updateBuilder(VehicleServiceSettings.newBuilder())
209-
.setEndpoint(Configuration.FLEET_ENGINE_ADDRESS)
213+
.setEndpoint(OdrdConfiguration.FLEET_ENGINE_ADDRESS)
210214
.build();
211215

212216
VehicleServiceClient client = VehicleServiceClient.create(settings);
@@ -224,7 +228,7 @@ private static void searchVehicles() throws SignerInitializationException, IOExc
224228
SearchVehiclesRequest request =
225229
SearchVehiclesRequest.newBuilder()
226230
// Set the parent to the format providers/{providerId}
227-
.setParent(String.format("providers/%s", Configuration.PROVIDER_ID))
231+
.setParent(String.format("providers/%s", OdrdConfiguration.PROVIDER_ID))
228232

229233
// Look for vehicles around a specific Lat \ Lng
230234
.setPickupPoint(TerminalLocation.newBuilder().setPoint(EXAMPLE_LAT_LNG).build())
@@ -247,7 +251,7 @@ private static void searchVehicles() throws SignerInitializationException, IOExc
247251
new FleetEngineClientSettingsModifier<
248252
VehicleServiceSettings, VehicleServiceSettings.Builder>(createMinter())
249253
.updateBuilder(VehicleServiceSettings.newBuilder())
250-
.setEndpoint(Configuration.FLEET_ENGINE_ADDRESS)
254+
.setEndpoint(OdrdConfiguration.FLEET_ENGINE_ADDRESS)
251255
.build();
252256

253257
VehicleServiceClient client = VehicleServiceClient.create(settings);
@@ -265,7 +269,7 @@ private static void searchTrips() throws SignerInitializationException, IOExcept
265269
SearchTripsRequest request =
266270
SearchTripsRequest.newBuilder()
267271
// Set the parent to the format providers/{providerId}
268-
.setParent(String.format("providers/%s", Configuration.PROVIDER_ID))
272+
.setParent(String.format("providers/%s", OdrdConfiguration.PROVIDER_ID))
269273

270274
// Look for both active and inactive trips
271275
.setActiveTripsOnly(false)
@@ -275,7 +279,7 @@ private static void searchTrips() throws SignerInitializationException, IOExcept
275279
new FleetEngineClientSettingsModifier<TripServiceSettings, TripServiceSettings.Builder>(
276280
createMinter())
277281
.updateBuilder(TripServiceSettings.newBuilder())
278-
.setEndpoint(Configuration.FLEET_ENGINE_ADDRESS)
282+
.setEndpoint(OdrdConfiguration.FLEET_ENGINE_ADDRESS)
279283
.build();
280284

281285
TripServiceClient client = TripServiceClient.create(settings);
@@ -292,14 +296,14 @@ private static void searchTrips() throws SignerInitializationException, IOExcept
292296
private static FleetEngineTokenProvider createMinter() throws SignerInitializationException {
293297
return AuthTokenMinter.builder()
294298
// Only the account for the server signer is needed in this example
295-
.setServerSigner(ImpersonatedSigner.create(Configuration.SERVER_TOKEN_ACCOUNT))
299+
.setServerSigner(ImpersonatedSigner.create(OdrdConfiguration.SERVER_TOKEN_ACCOUNT))
296300

297301
// When the audience is not set, it defaults to https://fleetengine.googleapis.com/.
298302
// This is fine in the vast majority of cases.
299303
.setTokenFactory(
300304
new FleetEngineTokenFactory(
301305
FleetEngineTokenFactorySettings.builder()
302-
.setAudience(Configuration.FLEET_ENGINE_AUDIENCE)
306+
.setAudience(OdrdConfiguration.FLEET_ENGINE_AUDIENCE)
303307
.build()))
304308

305309
// Build the minter

0 commit comments

Comments
 (0)