Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from launchdarkly/jko/hide-specific-attrs
Browse files Browse the repository at this point in the history
Hide specific user attributes, either globally or per user
  • Loading branch information
jkodumal authored May 23, 2017
2 parents d83d380 + 8287122 commit e2259e2
Show file tree
Hide file tree
Showing 7 changed files with 454 additions and 40 deletions.
10 changes: 2 additions & 8 deletions src/main/java/com/launchdarkly/client/EventProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ boolean sendEvent(Event e) {
return true;
}

// If all user data is hidden, or this user is marked hidden, replace the user with a new user
// containing only the key and the hidden attribute
if (config.hideUserData || (e.user.getHidden() != null && e.user.getHidden().getAsBoolean())) {
e.user = new LDUser.Builder(e.user.getKeyAsString()).hidden(true).build();
}

return queue.offer(e);
}

Expand Down Expand Up @@ -84,10 +78,10 @@ public void flush() {

private void postEvents(List<Event> events) {

String json = LDConfig.gson.toJson(events);
String json = config.gson.toJson(events);
logger.debug("Posting " + events.size() + " event(s) to " + config.eventsURI + " with payload: " + json);

String content = LDConfig.gson.toJson(events);
String content = config.gson.toJson(events);

Request request = config.getRequestBuilder(sdkKey)
.url(config.eventsURI.toString() + "/bulk")
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/launchdarkly/client/FeatureFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class FeatureFlag {
private final List<JsonElement> variations;
private final boolean deleted;

static FeatureFlag fromJson(String json) {
return LDConfig.gson.fromJson(json, FeatureFlag.class);
static FeatureFlag fromJson(LDConfig config, String json) {
return config.gson.fromJson(json, FeatureFlag.class);
}

static Map<String, FeatureFlag> fromJsonMap(String json) {
return LDConfig.gson.fromJson(json, mapType);
static Map<String, FeatureFlag> fromJsonMap(LDConfig config, String json) {
return config.gson.fromJson(json, mapType);
}

FeatureFlag(String key, int version, boolean on, List<Prerequisite> prerequisites, String salt, List<Target> targets, List<Rule> rules, VariationOrRollout fallthrough, Integer offVariation, List<JsonElement> variations, boolean deleted) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/launchdarkly/client/FeatureRequestor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class FeatureRequestor {

Map<String, FeatureFlag> getAllFlags() throws IOException {
String body = get(GET_LATEST_FLAGS_PATH);
return FeatureFlag.fromJsonMap(body);
return FeatureFlag.fromJsonMap(config, body);
}

FeatureFlag getFlag(String featureKey) throws IOException {
String body = get(GET_LATEST_FLAGS_PATH + "/" + featureKey);
return FeatureFlag.fromJson(body);
return FeatureFlag.fromJson(config, body);
}

private String get(String path) throws IOException {
Expand Down
33 changes: 26 additions & 7 deletions src/main/java/com/launchdarkly/client/LDConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.io.Files;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import okhttp3.Authenticator;
import okhttp3.Cache;
import okhttp3.ConnectionPool;
Expand All @@ -18,14 +19,17 @@
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URI;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
* This class exposes advanced configuration options for the {@link LDClient}. Instances of this class must be constructed with a {@link com.launchdarkly.client.LDConfig.Builder}.
*/
public final class LDConfig {
private static final Logger logger = LoggerFactory.getLogger(LDConfig.class);
static final Gson gson = new Gson();
final Gson gson = new GsonBuilder().registerTypeAdapter(LDUser.class, new LDUser.UserAdapter(this)).create();

private static final URI DEFAULT_BASE_URI = URI.create("https://app.launchdarkly.com");
private static final URI DEFAULT_EVENTS_URI = URI.create("https://events.launchdarkly.com");
Expand Down Expand Up @@ -57,7 +61,8 @@ public final class LDConfig {
final FeatureStore featureStore;
final boolean useLdd;
final boolean offline;
final boolean hideUserData;
final boolean privateUserData;
final Set<String> privateAttrNames;
final long pollingIntervalMillis;
final long startWaitMillis;
final int samplingInterval;
Expand All @@ -77,7 +82,8 @@ protected LDConfig(Builder builder) {
this.featureStore = builder.featureStore;
this.useLdd = builder.useLdd;
this.offline = builder.offline;
this.hideUserData = builder.hideUserData;
this.privateUserData = builder.privateUserData;
this.privateAttrNames = new HashSet<>(builder.privateAttrNames);
if (builder.pollingIntervalMillis < DEFAULT_POLLING_INTERVAL_MILLIS) {
this.pollingIntervalMillis = DEFAULT_POLLING_INTERVAL_MILLIS;
} else {
Expand Down Expand Up @@ -144,12 +150,13 @@ public static class Builder {
private boolean stream = true;
private boolean useLdd = false;
private boolean offline = false;
private boolean hideUserData = false;
private boolean privateUserData = false;
private long pollingIntervalMillis = DEFAULT_POLLING_INTERVAL_MILLIS;
private FeatureStore featureStore = new InMemoryFeatureStore();
private long startWaitMillis = DEFAULT_START_WAIT_MILLIS;
private int samplingInterval = DEFAULT_SAMPLING_INTERVAL;
private long reconnectTimeMillis = DEFAULT_RECONNECT_TIME_MILLIS;
private Set<String> privateAttrNames = new HashSet<>();

/**
* Creates a builder with all configuration parameters set to the default
Expand Down Expand Up @@ -373,11 +380,11 @@ public Builder offline(boolean offline) {

/**
* Set whether or not user data (other than the key) should be sent back to LaunchDarkly.
* @param hideUserData
* @param privateUserData
* @return the builder
*/
public Builder hideUserData(boolean hideUserData) {
this.hideUserData = hideUserData;
public Builder privateUserData(boolean privateUserData) {
this.privateUserData = privateUserData;
return this;
}

Expand Down Expand Up @@ -434,6 +441,18 @@ public Builder reconnectTimeMs(long reconnectTimeMs) {
return this;
}

/**
*
* Mark a set of attribute names private. Any users sent to LaunchDarkly with this configuration
* active will have attributes with these names removed.
*
* @param names a set of names that will be removed from user data set to LaunchDarkly
* @return the builder
*/
public Builder privateAttrNames(String... names) {
this.privateAttrNames = new HashSet<>(Arrays.asList(names));
return this;
}

// returns null if none of the proxy bits were configured. Minimum required part: port.
Proxy proxy() {
Expand Down
Loading

0 comments on commit e2259e2

Please sign in to comment.