3 * ============LICENSE_START=======================================================
4 * Copyright (C) 2021 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
23 import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_MANIFEST_FILE_EXT;
24 import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion251.ENTRY_CERTIFICATE;
25 import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion251.ENTRY_DEFINITIONS;
26 import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion251.ENTRY_MANIFEST;
29 import java.util.Optional;
30 import lombok.NoArgsConstructor;
31 import org.openecomp.sdc.common.errors.Messages;
32 import org.openecomp.sdc.datatypes.error.ErrorLevel;
33 import org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion251;
36 * 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
40 public class EtsiSol004Version251Validator extends SOL004MetaDirectoryValidator {
43 public boolean appliesTo(final String model) {
44 return "ETSI SOL001 v2.5.1".equals(model);
48 public int getOrder() {
53 protected Optional<String> getCertificatePath() {
54 return getToscaMetadata().getEntry(ENTRY_CERTIFICATE);
58 protected void handleEntry(final Map.Entry<String, String> entry) {
59 final String key = entry.getKey();
60 final var toscaMetaEntry = ToscaMetaEntryVersion251.parse(entry.getKey()).orElse(null);
61 // allows any other unknown entry
62 if (toscaMetaEntry == null) {
65 final String value = entry.getValue();
66 switch (toscaMetaEntry) {
67 case TOSCA_META_FILE_VERSION_ENTRY:
68 case CSAR_VERSION_ENTRY:
69 case CREATED_BY_ENTRY:
70 verifyMetadataEntryVersions(key, value);
72 case ENTRY_DEFINITIONS:
73 validateDefinitionFile(value);
76 validateManifestFile(value);
78 case ENTRY_CHANGE_LOG:
79 validateChangeLog(value);
83 validateOtherEntries(entry);
85 case ENTRY_CERTIFICATE:
86 validateCertificate(value);
89 handleOtherEntry(entry);
95 protected String getManifestFilePath() {
96 return getToscaMetadata().getMetaEntries().get(ENTRY_MANIFEST.getName());
100 protected void verifyManifestNameAndExtension() {
101 final Map<String, String> entries = getToscaMetadata().getMetaEntries();
102 final String manifestFileName = getFileName(entries.get(ENTRY_MANIFEST.getName()));
103 final String manifestExtension = getFileExtension(entries.get(ENTRY_MANIFEST.getName()));
104 final String mainDefinitionFileName = getFileName(entries.get(ENTRY_DEFINITIONS.getName()));
105 if (!(TOSCA_MANIFEST_FILE_EXT).equals(manifestExtension)) {
106 reportError(ErrorLevel.ERROR, Messages.MANIFEST_INVALID_EXT.getErrorMessage());
108 if (!mainDefinitionFileName.equals(manifestFileName)) {
109 reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_INVALID_NAME.getErrorMessage(), manifestFileName, mainDefinitionFileName));