]> git.basschouten.com Git - openhab-addons.git/blob
128cea2cda42ee3f0e5f3655d6c86746fac7fb30
[openhab-addons.git] /
1 /**
2  * Copyright 2017-2018 Gregory Moyer and contributors.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.openhab.binding.lametrictime.api.local;
17
18 import java.net.URI;
19 import java.net.URISyntaxException;
20
21 public class LocalConfiguration
22 {
23     private String host;
24     private String apiKey;
25
26     private boolean secure = true;
27     private boolean ignoreCertificateValidation = true;
28     private boolean ignoreHostnameValidation = true;
29
30     private String insecureScheme = "http";
31     private int insecurePort = 8080;
32
33     private String secureScheme = "https";
34     private int securePort = 4343;
35
36     private String basePath = "/api/v2";
37
38     private String authUser = "dev";
39
40     private boolean logging = false;
41     private String logLevel = "INFO";
42     private int logMax = 104857600; // 100kb
43
44     public String getHost()
45     {
46         return host;
47     }
48
49     public void setHost(String host)
50     {
51         this.host = host;
52     }
53
54     public LocalConfiguration withHost(String host)
55     {
56         this.host = host;
57         return this;
58     }
59
60     public String getApiKey()
61     {
62         return apiKey;
63     }
64
65     public void setApiKey(String apiKey)
66     {
67         this.apiKey = apiKey;
68     }
69
70     public LocalConfiguration withApiKey(String apiKey)
71     {
72         this.apiKey = apiKey;
73         return this;
74     }
75
76     public boolean isSecure()
77     {
78         return secure;
79     }
80
81     public void setSecure(boolean secure)
82     {
83         this.secure = secure;
84     }
85
86     public LocalConfiguration withSecure(boolean secure)
87     {
88         this.secure = secure;
89         return this;
90     }
91
92     public boolean isIgnoreCertificateValidation()
93     {
94         return ignoreCertificateValidation;
95     }
96
97     public void setIgnoreCertificateValidation(boolean ignoreCertificateValidation)
98     {
99         this.ignoreCertificateValidation = ignoreCertificateValidation;
100     }
101
102     public LocalConfiguration withIgnoreCertificateValidation(boolean ignoreCertificateValidation)
103     {
104         this.ignoreCertificateValidation = ignoreCertificateValidation;
105         return this;
106     }
107
108     public boolean isIgnoreHostnameValidation()
109     {
110         return ignoreHostnameValidation;
111     }
112
113     public void setIgnoreHostnameValidation(boolean ignoreHostnameValidation)
114     {
115         this.ignoreHostnameValidation = ignoreHostnameValidation;
116     }
117
118     public LocalConfiguration withIgnoreHostnameValidation(boolean ignoreHostnameValidation)
119     {
120         this.ignoreHostnameValidation = ignoreHostnameValidation;
121         return this;
122     }
123
124     public String getInsecureScheme()
125     {
126         return insecureScheme;
127     }
128
129     public void setInsecureScheme(String insecureScheme)
130     {
131         this.insecureScheme = insecureScheme;
132     }
133
134     public LocalConfiguration withInsecureScheme(String insecureScheme)
135     {
136         this.insecureScheme = insecureScheme;
137         return this;
138     }
139
140     public int getInsecurePort()
141     {
142         return insecurePort;
143     }
144
145     public void setInsecurePort(int insecurePort)
146     {
147         this.insecurePort = insecurePort;
148     }
149
150     public LocalConfiguration withInsecurePort(int insecurePort)
151     {
152         this.insecurePort = insecurePort;
153         return this;
154     }
155
156     public String getSecureScheme()
157     {
158         return secureScheme;
159     }
160
161     public void setSecureScheme(String secureScheme)
162     {
163         this.secureScheme = secureScheme;
164     }
165
166     public LocalConfiguration withSecureScheme(String secureScheme)
167     {
168         this.secureScheme = secureScheme;
169         return this;
170     }
171
172     public int getSecurePort()
173     {
174         return securePort;
175     }
176
177     public void setSecurePort(int securePort)
178     {
179         this.securePort = securePort;
180     }
181
182     public LocalConfiguration withSecurePort(int securePort)
183     {
184         this.securePort = securePort;
185         return this;
186     }
187
188     public String getBasePath()
189     {
190         return basePath;
191     }
192
193     public void setBasePath(String basePath)
194     {
195         this.basePath = basePath;
196     }
197
198     public LocalConfiguration withBasePath(String basePath)
199     {
200         this.basePath = basePath;
201         return this;
202     }
203
204     public String getAuthUser()
205     {
206         return authUser;
207     }
208
209     public void setAuthUser(String authUser)
210     {
211         this.authUser = authUser;
212     }
213
214     public LocalConfiguration withAuthUser(String authUser)
215     {
216         this.authUser = authUser;
217         return this;
218     }
219
220     public boolean isLogging()
221     {
222         return logging;
223     }
224
225     public void setLogging(boolean logging)
226     {
227         this.logging = logging;
228     }
229
230     public LocalConfiguration withLogging(boolean logging)
231     {
232         this.logging = logging;
233         return this;
234     }
235
236     public String getLogLevel()
237     {
238         return logLevel;
239     }
240
241     public void setLogLevel(String logLevel)
242     {
243         this.logLevel = logLevel;
244     }
245
246     public LocalConfiguration withLogLevel(String logLevel)
247     {
248         this.logLevel = logLevel;
249         return this;
250     }
251
252     public int getLogMax()
253     {
254         return logMax;
255     }
256
257     public void setLogMax(int logMax)
258     {
259         this.logMax = logMax;
260     }
261
262     public LocalConfiguration withLogMax(int logMax)
263     {
264         this.logMax = logMax;
265         return this;
266     }
267
268     public URI getBaseUri()
269     {
270         String scheme = secure ? secureScheme : insecureScheme;
271         int port = secure ? securePort : insecurePort;
272         try
273         {
274             return new URI(scheme, null, host, port, basePath, null, null);
275         }
276         catch (URISyntaxException e)
277         {
278             throw new RuntimeException("Invalid configuration", e);
279         }
280     }
281 }