|
20 | 20 | import static org.apache.kafka.common.config.ConfigDef.NO_DEFAULT_VALUE; |
21 | 21 |
|
22 | 22 | import java.lang.reflect.InvocationTargetException; |
| 23 | +import java.net.MalformedURLException; |
| 24 | +import java.net.URL; |
23 | 25 | import java.nio.charset.StandardCharsets; |
24 | 26 | import java.nio.file.Path; |
25 | 27 | import java.nio.file.Paths; |
@@ -122,6 +124,19 @@ public class FitbitRestSourceConnectorConfig extends RestSourceConnectorConfig { |
122 | 124 | private static final String FITBIT_INTRADAY_CALORIES_TOPIC_DISPLAY = "Intraday calories topic"; |
123 | 125 | private static final String FITBIT_INTRADAY_CALORIES_TOPIC_DEFAULT = "connect_fitbit_intraday_calories"; |
124 | 126 |
|
| 127 | + |
| 128 | + public static final String FITBIT_USER_REPOSITORY_CLIENT_ID_CONFIG = "fitbit.user.repository.client.id"; |
| 129 | + private static final String FITBIT_USER_REPOSITORY_CLIENT_ID_DOC = "Client ID for connecting to the service repository."; |
| 130 | + private static final String FITBIT_USER_REPOSITORY_CLIENT_ID_DISPLAY = "Client ID for user repository."; |
| 131 | + |
| 132 | + public static final String FITBIT_USER_REPOSITORY_CLIENT_SECRET_CONFIG = "fitbit.user.repository.client.secret"; |
| 133 | + private static final String FITBIT_USER_REPOSITORY_CLIENT_SECRET_DOC = "Client secret for connecting to the service repository."; |
| 134 | + private static final String FITBIT_USER_REPOSITORY_CLIENT_SECRET_DISPLAY = "Client Secret for user repository."; |
| 135 | + |
| 136 | + public static final String FITBIT_USER_REPOSITORY_TOKEN_URL_CONFIG = "fitbit.user.repository.oauth2.token.url"; |
| 137 | + private static final String FITBIT_USER_REPOSITORY_TOKEN_URL_DOC = "OAuth 2.0 token url for retrieving client credentials."; |
| 138 | + private static final String FITBIT_USER_REPOSITORY_TOKEN_URL_DISPLAY = "OAuth 2.0 token URL."; |
| 139 | + |
125 | 140 | public static final String FITBIT_USER_REPOSITORY_FIRESTORE_FITBIT_COLLECTION_CONFIG = "fitbit.user.firebase.collection.fitbit.name"; |
126 | 141 | private static final String FITBIT_USER_REPOSITORY_FIRESTORE_FITBIT_COLLECTION_DOC = "Firestore Collection for retrieving Fitbit Auth details. Only used when a Firebase based user repository is used."; |
127 | 142 | private static final String FITBIT_USER_REPOSITORY_FIRESTORE_FITBIT_COLLECTION_DISPLAY = "Firebase Fitbit collection name."; |
@@ -242,6 +257,37 @@ public String toString() { |
242 | 257 | Width.SHORT, |
243 | 258 | FITBIT_USER_REPOSITORY_URL_DISPLAY) |
244 | 259 |
|
| 260 | + |
| 261 | + .define(FITBIT_USER_REPOSITORY_CLIENT_ID_CONFIG, |
| 262 | + Type.STRING, |
| 263 | + "", |
| 264 | + Importance.MEDIUM, |
| 265 | + FITBIT_USER_REPOSITORY_CLIENT_ID_DOC, |
| 266 | + group, |
| 267 | + ++orderInGroup, |
| 268 | + Width.SHORT, |
| 269 | + FITBIT_USER_REPOSITORY_CLIENT_ID_DISPLAY) |
| 270 | + |
| 271 | + .define(FITBIT_USER_REPOSITORY_CLIENT_SECRET_CONFIG, |
| 272 | + Type.PASSWORD, |
| 273 | + "", |
| 274 | + Importance.MEDIUM, |
| 275 | + FITBIT_USER_REPOSITORY_CLIENT_SECRET_DOC, |
| 276 | + group, |
| 277 | + ++orderInGroup, |
| 278 | + Width.SHORT, |
| 279 | + FITBIT_USER_REPOSITORY_CLIENT_SECRET_DISPLAY) |
| 280 | + |
| 281 | + .define(FITBIT_USER_REPOSITORY_TOKEN_URL_CONFIG, |
| 282 | + Type.STRING, |
| 283 | + "", |
| 284 | + Importance.MEDIUM, |
| 285 | + FITBIT_USER_REPOSITORY_TOKEN_URL_DOC, |
| 286 | + group, |
| 287 | + ++orderInGroup, |
| 288 | + Width.SHORT, |
| 289 | + FITBIT_USER_REPOSITORY_TOKEN_URL_DISPLAY) |
| 290 | + |
245 | 291 | .define(FITBIT_INTRADAY_STEPS_TOPIC_CONFIG, |
246 | 292 | Type.STRING, |
247 | 293 | FITBIT_INTRADAY_STEPS_TOPIC_DEFAULT, |
@@ -447,4 +493,25 @@ public String getFitbitUserRepositoryFirestoreFitbitCollection() { |
447 | 493 | public String getFitbitUserRepositoryFirestoreUserCollection() { |
448 | 494 | return getString(FITBIT_USER_REPOSITORY_FIRESTORE_USER_COLLECTION_CONFIG); |
449 | 495 | } |
| 496 | + |
| 497 | + public String getFitbitUserRepositoryClientId() { |
| 498 | + return getString(FITBIT_USER_REPOSITORY_CLIENT_ID_CONFIG); |
| 499 | + } |
| 500 | + |
| 501 | + public String getFitbitUserRepositoryClientSecret() { |
| 502 | + return getPassword(FITBIT_USER_REPOSITORY_CLIENT_SECRET_CONFIG).value(); |
| 503 | + } |
| 504 | + |
| 505 | + public URL getFitbitUserRepositoryTokenUrl() { |
| 506 | + String value = getString(FITBIT_USER_REPOSITORY_TOKEN_URL_CONFIG); |
| 507 | + if (value == null || value.isEmpty()) { |
| 508 | + return null; |
| 509 | + } else { |
| 510 | + try { |
| 511 | + return new URL(getString(FITBIT_USER_REPOSITORY_TOKEN_URL_CONFIG)); |
| 512 | + } catch (MalformedURLException e) { |
| 513 | + throw new ConfigException("Fitbit user repository token URL is invalid."); |
| 514 | + } |
| 515 | + } |
| 516 | + } |
450 | 517 | } |
0 commit comments