Make babel runnable locally via mvn spring-boot:run 13/139613/4
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Fri, 29 Nov 2024 09:22:33 +0000 (10:22 +0100)
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Fri, 29 Nov 2024 11:09:29 +0000 (12:09 +0100)
- make it runnable mvn spring-boot:run
- remove certificate related config

Issue-ID: AAI-4073
Change-Id: Ie5762dd3d1e79312d72e0611c1d61ce6cfaeb1c2
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
.gitignore
pom.xml
src/main/bin/start.sh
src/main/java/org/onap/aai/babel/BabelApplication.java
src/main/java/org/onap/aai/babel/JerseyConfiguration.java
src/main/java/org/onap/aai/babel/config/PropertyPasswordConfiguration.java [deleted file]
src/main/resources/babel-auth.properties [new file with mode: 0644]
src/main/resources/logback.xml
src/main/resources/tosca-mappings.json [new file with mode: 0644]
src/test/java/org/onap/aai/babel/TestApplication.java

index d25b509..75986d5 100644 (file)
@@ -13,3 +13,5 @@ appconfig-local/
 *.iml
 .idea/
 .vscode/
+*.log
+output*
diff --git a/pom.xml b/pom.xml
index 63ee527..72f8e9b 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                                <version>${spring.boot.version}</version>
                                <configuration>
                                        <jvmArguments>
-                                               -DCONFIG_HOME=./appconfig-local
+                                               -DCONFIG_HOME=src/main/resources
                                                -DAPP_HOME=.
-                                               -Dtosca.mappings.config=./appconfig-local/tosca-mappings.json
-                                               -DKEY_STORE_PASSWORD=${KEY_STORE_PASSWORD}
+                                               -Dtosca.mappings.config=src/main/resources/tosca-mappings.json
                                        </jvmArguments>
                                </configuration>
                                <executions>
index 4d9912d..ed27c5a 100644 (file)
@@ -27,30 +27,16 @@ if [ -z "${CONFIG_HOME}" ]; then
        exit 1
 fi
 
-#Either keystore password or server certs location must be passed. Both cannot be null
-if [ -z "${KEY_STORE_PASSWORD}" -a -z "${SERVER_CERTS_LOCATION}" ]; then
-       echo "KEY_STORE_PASSWORD or SERVER_CERTS_LOCATION must be set in order to start the process"
-       exit 1
-fi
-
 PROPS="-DAPP_HOME=${APP_HOME}"
 PROPS="${PROPS} -DCONFIG_HOME=${CONFIG_HOME}"
 PROPS="${PROPS} -Dtosca.mappings.config=${CONFIG_HOME}/tosca-mappings.json"
 
-if [ ! -z "$KEY_STORE_PASSWORD" ]; then
-   PROPS="${PROPS} -DKEY_STORE_PASSWORD=${KEY_STORE_PASSWORD}"
-fi
-
 PROPS="${PROPS} -Dlogging.config=${APP_HOME}/config/logback.xml"
 
 if [ ! -z "$REQUIRE_CLIENT_AUTH" ]; then
    PROPS="$PROPS -Dserver.ssl.client-auth=${REQUIRE_CLIENT_AUTH}"
 fi
-if [ ! -z "$SERVER_CERTS_LOCATION" ]; then
-   PROPS="$PROPS -Dserver.certs.location=${SERVER_CERTS_LOCATION}"
-   PROPS="$PROPS -Dserver.ssl.key-store=${SERVER_CERTS_LOCATION}/${SERVER_KEY_STORE}"
-   PROPS="$PROPS -Dserver.ssl.trust-store=${SERVER_CERTS_LOCATION}/${SERVER_TRUST_STORE}"
-fi
+
 PROPS="${PROPS} -Dspring.profiles.active=${SPRING_PROFILES_ACTIVE}"
 PROPS="${PROPS} -Daaf.cadi.file=${CONFIG_HOME}/cadi.properties"
 PROPS="${PROPS} -Daaf.cadi.file=${CONFIG_HOME}/cadi.properties"
index 4f67b21..3270af5 100644 (file)
@@ -21,7 +21,6 @@
 
 package org.onap.aai.babel;
 
