-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUnifyAutoConfig.java
More file actions
504 lines (475 loc) · 16.5 KB
/
Copy pathUnifyAutoConfig.java
File metadata and controls
504 lines (475 loc) · 16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
package com.apideck.unify;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import java.util.concurrent.TimeUnit;
import com.apideck.unify.utils.BackoffStrategy;
import com.apideck.unify.utils.HTTPClient;
import com.apideck.unify.utils.RetryConfig;
import com.apideck.unify.utils.SpeakeasyHTTPClient;
import java.lang.IllegalStateException;
import java.lang.String;
import java.lang.System;
import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Consumer;
/**
* Spring Boot Auto Configuration for Apideck SDK
* This configuration class automatically configures the Apideck SDK
* when Spring Boot detects it on the classpath.
*/
@AutoConfiguration
@ConditionalOnClass(Apideck.class)
@EnableConfigurationProperties(UnifyAutoConfigProperties.class)
public class UnifyAutoConfig {
/**
* Constructor.
*/
public UnifyAutoConfig() {
}
/**
* Creates a RetryConfig bean from properties if retry is enabled.
*
* @param properties the configuration properties
* @return A configured RetryConfig instance
*/
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "unify.retry-config", name = "strategy")
public RetryConfig retryConfig(UnifyAutoConfigProperties properties) {
UnifyAutoConfigProperties.RetryConfig retryProps = properties.getRetryConfig();
if (RetryConfig.Strategy.BACKOFF.equals(retryProps.getStrategy())) {
UnifyAutoConfigProperties.RetryConfig.Backoff backoff = retryProps.getBackoff();
return RetryConfig.builder()
.backoff(
BackoffStrategy.builder()
.initialInterval(backoff.getInitialInterval().toMillis(), TimeUnit.MILLISECONDS)
.maxInterval(backoff.getMaxInterval().toMillis(), TimeUnit.MILLISECONDS)
.maxElapsedTime(backoff.getMaxElapsedTime().toMillis(), TimeUnit.MILLISECONDS)
.baseFactor(backoff.getBaseFactor())
.jitterFactor(backoff.getJitterFactor())
.retryConnectError(backoff.isRetryConnectError())
.retryReadTimeoutError(backoff.isRetryReadTimeoutError())
.build()
)
.build();
}
// Default retry config for other strategies
return RetryConfig.builder().build();
}
/**
* Creates a {@code Consumer<String>} bean for HTTP debug logging if none exists.
* This logger is used by the SpeakeasyHTTPClient for debug output when debug logging is enabled.
* By default, it logs to {@code System.out}, but can be customized by providing your own {@code Consumer<String>} bean.
*
* @return A {@code Consumer<String>} that logs messages to {@code System.out}
*/
@Bean
@ConditionalOnMissingBean
public Consumer<String> httpLogger() {
return System.out::println;
}
/**
* Creates an HTTPClient bean if none exists.
*
* @param properties the configuration properties
* @param httpLogger the logger for HTTP debug output
* @return A configured HTTPClient instance
*/
@Bean
@ConditionalOnMissingBean
public HTTPClient httpClient(UnifyAutoConfigProperties properties, Consumer<String> httpLogger) {
UnifyAutoConfigProperties.HttpClient httpClientProps = properties.getHttpClient();
// Configure the static logger
SpeakeasyHTTPClient.setLogger(httpLogger);
if (httpClientProps != null) {
// Configure debug logging
SpeakeasyHTTPClient.setDebugLogging(httpClientProps.isEnableDebugLogging());
// Configure redacted headers
if (httpClientProps.getRedactedHeaders() != null && !httpClientProps.getRedactedHeaders().isEmpty()) {
SpeakeasyHTTPClient.setRedactedHeaders(httpClientProps.getRedactedHeaders());
}
}
return new SpeakeasyHTTPClient();
}
/**
* Creates a SecuritySource bean if none exists and security properties are configured.
*
* @param properties the configuration properties
* @return A configured SecuritySource instance
*/
@Bean
@ConditionalOnMissingBean
@ConditionalOnPropertyPrefix(prefix = "unify.security")
public SecuritySource securitySource(UnifyAutoConfigProperties properties) {UnifyAutoConfigProperties.Security securityProps = properties.getSecurity();
com.apideck.unify.models.components.Security.Builder securityBuilder = com.apideck.unify.models.components.Security.builder();
boolean hasAnySecurityConfiguration = false;
// Build apiKey security from direct properties (primitive value)
if (securityProps.getApiKey() != null) {
securityBuilder.apiKey(securityProps.getApiKey());
hasAnySecurityConfiguration = true;
}
if (!hasAnySecurityConfiguration) {
throw new IllegalStateException("Security configuration is present but no security options are configured. " +
"Please configure at least one security option in your application properties.");
}
return SecuritySource.of(securityBuilder.build());
}
/**
* Creates the SDKConfiguration bean as the single source of truth for all SDK configuration.
*
* @param properties the configuration properties
* @param httpClient the HTTP client bean
* @param hooks the hooks bean
* @param asyncHooks the async hooks bean
* @param securitySource the security source bean (optional)
* @param globals the globals configuration bean
* @param retryConfig the retry config bean (optional)
* @return A configured SDKConfiguration instance
*/
@Bean
@ConditionalOnMissingBean
public SDKConfiguration sdkConfiguration(
UnifyAutoConfigProperties properties,
HTTPClient httpClient,
com.apideck.unify.utils.Hooks hooks,
com.apideck.unify.utils.AsyncHooks asyncHooks,
SecuritySource securitySource,
com.apideck.unify.utils.Globals globals,
Optional<RetryConfig> retryConfig) {
SDKConfiguration sdkConfiguration = new SDKConfiguration();
sdkConfiguration.setClient(httpClient);
sdkConfiguration.setHooks(hooks);
sdkConfiguration.setAsyncHooks(asyncHooks);
sdkConfiguration.setSecuritySource(securitySource);
if (properties.getServerUrl() != null) {
sdkConfiguration.setServerUrl(properties.getServerUrl());
}
sdkConfiguration.setServerIdx(properties.getServerIdx());
sdkConfiguration.setGlobals(globals);
sdkConfiguration.setRetryConfig(retryConfig);
return sdkConfiguration;
}
/**
* Creates the main SDK bean using the configured SDKConfiguration.
*
* @param sdkConfiguration the configured SDKConfiguration bean
* @return A configured Apideck instance
*/
@Bean
@ConditionalOnMissingBean
public Apideck apideck(SDKConfiguration sdkConfiguration) {
return new Apideck(sdkConfiguration);
}
/**
* Creates a Globals configuration bean if none exists, populated from properties.
*
* @param properties the configuration properties
* @return A configured Globals instance
*/
@Bean
@ConditionalOnMissingBean
public com.apideck.unify.utils.Globals globals(UnifyAutoConfigProperties properties) {
com.apideck.unify.utils.Globals globals = new com.apideck.unify.utils.Globals();
// Populate globals from properties
UnifyAutoConfigProperties.Globals globalProps = properties.getGlobals();
if (globalProps.getConsumerId() != null) {
globals.putParam("header", "x-apideck-consumer-id", globalProps.getConsumerId());
}
if (globalProps.getAppId() != null) {
globals.putParam("header", "x-apideck-app-id", globalProps.getAppId());
}
return globals;
}
/**
* Creates an AsyncHooks bean if none exists.
*
* @return A configured AsyncHooks instance
*/
@Bean
@ConditionalOnMissingBean
public com.apideck.unify.utils.AsyncHooks asyncHooks() {
return new com.apideck.unify.utils.AsyncHooks();
}
/**
* Creates a ScheduledExecutorService for async retry operations if none exists.
*
* @return A configured ScheduledExecutorService instance
*/
@Bean
@ConditionalOnMissingBean
public ScheduledExecutorService retryScheduler() {
return Executors.newSingleThreadScheduledExecutor();
}
/**
* Creates a Hooks configuration bean if none exists.
*
* @return A configured Hooks instance
*/
@Bean
@ConditionalOnMissingBean
public com.apideck.unify.utils.Hooks hooks() {
return new com.apideck.unify.utils.Hooks();
}
/**
* Creates a Accounting sub-SDK bean if none exists.
*
* @param apideck the main SDK instance
* @return A configured Accounting instance
*/
@Bean
@ConditionalOnMissingBean
public Accounting accounting(Apideck apideck) {
return apideck.accounting();
}
/**
* Creates a Ats sub-SDK bean if none exists.
*
* @param apideck the main SDK instance
* @return A configured Ats instance
*/
@Bean
@ConditionalOnMissingBean
public Ats ats(Apideck apideck) {
return apideck.ats();
}
/**
* Creates a Crm sub-SDK bean if none exists.
*
* @param apideck the main SDK instance
* @return A configured Crm instance
*/
@Bean
@ConditionalOnMissingBean
public Crm crm(Apideck apideck) {
return apideck.crm();
}
/**
* Creates a Ecommerce sub-SDK bean if none exists.
*
* @param apideck the main SDK instance
* @return A configured Ecommerce instance
*/
@Bean
@ConditionalOnMissingBean
public Ecommerce ecommerce(Apideck apideck) {
return apideck.ecommerce();
}
/**
* Creates a FileStorage sub-SDK bean if none exists.
*
* @param apideck the main SDK instance
* @return A configured FileStorage instance
*/
@Bean
@ConditionalOnMissingBean
public FileStorage fileStorage(Apideck apideck) {
return apideck.fileStorage();
}
/**
* Creates a Hris sub-SDK bean if none exists.
*
* @param apideck the main SDK instance
* @return A configured Hris instance
*/
@Bean
@ConditionalOnMissingBean
public Hris hris(Apideck apideck) {
return apideck.hris();
}
/**
* Creates a Sms sub-SDK bean if none exists.
*
* @param apideck the main SDK instance
* @return A configured Sms instance
*/
@Bean
@ConditionalOnMissingBean
public Sms sms(Apideck apideck) {
return apideck.sms();
}
/**
* Creates a IssueTracking sub-SDK bean if none exists.
*
* @param apideck the main SDK instance
* @return A configured IssueTracking instance
*/
@Bean
@ConditionalOnMissingBean
public IssueTracking issueTracking(Apideck apideck) {
return apideck.issueTracking();
}
/**
* Creates a Connector sub-SDK bean if none exists.
*
* @param apideck the main SDK instance
* @return A configured Connector instance
*/
@Bean
@ConditionalOnMissingBean
public Connector connector(Apideck apideck) {
return apideck.connector();
}
/**
* Creates a Vault sub-SDK bean if none exists.
*
* @param apideck the main SDK instance
* @return A configured Vault instance
*/
@Bean
@ConditionalOnMissingBean
public Vault vault(Apideck apideck) {
return apideck.vault();
}
/**
* Creates a Webhook sub-SDK bean if none exists.
*
* @param apideck the main SDK instance
* @return A configured Webhook instance
*/
@Bean
@ConditionalOnMissingBean
public Webhook webhook(Apideck apideck) {
return apideck.webhook();
}
/**
* Creates the async SDK bean if none exists.
*
* @param apideck the main SDK instance
* @param sdkConfiguration the configured SDKConfiguration bean
* @return A configured AsyncApideck instance
*/
@Bean
@ConditionalOnMissingBean
public AsyncApideck asyncApideck(Apideck apideck, SDKConfiguration sdkConfiguration) {
return new AsyncApideck(apideck, sdkConfiguration);
}
/**
* Creates an AsyncAccounting sub-SDK bean if none exists.
*
* @param asyncApideck the async SDK instance
* @return A configured AsyncAccounting instance
*/
@Bean
@ConditionalOnMissingBean
public AsyncAccounting asyncAccounting(AsyncApideck asyncApideck) {
return asyncApideck.accounting();
}
/**
* Creates an AsyncAts sub-SDK bean if none exists.
*
* @param asyncApideck the async SDK instance
* @return A configured AsyncAts instance
*/
@Bean
@ConditionalOnMissingBean
public AsyncAts asyncAts(AsyncApideck asyncApideck) {
return asyncApideck.ats();
}
/**
* Creates an AsyncCrm sub-SDK bean if none exists.
*
* @param asyncApideck the async SDK instance
* @return A configured AsyncCrm instance
*/
@Bean
@ConditionalOnMissingBean
public AsyncCrm asyncCrm(AsyncApideck asyncApideck) {
return asyncApideck.crm();
}
/**
* Creates an AsyncEcommerce sub-SDK bean if none exists.
*
* @param asyncApideck the async SDK instance
* @return A configured AsyncEcommerce instance
*/
@Bean
@ConditionalOnMissingBean
public AsyncEcommerce asyncEcommerce(AsyncApideck asyncApideck) {
return asyncApideck.ecommerce();
}
/**
* Creates an AsyncFileStorage sub-SDK bean if none exists.
*
* @param asyncApideck the async SDK instance
* @return A configured AsyncFileStorage instance
*/
@Bean
@ConditionalOnMissingBean
public AsyncFileStorage asyncFileStorage(AsyncApideck asyncApideck) {
return asyncApideck.fileStorage();
}
/**
* Creates an AsyncHris sub-SDK bean if none exists.
*
* @param asyncApideck the async SDK instance
* @return A configured AsyncHris instance
*/
@Bean
@ConditionalOnMissingBean
public AsyncHris asyncHris(AsyncApideck asyncApideck) {
return asyncApideck.hris();
}
/**
* Creates an AsyncSms sub-SDK bean if none exists.
*
* @param asyncApideck the async SDK instance
* @return A configured AsyncSms instance
*/
@Bean
@ConditionalOnMissingBean
public AsyncSms asyncSms(AsyncApideck asyncApideck) {
return asyncApideck.sms();
}
/**
* Creates an AsyncIssueTracking sub-SDK bean if none exists.
*
* @param asyncApideck the async SDK instance
* @return A configured AsyncIssueTracking instance
*/
@Bean
@ConditionalOnMissingBean
public AsyncIssueTracking asyncIssueTracking(AsyncApideck asyncApideck) {
return asyncApideck.issueTracking();
}
/**
* Creates an AsyncConnector sub-SDK bean if none exists.
*
* @param asyncApideck the async SDK instance
* @return A configured AsyncConnector instance
*/
@Bean
@ConditionalOnMissingBean
public AsyncConnector asyncConnector(AsyncApideck asyncApideck) {
return asyncApideck.connector();
}
/**
* Creates an AsyncVault sub-SDK bean if none exists.
*
* @param asyncApideck the async SDK instance
* @return A configured AsyncVault instance
*/
@Bean
@ConditionalOnMissingBean
public AsyncVault asyncVault(AsyncApideck asyncApideck) {
return asyncApideck.vault();
}
/**
* Creates an AsyncWebhook sub-SDK bean if none exists.
*
* @param asyncApideck the async SDK instance
* @return A configured AsyncWebhook instance
*/
@Bean
@ConditionalOnMissingBean
public AsyncWebhook asyncWebhook(AsyncApideck asyncApideck) {
return asyncApideck.webhook();
}
}