2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.lametrictime.internal.api.local;
16 import java.net.URISyntaxException;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
22 * Configuration class for local access.
24 * @author Gregory Moyer - Initial contribution
27 public class LocalConfiguration {
32 private String apiKey;
34 private boolean secure = true;
35 private boolean ignoreCertificateValidation = true;
36 private boolean ignoreHostnameValidation = true;
38 private String insecureScheme = "http";
39 private int insecurePort = 8080;
41 private String secureScheme = "https";
42 private int securePort = 4343;
44 private String basePath = "/api/v2";
46 private String authUser = "dev";
48 private boolean logging = false;
49 private String logLevel = "INFO";
50 private int logMax = 104857600; // 100kb
52 public @Nullable String getHost() {
56 public void setHost(String host) {
60 public LocalConfiguration withHost(@Nullable String host) {
65 public @Nullable String getApiKey() {
69 public void setApiKey(String apiKey) {
73 public LocalConfiguration withApiKey(@Nullable String apiKey) {
78 public boolean isSecure() {
82 public void setSecure(boolean secure) {
86 public LocalConfiguration withSecure(boolean secure) {
91 public boolean isIgnoreCertificateValidation() {
92 return ignoreCertificateValidation;
95 public void setIgnoreCertificateValidation(boolean ignoreCertificateValidation) {
96 this.ignoreCertificateValidation = ignoreCertificateValidation;
99 public LocalConfiguration withIgnoreCertificateValidation(boolean ignoreCertificateValidation) {
100 this.ignoreCertificateValidation = ignoreCertificateValidation;
104 public boolean isIgnoreHostnameValidation() {
105 return ignoreHostnameValidation;
108 public void setIgnoreHostnameValidation(boolean ignoreHostnameValidation) {
109 this.ignoreHostnameValidation = ignoreHostnameValidation;
112 public LocalConfiguration withIgnoreHostnameValidation(boolean ignoreHostnameValidation) {
113 this.ignoreHostnameValidation = ignoreHostnameValidation;
117 public String getInsecureScheme() {
118 return insecureScheme;
121 public void setInsecureScheme(String insecureScheme) {
122 this.insecureScheme = insecureScheme;
125 public LocalConfiguration withInsecureScheme(String insecureScheme) {
126 this.insecureScheme = insecureScheme;
130 public int getInsecurePort() {
134 public void setInsecurePort(int insecurePort) {
135 this.insecurePort = insecurePort;
138 public LocalConfiguration withInsecurePort(int insecurePort) {
139 this.insecurePort = insecurePort;
143 public String getSecureScheme() {
147 public void setSecureScheme(String secureScheme) {
148 this.secureScheme = secureScheme;
151 public LocalConfiguration withSecureScheme(String secureScheme) {
152 this.secureScheme = secureScheme;
156 public int getSecurePort() {
160 public void setSecurePort(int securePort) {
161 this.securePort = securePort;
164 public LocalConfiguration withSecurePort(int securePort) {
165 this.securePort = securePort;
169 public String getBasePath() {
173 public void setBasePath(String basePath) {
174 this.basePath = basePath;
177 public LocalConfiguration withBasePath(String basePath) {
178 this.basePath = basePath;
182 public String getAuthUser() {
186 public void setAuthUser(String authUser) {
187 this.authUser = authUser;
190 public LocalConfiguration withAuthUser(String authUser) {
191 this.authUser = authUser;
195 public boolean isLogging() {
199 public void setLogging(boolean logging) {
200 this.logging = logging;
203 public LocalConfiguration withLogging(boolean logging) {
204 this.logging = logging;
208 public String getLogLevel() {
212 public void setLogLevel(String logLevel) {
213 this.logLevel = logLevel;
216 public LocalConfiguration withLogLevel(String logLevel) {
217 this.logLevel = logLevel;
221 public int getLogMax() {
225 public void setLogMax(int logMax) {
226 this.logMax = logMax;
229 public LocalConfiguration withLogMax(int logMax) {
230 this.logMax = logMax;
234 public URI getBaseUri() {
235 String scheme = secure ? secureScheme : insecureScheme;
236 int port = secure ? securePort : insecurePort;
238 return new URI(scheme, null, host, port, basePath, null, null);
239 } catch (URISyntaxException e) {
240 throw new IllegalStateException("Invalid configuration", e);