mirror of https://github.com/apache/nifi.git
NIFI-13889 Removed Unused Protected Properties abstraction
- Removed unused methods from nifi-property-utils components Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com> This closes #9410.
This commit is contained in:
parent
09e5b030db
commit
7aabef305c
|
@ -21,10 +21,4 @@
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>nifi-property-utils</artifactId>
|
<artifactId>nifi-property-utils</artifactId>
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -16,9 +16,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.nifi.properties;
|
package org.apache.nifi.properties;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -31,8 +28,6 @@ import java.util.Properties;
|
||||||
* An abstract base class for an application-specific BootstrapProperties loader.
|
* An abstract base class for an application-specific BootstrapProperties loader.
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractBootstrapPropertiesLoader {
|
public abstract class AbstractBootstrapPropertiesLoader {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(AbstractBootstrapPropertiesLoader.class);
|
|
||||||
|
|
||||||
private static final String RELATIVE_APPLICATION_PROPERTIES_PATTERN = "conf/%s";
|
private static final String RELATIVE_APPLICATION_PROPERTIES_PATTERN = "conf/%s";
|
||||||
private static final String BOOTSTRAP_CONF = "bootstrap.conf";
|
private static final String BOOTSTRAP_CONF = "bootstrap.conf";
|
||||||
|
|
||||||
|
@ -134,12 +129,9 @@ public abstract class AbstractBootstrapPropertiesLoader {
|
||||||
String systemPath = System.getProperty(systemPropertyName);
|
String systemPath = System.getProperty(systemPropertyName);
|
||||||
|
|
||||||
if (systemPath == null || systemPath.trim().isEmpty()) {
|
if (systemPath == null || systemPath.trim().isEmpty()) {
|
||||||
logger.warn("System Property [{}] not found: Using Relative Path [{}]", systemPropertyName, defaultRelativePath);
|
|
||||||
System.setProperty(systemPropertyName, defaultRelativePath);
|
|
||||||
systemPath = defaultRelativePath;
|
systemPath = defaultRelativePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("Default Application Properties Path [{}]", systemPath);
|
|
||||||
return systemPath;
|
return systemPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,19 +17,14 @@
|
||||||
package org.apache.nifi.properties;
|
package org.apache.nifi.properties;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Properties representing bootstrap.conf.
|
* Properties representing bootstrap.conf.
|
||||||
*/
|
*/
|
||||||
public class BootstrapProperties extends StandardReadableProperties {
|
public class BootstrapProperties extends StandardReadableProperties {
|
||||||
private static final String PROPERTY_KEY_FORMAT = "%s.%s";
|
|
||||||
|
|
||||||
private final String propertyPrefix;
|
private final String propertyPrefix;
|
||||||
private final Path configFilePath;
|
private final Path configFilePath;
|
||||||
|
|
||||||
|
@ -66,14 +61,6 @@ public class BootstrapProperties extends StandardReadableProperties {
|
||||||
return isBlank(property) ? null : property;
|
return isBlank(property) ? null : property;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the path to the bootstrap config file.
|
|
||||||
* @return The path to the file
|
|
||||||
*/
|
|
||||||
public Path getConfigFilePath() {
|
|
||||||
return configFilePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Includes only the properties starting with the propertyPrefix.
|
* Includes only the properties starting with the propertyPrefix.
|
||||||
* @param properties Unfiltered properties
|
* @param properties Unfiltered properties
|
||||||
|
@ -90,40 +77,11 @@ public class BootstrapProperties extends StandardReadableProperties {
|
||||||
getRawProperties().putAll(filteredProperties);
|
getRawProperties().putAll(filteredProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPropertyKey(final String subKey) {
|
|
||||||
return String.format(PROPERTY_KEY_FORMAT, propertyPrefix, subKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("Bootstrap properties [%s] with prefix [%s]", configFilePath, propertyPrefix);
|
return String.format("Bootstrap properties [%s] with prefix [%s]", configFilePath, propertyPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* An empty instance of BootstrapProperties.
|
|
||||||
*/
|
|
||||||
public static final BootstrapProperties EMPTY = new BootstrapProperties("", new Properties(), Paths.get("conf/bootstrap.conf")) {
|
|
||||||
@Override
|
|
||||||
public Set<String> getPropertyKeys() {
|
|
||||||
return Collections.EMPTY_SET;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getProperty(String key) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getProperty(String key, String defaultValue) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private static boolean isBlank(final String string) {
|
private static boolean isBlank(final String string) {
|
||||||
return (string == null) || string.isEmpty() || string.trim().isEmpty();
|
return (string == null) || string.isEmpty() || string.trim().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.Properties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a protected set of ApplicationProperties, with methods regarding which sensitive properties
|
|
||||||
* are protected.
|
|
||||||
* @param <T> The ApplicationProperties type
|
|
||||||
*/
|
|
||||||
public interface ProtectedProperties<T extends ApplicationProperties> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Additional sensitive properties keys
|
|
||||||
* @return Additional sensitive properties keys
|
|
||||||
*/
|
|
||||||
String getAdditionalSensitivePropertiesKeys();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the name of the property that specifies the additional sensitive properties keys
|
|
||||||
* @return Name of additional sensitive properties keys
|
|
||||||
*/
|
|
||||||
String getAdditionalSensitivePropertiesKeysName();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Additional sensitive properties keys
|
|
||||||
* @return Additional sensitive properties keys
|
|
||||||
*/
|
|
||||||
List<String> getDefaultSensitiveProperties();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the application properties.
|
|
||||||
* @return The application properties
|
|
||||||
*/
|
|
||||||
T getApplicationProperties();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new ApplicationProperties object of the generic type.
|
|
||||||
* @param rawProperties Plain old properties
|
|
||||||
* @return The ApplicationProperties
|
|
||||||
*/
|
|
||||||
T createApplicationProperties(Properties rawProperties);
|
|
||||||
}
|
|
|
@ -1,83 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A context for protected properties, encapsulating the context name and property name.
|
|
||||||
*/
|
|
||||||
public class ProtectedPropertyContext {
|
|
||||||
private static final String DEFAULT_CONTEXT = "default";
|
|
||||||
|
|
||||||
private final String propertyName;
|
|
||||||
private final String contextName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a ProtectedPropertyContext for the given property name, with a specific context name, acting as
|
|
||||||
* a namespace for the property.
|
|
||||||
* @param propertyName The property name in this location
|
|
||||||
* @param contextName A custom context name. If null, the default context will be assigned.
|
|
||||||
* @return A property context representing a property within a specific context
|
|
||||||
*/
|
|
||||||
public static ProtectedPropertyContext contextFor(final String propertyName, final String contextName) {
|
|
||||||
return new ProtectedPropertyContext(propertyName, contextName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a ProtectedPropertyContext for the given property name, using the default context.
|
|
||||||
* @param propertyName The property name in this location
|
|
||||||
* @return A property context representing a property with the given name in the default context
|
|
||||||
*/
|
|
||||||
public static ProtectedPropertyContext defaultContext(final String propertyName) {
|
|
||||||
return new ProtectedPropertyContext(propertyName, DEFAULT_CONTEXT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a property context with a property name and custom location.
|
|
||||||
* @param propertyName The property name
|
|
||||||
* @param contextName The context name. If null, the default context will be assigned.
|
|
||||||
*/
|
|
||||||
private ProtectedPropertyContext(final String propertyName, final String contextName) {
|
|
||||||
this.propertyName = Objects.requireNonNull(propertyName);
|
|
||||||
this.contextName = contextName == null ? DEFAULT_CONTEXT : contextName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the context key, in the format [contextName]/[propertyName]
|
|
||||||
* @return The context key
|
|
||||||
*/
|
|
||||||
public String getContextKey() {
|
|
||||||
return String.format("%s/%s", contextName, propertyName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the property name
|
|
||||||
* @return The property name
|
|
||||||
*/
|
|
||||||
public String getPropertyName() {
|
|
||||||
return propertyName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the context name
|
|
||||||
* @return The context name
|
|
||||||
*/
|
|
||||||
public String getContextName() {
|
|
||||||
return contextName;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -16,8 +16,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.nifi.properties;
|
package org.apache.nifi.properties;
|
||||||
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -49,13 +47,7 @@ public class StandardReadableProperties implements ReadableProperties {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getPropertyKeys() {
|
public Set<String> getPropertyKeys() {
|
||||||
Set<String> propertyNames = new HashSet<>();
|
return rawProperties.stringPropertyNames();
|
||||||
Enumeration e = rawProperties.propertyNames();
|
|
||||||
for (; e.hasMoreElements(); ) {
|
|
||||||
propertyNames.add((String) e.nextElement());
|
|
||||||
}
|
|
||||||
|
|
||||||
return propertyNames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Properties getRawProperties() {
|
protected Properties getRawProperties() {
|
||||||
|
|
|
@ -24,6 +24,10 @@
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.nifi</groupId>
|
<groupId>org.apache.nifi</groupId>
|
||||||
<artifactId>nifi-property-utils</artifactId>
|
<artifactId>nifi-property-utils</artifactId>
|
||||||
|
|
Loading…
Reference in New Issue