Skip to content

Commit 24205e9

Browse files
authored
feat: Added SetDatafileAccessToken method in OptimizelyFactory (#384)
1 parent 7d0547e commit 24205e9

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

.travis.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ jobs:
5050
notifications:
5151
email: false
5252

53-
- stage: 'Lint markdown files'
54-
os: linux
55-
language: generic
56-
before_install: skip
57-
install:
58-
- npm i -g markdown-spellcheck
59-
before_script:
60-
- wget --quiet https://raw.githubusercontent.com/optimizely/mdspell-config/master/.spelling
61-
script:
62-
- mdspell -a -n -r --en-us '**/*.md'
63-
after_success: skip
64-
6553
- stage: 'Integration tests'
6654
addons:
6755
srcclr: true

core-httpclient-impl/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ The following builder methods can be used to custom configure the `HttpProjectCo
171171
|`withPollingInterval(Long, TimeUnit)`|5 minutes|Fixed delay between fetches for the datafile.|
172172
|`withBlockingTimeout(Long, TimeUnit)`|10 seconds|Maximum time to wait for initial bootstrapping.|
173173
|`withSdkKey(String)`|null|Optimizely project SDK key. Required unless source URL is overridden.|
174+
|`withDatafileAccessToken(String)`|null|Token for authenticated datafile access.|
174175

175176
### Advanced configuration
176177
The following properties can be set to override the default configuration.
@@ -182,6 +183,7 @@ The following properties can be set to override the default configuration.
182183
|**http.project.config.manager.blocking.duration**|10|Maximum time to wait for initial bootstrapping|
183184
|**http.project.config.manager.blocking.unit**|SECONDS|Time unit corresponding to blocking duration|
184185
|**http.project.config.manager.sdk.key**|null|Optimizely project SDK key|
186+
|**http.project.config.manager.datafile.auth.token**|null|Token for authenticated datafile access|
185187

186188
## Update Config Notifications
187189
A notification signal will be triggered whenever a _new_ datafile is fetched. To subscribe to these notifications you can

core-httpclient-impl/src/main/java/com/optimizely/ab/OptimizelyFactory.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2019, Optimizely
3+
* Copyright 2019-2020, Optimizely
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@
4242
* <li>{@link OptimizelyFactory#setBlockingTimeout}</li>
4343
* <li>{@link OptimizelyFactory#setPollingInterval}</li>
4444
* <li>{@link OptimizelyFactory#setSdkKey}</li>
45+
* <li>{@link OptimizelyFactory#setDatafileAccessToken}</li>
4546
* </ul>
4647
*
4748
*/
@@ -144,6 +145,19 @@ public static void setSdkKey(String sdkKey) {
144145
PropertyUtils.set(HttpProjectConfigManager.CONFIG_SDK_KEY, sdkKey);
145146
}
146147

148+
/**
149+
* Convenience method for setting the Datafile Access Token on System properties.
150+
* {@link HttpProjectConfigManager.Builder#withDatafileAccessToken(String)}
151+
*/
152+
public static void setDatafileAccessToken(String datafileAccessToken) {
153+
if (datafileAccessToken == null) {
154+
logger.warn("Datafile Access Token cannot be null. Reverting to default configuration.");
155+
return;
156+
}
157+
158+
PropertyUtils.set(HttpProjectConfigManager.CONFIG_DATAFILE_AUTH_TOKEN, datafileAccessToken);
159+
}
160+
147161
/**
148162
* Returns a new Optimizely instance based on preset configuration.
149163
* EventHandler - {@link AsyncEventHandler}

core-httpclient-impl/src/test/java/com/optimizely/ab/OptimizelyFactoryTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2019, Optimizely
3+
* Copyright 2019-2020, Optimizely
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -170,6 +170,22 @@ public void setInvalidSdkKey() {
170170
assertEquals(expected, PropertyUtils.get(HttpProjectConfigManager.CONFIG_SDK_KEY));
171171
}
172172

173+
@Test
174+
public void setDatafileAccessToken() {
175+
String expected = "datafile-access-token";
176+
OptimizelyFactory.setDatafileAccessToken(expected);
177+
178+
assertEquals(expected, PropertyUtils.get(HttpProjectConfigManager.CONFIG_DATAFILE_AUTH_TOKEN));
179+
}
180+
181+
@Test
182+
public void setInvalidDatafileAccessToken() {
183+
String expected = "datafile-access-token";
184+
OptimizelyFactory.setDatafileAccessToken(expected);
185+
OptimizelyFactory.setDatafileAccessToken(null);
186+
assertEquals(expected, PropertyUtils.get(HttpProjectConfigManager.CONFIG_DATAFILE_AUTH_TOKEN));
187+
}
188+
173189
@Test
174190
public void newDefaultInstanceInvalid() {
175191
optimizely = OptimizelyFactory.newDefaultInstance();

0 commit comments

Comments
 (0)