remove EncShellCommand 82/97282/4
authorSmokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Thu, 17 Oct 2019 19:15:42 +0000 (19:15 +0000)
committerKevin Smokowski <kevin.smokowski@att.com>
Wed, 30 Oct 2019 18:45:42 +0000 (18:45 +0000)
remove EncShellCommand to separate dblib from karaf and odl

Issue-ID: CCSDK-1848
Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Change-Id: If43abeceb556b4075d2866a18b8c9e92765e14a2

dblib/provider/pom.xml
dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBLIBResourceProvider.java
dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/EncShellCommand.java [deleted file]
dblib/provider/src/main/resources/OSGI-INF/blueprint/dblib-blueprint.xml
dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/EncShellCommandTest.java [deleted file]

index a3bd00f..0af3825 100755 (executable)
        <packaging>bundle</packaging>
 
        <name>ccsdk-sli-core :: dblib :: ${project.artifactId}</name>
-       <url>http://maven.apache.org</url>
-
-       <properties>
-               <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-       </properties>
 
        <dependencies>
                <dependency>
                        <artifactId>mariaDB4j</artifactId>
                        <scope>test</scope>
                </dependency>
-               <dependency>
-                       <groupId>org.osgi</groupId>
-                       <artifactId>org.osgi.core</artifactId>
-                       <scope>provided</scope>
-               </dependency>
                <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                </dependency>
-               <dependency>
-                       <groupId>org.slf4j</groupId>
-                       <artifactId>jcl-over-slf4j</artifactId>
-               </dependency>
                <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-simple</artifactId>
@@ -74,9 +60,5 @@
                        <artifactId>mockito-core</artifactId>
                        <scope>test</scope>
                </dependency>
-               <dependency>
-                       <groupId>org.apache.karaf.shell</groupId>
-                       <artifactId>org.apache.karaf.shell.console</artifactId>
-               </dependency>
        </dependencies>
 </project>
index 6d36d63..45e5a78 100755 (executable)
@@ -23,19 +23,14 @@ package org.onap.ccsdk.sli.core.dblib;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.lang.reflect.Method;
 import java.util.Optional;
 import java.util.Properties;
 import java.util.Vector;