-import org.onap.aai.babel.config.PropertyPasswordConfiguration;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@@ -46,14 +45,9 @@ public class BabelApplication extends SpringBootServletInitializer {
      *            main args (expected to be null)
      */
     public static void main(String[] args) {
-        String keyStorePassword = System.getProperty("KEY_STORE_PASSWORD");
-        if (keyStorePassword == null || keyStorePassword.isEmpty()) {
-            throw new IllegalArgumentException("Mandatory property KEY_STORE_PASSWORD not set");
-        }
         SpringApplication app = new SpringApplication(BabelApplication.class);
         app.setLogStartupInfo(false);
         app.setRegisterShutdownHook(true);
-        app.addInitializers(new PropertyPasswordConfiguration());
         context = app.run(args);
     }
 
index 84cda4d..ff8c5bb 100644 (file)
@@ -31,9 +31,9 @@ import org.springframework.context.annotation.Configuration;
 public class JerseyConfiguration extends ResourceConfig {
 
     public JerseyConfiguration() {
-        packages("org.onap.aai.babel");
-        // register(GenerateArtifactsControllerImpl.class);
-        // register(InfoService.class);
+        // packages("org.onap.aai.babel");
+        register(GenerateArtifactsControllerImpl.class);
+        register(InfoService.class);
     }
 
 }
diff --git a/src/main/java/org/onap/aai/babel/config/PropertyPasswordConfiguration.java b/src/main/java/org/onap/aai/babel/config/PropertyPasswordConfiguration.java
deleted file mode 100644 (file)
index 7539d41..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed 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.
- * ============LICENSE_END=========================================================
- */
-package org.onap.aai.babel.config;
-
-import java.nio.charset.StandardCharsets;
-import org.eclipse.jetty.util.security.Password;
-import org.springframework.context.ApplicationContextInitializer;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.core.env.ConfigurableEnvironment;
-import org.springframework.core.env.MapPropertySource;
-import org.springframework.core.env.PropertySource;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Properties;
-
-public class PropertyPasswordConfiguration implements ApplicationContextInitializer<ConfigurableApplicationContext> {
-
-    private static final String PROP_KEY_STORE_PASS = "server.ssl.key-store-password";
-
-    @Override
-    public void initialize(ConfigurableApplicationContext applicationContext) {
-
-        Map<String, Object> sslProps = new LinkedHashMap<>();
-        ConfigurableEnvironment environment = applicationContext.getEnvironment();
-        String certPath = environment.getProperty("server.certs.location");
-        String keystorePassword = null;
-        String truststorePassword = null;
-
-        if (certPath != null) {
-            try (InputStream passwordStream = new FileInputStream(certPath + ".password")) {
-                keystorePassword = new String(passwordStream.readAllBytes(), StandardCharsets.UTF_8);
-                keystorePassword = keystorePassword.trim();
-                sslProps.put(PROP_KEY_STORE_PASS, keystorePassword);
-            } catch (IOException e) {
-                keystorePassword = null;
-            }
-            try (InputStream passphrasesStream = new FileInputStream(certPath + ".passphrases");) {
-                Properties passphrasesProps = new Properties();
-                passphrasesProps.load(passphrasesStream);
-                truststorePassword = passphrasesProps.getProperty("cadi_truststore_password");
-                if (truststorePassword != null) {
-                    truststorePassword = truststorePassword.trim();
-                }
-                sslProps.put("server.ssl.trust-store-password", truststorePassword);
-            } catch (IOException e) {
-                truststorePassword = null;
-            }
-        }
-        if (keystorePassword == null || keystorePassword.isEmpty()) {
-            keystorePassword = System.getProperty("KEY_STORE_PASSWORD");
-            if (keystorePassword != null && (!keystorePassword.isEmpty()) ) {
-                System.setProperty(PROP_KEY_STORE_PASS, new Password(keystorePassword).toString());
-            }
-            if (keystorePassword == null || keystorePassword.isEmpty()) {
-                throw new IllegalArgumentException("Mandatory property KEY_STORE_PASSWORD not set");
-            }
-        }
-        else {
-            sslProps.put(PROP_KEY_STORE_PASS, keystorePassword);
-        }
-        if (truststorePassword != null && !truststorePassword.isEmpty()) {
-            sslProps.put("server.ssl.trust-store-password", truststorePassword);
-        }
-        if (!sslProps.isEmpty()) {
-            PropertySource<?> additionalProperties = new MapPropertySource("additionalProperties", sslProps);
-            environment.getPropertySources().addFirst(additionalProperties);
-        }
-    }
-}
diff --git a/src/main/resources/babel-auth.properties b/src/main/resources/babel-auth.properties
new file mode 100644 (file)
index 0000000..ba4e13a
--- /dev/null
@@ -0,0 +1,2 @@
+auth.policy.file=/auth/auth_policy.json
+auth.authentication.disable=true
\ No newline at end of file
index 74d2ae0..98c626b 100644 (file)
@@ -23,7 +23,7 @@ To find main logging config please check `logging.config` in the application.pro
   <include resource="org/springframework/boot/logging/logback/base.xml" />
 
   <property name="componentName" value="AAI-BAS" />
-  <property name="logDirectory" value="/var/log/onap/${componentName}" />
+  <property name="logDirectory" value="${LOG_DIRECTORY:-.}/${componentName}" />
 
   <!-- default EELF log file names -->
   <property name="generalLogName" value="error" />
diff --git a/src/main/resources/tosca-mappings.json b/src/main/resources/tosca-mappings.json
new file mode 100644 (file)
index 0000000..32491f6
--- /dev/null
@@ -0,0 +1,193 @@
+{
+       "instanceGroupTypes": [
+               "org.openecomp.groups.NetworkCollection",
+               "org.openecomp.groups.VfcInstanceGroup",
+               "org.openecomp.groups.ResourceInstanceGroup"
+       ],
+       "widgetTypes": [
+               {
+                       "type": "SERVICE",
+                       "name": "service-instance",
+                       "deleteFlag": true,
+            "modelInvariantId": "service-instance-invariant-id",
+            "modelVersionId": "service-instance-version-id"
+               },
+               {
+                       "type": "VF",
+                       "name": "generic-vnf",
+                       "deleteFlag": true,
+            "modelInvariantId": "generic-vnf-invariant-id",
+            "modelVersionId": "generic-vnf-version-id"
+               },
+               {
+                       "type": "VFC",
+                       "name": "vnfc",
+                       "deleteFlag": true,
+            "modelInvariantId": "vnfc-invariant-id",
+            "modelVersionId": "vnfc-version-id"
+               },
+               {
+                       "type": "VSERVER",
+                       "name": "vserver",
+                       "deleteFlag": true,
+            "modelInvariantId": "vserver-invariant-id",
+            "modelVersionId": "vserver-version-id"
+               },
+               {
+                       "type": "VOLUME",
+                       "name": "volume",
+                       "deleteFlag": true,
+            "modelInvariantId": "volume-invariant-id",
+            "modelVersionId": "volume-version-id"
+               },
+               {
+                       "type": "FLAVOR",
+                       "name": "flavor",
+                       "deleteFlag": false,
+            "modelInvariantId": "flavor-invariant-id",
+            "modelVersionId": "flavor-version-id"
+               },
+               {
+                       "type": "TENANT",
+                       "name": "tenant",
+                       "deleteFlag": false,
+            "modelInvariantId": "tenant-invariant-id",
+            "modelVersionId": "tenant-version-id"
+               },
+               {
+                       "type": "VOLUME_GROUP",
+                       "name": "volume-group",
+                       "deleteFlag": true,
+            "modelInvariantId": "volume-group-invariant-id",
+            "modelVersionId": "volume-group-version-id"
+               },
+               {
+                       "type": "LINT",
+                       "name": "l-interface",
+                       "deleteFlag": true,
+            "modelInvariantId": "l-interface-invariant-id",
+            "modelVersionId": "l-interface-version-id"
+               },
+               {
+                       "type": "L3_NET",
+                       "name": "l3-network",
+                       "deleteFlag": true,
+            "modelInvariantId": "l3-network-invariant-id",
+            "modelVersionId": "l3-network-version-id"
+               },
+               {
+                       "type": "VFMODULE",
+                       "name": "vf-module",
+                       "deleteFlag": true,
+            "modelInvariantId": "vf-module-invariant-id",
+            "modelVersionId": "vf-module-version-id"
+               },
+               {
+                       "type": "IMAGE",
+                       "name": "image",
+                       "deleteFlag": false,
+            "modelInvariantId": "image-invariant-id",
+            "modelVersionId": "image-version-id"
+               },
+               {
+                       "type": "OAM_NETWORK",
+                       "name": "oam-network",
+                       "deleteFlag": true,
+            "modelInvariantId": "oam-network-invariant-id",
+            "modelVersionId": "oam-network-version-id"
+               },
+               {
+                       "type": "ALLOTTED_RESOURCE",
+                       "name": "allotted-resource",
+                       "deleteFlag": true,
+            "modelInvariantId": "allotted-resource-invariant-id",
+                       "modelVersionId": "allotted-resource-version-id"
+               },
+               {
+                       "type": "TUNNEL_XCONNECT",
+                       "name": "tunnel-xconnect",
+                       "deleteFlag": true,
+            "modelInvariantId": "tunnel-xconnect-invariant-id",
+            "modelVersionId": "tunnel-xconnect-version-id"
+               },
+               {
+                       "type": "CONFIGURATION",
+                       "name": "configuration",
+                       "deleteFlag": true,
+            "modelInvariantId": "configuration-invariant-id",
+            "modelVersionId": "configuration-version-id"
+               },
+               {
+                       "type": "CR",
+                       "name": "cr",
+                       "deleteFlag": true,
+                       "modelInvariantId": "collection-resource-invariant-id",
+                       "modelVersionId": "collection-resource-version-id"
+               },
+               {
+                       "type": "INSTANCE_GROUP",
+                       "name": "instance-group",
+                       "deleteFlag": true,
+                       "modelInvariantId": "instance-group-invariant-id",
+                       "modelVersionId": "instance-group-version-id"
+               },
+               {
+                       "type": "PNF",
+                       "name": "pnf",
+                       "deleteFlag": true,
+                       "modelInvariantId": "pnf-instance-invariant-id",
+                       "modelVersionId": "pnf-instance-version-id"
+               }
+       ],
+       "widgetMappings": [
+               {
+                       "prefix": "org.openecomp.resource.vfc",
+                       "type": "widget",
+                       "widget": "VSERVER",
+                       "deleteFlag": true
+               },
+               {
+                       "prefix": "org.openecomp.resource.cp",
+                       "type": "widget",
+                       "widget": "LINT",
+                       "deleteFlag": true
+               },
+               {
+                       "prefix": "org.openecomp.cp",
+                       "type": "widget",
+                       "widget": "LINT",
+                       "deleteFlag": true
+               },
+               {
+                       "prefix": "org.openecomp.resource.vl",
+                       "widget": "L3_NET",
+                       "deleteFlag": false
+               },
+               {
+                       "prefix": "org.openecomp.resource.vf",
+                       "widget": "VF",
+                       "deleteFlag": true
+               },
+               {
+                       "prefix": "org.openecomp.groups.vfmodule",
+                       "widget": "VFMODULE",
+                       "deleteFlag": true
+               },
+               {
+                       "prefix": "org.openecomp.groups.VfModule",
+                       "widget": "VFMODULE",
+                       "deleteFlag": true
+               },
+               {
+                       "prefix": "org.openecomp.resource.vfc.nodes.heat.cinder",
+                       "type": "widget",
+                       "widget": "VOLUME",
+                       "deleteFlag": true
+               },
+               {
+                       "prefix": "org.openecomp.resource.pnf",
+                       "widget": "PNF",
+                       "deleteFlag": true
+               }
+       ]
+}
index 67e8a32..87158c0 100644 (file)
@@ -41,13 +41,11 @@ public class TestApplication {
     public void init() {
         System.setProperty("APP_HOME", ".");
         System.setProperty("CONFIG_HOME", "src/test/resources");
-        System.setProperty("server.ssl.key-store", "src/test/resources/auth/keystore.jks");
     }
 
     @Test
     public void testApplicationStarts() {
         assertDoesNotThrow(() -> {
-            System.setProperty("KEY_STORE_PASSWORD", "password");
             BabelApplication.main(new String[]{});
             BabelApplication.exit();
         });
@@ -56,7 +54,6 @@ public class TestApplication {
     @Test
     public void testApplicationStartsWithObfuscatedPassword() {
         assertDoesNotThrow(() -> {
-            System.setProperty("KEY_STORE_PASSWORD", Password.obfuscate("password"));
             BabelApplication.main(new String[]{});
             BabelApplication.exit();
         });
@@ -65,50 +62,9 @@ public class TestApplication {
     @Test
     public void testApplicationWithNullArgs() {
         Throwable exception = assertThrows(IllegalArgumentException.class, () -> {
-            System.setProperty("KEY_STORE_PASSWORD", "test");
             BabelApplication.main(null);
         });
         assertTrue(exception.getMessage().contains("Args must not be null"));
     }
 
-    @Test
-    public void testApplicationWithEmptyKeyStorePassword() {
-        Throwable exception = assertThrows(IllegalArgumentException.class, () -> {
-            System.setProperty("KEY_STORE_PASSWORD", "");
-            BabelApplication.main(new String[]{});
-        });
-        assertTrue(exception.getMessage().contains("roperty KEY_STORE_PASSWORD not set"));
-    }
-
-    @Test
-    public void testApplicationWithNullKeyStorePassword() {
-        Throwable exception = assertThrows(IllegalArgumentException.class, () -> {
-            System.clearProperty("KEY_STORE_PASSWORD");
-            BabelApplication.main(new String[]{});
-        });
-        assertTrue(exception.getMessage().contains("roperty KEY_STORE_PASSWORD not set"));
-    }
-
-    @Test
-    public void testApplicationWithIncorrectKeyStorePassword() {
-        Throwable exception = assertThrows(ApplicationContextException.class, () -> {
-            System.setProperty("KEY_STORE_PASSWORD", "test");
-            BabelApplication.main(new String[]{});
-        });
-    }
-
-    /**
-     * This test asserts that if the KEY_STORE_PASSWORD System Property is set (and is not empty) then the value is
-     * passed to Jetty, debobfuscated, and used to open the key store, even if the resulting password value is actually
-     * an empty string.
-     */
-    @Test
-    public void testApplicationWithBlankObfuscatedKeyStorePassword() {
-        // Note that "OBF:" is correctly deobfuscated and results in an empty string.
-        Throwable exception = assertThrows(ApplicationContextException.class, () -> {
-            System.setProperty("KEY_STORE_PASSWORD", "OBF:");
-            BabelApplication.main(new String[]{});
-        });
-    }
-
 }