Do not leak ClassToInstanceMap from NetconfSalKeystoreRpcs 89/107989/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 26 Sep 2023 12:36:39 +0000 (14:36 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 26 Sep 2023 12:37:16 +0000 (14:37 +0200)
A public method here is completely superfluous, do not leak it.

JIRA: NETCONF-1116
Change-Id: Ib2789ba44fd1ac00ace1d857a92f859c10b11e0f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
plugins/netconf-client-mdsal/src/main/java/org/opendaylight/netconf/client/mdsal/impl/NetconfSalKeystoreRpcs.java
plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/impl/NetconfSalKeystoreRpcsTest.java

index 975e3df5c7df57c16bc554b6b653c526b47633e9..4f4cb6db789ecf7d15855829ae97f4fd06c30911 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.netconf.client.mdsal.impl;
 
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableClassToInstanceMap;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -89,7 +89,14 @@ public final class NetconfSalKeystoreRpcs implements AutoCloseable {
         this.dataBroker = requireNonNull(dataBroker);
         this.encryptionService = requireNonNull(encryptionService);
 
-        reg = rpcProvider.registerRpcImplementations(getRpcClassToInstanceMap());
+        reg = rpcProvider.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
+            .put(RemoveKeystoreEntry.class, this::removeKeystoreEntry)
+            .put(AddKeystoreEntry.class, this::addKeystoreEntry)
+            .put(AddTrustedCertificate.class, this::addTrustedCertificate)
+            .put(RemoveTrustedCertificate.class, this::removeTrustedCertificate)
+            .put(AddPrivateKey.class, this::addPrivateKey)
+            .put(RemovePrivateKey.class, this::removePrivateKey)
+            .build());
         LOG.info("NETCONF keystore service started");
     }
 
@@ -166,7 +173,8 @@ public final class NetconfSalKeystoreRpcs implements AutoCloseable {
         return rpcResult;
     }
 
-    private ListenableFuture<RpcResult<AddTrustedCertificateOutput>> addTrustedCertificate(
+    @VisibleForTesting
+    ListenableFuture<RpcResult<AddTrustedCertificateOutput>> addTrustedCertificate(
             final AddTrustedCertificateInput input) {
         final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
 
@@ -222,7 +230,8 @@ public final class NetconfSalKeystoreRpcs implements AutoCloseable {
         return rpcResult;
     }
 
-    private ListenableFuture<RpcResult<AddPrivateKeyOutput>> addPrivateKey(final AddPrivateKeyInput input) {
+    @VisibleForTesting
+    ListenableFuture<RpcResult<AddPrivateKeyOutput>> addPrivateKey(final AddPrivateKeyInput input) {
         final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
 
         for (PrivateKey key: input.nonnullPrivateKey().values()) {
@@ -275,15 +284,4 @@ public final class NetconfSalKeystoreRpcs implements AutoCloseable {
 
         return rpcResult;
     }
-
-    public ClassToInstanceMap<Rpc<?, ?>> getRpcClassToInstanceMap() {
-        return ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
-            .put(RemoveKeystoreEntry.class, this::removeKeystoreEntry)
-            .put(AddKeystoreEntry.class, this::addKeystoreEntry)
-            .put(AddTrustedCertificate.class, this::addTrustedCertificate)
-            .put(RemoveTrustedCertificate.class, this::removeTrustedCertificate)
-            .put(AddPrivateKey.class, this::addPrivateKey)
-            .put(RemovePrivateKey.class, this::removePrivateKey)
-            .build();
-    }
 }
index 2a5460252c90a71946af4da8bb2750707aa19d6f..18e357e4c9ac1953d2c7e07293f4f1dfe20d4793 100644 (file)
@@ -29,10 +29,8 @@ import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netconf.api.xml.XmlUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddPrivateKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddPrivateKeyInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddPrivateKeyInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddTrustedCertificate;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddTrustedCertificateInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddTrustedCertificateInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017._private.keys.PrivateKey;
@@ -83,7 +81,7 @@ public class NetconfSalKeystoreRpcsTest {
         doReturn(emptyFluentFuture()).when(writeTx).commit();
         try (var keystoreService = new NetconfSalKeystoreRpcs(dataBroker, encryptionService, rpcProvider)) {
             final AddPrivateKeyInput input = getPrivateKeyInput();
-            keystoreService.getRpcClassToInstanceMap().getInstance(AddPrivateKey.class).invoke(input).get();
+            keystoreService.addPrivateKey(input).get();
 
             verify(writeTx, times(input.nonnullPrivateKey().size()))
                 .merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class));
@@ -95,7 +93,7 @@ public class NetconfSalKeystoreRpcsTest {
         doReturn(emptyFluentFuture()).when(writeTx).commit();
         try (var keystoreService = new NetconfSalKeystoreRpcs(dataBroker, encryptionService, rpcProvider)) {
             final var input = getTrustedCertificateInput();
-            keystoreService.getRpcClassToInstanceMap().getInstance(AddTrustedCertificate.class).invoke(input).get();
+            keystoreService.addTrustedCertificate(input).get();
 
             verify(writeTx, times(input.nonnullTrustedCertificate().size()))
                 .merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class));