diff options
author | 2022-07-11 10:55:53 +0100 | |
---|---|---|
committer | 2022-07-29 10:42:04 +0100 | |
commit | 82a550f6b080cb50912d93f7b13ba0fc97a95470 (patch) | |
tree | 1bb3ca97c99e46c9b5a5654b2848038c37f20c4d /cps-service/src/main | |
parent | 054873c7c52bdb9fae718a0d7651d57b1a995dfc (diff) |
Query CmHandles using CPS path
Added withCpsPath condition parameter
Validated to prevent misuse and blocking of querying using private properties
Updated OpenAPI with examples and links to documentation
Moved methods related to cmHandle querying using cps path from InventoryPersistence to CmHandleQueries
Renamed private method deleteSchemaSetAndListElementByCmHandleId to deleteCmHandleByCmHandleId
Issue-ID: CPS-977
Change-Id: I83827215b7e58de74f8f62cd0140516d217d93f1
Signed-off-by: lukegleeson <luke.gleeson@est.tech>
Diffstat (limited to 'cps-service/src/main')
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java | 36 | ||||
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/utils/ValidQueryProperties.java | 36 |
2 files changed, 68 insertions, 4 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java b/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java index c3811eb48..7fe47be2d 100644 --- a/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java +++ b/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java @@ -22,18 +22,17 @@ package org.onap.cps.utils; import com.google.common.base.Strings; import java.util.Arrays; -import java.util.List; import java.util.Map; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.onap.cps.spi.exceptions.DataValidationException; import org.onap.cps.spi.model.CmHandleQueryServiceParameters; +@Slf4j @NoArgsConstructor(access = AccessLevel.PRIVATE) public class CmHandleQueryRestParametersValidator { - private static final List<String> VALID_PROPERTY_NAMES = Arrays.asList("hasAllProperties", "hasAllModules"); - /** * Validate cm handle query parameters. * @param cmHandleQueryServiceParameters name of data to be validated @@ -45,7 +44,8 @@ public class CmHandleQueryRestParametersValidator { if (Strings.isNullOrEmpty(conditionApiProperty.getConditionName())) { throwDataValidationException("Missing 'conditionName' - please supply a valid name."); } - if (!VALID_PROPERTY_NAMES.contains(conditionApiProperty.getConditionName())) { + if (Arrays.stream(ValidQueryProperties.values()).noneMatch(validQueryProperty -> + validQueryProperty.getQueryProperty().equals(conditionApiProperty.getConditionName()))) { throwDataValidationException( String.format("Wrong 'conditionName': %s - please supply a valid name.", conditionApiProperty.getConditionName())); @@ -89,6 +89,34 @@ public class CmHandleQueryRestParametersValidator { throwDataValidationException("Wrong module condition property. - please supply a valid condition property."); } + /** + * Validate CPS path condition properties. + * @param conditionProperty name of data to be validated + */ + public static boolean validateCpsPathConditionProperties(final Map<String, String> conditionProperty) { + if (conditionProperty.isEmpty()) { + return true; + } + if (conditionProperty.size() > 1) { + throwDataValidationException("Only one condition property is allowed for the CPS path query."); + } + if (!conditionProperty.containsKey("cpsPath")) { + throwDataValidationException( + "Wrong CPS path condition property. - expecting \"cpsPath\" as the condition property."); + } + final String cpsPath = conditionProperty.get("cpsPath"); + if (cpsPath.isBlank()) { + throwDataValidationException( + "Wrong CPS path. - please supply a valid CPS path."); + } + if (cpsPath.contains("/additional-properties")) { + log.debug("{} - Private metadata cannot be queried. Nothing to be returned", + cpsPath); + return false; + } + return true; + } + private static void throwDataValidationException(final String details) { throw new DataValidationException("Invalid Query Parameter.", details); } diff --git a/cps-service/src/main/java/org/onap/cps/utils/ValidQueryProperties.java b/cps-service/src/main/java/org/onap/cps/utils/ValidQueryProperties.java new file mode 100644 index 000000000..1d7ccb91d --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/utils/ValidQueryProperties.java @@ -0,0 +1,36 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 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.onap.cps.utils; + +import lombok.Getter; + +@Getter +public enum ValidQueryProperties { + HAS_ALL_PROPERTIES("hasAllProperties"), + HAS_ALL_MODULES("hasAllModules"), + WITH_CPS_PATH("cmHandleWithCpsPath"); + + private final String queryProperty; + + ValidQueryProperties(final String queryProperty) { + this.queryProperty = queryProperty; + } +} |