From e64680cd62b468a25b763457c2e1d31414081c29 Mon Sep 17 00:00:00 2001 From: kjaniak Date: Wed, 8 Jul 2020 15:19:33 +0200 Subject: Add subfolders creation Added new not existing subfolders creation in output path to allow CMPv2 integration. Top up version to 1.2.0 Issue-ID: DCAEGEN2-2252 Change-Id: I59f8dfa7fddc5eb3a3fdd80ce18eb3e2272e1bfb Signed-off-by: kjaniak --- certService/pom.xml | 4 +- certService/version.properties | 2 +- certServiceClient/README.md | 2 +- certServiceClient/pom.xml | 4 +- .../certification/ArtifactsCreatorProvider.java | 2 +- .../ConvertedArtifactsCreatorFactory.java | 2 +- .../certification/writer/CertFileWriter.java | 16 +++++++- .../certification/writer/CertFileWriterTest.java | 48 ++++++++++------------ certServiceClient/version.properties | 2 +- docs/sections/release-notes.rst | 41 ++++++++++++++++++ pom.xml | 2 +- version.properties | 2 +- 12 files changed, 88 insertions(+), 39 deletions(-) diff --git a/certService/pom.xml b/certService/pom.xml index 5cc45cd5..9febd167 100644 --- a/certService/pom.xml +++ b/certService/pom.xml @@ -18,10 +18,10 @@ org.onap.aaf.certservice aaf-certservice - 1.1.0-SNAPSHOT + 1.2.0-SNAPSHOT aaf-certservice-api - 1.1.0-SNAPSHOT + 1.2.0-SNAPSHOT aaf-certservice-api AAF Certification Service Api jar diff --git a/certService/version.properties b/certService/version.properties index 7b8b963a..00ef5645 100644 --- a/certService/version.properties +++ b/certService/version.properties @@ -1,5 +1,5 @@ major=1 -minor=1 +minor=2 patch=0 base_version=${major}.${minor}.${patch} release_version=${base_version} diff --git a/certServiceClient/README.md b/certServiceClient/README.md index adb5d4fb..b3005345 100644 --- a/certServiceClient/README.md +++ b/certServiceClient/README.md @@ -26,7 +26,7 @@ CertService API and client must be running in same network. You need certificate and trust anchors (in JKS format) to connect to CertService API via HTTPS. Information how to generate truststore and keystore files you can find in CertService main README. -Information how to run you can find in CertService main README and official documentation, see [Read The Docs](https://onap-doc.readthedocs.io/projects/onap-aaf-certservice/en/latest/sections/usage.html) +Information how to run you can find in CertService main README and official documentation, see [Read The Docs](https://docs.onap.org/projects/onap-aaf-certservice/en/latest/sections/usage.html) ### Logs locally diff --git a/certServiceClient/pom.xml b/certServiceClient/pom.xml index 50ae677e..e176b18e 100644 --- a/certServiceClient/pom.xml +++ b/certServiceClient/pom.xml @@ -5,12 +5,12 @@ aaf-certservice org.onap.aaf.certservice - 1.1.0-SNAPSHOT + 1.2.0-SNAPSHOT 4.0.0 aaf-certservice-client - 1.1.0-SNAPSHOT + 1.2.0-SNAPSHOT aaf-certservice-client AAF Certification Service Api Client jar diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProvider.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProvider.java index 06a4cc6e..954f3d30 100644 --- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProvider.java +++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/ArtifactsCreatorProvider.java @@ -40,7 +40,7 @@ public enum ArtifactsCreatorProvider { PEM("PEM") { @Override ArtifactsCreator create(String destPath) { - return new PemArtifactsCreator(new CertFileWriter(destPath), new PrivateKeyToPemEncoder()); + return new PemArtifactsCreator(CertFileWriter.createWithDir(destPath), new PrivateKeyToPemEncoder()); } }; diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorFactory.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorFactory.java index 586e2952..bda796eb 100644 --- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorFactory.java +++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/conversion/ConvertedArtifactsCreatorFactory.java @@ -28,7 +28,7 @@ public class ConvertedArtifactsCreatorFactory { public static ConvertedArtifactsCreator createConverter(String destPath, String fileExtension, String keyStoreType) { return new ConvertedArtifactsCreator( - new CertFileWriter(destPath), + CertFileWriter.createWithDir(destPath), new RandomPasswordGenerator(), new PemConverter(keyStoreType), fileExtension); diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriter.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriter.java index 2829517c..fec3ebd3 100644 --- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriter.java +++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriter.java @@ -23,6 +23,7 @@ import org.onap.aaf.certservice.client.certification.exception.CertFileWriterExc import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Path; @@ -32,10 +33,15 @@ public class CertFileWriter { private static final Logger LOGGER = LoggerFactory.getLogger(CertFileWriter.class); private final String destPath; - public CertFileWriter(String destPath) { + private CertFileWriter(String destPath) { this.destPath = destPath; } + public static CertFileWriter createWithDir(String destPath) { + createDirIfNotExists(destPath); + return new CertFileWriter(destPath); + } + public void saveData(byte[] data, String filename) throws CertFileWriterException { LOGGER.debug("Attempt to save file {} in path {}", filename, destPath); try (FileOutputStream outputStream = new FileOutputStream(Path.of(destPath, filename).toString())) { @@ -45,4 +51,12 @@ public class CertFileWriter { throw new CertFileWriterException(e); } } + + private static void createDirIfNotExists(String destPath) { + File destFolderPath = new File(destPath); + if (!destFolderPath.exists()) { + LOGGER.debug("Destination path not exists, subdirectories are created"); + destFolderPath.mkdirs(); + } + } } diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriterTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriterTest.java index 61c4d835..c45876ec 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriterTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/certification/writer/CertFileWriterTest.java @@ -20,8 +20,8 @@ package org.onap.aaf.certservice.client.certification.writer; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.onap.aaf.certservice.client.certification.exception.CertFileWriterException; import java.io.File; @@ -35,48 +35,42 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; class CertFileWriterTest { - private static final String RESOURCES_PATH = "src/test/resources"; - private static final String OUTPUT_PATH = RESOURCES_PATH + "/generatedFiles/"; + private static final String RESOURCES_PATH = "src/test/resources/"; + private static final String OUTPUT_PATH = RESOURCES_PATH + "generatedFiles/"; + private static final String NOT_EXISTING_OUTPUT_PATH = OUTPUT_PATH + "directoryDoesNotExist/"; private static final String TRUSTSTORE_P12 = "truststore.p12"; - private static final String ERROR_MESSAGE = "java.io.FileNotFoundException: src/test/resources/generatedFiles/thisPathDoesNotExist/truststore.p12 (No such file or directory)"; - private File outputDirectory = new File(OUTPUT_PATH); - @BeforeEach - void createDirectory() { - outputDirectory.mkdir(); - } - @AfterEach void cleanUpFiles() { - List.of(outputDirectory.listFiles()).forEach(f -> f.delete()); - outputDirectory.delete(); + deleteDirectoryRecursive(outputDirectory); } - @Test - void certFileWriterShouldCreateFilesWithDataInGivenLocation() + @ParameterizedTest + @ValueSource(strings = {OUTPUT_PATH, NOT_EXISTING_OUTPUT_PATH}) + void certFileWriterShouldCreateFilesWithDataInGivenLocation(String outputPath) throws IOException, CertFileWriterException { // given + File truststore = new File(outputPath + TRUSTSTORE_P12); + CertFileWriter certFileWriter = CertFileWriter.createWithDir(outputPath); final byte[] data = new byte[]{-128, 1, 2, 3, 127}; - File truststore = new File(OUTPUT_PATH + TRUSTSTORE_P12); - CertFileWriter certFileWriter = new CertFileWriter(OUTPUT_PATH); // when certFileWriter.saveData(data, TRUSTSTORE_P12); // then assertThat(truststore.exists()).isTrue(); - assertThat(Files.readAllBytes(Path.of(OUTPUT_PATH + TRUSTSTORE_P12))).isEqualTo(data); + assertThat(Files.readAllBytes(Path.of(outputPath + TRUSTSTORE_P12))).isEqualTo(data); } - @Test - void certFileWriterShouldThrowCertFileWriterExceptionWhenOutputDirectoryDoesNotExist() { - // given - final byte[] data = new byte[]{-128, 1, 2, 3, 0}; - CertFileWriter certFileWriter = new CertFileWriter(OUTPUT_PATH + "thisPathDoesNotExist/"); - - // when then - assertThatThrownBy(() -> certFileWriter.saveData(data, TRUSTSTORE_P12)) - .isInstanceOf(CertFileWriterException.class).hasMessage(ERROR_MESSAGE); + private void deleteDirectoryRecursive(File dirForDeletion) { + List.of(dirForDeletion.listFiles()).forEach(file -> { + if (file.isDirectory()) { + deleteDirectoryRecursive(file); + } + file.delete(); + }); + dirForDeletion.delete(); } + } diff --git a/certServiceClient/version.properties b/certServiceClient/version.properties index 7b8b963a..00ef5645 100644 --- a/certServiceClient/version.properties +++ b/certServiceClient/version.properties @@ -1,5 +1,5 @@ major=1 -minor=1 +minor=2 patch=0 base_version=${major}.${minor}.${patch} release_version=${base_version} diff --git a/docs/sections/release-notes.rst b/docs/sections/release-notes.rst index 7d32480d..daeab0f2 100644 --- a/docs/sections/release-notes.rst +++ b/docs/sections/release-notes.rst @@ -6,6 +6,47 @@ Release Notes ============== +Version: 1.2.0 +-------------- + +:Release Date: + +**New Features** + + - Client creates subdirectories in given OUTPUT_PATH and place certificate into it. + +**Bug Fixes** + + N/A + +**Known Issues** + + N/A + +**Security Notes** + + N/A + +*Fixed Security Issues* + + N/A + +*Known Security Issues* + + N/A + +*Known Vulnerabilities in Used Modules* + + N/A + +**Upgrade Notes** + +**Deprecation Notes** + +**Other** + +=========== + Version: 1.1.0 -------------- diff --git a/pom.xml b/pom.xml index b5ca7eff..8126ee99 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ org.onap.aaf.certservice aaf-certservice - 1.1.0-SNAPSHOT + 1.2.0-SNAPSHOT aaf-certservice AAF Certification Service pom diff --git a/version.properties b/version.properties index 7b8b963a..00ef5645 100644 --- a/version.properties +++ b/version.properties @@ -1,5 +1,5 @@ major=1 -minor=1 +minor=2 patch=0 base_version=${major}.${minor}.${patch} release_version=${base_version} -- cgit 1.2.3-korg