2 * Copyright 2017 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.cli.fw.conf;
19 import java.io.IOException;
20 import java.util.Arrays;
21 import java.util.HashMap;
22 import java.util.List;
24 import java.util.Properties;
26 import java.util.UUID;
27 import java.util.stream.Collectors;
30 * Onap command constants.
33 public final class OnapCommandConfg {
35 private static Properties prps = new Properties();
38 * Private constructor.
40 private OnapCommandConfg() {
46 prps.load(OnapCommandConfg.class.getClassLoader().getResourceAsStream(Constants.CONF));
47 } catch (IOException e) {
48 throw new RuntimeException(e); // NOSONAR
53 * is auth service ignored.
57 public static boolean isAuthIgnored() {
58 if ("true".equals(prps.getProperty(Constants.ONAP_IGNORE_AUTH))) {
65 public static String getVersion() {
66 return prps.getProperty(Constants.ONAP_CLI_VERSION);
70 * checks if cookies based auth.
74 public static boolean isCookiesBasedAuth() {
75 if ("true".equals(prps.getProperty(Constants.HTTP_API_KEY_USE_COOKIES))) {
82 public static String getXAuthTokenName() {
83 return prps.getProperty(Constants.SERVICE_AUTH_BASIC_HTTP_HEADERS + "." + Constants.X_AUTH_TOKEN);
86 public static String getInternalCmd() {
87 return prps.getProperty(Constants.SERVICE_NAME);
90 public static String getApiGateway() {
91 return prps.getProperty(Constants.API_GATEWAY);
94 public static String getAuthService() {
95 return prps.getProperty(Constants.AUTH_SERVICE);
98 public static String getAuthType() {
99 return prps.getProperty(Constants.SERVICE_AUTH, Constants.AUTH_BASIC);
102 public static Map<String, String> getBasicCommonHeaders() {
103 Map<String, String> mapHeaders = new HashMap<String, String> ();
105 Arrays.stream(prps.getProperty(Constants.SERVICE_AUTH_BASIC_HTTP_HEADERS) // NOSONAR
106 .split(",")).map(String::trim).forEach(header -> {
107 String headerName = prps.getProperty(Constants.SERVICE_AUTH_BASIC_HTTP_HEADERS + "." + header);
108 String headerValue = prps.getProperty(Constants.SERVICE_AUTH_BASIC_HTTP_HEADERS + "." + header + ".value", null);
109 if (headerValue != null) {
110 headerValue = headerValue.replaceAll("uuid", UUID.randomUUID().toString());
112 mapHeaders.put(headerName, headerValue);
118 public static Set<String> getExcludeParamsForInternalCmd() {
119 return Arrays.stream(prps.getProperty(Constants.EXCLUDE_PARAMS_INTERNAL_CMD) // NOSONAR
120 .split(",")).map(String::trim).collect(Collectors.toSet());
123 public static Set<String> getIncludeParamsForNoAuthDisableExternalCmd() {
124 return Arrays.stream(prps.getProperty(Constants.NO_AUTH_DISABLE_INCLUDE_PARAMS_EXTERNAL_CMD) // NOSONAR
125 .split(",")).map(String::trim).collect(Collectors.toSet());
128 public static Set<String> getExcludeParamsForNoAuthEnableExternalCmd() {
129 return Arrays.stream(prps.getProperty(Constants.NO_AUTH_ENABLE_EXCLUDE_PARAMS_EXTERNAL_CMD) // NOSONAR
130 .split(",")).map(String::trim).collect(Collectors.toSet());
133 public static Set<String> getIncludeParamsForNoAuthEnableExternalCmd() {
134 return Arrays.stream(prps.getProperty(Constants.NO_AUTH_ENABLE_INCLUDE_PARAMS_EXTERNAL_CMD) // NOSONAR
135 .split(",")).map(String::trim).collect(Collectors.toSet());
138 public static List<String> getSchemaAttrInfo(String key) {
139 return Arrays.stream(prps.getProperty(key).split(",")).map(String::trim).collect(Collectors.toList()); // NOSONAR