Skip to content

Feat: Added SetDatafileAccessToken method in OptimizelyFactory #384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,6 @@ jobs:
notifications:
email: false

- stage: 'Lint markdown files'
os: linux
language: generic
before_install: skip
install:
- npm i -g markdown-spellcheck
before_script:
- wget --quiet https://raw.githubusercontent.com/optimizely/mdspell-config/master/.spelling
script:
- mdspell -a -n -r --en-us '**/*.md'
after_success: skip

- stage: 'Integration tests'
addons:
srcclr: true
Expand Down
2 changes: 2 additions & 0 deletions core-httpclient-impl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ The following builder methods can be used to custom configure the `HttpProjectCo
|`withPollingInterval(Long, TimeUnit)`|5 minutes|Fixed delay between fetches for the datafile.|
|`withBlockingTimeout(Long, TimeUnit)`|10 seconds|Maximum time to wait for initial bootstrapping.|
|`withSdkKey(String)`|null|Optimizely project SDK key. Required unless source URL is overridden.|
|`withDatafileAccessToken(String)`|null|Token for authenticated datafile access.|

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

## Update Config Notifications
A notification signal will be triggered whenever a _new_ datafile is fetched. To subscribe to these notifications you can
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2019, Optimizely
* Copyright 2019-2020, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,6 +42,7 @@
* <li>{@link OptimizelyFactory#setBlockingTimeout}</li>
* <li>{@link OptimizelyFactory#setPollingInterval}</li>
* <li>{@link OptimizelyFactory#setSdkKey}</li>
* <li>{@link OptimizelyFactory#setDatafileAccessToken}</li>
* </ul>
*
*/
Expand Down Expand Up @@ -144,6 +145,19 @@ public static void setSdkKey(String sdkKey) {
PropertyUtils.set(HttpProjectConfigManager.CONFIG_SDK_KEY, sdkKey);
}

/**
* Convenience method for setting the Datafile Access Token on System properties.
* {@link HttpProjectConfigManager.Builder#withDatafileAccessToken(String)}
*/
public static void setDatafileAccessToken(String datafileAccessToken) {
if (datafileAccessToken == null) {
logger.warn("Datafile Access Token cannot be null. Reverting to default configuration.");
return;
}

PropertyUtils.set(HttpProjectConfigManager.CONFIG_DATAFILE_AUTH_TOKEN, datafileAccessToken);
}

/**
* Returns a new Optimizely instance based on preset configuration.
* EventHandler - {@link AsyncEventHandler}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2019, Optimizely
* Copyright 2019-2020, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -170,6 +170,22 @@ public void setInvalidSdkKey() {
assertEquals(expected, PropertyUtils.get(HttpProjectConfigManager.CONFIG_SDK_KEY));
}

@Test
public void setDatafileAccessToken() {
String expected = "datafile-access-token";
OptimizelyFactory.setDatafileAccessToken(expected);

assertEquals(expected, PropertyUtils.get(HttpProjectConfigManager.CONFIG_DATAFILE_AUTH_TOKEN));
}

@Test
public void setInvalidDatafileAccessToken() {
String expected = "datafile-access-token";
OptimizelyFactory.setDatafileAccessToken(expected);
OptimizelyFactory.setDatafileAccessToken(null);
assertEquals(expected, PropertyUtils.get(HttpProjectConfigManager.CONFIG_DATAFILE_AUTH_TOKEN));
}

@Test
public void newDefaultInstanceInvalid() {
optimizely = OptimizelyFactory.newDefaultInstance();
Expand Down