diff options
author | bilal.iqbal <bilal.iqbal@est.tech> | 2019-03-10 00:47:55 +0000 |
---|---|---|
committer | bilal.iqbal <bilal.iqbal@est.tech> | 2019-03-10 00:47:55 +0000 |
commit | 0a1d82ac04a8ef78bfdcbcced4f5096c050edcfe (patch) | |
tree | 0d0dcc04d8ef8d77a00df89ddf93e31c5f5c0433 /openecomp-be/lib | |
parent | 90c460aa3c23c9a12885894b4664f7c742c8d29f (diff) |
CSAR Package validation
Change-Id: I11af8d93f5a2cd0566a5caf0dad0519d70bd57d7
Issue-ID: SDC-2147
Issue-ID: SDC-2148
Issue-ID: SDC-2149
Issue-ID: SDC-2150
Signed-off-by: bilal.iqbal <bilal.iqbal@est.tech>
Diffstat (limited to 'openecomp-be/lib')
9 files changed, 121 insertions, 20 deletions
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 6cb82b5d4d..095e5b49c2 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 @@ -32,9 +32,18 @@ public enum Messages { MANIFEST_INVALID_LINE("Manifest contains invalid line : %s"), MANIFEST_NO_METADATA("Manifest must contain metadata"), MANIFEST_NO_SOURCES("Manifest must contain Source"), + MANIFEST_METADATA_MISSING_ENTRY("Manifest metadata missing entry %s"), + MANIFEST_INVALID_NAME("Manifest file has a different name than main TOSCA definitions file"), + MANIFEST_INVALID_EXT("Manifest file does not have extension \".mf\" "), + MANIFEST_METADATA_INVALID_ENTRY("Manifest metadata should only have pnf or vnf entries"), + MANIFEST_METADATA_DOES_NOT_MATCH_LIMIT("Manifest metadata must only have the required number of values [%s]"), MANIFEST_EMPTY("Manifest must contain data"), MANIFEST_PARSER_INTERNAL("Invalid manifest file"), 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"), + METADATA_INVALID_VALUE("Invalid value %s in TOSCA.meta file"), + METADATA_MISSING_ENTRY("TOSCA.meta file missing entry %s"), 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"), @@ -93,6 +102,12 @@ public enum Messages { CSAR_MANIFEST_FILE_NOT_EXIST("CSAR manifest file does not exist"), CSAR_FAILED_TO_READ("CSAR file is not readable"), TOSCA_PARSING_FAILURE("Invalid tosca file. Error code : %s, Error message : %s/"), + + /*definition errors*/ + MISSING_DEFINITION_FILE("Definition file %s does not exist"), + MISSING_IMPORT_FILE("Package must contain the referenced import file %s"), + INVALID_IMPORT_STATEMENT("Definition file contains an invalid import statement"), + /* content errors*/ INVALID_YAML_FORMAT("Invalid YAML format - %s"), INVALID_YAML_FORMAT_REASON("Invalid YAML format Problem - [%s]"), diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIService.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIService.java index 69ce97efc5..d5dab46533 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIService.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIService.java @@ -22,16 +22,19 @@ package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.sdc.tosca.csar.Manifest; +import java.io.IOException; public interface ETSIService { + /** * Checks package structure is CSAR with TOSCA-Metadata directory according to SOL004 v2.5.1 * and contains mandatory Entries in Tosca.meta * @param handler contains csar artifacts * @return true if all condition matched, false otherwise + * @throws IOException when TOSCA.meta file is invalid */ - boolean isSol004WithToscaMetaDirectory(FileContentHandler handler); + boolean isSol004WithToscaMetaDirectory(FileContentHandler handler) throws IOException; /** * Update file structure. Moves non mano files to Artifacts/Deployment/non mano key location 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 b3002abf6e..9984df1ccc 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 @@ -30,11 +30,16 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; -import java.util.Optional; import org.openecomp.sdc.tosca.csar.Manifest; +import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata; +import org.openecomp.sdc.tosca.csar.ToscaMetadata; -import static org.openecomp.sdc.tosca.csar.CSARConstants.*; +import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_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_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; public class ETSIServiceImpl implements ETSIService { @@ -55,9 +60,9 @@ public class ETSIServiceImpl implements ETSIService { } @Override - public boolean isSol004WithToscaMetaDirectory(FileContentHandler handler) { + public boolean isSol004WithToscaMetaDirectory(FileContentHandler handler) throws IOException { Map<String, byte[]> templates = handler.getFiles(); - return isMetaFilePresent(templates) && hasMetaMandatoryEntries(templates); + return isMetaFilePresent(templates) && hasMetaMandatoryEntries(getMetadata(handler)); } @Override @@ -69,6 +74,15 @@ public class ETSIServiceImpl implements ETSIService { } } + private InputStream getMetadata(FileContentHandler contentHandler) throws IOException{ + if(contentHandler.containsFile(TOSCA_META_PATH_FILE_NAME)){ + return contentHandler.getFileContent(TOSCA_META_PATH_FILE_NAME); + }else if(contentHandler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)){ + return contentHandler.getFileContent(TOSCA_META_ORIG_PATH_FILE_NAME); + } + throw new IOException("TOSCA.meta file does not exist"); + } + private void updateNonManoLocation(FileContentHandler handler, String nonManoKey, List<String> sources) { Map<String, byte[]> files = handler.getFiles(); for (String key : sources) { @@ -98,15 +112,12 @@ public class ETSIServiceImpl implements ETSIService { return key.substring(key.lastIndexOf('/') + 1); } - private boolean hasMetaMandatoryEntries(Map<String, byte[]> templates) { - Optional<byte[]> meta = templates.entrySet().stream().filter(e -> e.getKey().equals(TOSCA_META_PATH_FILE_NAME) - || e.getKey().equals(TOSCA_META_ORIG_PATH_FILE_NAME)).findFirst().map(Map.Entry::getValue); - if (!meta.isPresent()) { - return false; - } - String metaContent = new String(meta.get(), StandardCharsets.UTF_8); - return metaContent.contains(TOSCA_META_ENTRY_DEFINITIONS) && metaContent.contains(TOSCA_META_ENTRY_MANIFEST) - && metaContent.contains(TOSCA_META_ENTRY_CHANGE_LOG); + private boolean hasMetaMandatoryEntries(InputStream metadataInputStream) throws IOException { + + ToscaMetadata toscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(metadataInputStream); + Map<String, String> metaDataEntries = toscaMetadata.getMetaEntries(); + return metaDataEntries.containsKey(TOSCA_META_ENTRY_DEFINITIONS) && metaDataEntries.containsKey(TOSCA_META_ENTRY_MANIFEST) + && metaDataEntries.containsKey(TOSCA_META_ENTRY_CHANGE_LOG); } private boolean isMetaFilePresent(Map<String, byte[]> handler) { diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java index ae69415f1d..2dc37f17e4 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java @@ -49,28 +49,28 @@ public class ETSIServiceImplTest { } @Test - public void testIsSol004TrueOrigin() { + public void testIsSol004TrueOrigin() throws IOException { FileContentHandler fileContentHandler = new FileContentHandler(); fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta.original", sol004MetaFile.getBytes(StandardCharsets.UTF_8)); assertTrue(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)); } @Test - public void testIsSol004True() { + public void testIsSol004True() throws IOException { FileContentHandler fileContentHandler = new FileContentHandler(); fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta", sol004MetaFile.getBytes(StandardCharsets.UTF_8)); assertTrue(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)); } @Test - public void testIsSol004False() { + public void testIsSol004False() throws IOException { FileContentHandler fileContentHandler = new FileContentHandler(); fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta.original", metaFile.getBytes(StandardCharsets.UTF_8)); assertFalse(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)); } @Test - public void testIsSol004FalseWithNull() { + public void testIsSol004FalseWithNull() throws IOException { FileContentHandler fileContentHandler = new FileContentHandler(); assertFalse(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler)); } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/ServiceTemplateReaderService.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/ServiceTemplateReaderService.java index 1bc97b4d69..3b861e425d 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/ServiceTemplateReaderService.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-api/src/main/java/org/openecomp/core/converter/ServiceTemplateReaderService.java @@ -1,5 +1,27 @@ + +/*- + * ============LICENSE_START======================================================= + * Modification 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.core.converter; +import java.util.List; import java.util.Map; public interface ServiceTemplateReaderService { @@ -21,4 +43,6 @@ public interface ServiceTemplateReaderService { Map<String, Object> getOutputs(); Map<String, Object> getSubstitutionMappings(); + + List<Object> getImports(); } diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java index b691d83267..44b0c80e24 100644 --- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java +++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/services/ServiceTemplateReaderServiceImpl.java @@ -1,9 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * Modification 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.core.impl.services; import org.onap.sdc.tosca.services.YamlUtil; import org.openecomp.core.converter.ServiceTemplateReaderService; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; @@ -26,6 +48,12 @@ public class ServiceTemplateReaderServiceImpl implements ServiceTemplateReaderSe } @Override + public List<Object> getImports(){ + return Objects.isNull(this.readServiceTemplate.get("imports")) ? + new ArrayList<>() : (List<Object>) this.readServiceTemplate.get("imports"); + } + + @Override public Object getMetadata(){ return this.readServiceTemplate.get(metadata); } 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 94786fe0df..97e7809828 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 @@ -1,5 +1,6 @@ /* * Copyright © 2016-2017 European Support Limited + * 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. @@ -27,18 +28,33 @@ public class CSARConstants { 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_ENTRY_MANIFEST="Entry-Manifest"; public static final String TOSCA_META_ENTRY_CHANGE_LOG="Entry-Change-Log"; + public static final String TOSCA_META_ENTRY_TESTS = "Entry-Tests"; + public static final String TOSCA_META_ENTRY_LICENSES= "Entry-Licenses"; 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("pnf_provider_id", "pnf_product_name", "pnf_release_date_time", "pnf_package_version"); + public static final ImmutableSet<String> MANIFEST_VNF_METADATA = + of("vnf_provider_id", "vnf_product_name", "vnf_release_date_time", "vnf_package_version"); + public static final int MANIFEST_METADATA_LIMIT = 4; public static final String METADATA_MF_ATTRIBUTE = "metadata"; public static final String SOURCE_MF_ATTRIBUTE = "Source"; public static final String SEPERATOR_MF_ATTRIBUTE = ":"; public static final String NON_MANO_MF_ATTRIBUTE = "non_mano_artifact_sets"; 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 = + ImmutableSet.of("repository", "namespace_uri", "namespace_prefix"); + private CSARConstants() { } diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingManifest.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingManifest.java index 8858128b38..efa7e0aa1a 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingManifest.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/csar/OnboardingManifest.java @@ -133,11 +133,12 @@ public class OnboardingManifest implements Manifest{ } String[] metaSplit = line.split(SEPERATOR_MF_ATTRIBUTE); if (metaSplit.length < 2){ + reportError(line); return; } if (!metaSplit[0].equals(SOURCE_MF_ATTRIBUTE) && !metaSplit[0].equals(NON_MANO_MF_ATTRIBUTE)){ String value = line.substring((metaSplit[0] + SEPERATOR_MF_ATTRIBUTE).length()).trim(); - metadata.put(metaSplit[0],value); + metadata.put(metaSplit[0].trim(),value.trim()); processMetadata(iterator); } else { 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 b4d7f84ca4..6dd6979751 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 @@ -56,6 +56,9 @@ public class OnboardingToscaMetadata implements ToscaMetadata{ * @throws IOException */ public static ToscaMetadata parseToscaMetadataFile(InputStream st) throws IOException { + if(st == null) { + throw new IOException(Messages.METADATA_PARSER_INTERNAL.getErrorMessage()); + } OnboardingToscaMetadata meta = new OnboardingToscaMetadata(); List<String> metadataLines = IOUtils.readLines(st, "utf-8"); for (String line : metadataLines) { |