2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
22 import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA_LIMIT_VERSION_3;
23 import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA_VERSION_3;
24 import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_VNF_METADATA_LIMIT_VERSION_3;
25 import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_VNF_METADATA_VERSION_3;
27 import com.google.common.collect.ImmutableSet;
28 import java.util.List;
30 import java.util.stream.Collectors;
31 import org.openecomp.sdc.common.errors.Messages;
32 import org.openecomp.sdc.datatypes.error.ErrorLevel;
33 import org.openecomp.sdc.logging.api.Logger;
34 import org.openecomp.sdc.logging.api.LoggerFactory;
35 import org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261;
36 import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager;
39 * 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
42 class SOL004Version3MetaDirectoryValidator extends SOL004MetaDirectoryValidator {
44 private static final Logger LOGGER = LoggerFactory.getLogger(SOL004Version3MetaDirectoryValidator.class);
46 public SOL004Version3MetaDirectoryValidator() {
50 SOL004Version3MetaDirectoryValidator(final SecurityManager securityManager) {
51 super(securityManager);
55 protected void handleOtherEntry(final Map.Entry<String, String> entry) {
56 if (!ToscaMetaEntryVersion261.OTHER_DEFINITIONS.getName().equals(entry.getKey())) {
57 reportError(ErrorLevel.ERROR, Messages.METADATA_UNSUPPORTED_ENTRY.formatMessage(entry.getKey()));
58 LOGGER.warn(Messages.METADATA_UNSUPPORTED_ENTRY.getErrorMessage(), entry.getKey());
60 validateDefinitionFile(entry.getValue());
65 protected boolean validMetaLimit(Map<String, String> metadata) {
66 int maxAllowedEntries = isPnfMetadata(metadata) ? MANIFEST_PNF_METADATA_LIMIT_VERSION_3 : MANIFEST_VNF_METADATA_LIMIT_VERSION_3;
67 return metadata.size() == maxAllowedEntries;
71 protected ImmutableSet<String> getManifestMetadata(final Map<String, String> metadata) {
72 return isPnfMetadata(metadata) ? MANIFEST_PNF_METADATA_VERSION_3 : MANIFEST_VNF_METADATA_VERSION_3;
76 protected boolean isPnfMetadata(final Map<String, String> metadata) {
77 List<String> keys = metadata.keySet().stream().collect(Collectors.toList());
78 //Both VNF and PNF share this attribute
79 return validatorUtils.isPnfMetadata(keys);