View Javadoc
1   /*-
2    * #%L
3    * Secured Properties
4    * ===============================================================
5    * Copyright (C) 2016 - 2019 Brabenetz Harald, Austria
6    * ===============================================================
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package net.brabenetz.lib.securedproperties.config;
21  
22  /**
23   * {@link ConfigInitializer} implementation to read from System Properties ({@link System#getProperty(String)}).
24   * <p>
25   * The property-Prefix is "secured-properties".<br>
26   * The Keys must be kebab-case like 'secured-properties.secret-file'.
27   */
28  public class ConfigBySystemProperties extends AbstractConfigInitializer {
29  
30      public ConfigBySystemProperties() {
31          this(ConfigKey.DEFAULT_PREFIX_KEBAB_CASE);
32      }
33  
34      public ConfigBySystemProperties(final String configKeyPrefix) {
35          super(configKeyPrefix, ConfigKey::getKebabCase, (final ConfigKey key) -> configKeyPrefix + "." + key.getKebabCase());
36      }
37  
38      @Override
39      protected String getValue(final ConfigKey key) {
40          return System.getProperty(getKeyFactory().apply(key));
41      }
42  
43  }