diff --git a/plugins/repository-gcs/src/main/java/org/opensearch/repositories/gcs/GoogleApplicationDefaultCredentials.java b/plugins/repository-gcs/src/main/java/org/opensearch/repositories/gcs/GoogleApplicationDefaultCredentials.java index 9c123aad1f91e..6c7a9ed041492 100644 --- a/plugins/repository-gcs/src/main/java/org/opensearch/repositories/gcs/GoogleApplicationDefaultCredentials.java +++ b/plugins/repository-gcs/src/main/java/org/opensearch/repositories/gcs/GoogleApplicationDefaultCredentials.java @@ -22,7 +22,7 @@ public GoogleCredentials get() { try { credentials = SocketAccess.doPrivilegedIOException(GoogleCredentials::getApplicationDefault); } catch (IOException e) { - logger.error("Failed to retrieve \"Application Default Credentials\"",e); + logger.error("Failed to retrieve \"Application Default Credentials\"", e); } return credentials; } diff --git a/plugins/repository-gcs/src/main/java/org/opensearch/repositories/gcs/GoogleCloudStorageService.java b/plugins/repository-gcs/src/main/java/org/opensearch/repositories/gcs/GoogleCloudStorageService.java index cec0d04ebb7cd..83a4146c99b99 100644 --- a/plugins/repository-gcs/src/main/java/org/opensearch/repositories/gcs/GoogleCloudStorageService.java +++ b/plugins/repository-gcs/src/main/java/org/opensearch/repositories/gcs/GoogleCloudStorageService.java @@ -80,6 +80,7 @@ public GoogleCloudStorageService() { public GoogleCloudStorageService(GoogleApplicationDefaultCredentials googleApplicationDefaultCredentials) { this.googleApplicationDefaultCredentials = googleApplicationDefaultCredentials; } + /** * Refreshes the client settings and clears the client cache. Subsequent calls to * {@code GoogleCloudStorageService#client} will return new clients constructed diff --git a/plugins/repository-gcs/src/test/java/org/opensearch/repositories/gcs/GoogleCloudStorageServiceTests.java b/plugins/repository-gcs/src/test/java/org/opensearch/repositories/gcs/GoogleCloudStorageServiceTests.java index 447e2dfc979e0..db958cd4dcb04 100644 --- a/plugins/repository-gcs/src/test/java/org/opensearch/repositories/gcs/GoogleCloudStorageServiceTests.java +++ b/plugins/repository-gcs/src/test/java/org/opensearch/repositories/gcs/GoogleCloudStorageServiceTests.java @@ -37,8 +37,6 @@ import com.google.cloud.http.HttpTransportOptions; import com.google.cloud.storage.Storage; import com.google.cloud.storage.StorageOptions; -import org.hamcrest.MatcherAssert; -import org.mockito.Mockito; import org.opensearch.common.settings.MockSecureSettings; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; @@ -46,6 +44,7 @@ import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.test.OpenSearchTestCase; +import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import java.io.IOException; @@ -58,6 +57,8 @@ import java.util.Locale; import java.util.UUID; +import org.mockito.Mockito; + import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -221,9 +222,9 @@ public void testApplicationDefaultCredential() throws Exception { Mockito.when(mockDefaultCredentials.get()).thenReturn(mockGoogleCredentials); GoogleCloudStorageService service = new GoogleCloudStorageService(mockDefaultCredentials); - StorageOptions storageOptions = service.createStorageOptions(settings,mockHttpTransportOptions); + StorageOptions storageOptions = service.createStorageOptions(settings, mockHttpTransportOptions); assertNotNull(storageOptions); - assertEquals(storageOptions.getCredentials().toString(),mockGoogleCredentials.toString()); + assertEquals(storageOptions.getCredentials().toString(), mockGoogleCredentials.toString()); } /** @@ -235,12 +236,12 @@ public void applicationDefaultCredentialThrowsErrorWhenNotAvailable() throws Exc GoogleCloudStorageClientSettings settings = getGCSClientSettingsWithoutCredentials(); HttpTransportOptions mockHttpTransportOptions = Mockito.mock(HttpTransportOptions.class); GoogleCloudStorageService service = new GoogleCloudStorageService(); - StorageOptions storageOptions = service.createStorageOptions(settings,mockHttpTransportOptions); + StorageOptions storageOptions = service.createStorageOptions(settings, mockHttpTransportOptions); Exception exception = assertThrows(IOException.class, GoogleCredentials::getApplicationDefault); assertNotNull(storageOptions); assertNull(storageOptions.getCredentials()); - MatcherAssert.assertThat(exception.getMessage(),containsString("The Application Default Credentials are not available")); + MatcherAssert.assertThat(exception.getMessage(), containsString("The Application Default Credentials are not available")); } private GoogleCloudStorageClientSettings getGCSClientSettingsWithoutCredentials() throws URISyntaxException { @@ -252,7 +253,8 @@ private GoogleCloudStorageClientSettings getGCSClientSettingsWithoutCredentials( readTimeValue, applicationName, new URI(""), - new ProxySettings(Proxy.Type.DIRECT, null, 0, null, null)); + new ProxySettings(Proxy.Type.DIRECT, null, 0, null, null) + ); } }