diff --git a/src/main/java/io/aiven/kafka/connect/gcs/GcsSinkConfig.java b/src/main/java/io/aiven/kafka/connect/gcs/GcsSinkConfig.java index 5b56b4f..7b71d1f 100644 --- a/src/main/java/io/aiven/kafka/connect/gcs/GcsSinkConfig.java +++ b/src/main/java/io/aiven/kafka/connect/gcs/GcsSinkConfig.java @@ -42,7 +42,6 @@ import io.aiven.kafka.connect.common.templating.Template; import com.google.auth.oauth2.OAuth2Credentials; -import com.google.cloud.NoCredentials; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.threeten.bp.Duration; @@ -329,10 +328,6 @@ private void validate() { public OAuth2Credentials getCredentials() { final String credentialsPath = getString(GCS_CREDENTIALS_PATH_CONFIG); final Password credentialsJsonPwd = getPassword(GCS_CREDENTIALS_JSON_CONFIG); - if (credentialsPath == null && credentialsJsonPwd == null) { - LOG.warn("No GCS credentials provided, trying to connect without credentials."); - return NoCredentials.getInstance(); - } try { String credentialsJson = null; if (credentialsJsonPwd != null) { diff --git a/src/test/java/io/aiven/kafka/connect/gcs/config/GcsSinkConfigTest.java b/src/test/java/io/aiven/kafka/connect/gcs/config/GcsSinkConfigTest.java index 54be164..25f4db7 100644 --- a/src/test/java/io/aiven/kafka/connect/gcs/config/GcsSinkConfigTest.java +++ b/src/test/java/io/aiven/kafka/connect/gcs/config/GcsSinkConfigTest.java @@ -23,6 +23,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; import java.io.IOException; import java.net.URL; @@ -50,13 +52,17 @@ import io.aiven.kafka.connect.common.templating.Template; import io.aiven.kafka.connect.common.templating.VariableTemplatePart; import io.aiven.kafka.connect.gcs.GcsSinkConfig; +import io.aiven.kafka.connect.gcs.GoogleCredentialsBuilder; +import com.google.auth.oauth2.GoogleCredentials; +import com.google.auth.oauth2.OAuth2Credentials; import com.google.auth.oauth2.UserCredentials; import com.google.common.io.Resources; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.NullSource; import org.junit.jupiter.params.provider.ValueSource; +import org.mockito.MockedStatic; import org.threeten.bp.Duration; /** @@ -377,6 +383,23 @@ void gcsCredentialsJson() throws IOException { assertEquals("test-client-secret", credentials.getClientSecret()); } + @Test + void gcsCredentialsDefault() { + final Map properties = Map.of("gcs.bucket.name", "test-bucket"); + + assertConfigDefValidationPasses(properties); + + try (MockedStatic mocked = mockStatic(GoogleCredentialsBuilder.class)) { + final GoogleCredentials googleCredentials = mock(GoogleCredentials.class); + mocked.when(() -> GoogleCredentialsBuilder.build(null, null)).thenReturn(googleCredentials); + + final GcsSinkConfig config = new GcsSinkConfig(properties); + + final OAuth2Credentials credentials = config.getCredentials(); + assertEquals(googleCredentials, credentials); + } + } + @Test void gcsCredentialsExclusivity() throws IOException { final Map properties = new HashMap<>();