gresockj commented on a change in pull request #5131: URL: https://github.com/apache/nifi/pull/5131#discussion_r648559487
########## File path: nifi-commons/nifi-sensitive-property-provider/src/main/java/org/apache/nifi/properties/SensitivePropertyProtector.java ########## @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +package org.apache.nifi.properties; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Encapsulates methods needed to protect application properties. + * @param <T> The ProtectedApplicationProperties type + * @param <U> The ApplicationProperties type + */ +public interface SensitivePropertyProtector<T extends ProtectedApplicationProperties<U>, U extends ApplicationProperties> { + + /** + * Returns the number of properties, excluding protection scheme properties. + * <p> + * Example: + * <p> + * key: E(value, key) + * key.protected: aes/gcm/256 + * key2: value2 + * <p> + * would return size 2 + * + * @return the count of real properties + */ + int size(); + + /** + * Retrieves all known property keys. + * + * @return all known property keys + */ + Set<String> getPropertyKeys(); + + /** + * Returns the complete set of property keys, including any protection keys (i.e. 'x.y.z.protected'). + * + * @return the set of property keys + */ + Set<String> getPropertyKeysIncludingProtectionSchemes(); + + /** + * Returns a list of the keys identifying "sensitive" properties. There is a default list, + * and additional keys can be provided in the {@code nifi.sensitive.props.additional.keys} property in the ApplicationProperties. + * + * @return the list of sensitive property keys + */ + List<String> getSensitivePropertyKeys(); + + /** + * Returns a list of the keys identifying "sensitive" properties. There is a default list, + * and additional keys can be provided in the {@code nifi.sensitive.props.additional.keys} property in the ApplicationProperties. + * + * @return the list of sensitive property keys + */ + List<String> getPopulatedSensitivePropertyKeys(); + + /** + * Returns true if any sensitive keys are protected. + * + * @return true if any key is protected; false otherwise + */ + boolean hasProtectedKeys(); + + /** + * Returns the unique set of all protection schemes currently in use for this instance. + * + * @return the set of protection schemes + */ + Set<String> getProtectionSchemes(); + + /** + * Returns a Map of the keys identifying "sensitive" properties that are currently protected and the "protection" key for each. + * This may or may not include all properties marked as sensitive. + * + * @return the Map of protected property keys and the protection identifier for each + */ + Map<String, String> getProtectedPropertyKeys(); + + /** + * Returns the local provider cache (null-safe) as a Map of protection schemes -> implementations. + * + * @return the map + */ + Map<String, SensitivePropertyProvider> getSensitivePropertyProviders(); + + /** + * Returns a percentage of the total number of populated properties marked as sensitive that are currently protected. + * + * @return the percent of sensitive properties marked as protected + */ + int getPercentOfSensitivePropertiesProtected(); Review comment: Actually, I only see it used in unit tests, so I'll refactor the implementation into the tests. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
