aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageContentHandler.java53
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessor.java19
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java8
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidator.java56
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java273
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/exception/MissingCertificateException.java27
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java2
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackage.java11
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java14
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidatorTest.java1
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java250
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java41
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java4
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java7
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java26
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java51
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java22
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java14
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingToscaMetadata.java18
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java52
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadata.java33
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java1
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java17
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/csar/MetadataParsingTest.java18
24 files changed, 639 insertions, 379 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageContentHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageContentHandler.java
new file mode 100644
index 0000000000..c519802568
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageContentHandler.java
@@ -0,0 +1,53 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import org.apache.commons.io.FilenameUtils;
+import org.openecomp.core.utilities.file.FileContentHandler;
+
+public class OnboardingPackageContentHandler extends FileContentHandler {
+
+ public OnboardingPackageContentHandler() {
+ }
+
+ public OnboardingPackageContentHandler(final FileContentHandler other) {
+ super(other);
+ }
+
+ public Map<String, String> getFileAndSignaturePathMap(final Set<String> signatureExtensionSet) {
+ final Map<String, byte[]> files = getFiles();
+ final Map<String, String> signedFilePairMap = new HashMap<>();
+ files.keySet().stream()
+ .filter(filePath -> !signatureExtensionSet.contains(FilenameUtils.getExtension(filePath)))
+ .forEach(filePath -> {
+ final String filePathWithoutExtension = FilenameUtils.removeExtension(filePath);
+ signatureExtensionSet.stream()
+ .map(extension -> String.format("%s.%s", filePathWithoutExtension, extension))
+ .filter(files::containsKey)
+ .forEach(file -> signedFilePairMap.put(filePath, file));
+ signedFilePairMap.putIfAbsent(filePath, null);
+ });
+ return signedFilePairMap;
+ }
+
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessor.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessor.java
index 1d502547dc..20d8e26cb0 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessor.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessor.java
@@ -25,8 +25,9 @@ import static org.openecomp.sdc.common.errors.Messages.PACKAGE_INVALID_EXTENSION
import static org.openecomp.sdc.common.errors.Messages.PACKAGE_MISSING_INTERNAL_PACKAGE;
import static org.openecomp.sdc.common.errors.Messages.PACKAGE_PROCESS_ERROR;
import static org.openecomp.sdc.common.errors.Messages.PACKAGE_PROCESS_INTERNAL_PACKAGE_ERROR;
+import static org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager.ALLOWED_CERTIFICATE_EXTENSIONS;
+import static org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager.ALLOWED_SIGNATURE_EXTENSIONS;
-import com.google.common.collect.ImmutableSet;
import java.nio.ByteBuffer;
import java.util.HashSet;
import java.util.Map;
@@ -43,15 +44,12 @@ import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
-import org.openecomp.sdc.vendorsoftwareproduct.exception.OnboardPackageException;
import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackage;
import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo;
import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardSignedPackage;
public class OnboardingPackageProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(OnboardingPackageProcessor.class);
- private static final Set<String> ALLOWED_SIGNATURE_EXTENSIONS = ImmutableSet.of("cms");
- private static final Set<String> ALLOWED_CERTIFICATE_EXTENSIONS = ImmutableSet.of("cert", "crt");
private static final String CSAR_EXTENSION = "csar";
private static final String ZIP_EXTENSION = "zip";
@@ -93,11 +91,13 @@ public class OnboardingPackageProcessor {
if (hasSignedPackageStructure()) {
return processSignedPackage(packageName, packageExtension);
} else {
- final OnboardPackage onboardPackage = new OnboardPackage(packageName, packageExtension,
- ByteBuffer.wrap(packageFileContent), onboardPackageContentHandler);
if (packageExtension.equalsIgnoreCase(CSAR_EXTENSION)) {
+ final OnboardPackage onboardPackage = new OnboardPackage(packageName, packageExtension,
+ ByteBuffer.wrap(packageFileContent), new OnboardingPackageContentHandler(onboardPackageContentHandler));
return new OnboardPackageInfo(onboardPackage, OnboardingTypesEnum.CSAR);
} else if (packageExtension.equalsIgnoreCase(ZIP_EXTENSION)) {
+ final OnboardPackage onboardPackage = new OnboardPackage(packageName, packageExtension,
+ ByteBuffer.wrap(packageFileContent), onboardPackageContentHandler);
return new OnboardPackageInfo(onboardPackage, OnboardingTypesEnum.ZIP);
}
}
@@ -127,12 +127,13 @@ public class OnboardingPackageProcessor {
final String internalPackageBaseName = FilenameUtils.getBaseName(internalPackagePath);
final String internalPackageExtension = FilenameUtils.getExtension(internalPackagePath);
final byte[] internalPackageContent = onboardPackageContentHandler.getFileContent(internalPackagePath);
-
final OnboardPackage onboardPackage;
try {
+ final OnboardingPackageContentHandler fileContentHandler =
+ new OnboardingPackageContentHandler(CommonUtil.getZipContent(internalPackageContent));
onboardPackage = new OnboardPackage(internalPackageBaseName, internalPackageExtension,
- internalPackageContent);
- } catch (final OnboardPackageException e) {
+ internalPackageContent, fileContentHandler);
+ } catch (final ZipException e) {
final String message = PACKAGE_PROCESS_INTERNAL_PACKAGE_ERROR.formatMessage(internalPackageName);
LOGGER.error(message, e);
reportError(ErrorLevel.ERROR, message);
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java
index 23cf41c5d5..68309106cd 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java
@@ -44,7 +44,7 @@ public abstract class BaseOrchestrationTemplateHandler implements OrchestrationT
final OnboardPackage onboardPackage = onboardPackageInfo.getOnboardPackage();
final UploadFileResponse uploadFileResponse = new UploadFileResponse();
uploadFileResponse.setOnboardingType(getHandlerType());
- if (isFileFileToUploadEmpty(onboardPackage, uploadFileResponse, candidateService)) {
+ if (isFileToUploadEmpty(onboardPackage, uploadFileResponse, candidateService)) {
return uploadFileResponse;
}
@@ -74,9 +74,9 @@ public abstract class BaseOrchestrationTemplateHandler implements OrchestrationT
final OnboardPackageInfo onboardPackageInfo,
final CandidateService candidateService);
- private boolean isFileFileToUploadEmpty(final OnboardPackage onboardPackage,
- final UploadFileResponse uploadFileResponse,
- final CandidateService candidateService) {
+ private boolean isFileToUploadEmpty(final OnboardPackage onboardPackage,
+ final UploadFileResponse uploadFileResponse,
+ final CandidateService candidateService) {
final ByteArrayInputStream fileToUpload = new ByteArrayInputStream(
onboardPackage.getFileContent().array());
Optional<ErrorMessage> errorMessage =
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidator.java
index ceee5facd0..6597beb9f5 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidator.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidator.java
@@ -20,7 +20,22 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.ELIGBLE_FOLDERS;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.ELIGIBLE_FILES;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.sdc.common.errors.Messages;
import org.openecomp.sdc.common.utils.SdcCommon;
@@ -32,21 +47,6 @@ import org.openecomp.sdc.tosca.csar.Manifest;
import org.openecomp.sdc.tosca.csar.ONAPManifestOnboarding;
import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata;
import org.openecomp.sdc.tosca.csar.ToscaMetadata;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.ELIGBLE_FOLDERS;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.ELIGIBLE_FILES;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
class ONAPCsarValidator implements Validator {
@@ -56,7 +56,6 @@ class ONAPCsarValidator implements Validator {
@Override
public Map<String, List<ErrorMessage>> validateContent(final FileContentHandler contentHandler) {
-
Map<String, List<ErrorMessage>> errors = new HashMap<>();
validateManifest(contentHandler);
validateMetadata(contentHandler);
@@ -72,10 +71,10 @@ class ONAPCsarValidator implements Validator {
private void validateMetadata(FileContentHandler contentMap){
if (!validateTOSCAYamlFileInRootExist(contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME)) {
- try (InputStream metaFileContent = contentMap.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME)) {
+ try (InputStream metaFileContent = contentMap.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME.getName())) {
ToscaMetadata onboardingToscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(metaFileContent);
- String entryDefinitionsPath = onboardingToscaMetadata.getMetaEntries().get(TOSCA_META_ENTRY_DEFINITIONS);
+ String entryDefinitionsPath = onboardingToscaMetadata.getMetaEntries().get(ENTRY_DEFINITIONS.getName());
if (entryDefinitionsPath != null) {
validateFileExist(contentMap, entryDefinitionsPath);
} else {
@@ -92,24 +91,23 @@ class ONAPCsarValidator implements Validator {
}
}
- private void validateManifest(FileContentHandler contentMap) {
-
+ private void validateManifest(final FileContentHandler contentMap) {
if (!validateFileExist(contentMap, MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)) {
return;
}
- try (InputStream fileContent = contentMap.getFileContentAsStream(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)) {
-
- Manifest onboardingManifest = new ONAPManifestOnboarding();
+ try (final InputStream fileContent = contentMap.getFileContentAsStream(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)) {
+ final Manifest onboardingManifest = new ONAPManifestOnboarding();
onboardingManifest.parse(fileContent);
if (!onboardingManifest.isValid()) {
- onboardingManifest.getErrors().forEach(error -> uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR,
- error)));
+ onboardingManifest.getErrors()
+ .forEach(error -> uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR, error)));
}
-
- } catch (IOException e) {
- // convert to runtime to keep the throws unchanged
- throw new RuntimeException("Failed to validateContent manifest", e);
+ } catch (final IOException ex) {
+ final String errorMessage =
+ Messages.MANIFEST_UNEXPECTED_ERROR.formatMessage(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, ex.getMessage());
+ uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR, errorMessage));
+ logger.error(errorMessage, ex);
}
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java
index 6274a54a58..9481a021e2 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java
@@ -20,7 +20,38 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+
+import static org.openecomp.sdc.tosca.csar.CSARConstants.CSAR_VERSION_1_0;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.CSAR_VERSION_1_1;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_METADATA_LIMIT;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_VNF_METADATA;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_MANIFEST_FILE_EXT;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_TYPE_PNF;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_TYPE_VNF;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.CREATED_BY_ENTRY;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.CSAR_VERSION_ENTRY;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_CERTIFICATE;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_MANIFEST;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_FILE_VERSION;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_FILE_VERSION_ENTRY;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_PM_DICTIONARY;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_VES_EVENTS;
+
+import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.openecomp.core.impl.ToscaDefinitionImportHandler;
@@ -35,42 +66,15 @@ import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.csar.Manifest;
import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata;
import org.openecomp.sdc.tosca.csar.SOL004ManifestOnboarding;
+import org.openecomp.sdc.tosca.csar.ToscaMetaEntry;
import org.openecomp.sdc.tosca.csar.ToscaMetadata;
+import org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding.OnboardingPackageContentHandler;
+import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.exception.MissingCertificateException;
import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.exceptions.InvalidManifestMetadataException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
+import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager;
+import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManagerException;
import org.yaml.snakeyaml.Yaml;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.CSAR_VERSION_1_0;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.CSAR_VERSION_1_1;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_METADATA_LIMIT;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_VNF_METADATA;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_MANIFEST_FILE_EXT;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CERTIFICATE;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_FILE_VERSION_ENTRY;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_CREATED_BY_ENTRY;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_CSAR_VERSION_ENTRY;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CHANGE_LOG;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_LICENSES;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_MANIFEST;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_TESTS;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_FILE_VERSION;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_TYPE_PNF;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_TYPE_VNF;
-import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_PM_DICTIONARY;
-import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_VES_EVENTS;
-
/**
* Validates the contents of the package to ensure it complies with the "CSAR with TOSCA-Metadata directory" structure
* as defined in ETSI GS NFV-SOL 004 v2.6.1.
@@ -81,28 +85,42 @@ class SOL004MetaDirectoryValidator implements Validator {
private static final String MANIFEST_SOURCE = "Source";
private static final String MANIFEST_NON_MANO_SOURCE = "Non-MANO Source";
- private final List<ErrorMessage> errorsByFile = new ArrayList<>();
- private FileContentHandler contentHandler;
+ private final List<ErrorMessage> errorsByFile = new CopyOnWriteArrayList<>();
+ private final SecurityManager securityManager = SecurityManager.getInstance();
+ private OnboardingPackageContentHandler contentHandler;
private Set<String> folderList;
private ToscaMetadata toscaMetadata;
@Override
- public Map<String, List<ErrorMessage>> validateContent(final FileContentHandler contentHandler) {
- this.contentHandler = contentHandler;
+ public Map<String, List<ErrorMessage>> validateContent(final FileContentHandler fileContentHandler) {
+ this.contentHandler = (OnboardingPackageContentHandler) fileContentHandler;
this.folderList = contentHandler.getFolderList();
parseToscaMetadata();
verifyMetadataFile();
+
+ if (packageHasCertificate()) {
+ verifySignedFiles();
+ }
return Collections.unmodifiableMap(getAnyValidationErrors());
}
+ private boolean packageHasCertificate() {
+ final String certificatePath = getCertificatePath().orElse(null);
+ return contentHandler.containsFile(certificatePath);
+ }
+
+ private Optional<String> getCertificatePath() {
+ return toscaMetadata.getEntry(ETSI_ENTRY_CERTIFICATE);
+ }
+
/**
- * Parses the {@link org.openecomp.sdc.tosca.csar.CSARConstants#TOSCA_META_PATH_FILE_NAME} file
+ * Parses the {@link ToscaMetaEntry#TOSCA_META_PATH_FILE_NAME;} file
*/
private void parseToscaMetadata() {
try {
toscaMetadata =
OnboardingToscaMetadata
- .parseToscaMetadataFile(contentHandler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME));
+ .parseToscaMetadataFile(contentHandler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME.getName()));
} catch (final IOException e) {
reportError(ErrorLevel.ERROR, Messages.METADATA_PARSER_INTERNAL.getErrorMessage());
LOGGER.error(Messages.METADATA_PARSER_INTERNAL.getErrorMessage(), e.getMessage(), e);
@@ -118,17 +136,43 @@ class SOL004MetaDirectoryValidator implements Validator {
}
}
+ private void verifySignedFiles() {
+ final Map<String, String> signedFileMap = contentHandler.getFileAndSignaturePathMap(SecurityManager.ALLOWED_SIGNATURE_EXTENSIONS);
+ final String packageCertificatePath = getCertificatePath().orElse(null);
+ final byte[] packageCert = contentHandler.getFileContent(packageCertificatePath);
+ if(packageCert == null) {
+ throw new MissingCertificateException("Expected package certificate");
+ }
+ signedFileMap.entrySet().stream().filter(entry -> entry.getValue() != null).forEach(entry -> {
+ final String filePath = entry.getKey();
+ final String fileSignaturePath = entry.getValue();
+ final byte[] fileBytes = contentHandler.getFileContent(filePath);
+ final byte[] fileSignatureBytes = contentHandler.getFileContent(fileSignaturePath);
+ try {
+ if (!securityManager.verifySignedData(fileSignatureBytes, packageCert, fileBytes)) {
+ reportError(ErrorLevel.ERROR,
+ Messages.ARTIFACT_INVALID_SIGNATURE.formatMessage(fileSignaturePath, filePath));
+ }
+ } catch (final SecurityManagerException e) {
+ final String errorMessage = Messages.ARTIFACT_SIGNATURE_VALIDATION_ERROR
+ .formatMessage(fileSignaturePath, filePath, packageCertificatePath, e.getMessage());
+ reportError(ErrorLevel.ERROR, errorMessage);
+ LOGGER.error(errorMessage, e);
+ }
+ });
+ }
+
private void verifyManifestNameAndExtension() {
final Map<String, String> entries = toscaMetadata.getMetaEntries();
- final String manifestFileName = getFileName(entries.get(TOSCA_META_ETSI_ENTRY_MANIFEST));
- final String manifestExtension = getFileExtension(entries.get(TOSCA_META_ETSI_ENTRY_MANIFEST));
- final String mainDefinitionFileName = getFileName(entries.get(TOSCA_META_ENTRY_DEFINITIONS));
+ final String manifestFileName = getFileName(entries.get(ETSI_ENTRY_MANIFEST.getName()));
+ final String manifestExtension = getFileExtension(entries.get(ETSI_ENTRY_MANIFEST.getName()));
+ final String mainDefinitionFileName = getFileName(entries.get(ENTRY_DEFINITIONS.getName()));
if (!(TOSCA_MANIFEST_FILE_EXT).equals(manifestExtension)) {
reportError(ErrorLevel.ERROR, Messages.MANIFEST_INVALID_EXT.getErrorMessage());
}
if (!mainDefinitionFileName.equals(manifestFileName)) {
reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_INVALID_NAME.getErrorMessage(),
- manifestFileName, mainDefinitionFileName));
+ manifestFileName, mainDefinitionFileName));
}
}
@@ -140,90 +184,99 @@ class SOL004MetaDirectoryValidator implements Validator {
return FilenameUtils.getBaseName(filePath);
}
- private boolean hasETSIMetadata(){
+ private boolean hasETSIMetadata() {
final Map<String, String> entries = toscaMetadata.getMetaEntries();
- return hasEntry(entries, TOSCA_META_FILE_VERSION_ENTRY)
- && hasEntry(entries, TOSCA_META_CSAR_VERSION_ENTRY)
- && hasEntry(entries, TOSCA_META_CREATED_BY_ENTRY);
+ return hasEntry(entries, TOSCA_META_FILE_VERSION_ENTRY.getName())
+ && hasEntry(entries, CSAR_VERSION_ENTRY.getName())
+ && hasEntry(entries, CREATED_BY_ENTRY.getName());
}
private boolean hasEntry(final Map<String, String> entries, final String mandatoryEntry) {
if (!entries.containsKey(mandatoryEntry)) {
- reportError(ErrorLevel.ERROR, String.format(Messages.METADATA_MISSING_ENTRY.getErrorMessage(),mandatoryEntry));
+ reportError(ErrorLevel.ERROR,
+ String.format(Messages.METADATA_MISSING_ENTRY.getErrorMessage(), mandatoryEntry));
return false;
}
return true;
}
private void handleMetadataEntries() {
- for(final Map.Entry entry: toscaMetadata.getMetaEntries().entrySet()){
- handleEntry(entry);
- }
+ toscaMetadata.getMetaEntries().entrySet().parallelStream().forEach(this::handleEntry);
}
private void handleEntry(final Map.Entry<String, String> entry) {
final String key = entry.getKey();
+ final ToscaMetaEntry toscaMetaEntry = ToscaMetaEntry.parse(entry.getKey()).orElse(null);
+ if (toscaMetaEntry == null) {
+ reportError(ErrorLevel.ERROR, Messages.METADATA_UNSUPPORTED_ENTRY.formatMessage(key));
+ LOGGER.warn(Messages.METADATA_UNSUPPORTED_ENTRY.getErrorMessage(), key);
+ return;
+ }
final String value = entry.getValue();
- switch (key){
+
+ switch (toscaMetaEntry) {
case TOSCA_META_FILE_VERSION_ENTRY:
- case TOSCA_META_CSAR_VERSION_ENTRY:
- case TOSCA_META_CREATED_BY_ENTRY:
+ case CSAR_VERSION_ENTRY:
+ case CREATED_BY_ENTRY:
verifyMetadataEntryVersions(key, value);
break;
- case TOSCA_META_ENTRY_DEFINITIONS:
+ case ENTRY_DEFINITIONS:
validateDefinitionFile(value);
break;
- case TOSCA_META_ETSI_ENTRY_MANIFEST:
+ case ETSI_ENTRY_MANIFEST:
validateManifestFile(value);
break;
- case TOSCA_META_ETSI_ENTRY_CHANGE_LOG:
+ case ETSI_ENTRY_CHANGE_LOG:
validateChangeLog(value);
break;
- case TOSCA_META_ETSI_ENTRY_TESTS:
- case TOSCA_META_ETSI_ENTRY_LICENSES:
+ case ETSI_ENTRY_TESTS:
+ case ETSI_ENTRY_LICENSES:
validateOtherEntries(entry);
break;
- case TOSCA_META_ETSI_ENTRY_CERTIFICATE:
- validateOtherEntries(value);
+ case ETSI_ENTRY_CERTIFICATE:
+ validateCertificate(value);
break;
default:
- reportError(ErrorLevel.ERROR, Messages.METADATA_UNSUPPORTED_ENTRY.formatMessage(entry.toString()));
- LOGGER.warn(Messages.METADATA_UNSUPPORTED_ENTRY.getErrorMessage(), entry);
+ reportError(ErrorLevel.ERROR, Messages.METADATA_UNSUPPORTED_ENTRY.formatMessage(key));
+ LOGGER.warn(Messages.METADATA_UNSUPPORTED_ENTRY.getErrorMessage(), key);
break;
}
}
private void validateOtherEntries(final Map.Entry entry) {
- final String manifestFile = toscaMetadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_MANIFEST);
- if(verifyFileExists(contentHandler.getFileList(), manifestFile)){
+ final String manifestFile = toscaMetadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName());
+ if (verifyFileExists(contentHandler.getFileList(), manifestFile)) {
final Manifest onboardingManifest = new SOL004ManifestOnboarding();
onboardingManifest.parse(contentHandler.getFileContentAsStream(manifestFile));
final Optional<ResourceTypeEnum> resourceType = onboardingManifest.getType();
- if (resourceType.isPresent() && resourceType.get() == ResourceTypeEnum.VF){
+ if (resourceType.isPresent() && resourceType.get() == ResourceTypeEnum.VF) {
final String value = (String) entry.getValue();
validateOtherEntries(value);
} else {
final String key = (String) entry.getKey();
- reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_INVALID_PNF_METADATA.getErrorMessage(), key));
+ reportError(ErrorLevel.ERROR,
+ String.format(Messages.MANIFEST_INVALID_PNF_METADATA.getErrorMessage(), key));
}
}
}
private void verifyMetadataEntryVersions(final String key, final String version) {
- if(!(isValidTOSCAVersion(key,version) || isValidCSARVersion(key, version) || TOSCA_META_CREATED_BY_ENTRY.equals(key))) {
- errorsByFile.add(new ErrorMessage(ErrorLevel.ERROR, String.format(Messages.METADATA_INVALID_VERSION.getErrorMessage(), key, version)));
+ if (!(isValidTOSCAVersion(key, version) || isValidCSARVersion(key, version)
+ || CREATED_BY_ENTRY.getName().equals(key))) {
+ errorsByFile.add(new ErrorMessage(ErrorLevel.ERROR,
+ String.format(Messages.METADATA_INVALID_VERSION.getErrorMessage(), key, version)));
LOGGER.error("{}: key {} - value {} ", Messages.METADATA_INVALID_VERSION.getErrorMessage(), key, version);
}
}
- private boolean isValidTOSCAVersion(final String key, final String version){
- return TOSCA_META_FILE_VERSION_ENTRY.equals(key) && TOSCA_META_FILE_VERSION.equals(version);
+ private boolean isValidTOSCAVersion(final String key, final String version) {
+ return TOSCA_META_FILE_VERSION_ENTRY.getName().equals(key) && TOSCA_META_FILE_VERSION.getName().equals(version);
}
- private boolean isValidCSARVersion(final String value, final String version){
- return TOSCA_META_CSAR_VERSION_ENTRY.equals(value) && (CSAR_VERSION_1_1.equals(version)
- || CSAR_VERSION_1_0.equals(version));
+ private boolean isValidCSARVersion(final String value, final String version) {
+ return CSAR_VERSION_ENTRY.getName().equals(value) && (CSAR_VERSION_1_1.equals(version)
+ || CSAR_VERSION_1_0.equals(version));
}
private void validateDefinitionFile(final String filePath) {
@@ -274,9 +327,9 @@ class SOL004MetaDirectoryValidator implements Validator {
MANIFEST_METADATA_LIMIT));
}
if (isPnfMetadata(metadata)) {
- handlePnfMetadataEntries(metadata);
+ handleMetadataEntries(metadata, MANIFEST_PNF_METADATA);
} else {
- handleVnfMetadataEntries(metadata);
+ handleMetadataEntries(metadata, MANIFEST_VNF_METADATA);
}
}
@@ -292,26 +345,18 @@ class SOL004MetaDirectoryValidator implements Validator {
return TOSCA_TYPE_PNF.equals(expectedMetadataType);
}
- private void handleVnfMetadataEntries(final Map<String, String> metadata) {
- for (final String requiredVnfEntry : MANIFEST_VNF_METADATA) {
- if (!metadata.containsKey(requiredVnfEntry)) {
- reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_METADATA_MISSING_ENTRY.getErrorMessage(), requiredVnfEntry));
- }
- }
- }
-
- private void handlePnfMetadataEntries(final Map<String, String> metadata) {
- for (final String requiredPnfEntry : MANIFEST_PNF_METADATA) {
- if (!metadata.containsKey(requiredPnfEntry)) {
- reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_METADATA_MISSING_ENTRY.getErrorMessage(), requiredPnfEntry));
- }
- }
+ private void handleMetadataEntries(final Map<String, String> metadata, final Set<String> manifestMetadata) {
+ manifestMetadata.stream()
+ .filter(requiredEntry -> !metadata.containsKey(requiredEntry))
+ .forEach(requiredEntry ->
+ reportError(ErrorLevel.ERROR,
+ String.format(Messages.MANIFEST_METADATA_MISSING_ENTRY.getErrorMessage(), requiredEntry)));
}
/**
* Checks if all manifest sources exists within the package and if all package files are being referred.
*
- * @param onboardingManifest The manifest
+ * @param onboardingManifest The manifest
*/
private void verifyManifestSources(final Manifest onboardingManifest) {
final Set<String> packageFiles = contentHandler.getFileList();
@@ -338,10 +383,10 @@ class SOL004MetaDirectoryValidator implements Validator {
}
/**
- * Validates if a YAML file has the correct extension, is not empty and the content is a valid YAML.
- * Reports each error found.
+ * Validates if a YAML file has the correct extension, is not empty and the content is a valid YAML. Reports each
+ * error found.
*
- * @param filePath the file path inside the package
+ * @param filePath the file path inside the package
*/
private void validateYaml(final String filePath) {
if (!contentHandler.containsFile(filePath)) {
@@ -366,34 +411,43 @@ class SOL004MetaDirectoryValidator implements Validator {
}
/**
- * Checks if all package files are referred in manifest.
- * Reports missing references.
+ * Checks if all package files are referred in manifest. Reports missing references.
*
- * @param referredFileSet the list of referred files path
- * @param packageFileSet the list of package file path
+ * @param referredFileSet the list of referred files path
+ * @param packageFileSet the list of package file path
*/
private void verifyFilesBeingReferred(final Set<String> referredFileSet, final Set<String> packageFileSet) {
packageFileSet.forEach(filePath -> {
if (!referredFileSet.contains(filePath)) {
- reportError(ErrorLevel.ERROR, String.format(Messages.MISSING_MANIFEST_REFERENCE.getErrorMessage(), filePath));
+ reportError(ErrorLevel.ERROR,
+ String.format(Messages.MISSING_MANIFEST_REFERENCE.getErrorMessage(), filePath));
}
});
}
- private List<String> filterSources(final List<String> source){
+ private List<String> filterSources(final List<String> source) {
return source.stream()
- .filter(this::externalFileReferences)
- .collect(Collectors.toList());
+ .filter(this::externalFileReferences)
+ .collect(Collectors.toList());
}
- private boolean externalFileReferences(final String filePath){
+ private boolean externalFileReferences(final String filePath) {
return !filePath.contains("://");
}
private void validateOtherEntries(final String folderPath) {
- if(!verifyFoldersExist(folderList, folderPath))
+ if (!verifyFoldersExist(folderList, folderPath)) {
reportError(ErrorLevel.ERROR, String.format(Messages.METADATA_MISSING_OPTIONAL_FOLDERS.getErrorMessage(),
- folderPath));
+ folderPath));
+ }
+ }
+
+ private void validateCertificate(final String file) {
+ final Set<String> packageFiles = contentHandler.getFileList();
+ if (!verifyFileExist(packageFiles, file)) {
+ reportError(ErrorLevel.ERROR,
+ String.format(Messages.MISSING_METADATA_FILES.getErrorMessage(), file, file));
+ }
}
private boolean verifyFoldersExist(final Set<String> folderList, final String folderPath) {
@@ -402,14 +456,19 @@ class SOL004MetaDirectoryValidator implements Validator {
private void verifyFilesExist(final Set<String> existingFiles, final List<String> sources, final String type) {
sources.forEach(file -> {
- if(!existingFiles.contains(file)){
- reportError(ErrorLevel.ERROR, String.format(Messages.MISSING_MANIFEST_SOURCE.getErrorMessage(), type, file));
+ if (!existingFiles.contains(file)) {
+ reportError(ErrorLevel.ERROR,
+ String.format(Messages.MISSING_MANIFEST_SOURCE.getErrorMessage(), type, file));
}
});
}
+ private boolean verifyFileExist(final Set<String> existingFiles, final String file) {
+ return existingFiles.contains(file);
+ }
+
private void validateChangeLog(final String filePath) {
- if(!verifyFileExists(contentHandler.getFileList(), filePath)){
+ if (!verifyFileExists(contentHandler.getFileList(), filePath)) {
reportError(ErrorLevel.ERROR, String.format(Messages.MISSING_METADATA_FILES.getErrorMessage(), filePath));
}
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/exception/MissingCertificateException.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/exception/MissingCertificateException.java
new file mode 100644
index 0000000000..620ff345ad
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/exception/MissingCertificateException.java
@@ -0,0 +1,27 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.exception;
+
+public class MissingCertificateException extends RuntimeException {
+
+ public MissingCertificateException(String s) {
+ super(s);
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java
index 2928905603..53c2e1d0bc 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManager.java
@@ -72,6 +72,8 @@ import org.openecomp.sdc.logging.api.LoggerFactory;
public class SecurityManager {
private static final String CERTIFICATE_DEFAULT_LOCATION = "cert";
+ public static final Set<String> ALLOWED_SIGNATURE_EXTENSIONS = ImmutableSet.of("cms");
+ public static final Set<String> ALLOWED_CERTIFICATE_EXTENSIONS = ImmutableSet.of("cert", "crt");
private Logger logger = LoggerFactory.getLogger(SecurityManager.class);
private Set<X509Certificate> trustedCertificates = new HashSet<>();
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackage.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackage.java
index 60bd5ae0a0..1551cd8a1d 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackage.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/OnboardPackage.java
@@ -22,9 +22,10 @@ package org.openecomp.sdc.vendorsoftwareproduct.types;
import java.nio.ByteBuffer;
import lombok.Getter;
import org.openecomp.core.utilities.file.FileContentHandler;
-import org.openecomp.sdc.common.zip.exception.ZipException;
import org.openecomp.sdc.common.utils.CommonUtil;
+import org.openecomp.sdc.common.zip.exception.ZipException;
import org.openecomp.sdc.vendorsoftwareproduct.exception.OnboardPackageException;
+import org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding.OnboardingPackageContentHandler;
@Getter
public class OnboardPackage {
@@ -48,14 +49,14 @@ public class OnboardPackage {
this.fileExtension = fileExtension;
this.fileContent = fileContent;
try {
- fileContentHandler = CommonUtil.getZipContent(fileContent.array());
+ fileContentHandler = new OnboardingPackageContentHandler(CommonUtil.getZipContent(fileContent.array()));
} catch (final ZipException e) {
throw new OnboardPackageException("Could not read the package content", e);
}
}
- public OnboardPackage(final String packageName, final String packageExtension, final byte[] packageContentBytes)
- throws OnboardPackageException {
- this(packageName, packageExtension, ByteBuffer.wrap(packageContentBytes));
+ public OnboardPackage(final String packageName, final String packageExtension, final byte[] packageContentBytes,
+ final FileContentHandler fileContentHandler) {
+ this(packageName, packageExtension, ByteBuffer.wrap(packageContentBytes), fileContentHandler);
}
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java
index fb1ab0306e..e203187183 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java
@@ -32,7 +32,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME;
import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME;
import java.io.IOException;
import java.io.InputStream;
@@ -91,6 +91,8 @@ import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.openecomp.sdc.versioning.types.VersionInfo;
import org.openecomp.sdc.versioning.types.VersionableEntityAction;
+//import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
+
public class VendorSoftwareProductManagerImplTest {
@@ -159,7 +161,7 @@ public class VendorSoftwareProductManagerImplTest {
final FileContentHandler handler = new FileContentHandler();
final byte[] metadataInputBytes = IOUtils.toByteArray(metadataInput);
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metadataInputBytes);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metadataInputBytes);
handler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME, metadataInputBytes);
handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput));
final ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
@@ -183,7 +185,7 @@ public class VendorSoftwareProductManagerImplTest {
try(InputStream metadataInput = getClass().getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta"))
{
FileContentHandler handler = new FileContentHandler();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, IOUtils.toByteArray(metadataInput));
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), IOUtils.toByteArray(metadataInput));
ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata );
VspDetails vsp =
@@ -210,7 +212,7 @@ public class VendorSoftwareProductManagerImplTest {
final FileContentHandler handler = new FileContentHandler();
final byte[] metadataInputBytes = IOUtils.toByteArray(metadataInput);
handler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME, metadataInputBytes);
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metadataInputBytes);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metadataInputBytes);
handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput));
final ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata);
@@ -492,7 +494,7 @@ public class VendorSoftwareProductManagerImplTest {
Assert.assertNotNull(validationResponse);
Assert.assertFalse(validationResponse.isValid());
Assert.assertNotNull(validationResponse.getVspErrors());
- Assert.assertEquals(validationResponse.getVspErrors().size(), 1);
+ Assert.assertEquals(1, validationResponse.getVspErrors().size());
}
@@ -516,7 +518,7 @@ public class VendorSoftwareProductManagerImplTest {
Assert.assertNotNull(validationResponse);
Assert.assertFalse(validationResponse.isValid());
Assert.assertNotNull(validationResponse.getVspErrors());
- Assert.assertEquals(validationResponse.getVspErrors().size(), 1);
+ Assert.assertEquals(1, validationResponse.getVspErrors().size());
}
private static VspDetails createVspDetails(String id, Version version, String name, String desc,
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidatorTest.java
index 799e0cc342..3ba50afea5 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidatorTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidatorTest.java
@@ -26,7 +26,6 @@ import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.sdc.common.utils.SdcCommon;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
import java.util.Map;
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java
index 17b06793a2..7ff800d07b 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java
@@ -23,17 +23,11 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validati
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CERTIFICATE;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CHANGE_LOG;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_LICENSES;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_MANIFEST;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_TESTS;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ATTRIBUTE_VALUE_SEPARATOR;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_ARCHIVE_VERSION;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.PNFD_NAME;
@@ -42,6 +36,16 @@ import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_PACKAGE_VERSION
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_PRODUCT_NAME;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_PROVIDER_ID;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.VNF_RELEASE_DATE_TIME;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.CREATED_BY_ENTRY;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.CSAR_VERSION_ENTRY;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_EVENTS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_CHANGE_LOG;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_LICENSES;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_MANIFEST;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_TESTS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_FILE_VERSION_ENTRY;
import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_PM_DICTIONARY;
import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_VES_EVENTS;
import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.EMPTY_YAML_FILE_PATH;
@@ -62,7 +66,6 @@ import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.junit.Before;
import org.junit.Test;
-import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.sdc.common.errors.Messages;
import org.openecomp.sdc.common.utils.SdcCommon;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
@@ -70,26 +73,34 @@ import org.openecomp.sdc.datatypes.error.ErrorMessage;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.tosca.csar.ManifestTokenType;
+import org.openecomp.sdc.tosca.csar.ToscaMetaEntry;
+import org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding.OnboardingPackageContentHandler;
public class SOL004MetaDirectoryValidatorTest {
private static final Logger LOGGER = LoggerFactory.getLogger(SOL004MetaDirectoryValidatorTest.class);
private SOL004MetaDirectoryValidator sol004MetaDirectoryValidator;
- private FileContentHandler handler;
- private String metaFile;
+ private OnboardingPackageContentHandler handler;
+ private StringBuilder metaFileBuilder;
@Before
public void setUp() {
sol004MetaDirectoryValidator = new SOL004MetaDirectoryValidator();
- handler = new FileContentHandler();
- metaFile =
- "TOSCA-Meta-File-Version: 1.0\n"+
- "CSAR-Version: 1.1\n"+
- "Created-By: Vendor\n"+
- TOSCA_META_ENTRY_DEFINITIONS + ATTRIBUTE_VALUE_SEPARATOR.getToken() + "Definitions/MainServiceTemplate.yaml\n"+
- TOSCA_META_ETSI_ENTRY_MANIFEST + ATTRIBUTE_VALUE_SEPARATOR.getToken() + "Definitions/MainServiceTemplate.mf\n"+
- TOSCA_META_ETSI_ENTRY_CHANGE_LOG + ATTRIBUTE_VALUE_SEPARATOR.getToken() + "Artifacts/changeLog.text\n";
+ handler = new OnboardingPackageContentHandler();
+ metaFileBuilder = new StringBuilder()
+ .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.0").append("\n")
+ .append(CSAR_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.1").append("\n")
+ .append(CREATED_BY_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Vendor").append("\n")
+ .append(ENTRY_DEFINITIONS.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Definitions/MainServiceTemplate.yaml").append("\n")
+ .append(ETSI_ENTRY_MANIFEST.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Definitions/MainServiceTemplate.mf").append("\n")
+ .append(ETSI_ENTRY_CHANGE_LOG.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Artifacts/changeLog.text").append("\n");
}
@Test
@@ -97,7 +108,7 @@ public class SOL004MetaDirectoryValidatorTest {
final String metaFileWithInvalidEntry = "TOSCA-Meta-File-Version: \n" +
"Entry-Definitions: Definitions/MainServiceTemplate.yaml";
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileWithInvalidEntry.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileWithInvalidEntry.getBytes(StandardCharsets.UTF_8));
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
@@ -112,12 +123,13 @@ public class SOL004MetaDirectoryValidatorTest {
handler.addFolder("Files/Tests/");
handler.addFolder("Files/Licenses/");
+ metaFileBuilder
+ .append(ETSI_ENTRY_TESTS.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(entryTestFilePath).append("\n")
+ .append(ETSI_ENTRY_LICENSES.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(entryLicenseFilePath).append("\n");
- metaFile = metaFile +
- TOSCA_META_ETSI_ENTRY_TESTS + ATTRIBUTE_VALUE_SEPARATOR.getToken() + entryTestFilePath + "\n" +
- TOSCA_META_ETSI_ENTRY_LICENSES + ATTRIBUTE_VALUE_SEPARATOR.getToken() + entryLicenseFilePath +"\n";
-
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
@@ -127,7 +139,7 @@ public class SOL004MetaDirectoryValidatorTest {
handler.addFile(entryLicenseFilePath, "".getBytes());
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder()
- .withSource(TOSCA_META_PATH_FILE_NAME)
+ .withSource(TOSCA_META_PATH_FILE_NAME.getName())
.withSource(TOSCA_DEFINITION_FILEPATH)
.withSource(TOSCA_CHANGELOG_FILEPATH)
.withSource(TOSCA_MANIFEST_FILEPATH).withSource(SAMPLE_SOURCE)
@@ -143,9 +155,12 @@ public class SOL004MetaDirectoryValidatorTest {
@Test
public void testGivenTOSCAMeta_withUnsupportedEntry_thenWarningIsReturned() {
- metaFile = "Entry-Events: Definitions/events.log";
+ metaFileBuilder = new StringBuilder()
+ .append(ENTRY_EVENTS.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken())
+ .append(" Definitions/events.log");
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
assertTrue(errors.size() == 1 && errorMessages.size() == 1);
@@ -157,18 +172,23 @@ public class SOL004MetaDirectoryValidatorTest {
*/
@Test
public void testGivenTOSCAMetaFile_withInvalidTOSCAMetaFileVersionAndCSARVersion_thenErrorIsReturned() {
- final String metaFile =
- "TOSCA-Meta-File-Version: " + Integer.MAX_VALUE +
- "\nCSAR-Version: " + Integer.MAX_VALUE +
- "\nCreated-By: Bilal Iqbal\n" +
- TOSCA_META_ENTRY_DEFINITIONS + ATTRIBUTE_VALUE_SEPARATOR.getToken() + "Definitions/MainServiceTemplate.yaml\n" +
- TOSCA_META_ETSI_ENTRY_MANIFEST + ATTRIBUTE_VALUE_SEPARATOR.getToken() + "Definitions/MainServiceTemplate.mf\n"+
- TOSCA_META_ETSI_ENTRY_CHANGE_LOG + ATTRIBUTE_VALUE_SEPARATOR.getToken() + "Artifacts/changeLog.text";
-
+ final StringBuilder metaFileBuilder = new StringBuilder()
+ .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(Integer.MAX_VALUE).append("\n")
+ .append(CSAR_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(Integer.MAX_VALUE).append("\n")
+ .append(CREATED_BY_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Vendor").append("\n")
+ .append(ENTRY_DEFINITIONS.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Definitions/MainServiceTemplate.yaml").append("\n")
+ .append(ETSI_ENTRY_MANIFEST.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Definitions/MainServiceTemplate.mf").append("\n")
+ .append(ETSI_ENTRY_CHANGE_LOG.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Artifacts/changeLog.text");
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
@@ -185,11 +205,12 @@ public class SOL004MetaDirectoryValidatorTest {
@Test
public void testGivenTOSCAMetaFile_withNonExistentFileReferenced_thenErrorsReturned() {
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
- assertTrue(errors.size() == 1 && errorMessages.size() == 3);
+ assertThat("Total of errors should be as expected", errors.size(), is(1));
+ final List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
+ assertThat("Total of errors messages should be as expected", errorMessages.size(), is(3));
}
@@ -197,8 +218,8 @@ public class SOL004MetaDirectoryValidatorTest {
public void testGivenDefinitionFile_whenValidImportStatementExist_thenNoErrorsReturned() {
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -224,8 +245,8 @@ public class SOL004MetaDirectoryValidatorTest {
public void testGivenDefinitionFile_whenMultipleDefinitionsImportStatementExist_thenNoErrorsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -256,8 +277,8 @@ public class SOL004MetaDirectoryValidatorTest {
public void testGivenDefinitionFile_whenInvalidImportStatementExist_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -284,8 +305,8 @@ public class SOL004MetaDirectoryValidatorTest {
public void testGivenDefinitionFile_whenReferencedImportDoesNotExist_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -313,8 +334,8 @@ public class SOL004MetaDirectoryValidatorTest {
public void testGivenDefinitionFile_withInvalidYAML_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -337,8 +358,8 @@ public class SOL004MetaDirectoryValidatorTest {
public void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() {
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -372,8 +393,8 @@ public class SOL004MetaDirectoryValidatorTest {
//non existent reference
manifestBuilder.withSource("Artifacts/Deployment/Events/RadioNode_pnf_v1.yaml");
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -400,7 +421,7 @@ public class SOL004MetaDirectoryValidatorTest {
*/
@Test
public void testGivenManifestFile_withInvalidData_thenErrorIsReturned() {
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
handler.addFile(TOSCA_MANIFEST_FILEPATH, getResourceBytes("/validation.files/manifest/invalidManifest.mf"));
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
@@ -414,8 +435,8 @@ public class SOL004MetaDirectoryValidatorTest {
public void testGivenManifestAndDefinitionFile_withSameNames_thenNoErrorReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -438,18 +459,24 @@ public class SOL004MetaDirectoryValidatorTest {
*/
@Test
public void testGivenManifestAndMainDefinitionFile_withDifferentNames_thenErrorIsReturned() {
- metaFile =
- "TOSCA-Meta-File-Version: 1.0\n"+
- "CSAR-Version: 1.1\n"+
- "Created-By: Vendor\n"+
- TOSCA_META_ENTRY_DEFINITIONS + ATTRIBUTE_VALUE_SEPARATOR.getToken() + "Definitions/MainServiceTemplate.yaml\n"+
- TOSCA_META_ETSI_ENTRY_MANIFEST + ATTRIBUTE_VALUE_SEPARATOR.getToken() +"Definitions/MainServiceTemplate2.mf\n"+
- TOSCA_META_ETSI_ENTRY_CHANGE_LOG + ATTRIBUTE_VALUE_SEPARATOR.getToken() +"Artifacts/changeLog.text\n";
+ metaFileBuilder = new StringBuilder()
+ .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.0").append("\n")
+ .append(CSAR_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.1").append("\n")
+ .append(CREATED_BY_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Vendor").append("\n")
+ .append(ENTRY_DEFINITIONS.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Definitions/MainServiceTemplate.yaml\n")
+ .append(ETSI_ENTRY_MANIFEST.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Definitions/MainServiceTemplate2.mf\n")
+ .append(ETSI_ENTRY_CHANGE_LOG.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Artifacts/changeLog.text\n");
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -470,18 +497,24 @@ public class SOL004MetaDirectoryValidatorTest {
@Test
public void testGivenManifestFile_withDifferentExtension_thenErrorIsReturned() {
- metaFile =
- "TOSCA-Meta-File-Version: 1.0\n"+
- "CSAR-Version: 1.1\n"+
- "Created-By: Vendor\n"+
- "Entry-Definitions: Definitions/MainServiceTemplate.yaml\n"+
- TOSCA_META_ETSI_ENTRY_MANIFEST + ATTRIBUTE_VALUE_SEPARATOR.getToken() + "Definitions/MainServiceTemplate.txt\n"+
- TOSCA_META_ETSI_ENTRY_CHANGE_LOG + ATTRIBUTE_VALUE_SEPARATOR.getToken() + "Artifacts/changeLog.text\n";
+ metaFileBuilder = new StringBuilder()
+ .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.0").append("\n")
+ .append(CSAR_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.1").append("\n")
+ .append(CREATED_BY_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Vendor").append("\n")
+ .append(ENTRY_DEFINITIONS.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Definitions/MainServiceTemplate.yaml\n")
+ .append(ETSI_ENTRY_MANIFEST.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Definitions/MainServiceTemplate.txt\n")
+ .append(ETSI_ENTRY_CHANGE_LOG.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Artifacts/changeLog.text\n");
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -504,8 +537,8 @@ public class SOL004MetaDirectoryValidatorTest {
public void testGivenManifestFile_withValidVnfMetadata_thenNoErrorsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
@@ -522,8 +555,8 @@ public class SOL004MetaDirectoryValidatorTest {
public void testGivenManifestFile_withValidPnfMetadata_thenNoErrorsReturned() {
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -550,8 +583,8 @@ public class SOL004MetaDirectoryValidatorTest {
.withMetaData(PNFD_ARCHIVE_VERSION.getToken(), "1.0")
.withMetaData(VNF_RELEASE_DATE_TIME.getToken(), "2019-12-14T11:25:00+00:00");
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
@@ -573,8 +606,8 @@ public class SOL004MetaDirectoryValidatorTest {
.withMetaData("invalid_package_version", "1.0")
.withMetaData("invalid_release_date_time", "2019-12-14T11:25:00+00:00");
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -596,8 +629,8 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withMetaData(PNFD_NAME.getToken(), "RadioNode");
manifestBuilder.withMetaData(PNFD_RELEASE_DATE_TIME.getToken(), "2019-12-14T11:25:00+00:00");
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -619,8 +652,8 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withMetaData(VNF_PRODUCT_NAME.getToken(), "RadioNode");
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -647,8 +680,8 @@ public class SOL004MetaDirectoryValidatorTest {
.withMetaData(PNFD_ARCHIVE_VERSION.getToken(), "1.0")
.withMetaData(PNFD_RELEASE_DATE_TIME.getToken(), "2019-03-11T11:25:00+00:00");
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -666,14 +699,14 @@ public class SOL004MetaDirectoryValidatorTest {
@Test
public void testGivenManifestFile_withPnfMetadataAndVfEntries_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
+ metaFileBuilder
+ .append(ETSI_ENTRY_TESTS.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Files/Tests").append("\n")
+ .append(ETSI_ENTRY_LICENSES.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Files/Licenses");
- metaFile = metaFile +
- TOSCA_META_ETSI_ENTRY_TESTS + ATTRIBUTE_VALUE_SEPARATOR.getToken() + "Files/Tests\n" +
- TOSCA_META_ETSI_ENTRY_LICENSES + ATTRIBUTE_VALUE_SEPARATOR.getToken() + "Files/Licenses\n" +
- TOSCA_META_ETSI_ENTRY_CERTIFICATE + ATTRIBUTE_VALUE_SEPARATOR.getToken() + "Files/Certificates";
-
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -683,7 +716,6 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- handler.addFolder("Files/Certificates/");
final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
assertExpectedErrors("Tosca.meta should not have entries applicable only to VF", errors, 2);
@@ -696,8 +728,8 @@ public class SOL004MetaDirectoryValidatorTest {
public void testGivenDefinitionFileWithImportedDescriptor_whenImportedDescriptorImportsMissingFile_thenMissingImportErrorOccur() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -733,8 +765,8 @@ public class SOL004MetaDirectoryValidatorTest {
public void testGivenDefinitionFileWithImportedDescriptor_whenInvalidImportStatementExistInImportedDescriptor_thenInvalidImportErrorOccur() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
@@ -767,8 +799,8 @@ public class SOL004MetaDirectoryValidatorTest {
public void givenManifestWithNonManoPmAndVesArtifacts_whenNonManoArtifactsAreValid_thenNoErrorsOccur() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
@@ -797,8 +829,8 @@ public class SOL004MetaDirectoryValidatorTest {
public void givenManifestWithNonManoPmOrVesArtifacts_whenNonManoArtifactsYamlAreInvalid_thenInvalidYamlErrorOccur() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
@@ -835,8 +867,8 @@ public class SOL004MetaDirectoryValidatorTest {
public void givenManifestWithNonManoPmOrVesArtifacts_whenNonManoArtifactsYamlAreEmpty_thenEmptyYamlErrorOccur() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
@@ -873,8 +905,8 @@ public class SOL004MetaDirectoryValidatorTest {
public void givenManifestWithNonManoPmOrVesArtifacts_whenNonManoArtifactsHaveNotYamlExtension_thenInvalidYamlExtensionErrorOccur() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME.getName());
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java
index 344fe8b6f5..c8ca1a554b 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java
@@ -27,11 +27,14 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import static org.junit.Assert.assertEquals;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CHANGE_LOG;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_MANIFEST;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ATTRIBUTE_VALUE_SEPARATOR;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.CREATED_BY_ENTRY;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.CSAR_VERSION_ENTRY;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_CHANGE_LOG;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_MANIFEST;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_FILE_VERSION_ENTRY;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME;
import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_CHANGELOG_FILEPATH;
import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_DEFINITION_FILEPATH;
import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_MANIFEST_FILEPATH;
@@ -44,15 +47,19 @@ public class ValidatorFactoryTest {
@Before
public void setUp(){
handler = new FileContentHandler();
- metaFile =
- "TOSCA-Meta-File-Version: 1.0\n" +
- "CSAR-Version: 1.1\n" +
- "Created-By: Bilal Iqbal\n";
+ metaFile = new StringBuilder()
+ .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.0").append("\n")
+ .append(CSAR_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.1").append("\n")
+ .append(CREATED_BY_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Vendor").append("\n")
+ .toString();
}
@Test(expected = IOException.class)
public void testGivenEmptyMetaFile_thenIOExceptionIsThrown() throws IOException{
- handler.addFile(TOSCA_META_PATH_FILE_NAME, "".getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), "".getBytes(StandardCharsets.UTF_8));
handler.addFile(TOSCA_DEFINITION_FILEPATH, "".getBytes());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
handler.addFile(TOSCA_MANIFEST_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
@@ -62,7 +69,7 @@ public class ValidatorFactoryTest {
@Test
public void testGivenEmptyBlock0_thenONAPCsarValidatorIsReturned() throws IOException{
- handler.addFile(TOSCA_META_PATH_FILE_NAME, " ".getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), " ".getBytes(StandardCharsets.UTF_8));
handler.addFile(TOSCA_DEFINITION_FILEPATH, "".getBytes());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
handler.addFile(TOSCA_MANIFEST_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
@@ -74,8 +81,8 @@ public class ValidatorFactoryTest {
@Test
public void testGivenNonSOL004MetaDirectoryCompliantMetaFile_thenONAPCSARValidatorIsReturned() throws IOException{
metaFile = metaFile +
- TOSCA_META_ENTRY_DEFINITIONS + ATTRIBUTE_VALUE_SEPARATOR.getToken() + TOSCA_DEFINITION_FILEPATH;
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+ ENTRY_DEFINITIONS.getName() + ATTRIBUTE_VALUE_SEPARATOR.getToken() + TOSCA_DEFINITION_FILEPATH;
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFile.getBytes(StandardCharsets.UTF_8));
assertEquals(ONAPCsarValidator.class, ValidatorFactory.getValidator(handler).getClass());
}
@@ -84,10 +91,10 @@ public class ValidatorFactoryTest {
public void testGivenSOL004MetaDirectoryCompliantMetafile_thenONAPCsarValidatorIsReturned() throws IOException{
metaFile = metaFile +
- TOSCA_META_ENTRY_DEFINITIONS + ATTRIBUTE_VALUE_SEPARATOR.getToken() + TOSCA_DEFINITION_FILEPATH + "\n"
- + TOSCA_META_ETSI_ENTRY_MANIFEST + ATTRIBUTE_VALUE_SEPARATOR.getToken() + TOSCA_MANIFEST_FILEPATH + "\n"
- + TOSCA_META_ETSI_ENTRY_CHANGE_LOG + ATTRIBUTE_VALUE_SEPARATOR.getToken() + TOSCA_CHANGELOG_FILEPATH + "\n";
- handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+ ENTRY_DEFINITIONS.getName() + ATTRIBUTE_VALUE_SEPARATOR.getToken() + TOSCA_DEFINITION_FILEPATH + "\n"
+ + ETSI_ENTRY_MANIFEST.getName() + ATTRIBUTE_VALUE_SEPARATOR.getToken() + TOSCA_MANIFEST_FILEPATH + "\n"
+ + ETSI_ENTRY_CHANGE_LOG.getName() + ATTRIBUTE_VALUE_SEPARATOR.getToken() + TOSCA_CHANGELOG_FILEPATH + "\n";
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metaFile.getBytes(StandardCharsets.UTF_8));
assertEquals(SOL004MetaDirectoryValidator.class, ValidatorFactory.getValidator(handler).getClass());
}
@@ -95,7 +102,7 @@ public class ValidatorFactoryTest {
@Test
public void testGivenMultiBlockMetadataWithSOL00CompliantMetaFile_thenSOL004MetaDirectoryValidatorReturned() throws IOException {
- handler.addFile(TOSCA_META_PATH_FILE_NAME, ValidatorUtil.getFileResource("/validation.files/metafile/metaFileWithMultipleBlocks.meta"));
+ handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), ValidatorUtil.getFileResource("/validation.files/metafile/metaFileWithMultipleBlocks.meta"));
handler.addFile(TOSCA_DEFINITION_FILEPATH, "".getBytes());
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
handler.addFile(TOSCA_MANIFEST_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
index 99de164fb3..5e5f82862e 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
@@ -59,6 +59,7 @@ public enum Messages {
MANIFEST_EMPTY("The manifest is empty"),
MANIFEST_ERROR_WITH_LINE("%s;%nAt line %s: '%s'."),
MANIFEST_PARSER_INTERNAL("Invalid manifest file"),
+ MANIFEST_UNEXPECTED_ERROR("An unexpected error occurred while validating manifest '%s': %s"),
METADATA_PARSER_INTERNAL("Invalid Metadata file"),
METADATA_MISSING_OPTIONAL_FOLDERS("Missing folder %s in package"),
METADATA_UNSUPPORTED_ENTRY("Following entry not supported in TOSCA.meta %s"),
@@ -68,6 +69,9 @@ public enum Messages {
METADATA_NO_ENTRY_DEFINITIONS("TOSCA.meta must contain Entry Definitions"),
METADATA_INVALID_ENTRY_DEFINITIONS("TOSCA.meta must contain key:value entries"),
FAILED_TO_VALIDATE_METADATA("Failed to validate metadata file"),
+ ARTIFACT_INVALID_SIGNATURE("Invalid signature '%s' provided for artifact '%s'"),
+ ARTIFACT_SIGNATURE_VALIDATION_ERROR(
+ "Could not validate signature '%s' provided for artifact '%s' with certificate '%s': %s"),
FAILED_TO_TRANSLATE_ZIP_FILE("Failed to translate zip file"),
ZIP_NOT_EXIST("Zip file doesn't exist"),
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java
index cc13879b96..db5be60149 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java
@@ -33,6 +33,13 @@ public class FileContentHandler {
private Map<String, byte[]> files = new HashMap<>();
+ public FileContentHandler() {
+ }
+
+ public FileContentHandler(final FileContentHandler other) {
+ addAll(other);
+ }
+
/**
* Gets file content as stream.
*
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java
index ca60577b29..d6b1194b81 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java
@@ -23,11 +23,11 @@ package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi;
import static org.openecomp.sdc.tosca.csar.CSARConstants.ARTIFACTS_FOLDER;
import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME;
import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CHANGE_LOG;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_MANIFEST;
import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_CHANGE_LOG;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_MANIFEST;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME;
import java.io.IOException;
import java.io.InputStream;
@@ -203,18 +203,18 @@ public class ETSIServiceImpl implements ETSIService {
private boolean hasMetaMandatoryEntries(final ToscaMetadata toscaMetadata) {
final Map<String, String> metaDataEntries = toscaMetadata.getMetaEntries();
- return metaDataEntries.containsKey(TOSCA_META_ENTRY_DEFINITIONS) && metaDataEntries
- .containsKey(TOSCA_META_ETSI_ENTRY_MANIFEST)
- && metaDataEntries.containsKey(TOSCA_META_ETSI_ENTRY_CHANGE_LOG);
+ return metaDataEntries.containsKey(ENTRY_DEFINITIONS.getName()) && metaDataEntries
+ .containsKey(ETSI_ENTRY_MANIFEST.getName())
+ && metaDataEntries.containsKey(ETSI_ENTRY_CHANGE_LOG.getName());
}
private boolean isMetaFilePresent(Map<String, byte[]> handler) {
- return handler.containsKey(TOSCA_META_PATH_FILE_NAME) || handler.containsKey(TOSCA_META_ORIG_PATH_FILE_NAME);
+ return handler.containsKey(TOSCA_META_PATH_FILE_NAME.getName()) || handler.containsKey(TOSCA_META_ORIG_PATH_FILE_NAME);
}
public ResourceTypeEnum getResourceType(FileContentHandler handler) throws IOException {
ToscaMetadata metadata = getMetadata(handler);
- Manifest manifest = getManifest(handler, metadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_MANIFEST));
+ Manifest manifest = getManifest(handler, metadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName()));
return getResourceType(manifest);
}
@@ -231,7 +231,7 @@ public class ETSIServiceImpl implements ETSIService {
public Manifest getManifest(FileContentHandler handler) throws IOException {
ToscaMetadata metadata = getMetadata(handler);
- return getManifest(handler, metadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_MANIFEST));
+ return getManifest(handler, metadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName()));
}
private Manifest getManifest(FileContentHandler handler, String manifestLocation) throws IOException {
@@ -244,16 +244,16 @@ public class ETSIServiceImpl implements ETSIService {
public Path getOriginalManifestPath(final FileContentHandler handler) throws IOException {
final ToscaMetadata metadata = getOriginalMetadata(handler);
- final String originalMetadataPath = metadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_MANIFEST);
+ final String originalMetadataPath = metadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName());
final Path path = Paths.get(originalMetadataPath);
return path.getParent() == null ? Paths.get("") : path.getParent();
}
private ToscaMetadata getMetadata(FileContentHandler handler) throws IOException {
ToscaMetadata metadata;
- if (handler.containsFile(TOSCA_META_PATH_FILE_NAME)) {
+ if (handler.containsFile(TOSCA_META_PATH_FILE_NAME.getName())) {
metadata = OnboardingToscaMetadata
- .parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME));
+ .parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME.getName()));
} else if (handler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)) {
metadata = OnboardingToscaMetadata
.parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_ORIG_PATH_FILE_NAME));
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java
index 0b0c6e42f9..fa1de6751c 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaConverter.java
@@ -22,6 +22,27 @@
package org.openecomp.core.impl;
+import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX;
+import static org.openecomp.core.converter.datatypes.Constants.definitionsDir;
+import static org.openecomp.core.converter.datatypes.Constants.globalStName;
+import static org.openecomp.core.converter.datatypes.Constants.globalSubstitution;
+import static org.openecomp.core.converter.datatypes.Constants.mainStName;
+import static org.openecomp.core.converter.datatypes.Constants.openecompHeatIndex;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.HEAT_INDEX_IMPORT_FILE;
+import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.ONAP_INDEX_IMPORT_FILE;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.regex.Pattern;
import org.apache.commons.collections.MapUtils;
import org.onap.sdc.tosca.datatypes.model.Import;
import org.onap.sdc.tosca.datatypes.model.NodeType;
@@ -41,39 +62,13 @@ import org.openecomp.sdc.tosca.services.ToscaUtil;
import org.openecomp.sdc.translator.services.heattotosca.globaltypes.GlobalTypesGenerator;
import org.yaml.snakeyaml.error.YAMLException;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.regex.Pattern;
-
-import static org.openecomp.core.converter.datatypes.Constants.ONAP_INDEX;
-import static org.openecomp.core.converter.datatypes.Constants.definitionsDir;
-import static org.openecomp.core.converter.datatypes.Constants.globalStName;
-import static org.openecomp.core.converter.datatypes.Constants.globalSubstitution;
-import static org.openecomp.core.converter.datatypes.Constants.mainStName;
-import static org.openecomp.core.converter.datatypes.Constants.openecompHeatIndex;
-import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.GLOBAL_SUBSTITUTION_SERVICE_FILE_NAME;
-import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.HEAT_INDEX_IMPORT_FILE;
-import static org.openecomp.core.impl.GlobalSubstitutionServiceTemplate.ONAP_INDEX_IMPORT_FILE;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
-
public abstract class AbstractToscaConverter implements ToscaConverter {
- @Override
- public abstract ToscaServiceModel convert(FileContentHandler fileContentHandler) throws IOException;
-
public abstract void convertTopologyTemplate(ServiceTemplate serviceTemplate,
ServiceTemplateReaderService readerService);
protected void handleMetadataFile(Map<String, byte[]> csarFiles) {
- byte[] bytes = csarFiles.remove(TOSCA_META_PATH_FILE_NAME);
+ byte[] bytes = csarFiles.remove(TOSCA_META_PATH_FILE_NAME.getName());
if (bytes != null) {
csarFiles.put(TOSCA_META_ORIG_PATH_FILE_NAME, bytes);
}
@@ -251,7 +246,7 @@ public abstract class AbstractToscaConverter implements ToscaConverter {
}
protected boolean isMetadataFile(String fileName) {
- return fileName.equals(TOSCA_META_PATH_FILE_NAME);
+ return fileName.equals(TOSCA_META_PATH_FILE_NAME.getName());
}
protected boolean isGlobalServiceTemplate(String fileName) {
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java
index ce7024015b..4be9379c1e 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java
@@ -22,6 +22,15 @@
package org.openecomp.core.impl;
+import static org.openecomp.core.converter.datatypes.Constants.globalStName;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.sdc.logging.api.Logger;
@@ -30,15 +39,6 @@ import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata;
import org.openecomp.sdc.tosca.csar.ToscaMetadata;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import static org.openecomp.core.converter.datatypes.Constants.globalStName;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
public abstract class AbstractToscaSolConverter extends AbstractToscaConverter {
@@ -96,8 +96,8 @@ public abstract class AbstractToscaSolConverter extends AbstractToscaConverter {
private String getMainServiceDefinitionFileName(FileContentHandler contentHandler) throws IOException {
try {
ToscaMetadata toscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(
- contentHandler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME));
- return toscaMetadata.getMetaEntries().get(TOSCA_META_ENTRY_DEFINITIONS);
+ contentHandler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME.getName()));
+ return toscaMetadata.getMetaEntries().get(ENTRY_DEFINITIONS.getName());
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
throw new IOException(e.getMessage());
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java
index 1de91f9549..783636b3d9 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/CSARConstants.java
@@ -34,22 +34,10 @@ public class CSARConstants {
public static final ImmutableSet<String> ELIGBLE_FOLDERS = of("Artifacts/","Definitions/",
"Licenses/", "TOSCA-Metadata/");
public static final String ARTIFACTS_FOLDER = "Artifacts";
-
public static final String MAIN_SERVICE_TEMPLATE_MF_FILE_NAME = "MainServiceTemplate.mf";
public static final String MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME = "MainServiceTemplate.yaml";
- public static final String TOSCA_META_PATH_FILE_NAME = "TOSCA-Metadata/TOSCA.meta";
- public static final String TOSCA_META_FILE_VERSION_ENTRY = "TOSCA-Meta-File-Version";
- public static final String TOSCA_META_CSAR_VERSION_ENTRY = "CSAR-Version";
- public static final String TOSCA_META_CREATED_BY_ENTRY = "Created-By";
- public static final String TOSCA_META_ENTRY_DEFINITIONS ="Entry-Definitions";
- public static final String TOSCA_META_ETSI_ENTRY_MANIFEST = "ETSI-Entry-Manifest";
- public static final String TOSCA_META_ETSI_ENTRY_CHANGE_LOG = "ETSI-Entry-Change-Log";
- public static final String TOSCA_META_ETSI_ENTRY_TESTS = "ETSI-Entry-Tests";
- public static final String TOSCA_META_ETSI_ENTRY_LICENSES = "ETSI-Entry-Licenses";
- public static final String TOSCA_META_ETSI_ENTRY_CERTIFICATE = "ETSI-Entry-Certificate";
public static final ImmutableSet<String> ELIGIBLE_FILES =
of(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME,MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME);
-
public static final ImmutableSet<String> MANIFEST_PNF_METADATA =
of(PNFD_PROVIDER.getToken(), PNFD_NAME.getToken(), PNFD_RELEASE_DATE_TIME.getToken(),
PNFD_ARCHIVE_VERSION.getToken());
@@ -58,8 +46,6 @@ public class CSARConstants {
VNF_PACKAGE_VERSION.getToken());
public static final int MANIFEST_METADATA_LIMIT = 4;
public static final String TOSCA_META_ORIG_PATH_FILE_NAME = "TOSCA-Metadata/TOSCA.meta.original";
-
- public static final String TOSCA_META_FILE_VERSION = "1.0";
public static final String CSAR_VERSION_1_0 = "1.0";
public static final String CSAR_VERSION_1_1 = "1.1";
public static final ImmutableSet<String> NON_FILE_IMPORT_ATTRIBUTES =
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingToscaMetadata.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingToscaMetadata.java
index 3fc55adb51..20bcf84aa2 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingToscaMetadata.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingToscaMetadata.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.tosca.csar;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.util.Optional;
import org.openecomp.sdc.common.errors.Messages;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
@@ -36,8 +37,8 @@ import java.util.List;
import java.util.Map;
import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ATTRIBUTE_VALUE_SEPARATOR;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
public class OnboardingToscaMetadata implements ToscaMetadata {
@@ -77,7 +78,7 @@ public class OnboardingToscaMetadata implements ToscaMetadata {
}
}
- if (!meta.metaEntries.containsKey(TOSCA_META_ENTRY_DEFINITIONS)) {
+ if (!meta.metaEntries.containsKey(ENTRY_DEFINITIONS.getName())) {
meta.errors.add(new ErrorMessage(ErrorLevel.ERROR, getErrorWithParameters(
Messages.METADATA_NO_ENTRY_DEFINITIONS.getErrorMessage())));
}
@@ -90,7 +91,7 @@ public class OnboardingToscaMetadata implements ToscaMetadata {
@Override
public List<ErrorMessage> getErrors() {
- return ImmutableList.copyOf(errors);
+ return ImmutableList.copyOf(errors);
}
@@ -101,5 +102,16 @@ public class OnboardingToscaMetadata implements ToscaMetadata {
}
return ImmutableMap.copyOf(metaEntries);
}
+
+ @Override
+ public boolean hasEntry(final String entry) {
+ return metaEntries.containsKey(entry);
+
+ }
+
+ @Override
+ public Optional<String> getEntry(final ToscaMetaEntry entry) {
+ return Optional.ofNullable(metaEntries.get(entry.getName()));
+ }
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java
new file mode 100644
index 0000000000..56dabc5dc2
--- /dev/null
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetaEntry.java
@@ -0,0 +1,52 @@
+/*
+ *(===========LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * (===============================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * (===========LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.tosca.csar;
+
+import java.util.Arrays;
+import java.util.Optional;
+
+public enum ToscaMetaEntry {
+ TOSCA_META_PATH_FILE_NAME("TOSCA-Metadata/TOSCA.meta"),
+ TOSCA_META_FILE_VERSION_ENTRY("TOSCA-Meta-File-Version"),
+ CSAR_VERSION_ENTRY("CSAR-Version"),
+ CREATED_BY_ENTRY("Created-By"),
+ ENTRY_DEFINITIONS("Entry-Definitions"),
+ ENTRY_EVENTS("Entry-Events"),
+ ETSI_ENTRY_MANIFEST("ETSI-Entry-Manifest"),
+ ETSI_ENTRY_CHANGE_LOG("ETSI-Entry-Change-Log"),
+ ETSI_ENTRY_TESTS("ETSI-Entry-Tests"),
+ ETSI_ENTRY_LICENSES("ETSI-Entry-Licenses"),
+ ETSI_ENTRY_CERTIFICATE("ETSI-Entry-Certificate"),
+ TOSCA_META_FILE_VERSION("1.0");
+
+ private final String name;
+
+ ToscaMetaEntry(final String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static Optional<ToscaMetaEntry> parse(final String name) {
+ return Arrays.stream(values()).filter(toscaMetaEntry -> toscaMetaEntry.getName().equals(name)).findFirst();
+ }
+}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadata.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadata.java
index a26e5195a5..c02c2f31c6 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadata.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/ToscaMetadata.java
@@ -20,27 +20,48 @@
package org.openecomp.sdc.tosca.csar;
+import java.util.Optional;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
import java.util.List;
import java.util.Map;
public interface ToscaMetadata {
+
/**
- * checks if metadata file is valid
- * @return
+ * Checks if metadata file is valid.
+ *
+ * @return {@code true} if the metadata is valid, {@code false} otherwise
*/
boolean isValid();
/**
- * List of errors occured during manifest parsing
- * @return
+ * Gets the list of errors occurred during manifest parsing.
+ *
+ * @return the list of errors
*/
List<ErrorMessage> getErrors();
/**
- * Metadata entries of block_0
- * @return
+ * Metadata entries of block_0.
+ *
+ * @return a map representing the entries
*/
Map<String, String> getMetaEntries();
+
+ /**
+ * Checks if the entry exists.
+ *
+ * @param entry the entry name.
+ * @return {@code true} if the entry exists, {@code false} otherwise.
+ */
+ boolean hasEntry(String entry);
+
+ /**
+ * Get the entry value if it exists.
+ *
+ * @param entry the entry to retrieve the value.
+ * @return an optional with the entry value if it exists.
+ */
+ Optional<String> getEntry(ToscaMetaEntry entry);
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java
index a0545fdd94..bbbcb202ef 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/ToscaServiceModel.java
@@ -24,7 +24,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
-
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java
index 29b083853a..7c0d1271fb 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java
@@ -16,6 +16,11 @@
package org.openecomp.sdc.tosca.services.impl;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.CREATED_BY_ENTRY;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.CSAR_VERSION_ENTRY;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_FILE_VERSION_ENTRY;
+
import org.apache.commons.io.IOUtils;
import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.openecomp.core.utilities.file.FileContentHandler;
@@ -46,14 +51,10 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService {
private static final String ARTIFACTS_FOLDER_NAME = "Artifacts";
//todo currently duplicated, to be changed when external artifacts are separated from internal
private static final String TOSCA_META_FOLDER_NAME = "TOSCA-Metadata";
- private static final String TOSCA_META_FILE_VERSION = "TOSCA-Meta-File-Version";
private static final String TOSCA_META_FILE_VERSION_VALUE = "1.0";
private static final String TOSCA_META_FILE_NAME = "TOSCA.meta";
- private static final String CSAR_VERSION = "CSAR-Version";
private static final String CSAR_VERSION_VALUE = "1.1";
- private static final String CREATED_BY = "Created-By";
private static final String CREATED_BY_VALUE = "ASDC Onboarding portal";
- private static final String ENTRY_DEFINITIONS = "Entry-Definitions";
private static final String META_FILE_DELIMITER = ":";
private static final String SPACE = " ";
private static final String FILE_SEPARATOR = File.separator;
@@ -86,11 +87,11 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService {
@Override
public String createMetaFile(String entryDefinitionsFileName) {
- return TOSCA_META_FILE_VERSION + META_FILE_DELIMITER + SPACE + TOSCA_META_FILE_VERSION_VALUE
+ return TOSCA_META_FILE_VERSION_ENTRY.getName() + META_FILE_DELIMITER + SPACE + TOSCA_META_FILE_VERSION_VALUE
+ System.lineSeparator()
- + CSAR_VERSION + META_FILE_DELIMITER + SPACE + CSAR_VERSION_VALUE + System.lineSeparator()
- + CREATED_BY + META_FILE_DELIMITER + SPACE + CREATED_BY_VALUE + System.lineSeparator()
- + ENTRY_DEFINITIONS + META_FILE_DELIMITER + SPACE + DEFINITIONS_FOLDER_NAME
+ + CSAR_VERSION_ENTRY.getName() + META_FILE_DELIMITER + SPACE + CSAR_VERSION_VALUE + System.lineSeparator()
+ + CREATED_BY_ENTRY.getName() + META_FILE_DELIMITER + SPACE + CREATED_BY_VALUE + System.lineSeparator()
+ + ENTRY_DEFINITIONS.getName() + META_FILE_DELIMITER + SPACE + DEFINITIONS_FOLDER_NAME
+ FILE_SEPARATOR
+ entryDefinitionsFileName;
}
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/csar/MetadataParsingTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/csar/MetadataParsingTest.java
index 936371990a..51cdfa990d 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/csar/MetadataParsingTest.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/csar/MetadataParsingTest.java
@@ -24,9 +24,9 @@ package org.openecomp.sdc.tosca.csar;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CHANGE_LOG;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_MANIFEST;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_CHANGE_LOG;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.ETSI_ENTRY_MANIFEST;
import java.io.IOException;
import java.io.InputStream;
@@ -43,7 +43,7 @@ public class MetadataParsingTest {
.getResourceAsStream("/vspmanager.csar/metadata/Invalidtosca.meta")) {
ToscaMetadata onboardingToscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(is);
assertFalse(onboardingToscaMetadata.isValid());
- assertNull(onboardingToscaMetadata.getMetaEntries().get(TOSCA_META_ENTRY_DEFINITIONS));
+ assertNull(onboardingToscaMetadata.getMetaEntries().get(ENTRY_DEFINITIONS.getName()));
}
}
@@ -52,7 +52,8 @@ public class MetadataParsingTest {
try (InputStream is = getClass()
.getResourceAsStream("/vspmanager.csar/metadata/Validtosca.meta")) {
ToscaMetadata onboardingToscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(is);
- assertEquals(onboardingToscaMetadata.getMetaEntries().get(TOSCA_META_ENTRY_DEFINITIONS), "Definitions/MainServiceTemplate.yaml");
+ assertEquals("Definitions/MainServiceTemplate.yaml", onboardingToscaMetadata.getMetaEntries().get(
+ ENTRY_DEFINITIONS.getName()));
}
}
@@ -80,9 +81,10 @@ public class MetadataParsingTest {
try (InputStream is = getClass()
.getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta")) {
ToscaMetadata onboardingToscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(is);
- assertEquals(onboardingToscaMetadata.getMetaEntries().get(TOSCA_META_ENTRY_DEFINITIONS), "Definitions/MainServiceTemplate.yaml");
- assertEquals(onboardingToscaMetadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_MANIFEST), "MainServiceTemplate.mf");
- assertEquals(onboardingToscaMetadata.getMetaEntries().get(TOSCA_META_ETSI_ENTRY_CHANGE_LOG), "change.log");
+ assertEquals("Definitions/MainServiceTemplate.yaml", onboardingToscaMetadata.getMetaEntries().get(
+ ENTRY_DEFINITIONS.getName()));
+ assertEquals("MainServiceTemplate.mf", onboardingToscaMetadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName()));
+ assertEquals("change.log", onboardingToscaMetadata.getMetaEntries().get(ETSI_ENTRY_CHANGE_LOG.getName()));
}
}