Skip to content

Feat: added SDKkey and environment in datafile #434

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
Jun 21, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class DatafileProjectConfig implements ProjectConfig {
private final String accountId;
private final String projectId;
private final String revision;
private final String sdkKey;
private final String environmentKey;
private final String version;
private final boolean anonymizeIP;
private final boolean sendFlagDecisions;
Expand Down Expand Up @@ -108,6 +110,8 @@ public DatafileProjectConfig(String accountId, String projectId, String version,
null,
projectId,
revision,
null,
null,
version,
attributes,
audiences,
Expand All @@ -127,6 +131,8 @@ public DatafileProjectConfig(String accountId,
Boolean botFiltering,
String projectId,
String revision,
String sdkKey,
String environmentKey,
String version,
List<Attribute> attributes,
List<Audience> audiences,
Expand All @@ -141,6 +147,8 @@ public DatafileProjectConfig(String accountId,
this.projectId = projectId;
this.version = version;
this.revision = revision;
this.sdkKey = sdkKey;
this.environmentKey = environmentKey;
this.anonymizeIP = anonymizeIP;
this.sendFlagDecisions = sendFlagDecisions;
this.botFiltering = botFiltering;
Expand Down Expand Up @@ -326,6 +334,16 @@ public String getRevision() {
return revision;
}

@Override
public String getSdkKey() {
return sdkKey;
}

@Override
public String getEnvironmentKey() {
return environmentKey;
}

@Override
public boolean getSendFlagDecisions() { return sendFlagDecisions; }

Expand Down Expand Up @@ -451,6 +469,8 @@ public String toString() {
"accountId='" + accountId + '\'' +
", projectId='" + projectId + '\'' +
", revision='" + revision + '\'' +
", sdkKey='" + sdkKey + '\'' +
", environmentKey='" + environmentKey + '\'' +
", version='" + version + '\'' +
", anonymizeIP=" + anonymizeIP +
", botFiltering=" + botFiltering +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016-2020, Optimizely and contributors
* Copyright 2016-2021, Optimizely and contributors
*
* 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 @@ -55,6 +55,10 @@ Experiment getExperimentForKey(@Nonnull String experimentKey,

String getRevision();

String getSdkKey();

String getEnvironmentKey();

boolean getSendFlagDecisions();

boolean getAnonymizeIP();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016-2020, Optimizely and contributors
* Copyright 2016-2021, Optimizely and contributors
*
* 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 @@ -87,6 +87,8 @@ public ProjectConfig deserialize(JsonElement json, Type typeOfT, JsonDeserializa
List<FeatureFlag> featureFlags = null;
List<Rollout> rollouts = null;
Boolean botFiltering = null;
String sdkKey = null;
String environmentKey = null;
boolean sendFlagDecisions = false;
if (datafileVersion >= Integer.parseInt(DatafileProjectConfig.Version.V4.toString())) {
Type featureFlagsType = new TypeToken<List<FeatureFlag>>() {
Expand All @@ -95,6 +97,10 @@ public ProjectConfig deserialize(JsonElement json, Type typeOfT, JsonDeserializa
Type rolloutsType = new TypeToken<List<Rollout>>() {
}.getType();
rollouts = context.deserialize(jsonObject.get("rollouts").getAsJsonArray(), rolloutsType);
if (jsonObject.has("sdkKey"))
sdkKey = jsonObject.get("sdkKey").getAsString();
if (jsonObject.has("environmentKey"))
environmentKey = jsonObject.get("environmentKey").getAsString();
if (jsonObject.has("botFiltering"))
botFiltering = jsonObject.get("botFiltering").getAsBoolean();
if (jsonObject.has("sendFlagDecisions"))
Expand All @@ -108,6 +114,8 @@ public ProjectConfig deserialize(JsonElement json, Type typeOfT, JsonDeserializa
botFiltering,
projectId,
revision,
sdkKey,
environmentKey,
version,
attributes,
audiences,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016-2020, Optimizely and contributors
* Copyright 2016-2021, Optimizely and contributors
*
* 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 @@ -63,11 +63,19 @@ public DatafileProjectConfig deserialize(JsonParser parser, DeserializationConte

List<FeatureFlag> featureFlags = null;
List<Rollout> rollouts = null;
String sdkKey = null;
String environmentKey = null;
Boolean botFiltering = null;
boolean sendFlagDecisions = false;
if (datafileVersion >= Integer.parseInt(DatafileProjectConfig.Version.V4.toString())) {
featureFlags = JacksonHelpers.arrayNodeToList(node.get("featureFlags"), FeatureFlag.class, codec);
rollouts = JacksonHelpers.arrayNodeToList(node.get("rollouts"), Rollout.class, codec);
if (node.hasNonNull("sdkKey")) {
sdkKey = node.get("sdkKey").textValue();
}
if (node.hasNonNull("environmentKey")) {
environmentKey = node.get("environmentKey").textValue();
}
if (node.hasNonNull("botFiltering")) {
botFiltering = node.get("botFiltering").asBoolean();
}
Expand All @@ -83,6 +91,8 @@ public DatafileProjectConfig deserialize(JsonParser parser, DeserializationConte
botFiltering,
projectId,
revision,
sdkKey,
environmentKey,
version,
attributes,
audiences,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016-2019, 2020, Optimizely and contributors
* Copyright 2016-2021, Optimizely and contributors
*
* 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 @@ -72,11 +72,17 @@ public ProjectConfig parseProjectConfig(@Nonnull String json) throws ConfigParse

List<FeatureFlag> featureFlags = null;
List<Rollout> rollouts = null;
String sdkKey = null;
String environmentKey = null;
Boolean botFiltering = null;
boolean sendFlagDecisions = false;
if (datafileVersion >= Integer.parseInt(ProjectConfig.Version.V4.toString())) {
featureFlags = parseFeatureFlags(rootObject.getJSONArray("featureFlags"));
rollouts = parseRollouts(rootObject.getJSONArray("rollouts"));
if (rootObject.has("sdkKey"))
sdkKey = rootObject.getString("sdkKey");
if (rootObject.has("environmentKey"))
environmentKey = rootObject.getString("environmentKey");
if (rootObject.has("botFiltering"))
botFiltering = rootObject.getBoolean("botFiltering");
if (rootObject.has("sendFlagDecisions"))
Expand All @@ -90,6 +96,8 @@ public ProjectConfig parseProjectConfig(@Nonnull String json) throws ConfigParse
botFiltering,
projectId,
revision,
sdkKey,
environmentKey,
version,
attributes,
audiences,
Expand All @@ -100,6 +108,8 @@ public ProjectConfig parseProjectConfig(@Nonnull String json) throws ConfigParse
groups,
rollouts
);
} catch (RuntimeException e) {
throw new ConfigParseException("Unable to parse datafile: " + json, e);
} catch (Exception e) {
throw new ConfigParseException("Unable to parse datafile: " + json, e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016-2019, 2020, Optimizely and contributors
* Copyright 2016-2021, Optimizely and contributors
*
* 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 @@ -50,6 +50,8 @@ public ProjectConfig parseProjectConfig(@Nonnull String json) throws ConfigParse
String accountId = (String) rootObject.get("accountId");
String projectId = (String) rootObject.get("projectId");
String revision = (String) rootObject.get("revision");
String sdkKey = (String) rootObject.get("sdkKey");
String environmentKey = (String) rootObject.get("environmentKey");
String version = (String) rootObject.get("version");
int datafileVersion = Integer.parseInt(version);

Expand Down Expand Up @@ -97,6 +99,8 @@ public ProjectConfig parseProjectConfig(@Nonnull String json) throws ConfigParse
botFiltering,
projectId,
revision,
sdkKey,
environmentKey,
version,
attributes,
audiences,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2020, Optimizely, Inc. and contributors *
* Copyright 2020-2021, Optimizely, Inc. and contributors *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand All @@ -16,31 +16,40 @@
package com.optimizely.ab.optimizelyconfig;


import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.*;

/**
* Interface for OptimizleyConfig
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OptimizelyConfig {

private Map<String, OptimizelyExperiment> experimentsMap;
private Map<String, OptimizelyFeature> featuresMap;
private String revision;
private String sdkKey;
private String environmentKey;
private String datafile;

public OptimizelyConfig(Map<String, OptimizelyExperiment> experimentsMap,
Map<String, OptimizelyFeature> featuresMap,
String revision) {
this(experimentsMap, featuresMap, revision, null);
String revision, String sdkKey, String environmentKey) {
this(experimentsMap, featuresMap, revision, sdkKey, environmentKey, null);
}

public OptimizelyConfig(Map<String, OptimizelyExperiment> experimentsMap,
Map<String, OptimizelyFeature> featuresMap,
String revision,
String sdkKey,
String environmentKey,
String datafile) {
this.experimentsMap = experimentsMap;
this.featuresMap = featuresMap;
this.revision = revision;
this.sdkKey = sdkKey;
this.environmentKey = environmentKey;
this.datafile = datafile;
}

Expand All @@ -56,6 +65,12 @@ public String getRevision() {
return revision;
}

public String getSdkKey() { return sdkKey; }

public String getEnvironmentKey() {
return environmentKey;
}

public String getDatafile() {
return datafile;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2020, Optimizely, Inc. and contributors *
* Copyright 2020-2021, Optimizely, Inc. and contributors *
* *
* 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 @@ -32,6 +32,8 @@ public OptimizelyConfigService(ProjectConfig projectConfig) {
experimentsMap,
getFeaturesMap(experimentsMap),
projectConfig.getRevision(),
projectConfig.getSdkKey(),
projectConfig.getEnvironmentKey(),
projectConfig.toDatafile()
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2019-2020, Optimizely and contributors
* Copyright 2019-2021, Optimizely and contributors
*
* 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 @@ -156,6 +156,8 @@ public void testSetOptimizelyConfig(){

testProjectConfigManager.setConfig(projectConfig);
assertEquals("1480511547", testProjectConfigManager.getOptimizelyConfig().getRevision());
assertEquals("ValidProjectConfigV4", testProjectConfigManager.getOptimizelyConfig().getSdkKey());
assertEquals("production", testProjectConfigManager.getOptimizelyConfig().getEnvironmentKey());

// cached config because project config is null
testProjectConfigManager.setConfig(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2017-2020, Optimizely and contributors
* Copyright 2017-2021, Optimizely and contributors
*
* 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 @@ -36,6 +36,8 @@ public class ValidProjectConfigV4 {
private static final boolean BOT_FILTERING = true;
private static final String PROJECT_ID = "3918735994";
private static final String REVISION = "1480511547";
private static final String SDK_KEY = "ValidProjectConfigV4";
private static final String ENVIRONMENT_KEY = "production";
private static final String VERSION = "4";
private static final Boolean SEND_FLAG_DECISIONS = true;

Expand Down Expand Up @@ -1434,6 +1436,8 @@ public static ProjectConfig generateValidProjectConfigV4() {
BOT_FILTERING,
PROJECT_ID,
REVISION,
SDK_KEY,
ENVIRONMENT_KEY,
VERSION,
attributes,
audiences,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2020, Optimizely, Inc. and contributors *
* Copyright 2020-2021, Optimizely, Inc. and contributors *
* *
* 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 @@ -52,6 +52,18 @@ public void testRevision() {
assertEquals(expectedConfig.getRevision(), revision);
}

@Test
public void testSdkKey() {
String sdkKey = optimizelyConfigService.getConfig().getSdkKey();
assertEquals(expectedConfig.getSdkKey(), sdkKey);
}

@Test
public void testEnvironmentKey() {
String environmentKey = optimizelyConfigService.getConfig().getEnvironmentKey();
assertEquals(expectedConfig.getEnvironmentKey(), environmentKey);
}

@Test
public void testGetFeaturesMap() {
Map<String, OptimizelyExperiment> optimizelyExperimentMap = optimizelyConfigService.getExperimentsMap();
Expand Down Expand Up @@ -152,6 +164,8 @@ private ProjectConfig generateOptimizelyConfig() {
true,
"3918735994",
"1480511547",
"ValidProjectConfigV4",
"production",
"4",
asList(
new Attribute(
Expand Down Expand Up @@ -510,7 +524,9 @@ OptimizelyConfig getExpectedConfig() {
return new OptimizelyConfig(
optimizelyExperimentMap,
optimizelyFeatureMap,
"1480511547"
"1480511547",
"ValidProjectConfigV4",
"production"
);
}
}
Loading