frankgh commented on code in PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#discussion_r2968315592
##########
server/src/main/java/org/apache/cassandra/sidecar/modules/ConfigurationModule.java:
##########
@@ -117,15 +125,51 @@ CassandraInputValidationConfiguration
validationConfiguration(SidecarConfigurati
@Singleton
CQLSessionProvider cqlSessionProvider(Vertx vertx,
SidecarConfiguration
sidecarConfiguration,
+ CqlAuthProvider cqlAuthProvider,
DriverUtils driverUtils)
{
CQLSessionProviderImpl cqlSessionProvider = new
CQLSessionProviderImpl(sidecarConfiguration,
NettyOptions.DEFAULT_INSTANCE,
+
cqlAuthProvider,
driverUtils);
vertx.eventBus().localConsumer(ON_SERVER_STOP.address(), message ->
cqlSessionProvider.close());
return cqlSessionProvider;
}
+ @Provides
+ @Singleton
+ CqlAuthProvider cqlAuthProvider(SidecarConfiguration sidecarConfiguration)
+ {
+ DriverConfiguration driverConfiguration =
sidecarConfiguration.driverConfiguration();
+
+ ParameterizedClassConfiguration config =
driverConfiguration.authProvider();
+ if (config == null)
+ {
+ // Fallback to the old one
+ Map<String, String> namedParameters = new HashMap<>();
+ namedParameters.put("username", driverConfiguration.username());
+ namedParameters.put("password", driverConfiguration.password());
Review Comment:
minor NIT:
```suggestion
Map<String, String> namedParameters = Map<String, String>
namedParameters = Map.of("username", driverConfiguration.username(),
"password",
driverConfiguration.password());
```
##########
integration-tests/src/integrationTest/resources/config/sidecar.yaml.template:
##########
@@ -267,8 +267,19 @@ access_control:
driver_parameters:
contact_points:
- "127.0.0.1:9042"
- username: cassandra
- password: cassandra
+ auth_provider:
+ # Authentication information, implementing
org.apache.cassandra.sidecar.cluster.auth.CqlAuthProvider;
+ # used to provide username/password to connect to the Cassandra cluster.
+ # class_name: org.apache.cassandra.sidecar.cluster.auth.FileProvider
+ # parameters:
+ # username_path: /opt/sidecar/superuser/username
+ # password_path: /opt/sidecar/superuser/password
+ class_name: org.apache.cassandra.sidecar.cluster.auth.ConfigProvider
+ parameters:
+ username: cassandra
+ password: cassandra
+# username: cassandra
+# password: cassandra
Review Comment:
NIT, not required to keep :
```suggestion
```
##########
server/src/main/java/org/apache/cassandra/sidecar/cluster/CQLSessionProviderImpl.java:
##########
@@ -119,8 +122,10 @@ public CQLSessionProviderImpl(List<InetSocketAddress>
contactPoints,
this.localInstances = localInstances;
this.localDc = localDc;
this.numAdditionalConnections = numAdditionalConnections;
- this.username = username;
- this.password = password;
+ Map<String, String> namedParameters = new HashMap<>();
+ namedParameters.put("username", username);
+ namedParameters.put("password", password);
Review Comment:
tiny NIT:
```suggestion
Map<String, String> namedParameters = Map.of("username", username,
"password", password);
```
##########
server/src/test/java/org/apache/cassandra/sidecar/cluster/auth/FileProviderTest.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.sidecar.cluster.auth;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import org.apache.cassandra.sidecar.exceptions.ConfigurationException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+class FileProviderTest
+{
+ @TempDir
+ Path tempDir;
+
+ @Test
+ void testInterfaceGetters() throws IOException
+ {
+ Path usernamePath = tempDir.resolve("username");
+ Path passwordPath = tempDir.resolve("password");
+ Files.writeString(usernamePath, "cassandra-user\n");
+ Files.writeString(passwordPath, "cassandra-pass\n");
+
+ CqlAuthProvider provider = new
FileProvider(Map.of(FileProvider.USERNAME_PATH_PARAM,
+
usernamePath.toString(),
+
FileProvider.PASSWORD_PATH_PARAM,
+
passwordPath.toString()));
+ assertThat(provider.username()).isEqualTo("cassandra-user");
+ assertThat(provider.password()).isEqualTo("cassandra-pass");
+ }
+
+ @Test
+ void testMissingParameterThrows()
+ {
+ assertThatExceptionOfType(ConfigurationException.class)
+ .isThrownBy(() -> new
FileProvider(Map.of(FileProvider.USERNAME_PATH_PARAM, "/tmp/username")))
+ .withMessageContaining("Missing required auth_provider parameter");
+ }
+
+ @Test
+ void testEmptySecretThrows() throws IOException
+ {
+ Path usernamePath = tempDir.resolve("username");
+ Path passwordPath = tempDir.resolve("password");
+ Files.writeString(usernamePath, " \n");
+ Files.writeString(passwordPath, "secret");
+
+ FileProvider provider = new
FileProvider(Map.of(FileProvider.USERNAME_PATH_PARAM,
+
usernamePath.toString(),
+
FileProvider.PASSWORD_PATH_PARAM,
+
passwordPath.toString()));
Review Comment:
minor NIT:
```suggestion
FileProvider provider = new
FileProvider(Map.of(FileProvider.USERNAME_PATH_PARAM, usernamePath.toString(),
FileProvider.PASSWORD_PATH_PARAM, passwordPath.toString()));
```
##########
server/src/test/java/org/apache/cassandra/sidecar/cluster/auth/FileProviderTest.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.sidecar.cluster.auth;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import org.apache.cassandra.sidecar.exceptions.ConfigurationException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+class FileProviderTest
+{
+ @TempDir
+ Path tempDir;
+
+ @Test
+ void testInterfaceGetters() throws IOException
+ {
+ Path usernamePath = tempDir.resolve("username");
+ Path passwordPath = tempDir.resolve("password");
+ Files.writeString(usernamePath, "cassandra-user\n");
+ Files.writeString(passwordPath, "cassandra-pass\n");
+
+ CqlAuthProvider provider = new
FileProvider(Map.of(FileProvider.USERNAME_PATH_PARAM,
+
usernamePath.toString(),
+
FileProvider.PASSWORD_PATH_PARAM,
+
passwordPath.toString()));
Review Comment:
minor NIT: formatting
```suggestion
CqlAuthProvider provider = new
FileProvider(Map.of(FileProvider.USERNAME_PATH_PARAM, usernamePath.toString(),
FileProvider.PASSWORD_PATH_PARAM, passwordPath.toString()));
```
##########
server/src/test/java/org/apache/cassandra/sidecar/cluster/auth/ConfigProviderTest.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.sidecar.cluster.auth;
+
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+
+import org.apache.cassandra.sidecar.exceptions.ConfigurationException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+class ConfigProviderTest
+{
+ @Test
+ void testInterfaceGetters()
+ {
+ CqlAuthProvider provider = new
ConfigProvider(Map.of(ConfigProvider.USERNAME_PARAM, "cassandra",
+
ConfigProvider.PASSWORD_PARAM, "cassandra"));
Review Comment:
tiny NIT: formatting
```suggestion
CqlAuthProvider provider = new
ConfigProvider(Map.of(ConfigProvider.USERNAME_PARAM, "cassandra",
ConfigProvider.PASSWORD_PARAM, "cassandra"));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]