Skip to content

Commit 3c0eeb8

Browse files
authored
Update image-server configuration environment variable names (#508)
1 parent a31ea2c commit 3c0eeb8

6 files changed

Lines changed: 61 additions & 22 deletions

File tree

‎api/src/main/java/com/google/appengine/api/images/GrpcImagesClient.java‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,40 @@ private static GoogleCredentials getApplicationDefaultCredentials() {
7272
}
7373

7474
private String getTarget() {
75-
String endpoint = environmentProvider.getenv("IMAGES_SERVICE_ENDPOINT");
75+
String endpoint =
76+
environmentProvider.getenv(ImagesServiceFactoryImpl.IMAGES_SERVICE_ENDPOINT_ENV);
7677
if (isNullOrEmpty(endpoint)) {
77-
throw new IllegalStateException("IMAGES_SERVICE_ENDPOINT environment variable not set.");
78+
throw new IllegalStateException(
79+
ImagesServiceFactoryImpl.IMAGES_SERVICE_ENDPOINT_ENV + " environment variable not set.");
7880
}
7981
try {
8082
URI uri = new URI(endpoint);
8183
String host = uri.getHost();
8284
if (host == null) {
83-
throw new IllegalStateException("Invalid URI in IMAGES_SERVICE_ENDPOINT: " + endpoint);
85+
throw new IllegalStateException(
86+
"Invalid URI in "
87+
+ ImagesServiceFactoryImpl.IMAGES_SERVICE_ENDPOINT_ENV
88+
+ ": "
89+
+ endpoint);
8490
}
8591
return host + ":443";
8692
} catch (URISyntaxException e) {
87-
throw new IllegalStateException("Invalid URI in IMAGES_SERVICE_ENDPOINT: " + endpoint, e);
93+
throw new IllegalStateException(
94+
"Invalid URI in "
95+
+ ImagesServiceFactoryImpl.IMAGES_SERVICE_ENDPOINT_ENV
96+
+ ": "
97+
+ endpoint,
98+
e);
8899
}
89100
}
90101

91102
private static CallCredentials createOidcCredentials(
92103
EnvironmentProvider environmentProvider, GoogleCredentials googleCredentials) {
93-
String endpoint = environmentProvider.getenv("IMAGES_SERVICE_ENDPOINT");
104+
String endpoint =
105+
environmentProvider.getenv(ImagesServiceFactoryImpl.IMAGES_SERVICE_ENDPOINT_ENV);
94106
if (isNullOrEmpty(endpoint)) {
95-
throw new IllegalStateException("IMAGES_SERVICE_ENDPOINT environment variable not set.");
107+
throw new IllegalStateException(
108+
ImagesServiceFactoryImpl.IMAGES_SERVICE_ENDPOINT_ENV + " environment variable not set.");
96109
}
97110

98111
if (!(googleCredentials instanceof IdTokenProvider idTokenProvider)) {

‎api/src/main/java/com/google/appengine/api/images/ImagesServiceFactoryImpl.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@
3333
final class ImagesServiceFactoryImpl implements IImagesServiceFactory {
3434

3535
@VisibleForTesting
36-
static final String USE_CUSTOM_IMAGES_GRPC_SERVICE_ENV = "USE_CUSTOM_IMAGES_GRPC_SERVICE";
36+
static final String USE_CUSTOM_IMAGES_GRPC_SERVICE_ENV =
37+
"APPENGINE_USE_CUSTOM_IMAGES_GRPC_SERVICE";
38+
39+
@VisibleForTesting
40+
static final String IMAGES_SERVICE_ENDPOINT_ENV = "APPENGINE_IMAGES_SERVICE_ENDPOINT";
3741

3842
private EnvironmentProvider environmentProvider = new SystemEnvironmentProvider();
3943

‎api/src/main/java/com/google/appengine/api/images/ImagesServiceImpl.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ private ImagesServiceBlockingStub getGrpcStub() {
164164

165165
@VisibleForTesting
166166
boolean useGrpc() {
167-
String envVar = environmentProvider.getenv("USE_CUSTOM_IMAGES_GRPC_SERVICE");
167+
String envVar =
168+
environmentProvider.getenv(ImagesServiceFactoryImpl.USE_CUSTOM_IMAGES_GRPC_SERVICE_ENV);
168169
return Boolean.parseBoolean(envVar);
169170
}
170171

‎api/src/test/java/com/google/appengine/api/images/GrpcImagesClientTest.java‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class GrpcImagesClientTest {
3737

3838
@Test
3939
public void constructor_validEndpointAndCreds_success() {
40-
when(mockEnvironmentProvider.getenv("IMAGES_SERVICE_ENDPOINT"))
40+
when(mockEnvironmentProvider.getenv(ImagesServiceFactoryImpl.IMAGES_SERVICE_ENDPOINT_ENV))
4141
.thenReturn("https://my-service.run.app");
4242

4343
GrpcImagesClient client = new GrpcImagesClient(mockEnvironmentProvider, mockCallCredentials);
@@ -46,37 +46,47 @@ public void constructor_validEndpointAndCreds_success() {
4646

4747
@Test
4848
public void constructor_endpointNotSet_throwsException() {
49-
when(mockEnvironmentProvider.getenv("IMAGES_SERVICE_ENDPOINT")).thenReturn(null);
49+
when(mockEnvironmentProvider.getenv(ImagesServiceFactoryImpl.IMAGES_SERVICE_ENDPOINT_ENV))
50+
.thenReturn(null);
5051
IllegalStateException e =
5152
assertThrows(
5253
IllegalStateException.class,
5354
() -> new GrpcImagesClient(mockEnvironmentProvider, mockCallCredentials));
54-
assertThat(e).hasMessageThat().contains("IMAGES_SERVICE_ENDPOINT environment variable not set");
55+
assertThat(e)
56+
.hasMessageThat()
57+
.contains(
58+
ImagesServiceFactoryImpl.IMAGES_SERVICE_ENDPOINT_ENV + " environment variable not set");
5559
}
5660

5761
@Test
5862
public void constructor_invalidEndpoint_throwsException() {
59-
when(mockEnvironmentProvider.getenv("IMAGES_SERVICE_ENDPOINT")).thenReturn("://my-service");
63+
when(mockEnvironmentProvider.getenv(ImagesServiceFactoryImpl.IMAGES_SERVICE_ENDPOINT_ENV))
64+
.thenReturn("://my-service");
6065
IllegalStateException e =
6166
assertThrows(
6267
IllegalStateException.class,
6368
() -> new GrpcImagesClient(mockEnvironmentProvider, mockCallCredentials));
64-
assertThat(e).hasMessageThat().contains("Invalid URI in IMAGES_SERVICE_ENDPOINT");
69+
assertThat(e)
70+
.hasMessageThat()
71+
.contains("Invalid URI in " + ImagesServiceFactoryImpl.IMAGES_SERVICE_ENDPOINT_ENV);
6572
}
6673

6774
@Test
6875
public void constructor_endpointMissingHost_throwsException() {
69-
when(mockEnvironmentProvider.getenv("IMAGES_SERVICE_ENDPOINT")).thenReturn("https://");
76+
when(mockEnvironmentProvider.getenv(ImagesServiceFactoryImpl.IMAGES_SERVICE_ENDPOINT_ENV))
77+
.thenReturn("https://");
7078
IllegalStateException e =
7179
assertThrows(
7280
IllegalStateException.class,
7381
() -> new GrpcImagesClient(mockEnvironmentProvider, mockCallCredentials));
74-
assertThat(e).hasMessageThat().contains("Invalid URI in IMAGES_SERVICE_ENDPOINT");
82+
assertThat(e)
83+
.hasMessageThat()
84+
.contains("Invalid URI in " + ImagesServiceFactoryImpl.IMAGES_SERVICE_ENDPOINT_ENV);
7585
}
7686

7787
@Test
7888
public void getBlockingStub_returnsStub() {
79-
when(mockEnvironmentProvider.getenv("IMAGES_SERVICE_ENDPOINT"))
89+
when(mockEnvironmentProvider.getenv(ImagesServiceFactoryImpl.IMAGES_SERVICE_ENDPOINT_ENV))
8090
.thenReturn("https://my-service.run.app");
8191
GrpcImagesClient client = new GrpcImagesClient(mockEnvironmentProvider, mockCallCredentials);
8292
assertThat(client.getBlockingStub()).isNotNull();

‎api/src/test/java/com/google/appengine/api/images/ImagesServiceFactoryImplTest.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public void setUp() {
4141

4242
@Test
4343
public void makeImageFromFilename_newBehavior_trueEnv_gsPrefix() {
44-
when(mockEnvironmentProvider.getenv("USE_CUSTOM_IMAGES_GRPC_SERVICE")).thenReturn("true");
44+
when(mockEnvironmentProvider.getenv(
45+
ImagesServiceFactoryImpl.USE_CUSTOM_IMAGES_GRPC_SERVICE_ENV))
46+
.thenReturn("true");
4547
String filename = "/gs/bucket/object";
4648

4749
// Should NOT call BlobstoreServiceFactory (which would fail in this env)
@@ -53,7 +55,9 @@ public void makeImageFromFilename_newBehavior_trueEnv_gsPrefix() {
5355

5456
@Test
5557
public void makeImageFromFilename_newBehavior_trueEnv_noGsPrefix_throwsException() {
56-
when(mockEnvironmentProvider.getenv("USE_CUSTOM_IMAGES_GRPC_SERVICE")).thenReturn("true");
58+
when(mockEnvironmentProvider.getenv(
59+
ImagesServiceFactoryImpl.USE_CUSTOM_IMAGES_GRPC_SERVICE_ENV))
60+
.thenReturn("true");
5761
String filename = "not/gs/path";
5862

5963
IllegalArgumentException e =

‎api/src/test/java/com/google/appengine/api/images/ImagesServiceImplTest.java‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ private void setupGrpcService(ImagesServiceGrpc.ImagesServiceImplBase serviceImp
172172
new ImagesServiceImpl(
173173
mockEnvironmentProvider, mockGrpcImagesClient, null, mockBlobstoreReference);
174174

175-
when(mockEnvironmentProvider.getenv("USE_CUSTOM_IMAGES_GRPC_SERVICE")).thenReturn("true");
175+
when(mockEnvironmentProvider.getenv(
176+
ImagesServiceFactoryImpl.USE_CUSTOM_IMAGES_GRPC_SERVICE_ENV))
177+
.thenReturn("true");
176178
}
177179

178180
@Test
@@ -354,7 +356,8 @@ public void loadImageData_withLegacyBlobKey_failure() throws Exception {
354356

355357
public void setUpGrpc(boolean useGrpc) throws Exception {
356358
ImagesServiceImpl.setStorageForTesting(mockStorage);
357-
when(mockEnvironmentProvider.getenv("USE_CUSTOM_IMAGES_GRPC_SERVICE"))
359+
when(mockEnvironmentProvider.getenv(
360+
ImagesServiceFactoryImpl.USE_CUSTOM_IMAGES_GRPC_SERVICE_ENV))
358361
.thenReturn(Boolean.toString(useGrpc));
359362

360363
if (useGrpc) {
@@ -407,7 +410,9 @@ public void useGrpc_envVarSetFalse_returnsFalse() throws Exception {
407410

408411
@Test
409412
public void useGrpc_envVarNotSet_returnsFalse() {
410-
when(mockEnvironmentProvider.getenv("USE_CUSTOM_IMAGES_GRPC_SERVICE")).thenReturn(null);
413+
when(mockEnvironmentProvider.getenv(
414+
ImagesServiceFactoryImpl.USE_CUSTOM_IMAGES_GRPC_SERVICE_ENV))
415+
.thenReturn(null);
411416
imagesService =
412417
new ImagesServiceImpl(
413418
mockEnvironmentProvider, null, null, mockBlobstoreReference, null, mockBlobInfoFactory);
@@ -416,7 +421,9 @@ public void useGrpc_envVarNotSet_returnsFalse() {
416421

417422
@Test
418423
public void useGrpc_envVarInvalid_returnsFalse() {
419-
when(mockEnvironmentProvider.getenv("USE_CUSTOM_IMAGES_GRPC_SERVICE")).thenReturn("yes");
424+
when(mockEnvironmentProvider.getenv(
425+
ImagesServiceFactoryImpl.USE_CUSTOM_IMAGES_GRPC_SERVICE_ENV))
426+
.thenReturn("yes");
420427
imagesService =
421428
new ImagesServiceImpl(
422429
mockEnvironmentProvider, null, null, mockBlobstoreReference, null, mockBlobInfoFactory);

0 commit comments

Comments
 (0)