diff options
author | Vijay Venkatesh Kumar <vv770d@att.com> | 2020-02-18 19:04:42 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-02-18 19:04:42 +0000 |
commit | 9d924537e89a61a85fb7722ec7b5e7208df38937 (patch) | |
tree | 019ae866b716f421510a4d1d696a4563c2709d1a | |
parent | 46b5a59db7edba526548df38ea058339c2389dbd (diff) | |
parent | 93722f9202d0f487dd1aceb2f40e88dd8f5f128c (diff) |
Merge "Get keyStorePassword from file"
-rw-r--r-- | pom.xml | 13 | ||||
-rw-r--r-- | src/main/java/org/onap/dcae/inventory/InventoryApplication.java | 70 | ||||
-rw-r--r-- | src/test/java/org/onap/dcae/inventory/InventoryApplicationTest.java | 8 | ||||
-rw-r--r-- | version.properties | 2 |
4 files changed, 80 insertions, 13 deletions
@@ -1,7 +1,7 @@ <?xml version="1.0"?> <!-- ================================================================================ -Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved. +Copyright (c) 2017-2020 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. @@ -29,7 +29,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. <groupId>org.onap.dcaegen2.platform</groupId> <artifactId>inventory-api</artifactId> - <version>3.4.0-SNAPSHOT</version> + <version>3.4.1-SNAPSHOT</version> <name>dcaegen2-platform-inventory-api</name> <!--internal <version>3.0.0</version>--> @@ -201,7 +201,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> - + <version>19.0</version> </dependency> <dependency> <groupId>org.glassfish.jersey.media</groupId> @@ -215,6 +215,11 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. <scope>test</scope> </dependency> <dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>20131018</version> + </dependency> + <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-all</artifactId> <version>2.0.2-beta</version> @@ -356,6 +361,8 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. <runs> <run>addgroup -S inventory</run> <run>adduser -S -G inventory inventory</run> + <run>mkdir -p /opt/logs</run> + <run>chown -R inventory:inventory /opt</run> </runs> <entryPoint>["java", "-jar", "/opt/${project.build.finalName}.jar", "server"]</entryPoint> <resources> diff --git a/src/main/java/org/onap/dcae/inventory/InventoryApplication.java b/src/main/java/org/onap/dcae/inventory/InventoryApplication.java index 7b0911e..5f0104f 100644 --- a/src/main/java/org/onap/dcae/inventory/InventoryApplication.java +++ b/src/main/java/org/onap/dcae/inventory/InventoryApplication.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * dcae-inventory * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 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. @@ -51,14 +51,23 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.util.ContextInitializer; - import javax.servlet.DispatcherType; import javax.servlet.FilterRegistration; import javax.validation.Validator; import javax.ws.rs.client.Client; import javax.ws.rs.core.Link; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; import java.util.EnumSet; import java.util.Locale; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.json.JSONTokener; /** @@ -68,7 +77,9 @@ public class InventoryApplication extends Application<InventoryConfiguration> { static final Logger metricsLogger = LoggerFactory.getLogger("metricsLogger"); static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); static boolean shouldRemoteFetchConfig = false; + static final String configFile = "/opt/config_active.json"; /** * Parses user's args and makes adjustments if necessary @@ -91,6 +102,16 @@ public class InventoryApplication extends Application<InventoryConfiguration> { return customArgs; } else { // You are here because you want to use the default way of configuring inventory - YAML file. + // The config file yaml file however has the path to the file that has the cert jks password in the keyStorePassword filed + // Update config file's keyStorePassword to have actual password instead of path to the password file + // for junit purposes, it's not possible to do the above with keyStorePassword so return userArgs as we used to do before + if ( "some-junit-yaml.yaml".equals(userArgs[1]) ) { + return userArgs; + } + debugLogger.debug(String.format("Default configuration file received: %s", userArgs[1])); + createConfigFileFromDefault(userArgs[1]); + userArgs[1] = configFile; + debugLogger.debug(String.format("Active config file that will be used: %s", userArgs[1])); return userArgs; } } @@ -201,5 +222,50 @@ public class InventoryApplication extends Application<InventoryConfiguration> { environment.jersey().register(new ApiListingResource()); environment.jersey().register(new SwaggerSerializers()); } + + + private static void createConfigFileFromDefault (String defaultConfigFile) { + + try { + JSONObject dzConfig = new JSONObject ( new JSONTokener ( new FileInputStream ( new File ( defaultConfigFile ) ) ) ); + JSONObject server = dzConfig.getJSONObject("server"); + JSONArray applicationConnectors = server.getJSONArray("applicationConnectors"); + String jksPasswdFile = applicationConnectors.getJSONObject(0).getString("keyStorePassword"); + if ( jksPasswdFile != null ) { + applicationConnectors.getJSONObject(0).put("keyStorePassword", getFileContents(jksPasswdFile)); + } + else { + errorLogger.error(String.format("Exiting due to null value for JKS password file: %s", jksPasswdFile)); + System.exit(1); + } + FileWriter fileWriter = new FileWriter(configFile); + fileWriter.write(dzConfig.toString()); + fileWriter.flush(); + fileWriter.close(); + } catch (JSONException | FileNotFoundException e) { + errorLogger.error(String.format("JSONException | FileNotFoundException while processing default config file: %s; execption: %s", + defaultConfigFile, e)); + System.exit(1); + } catch ( Exception e ) { + errorLogger.error(String.format("Exception while processing default config file: %s; execption: %s", + defaultConfigFile, e)); + System.exit(1); + } + } + + public static String getFileContents (String filename) { + File f = new File(filename); + try { + byte[] bytes = Files.readAllBytes(f.toPath()); + return new String(bytes,"UTF-8").trim(); + } catch (FileNotFoundException e) { + errorLogger.error(String.format("FileNotFoundException for filename: %s; execption: %s", filename, e)); + System.exit(1); + } catch (IOException e) { + errorLogger.error(String.format("IOException for filename: %s; execption: %s", filename, e)); + System.exit(1); + } + return null; + } } diff --git a/src/test/java/org/onap/dcae/inventory/InventoryApplicationTest.java b/src/test/java/org/onap/dcae/inventory/InventoryApplicationTest.java index 8011452..aacbd25 100644 --- a/src/test/java/org/onap/dcae/inventory/InventoryApplicationTest.java +++ b/src/test/java/org/onap/dcae/inventory/InventoryApplicationTest.java @@ -59,13 +59,7 @@ public class InventoryApplicationTest { String userArgs[] = {"server"}; assertEquals(InventoryApplication.processArgs(userArgs).length, 2); - userArgs = new String[] {"server some-yaml.yaml"}; - assertArrayEquals(InventoryApplication.processArgs(userArgs), userArgs); - - userArgs = new String[] {"foo"}; - assertArrayEquals(InventoryApplication.processArgs(userArgs), userArgs); - - userArgs = new String[] {"foo bar"}; + userArgs = new String[] {"server", "some-junit-yaml.yaml"}; assertArrayEquals(InventoryApplication.processArgs(userArgs), userArgs); } diff --git a/version.properties b/version.properties index 1ba9fb5..5a6199f 100644 --- a/version.properties +++ b/version.properties @@ -3,7 +3,7 @@ # because they are used in Jenkins, whose plug-in doesn't support major=3 minor=4 -patch=0 +patch=1 base_version=${major}.${minor}.${patch} # Release must be completed with git revision # in Jenkins |