]> git.basschouten.com Git - openhab-addons.git/blob
09580d93f68e6c2d0b7a438c05c087a633f82ce9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.lametrictime.internal.api.local;
14
15 import java.net.URI;
16 import java.net.URISyntaxException;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 /**
22  * Configuration class for local access.
23  *
24  * @author Gregory Moyer - Initial contribution
25  */
26 @NonNullByDefault
27 public class LocalConfiguration {
28     @Nullable
29     private String host;
30
31     @Nullable
32     private String apiKey;
33
34     private boolean secure = true;
35     private boolean ignoreCertificateValidation = true;
36     private boolean ignoreHostnameValidation = true;
37
38     private String insecureScheme = "http";
39     private int insecurePort = 8080;
40
41     private String secureScheme = "https";
42     private int securePort = 4343;
43
44     private String basePath = "/api/v2";
45
46     private String authUser = "dev";
47
48     private boolean logging = false;
49     private String logLevel = "INFO";
50     private int logMax = 104857600; // 100kb
51
52     public @Nullable String getHost() {
53         return host;
54     }
55
56     public void setHost(String host) {
57         this.host = host;
58     }
59
60     public LocalConfiguration withHost(@Nullable String host) {
61         this.host = host;
62         return this;
63     }
64
65     public @Nullable String getApiKey() {
66         return apiKey;
67     }
68
69     public void setApiKey(String apiKey) {
70         this.apiKey = apiKey;
71     }
72
73     public LocalConfiguration withApiKey(@Nullable String apiKey) {
74         this.apiKey = apiKey;
75         return this;
76     }
77
78     public boolean isSecure() {
79         return secure;
80     }
81
82     public void setSecure(boolean secure) {
83         this.secure = secure;
84     }
85
86     public LocalConfiguration withSecure(boolean secure) {
87         this.secure = secure;
88         return this;
89     }
90
91     public boolean isIgnoreCertificateValidation() {
92         return ignoreCertificateValidation;
93     }
94
95     public void setIgnoreCertificateValidation(boolean ignoreCertificateValidation) {
96         this.ignoreCertificateValidation = ignoreCertificateValidation;
97     }
98
99     public LocalConfiguration withIgnoreCertificateValidation(boolean ignoreCertificateValidation) {
100         this.ignoreCertificateValidation = ignoreCertificateValidation;
101         return this;
102     }
103
104     public boolean isIgnoreHostnameValidation() {
105         return ignoreHostnameValidation;
106     }
107
108     public void setIgnoreHostnameValidation(boolean ignoreHostnameValidation) {
109         this.ignoreHostnameValidation = ignoreHostnameValidation;
110     }
111
112     public LocalConfiguration withIgnoreHostnameValidation(boolean ignoreHostnameValidation) {
113         this.ignoreHostnameValidation = ignoreHostnameValidation;
114         return this;
115     }
116
117     public String getInsecureScheme() {
118         return insecureScheme;
119     }
120
121     public void setInsecureScheme(String insecureScheme) {
122         this.insecureScheme = insecureScheme;
123     }
124
125     public LocalConfiguration withInsecureScheme(String insecureScheme) {
126         this.insecureScheme = insecureScheme;
127         return this;
128     }
129
130     public int getInsecurePort() {
131         return insecurePort;
132     }
133
134     public void setInsecurePort(int insecurePort) {
135         this.insecurePort = insecurePort;
136     }
137
138     public LocalConfiguration withInsecurePort(int insecurePort) {
139         this.insecurePort = insecurePort;
140         return this;
141     }
142
143     public String getSecureScheme() {
144         return secureScheme;
145     }
146
147     public void setSecureScheme(String secureScheme) {
148         this.secureScheme = secureScheme;
149     }
150
151     public LocalConfiguration withSecureScheme(String secureScheme) {
152         this.secureScheme = secureScheme;
153         return this;
154     }
155
156     public int getSecurePort() {
157         return securePort;
158     }
159
160     public void setSecurePort(int securePort) {
161         this.securePort = securePort;
162     }
163
164     public LocalConfiguration withSecurePort(int securePort) {
165         this.securePort = securePort;
166         return this;
167     }
168
169     public String getBasePath() {
170         return basePath;
171     }
172
173     public void setBasePath(String basePath) {
174         this.basePath = basePath;
175     }
176
177     public LocalConfiguration withBasePath(String basePath) {
178         this.basePath = basePath;
179         return this;
180     }
181
182     public String getAuthUser() {
183         return authUser;
184     }
185
186     public void setAuthUser(String authUser) {
187         this.authUser = authUser;
188     }
189
190     public LocalConfiguration withAuthUser(String authUser) {
191         this.authUser = authUser;
192         return this;
193     }
194
195     public boolean isLogging() {
196         return logging;
197     }
198
199     public void setLogging(boolean logging) {
200         this.logging = logging;
201     }
202
203     public LocalConfiguration withLogging(boolean logging) {
204         this.logging = logging;
205         return this;
206     }
207
208     public String getLogLevel() {
209         return logLevel;
210     }
211
212     public void setLogLevel(String logLevel) {
213         this.logLevel = logLevel;
214     }
215
216     public LocalConfiguration withLogLevel(String logLevel) {
217         this.logLevel = logLevel;
218         return this;
219     }
220
221     public int getLogMax() {
222         return logMax;
223     }
224
225     public void setLogMax(int logMax) {
226         this.logMax = logMax;
227     }
228
229     public LocalConfiguration withLogMax(int logMax) {
230         this.logMax = logMax;
231         return this;
232     }
233
234     public URI getBaseUri() {
235         String scheme = secure ? secureScheme : insecureScheme;
236         int port = secure ? securePort : insecurePort;
237         try {
238             return new URI(scheme, null, host, port, basePath, null, null);
239         } catch (URISyntaxException e) {
240             throw new IllegalStateException("Invalid configuration", e);
241         }
242     }
243 }