-
 import org.onap.ccsdk.sli.core.utils.JREFileResolver;
 import org.onap.ccsdk.sli.core.utils.KarafRootFileResolver;
 import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver;
 import org.onap.ccsdk.sli.core.utils.common.CoreDefaultFileResolver;
 import org.onap.ccsdk.sli.core.utils.common.SdncConfigEnvVarFileResolver;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -99,20 +94,6 @@ public class DBLIBResourceProvider {
             try(FileInputStream fileInputStream = new FileInputStream(propertiesFile)) {
                 properties = new Properties();
                 properties.load(fileInputStream);
-
-                if(properties.containsKey(DBLIB_PROPERTY_NAME)) {
-                    String sensitive = properties.getProperty(DBLIB_PROPERTY_NAME);
-                    if(sensitive != null && sensitive.startsWith("ENC:")) {
-                        try {
-                            sensitive = sensitive.substring(4);
-                            String postsense = decrypt(sensitive);
-                            properties.setProperty(DBLIB_PROPERTY_NAME, postsense);
-                        } catch(Exception exc) {
-                            LOG.error("Failed to translate property", exc);
-                        }
-                    }
-                }
-
             } catch (final IOException e) {
                 LOG.error("Failed to load properties for file: {}", propertiesFile.toString(),
                         new DblibConfigurationException("Failed to load properties for file: "
@@ -121,36 +102,6 @@ public class DBLIBResourceProvider {
         }
     }
 
-    /**
-     *
-     * @param value
-     * @return decrypted string if successful or the original value if unsuccessful
-     */
-    private String decrypt(String value) {
-        try {
-            BundleContext bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
-
-            ServiceReference sref = bctx.getServiceReference("org.opendaylight.aaa.encrypt.AAAEncryptionService");
-            if(sref == null) {
-                LOG.warn("Could not acquire service reference for 'org.opendaylight.aaa.encrypt.AAAEncryptionService'");
-                return value;
-            }
-            Object encrSvc = bctx.getService(sref);
-            if(encrSvc == null) {
-                LOG.warn("Could not access service for 'org.opendaylight.aaa.encrypt.AAAEncryptionService'");
-                return value;
-            }
-
-            Method gs2Method = encrSvc.getClass().getMethod("decrypt", new Class[] { "".getClass() });
-            Object unmasked = gs2Method.invoke(encrSvc, new Object[] { value });
-            return unmasked.toString();
-
-        } catch (Exception exc) {
-            LOG.error("Failure", exc);
-            return value;
-        }
-    }
-
     /**
      * Extract db config properties.
      *
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/EncShellCommand.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/EncShellCommand.java
deleted file mode 100755 (executable)
index eaa5700..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-package org.onap.ccsdk.sli.core.dblib;
-
-import java.lang.reflect.Method;
-
-/**
- * https://karaf.apache.org/manual/latest-2.x/developers-guide/extending-console.html
- * https://github.com/apache/karaf/tree/master/shell/console/src/main/java/org/apache/felix/gogo/commands
- */
-import org.apache.karaf.shell.commands.Argument;
-import org.apache.karaf.shell.commands.Command;
-import org.apache.karaf.shell.console.OsgiCommandSupport;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Command(scope = "dblib", name = "encode", description="Says hello")
-public class EncShellCommand extends OsgiCommandSupport {
-    private static Logger LOGGER = LoggerFactory.getLogger(EncShellCommand.class);
-
-    @Argument(index = 0, name = "arg", description = "The command argument", required = true, multiValued = false)
-    String arg = null;
-
-    @Override
-    protected Object doExecute() throws Exception {
-        System.out.println(String.format("Original value: %s", arg));
-        System.out.println(String.format("Encrypted value: %s", encrypt(arg)));
-        return null;
-    }
-
-    private String encrypt(String value) {
-        try {
-            BundleContext bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
-
-            ServiceReference sref = bctx.getServiceReference("org.opendaylight.aaa.encrypt.AAAEncryptionService");
-            Object encrSvc = bctx.getService(sref);
-
-            Method gs2Method = encrSvc.getClass().getMethod("encrypt", new Class[] { "".getClass() });
-            Object unmasked = gs2Method.invoke(encrSvc, new Object[] { value });
-            return String.format("ENC:%s", unmasked.toString());
-
-        } catch (Exception exc) {
-            LOGGER.error("Failure", exc);
-            return value;
-        }
-    }
-}
\ No newline at end of file
index d9bb99c..f1d5166 100755 (executable)
         </interfaces>
     </service>
 
-    <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
-        <command name="dblib/encode">
-            <action class="org.onap.ccsdk.sli.core.dblib.EncShellCommand"/>
-        </command>
-    </command-bundle>
-
 </blueprint>
\ No newline at end of file
diff --git a/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/EncShellCommandTest.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/EncShellCommandTest.java
deleted file mode 100644 (file)
index 740e69d..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.onap.ccsdk.sli.core.dblib;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.util.Arrays;
-
-import static org.junit.Assert.*;
-
-public class EncShellCommandTest {
-
-    private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
-    private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
-    private final PrintStream originalOut = System.out;
-    private final PrintStream originalErr = System.err;
-
-    @Before
-    public void setUp() {
-        System.setOut(new PrintStream(outContent));
-        System.setErr(new PrintStream(errContent));
-    }
-
-    @After
-    public void tearDown() {
-        System.setOut(originalOut);
-        System.setErr(originalErr);
-    }
-
-    @Test
-    public void testDoExecute() throws Exception {
-        String expected = "Original value: test" + System.getProperty("line.separator") +
-                "Encrypted value: test";
-        EncShellCommand encShellCommand = new EncShellCommand();
-        encShellCommand.arg = "test";
-        encShellCommand.doExecute();
-        assertEquals(expected.trim(), outContent.toString().trim());
-    }
-}
\ No newline at end of file