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  import java.util.Arrays;
23  import java.util.stream.Collectors;
24  
25  /**
26   * The Keys which can be external configured to set values in {@link Config}.
27   */
28  public enum ConfigKey {
29  
30      /** for setting the value {@link Config#withSecretFile(java.io.File)}. */
31      SECRET_FILE,
32      /** for setting the value {@link Config#withSaltLength(int)}. */
33      SALT_LENGTH,
34      /** for setting the value {@link Config#withAllowedAlgorithm(net.brabenetz.lib.securedproperties.core.Algorithm...)}. */
35      ALLOWED_ALGORITHM,
36      /** for setting the value {@link Config#withAutoCreateSecretKey(boolean)}. */
37      AUTO_CREATE_SECRET_KEY;
38  
39      /** default prefix for UPPER_CASE keys. */
40      public static final String DEFAULT_PREFIX_UPPER_CASE = "SECURED_PROPERTIES";
41      /** default prefix for kebab-case keys. */
42      public static final String DEFAULT_PREFIX_KEBAB_CASE = getKebabCase(DEFAULT_PREFIX_UPPER_CASE);
43  
44      private final String kebabCase;
45  
46      ConfigKey() {
47          kebabCase = getKebabCase(getUpperCase());
48      }
49  
50      public String getUpperCase() {
51          return name();
52      }
53  
54      public String getKebabCase() {
55          return kebabCase;
56      }
57  
58      private static String getKebabCase(final String upperCase) {
59          return Arrays.stream(upperCase.split("_"))
60                  .map(String::toLowerCase)
61                  .collect(Collectors.joining("-"));
62      }
63  }