Skip to content

Commit c6e659e

Browse files
authored
Feat: added SDKkey and environmentKey in datafile (#281)
* init * unit test fixes * duplicate revision removed * comments addressed * get_experiment_from_key reinserted * spec updated * robo cop issues resolved * tests for test getters removed * null sdk and environment values removed from config * extra spacing removed
1 parent b394e9c commit c6e659e

6 files changed

+32
-7
lines changed

lib/optimizely/config/datafile_project_config.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
# Copyright 2019-2020, Optimizely and contributors
3+
# Copyright 2019-2021, Optimizely and contributors
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.
@@ -38,6 +38,8 @@ class DatafileProjectConfig < ProjectConfig
3838
attr_reader :anonymize_ip
3939
attr_reader :bot_filtering
4040
attr_reader :revision
41+
attr_reader :sdk_key
42+
attr_reader :environment_key
4143
attr_reader :rollouts
4244
attr_reader :version
4345
attr_reader :send_flag_decisions
@@ -83,6 +85,8 @@ def initialize(datafile, logger, error_handler)
8385
@anonymize_ip = config.key?('anonymizeIP') ? config['anonymizeIP'] : false
8486
@bot_filtering = config['botFiltering']
8587
@revision = config['revision']
88+
@sdk_key = config.fetch('sdkKey', nil)
89+
@environment_key = config.fetch('environmentKey', nil)
8690
@rollouts = config.fetch('rollouts', [])
8791
@send_flag_decisions = config.fetch('sendFlagDecisions', false)
8892

lib/optimizely/optimizely_config.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
# Copyright 2019-2020, Optimizely and contributors
3+
# Copyright 2019-2021, Optimizely and contributors
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.
@@ -24,12 +24,15 @@ def initialize(project_config)
2424
def config
2525
experiments_map_object = experiments_map
2626
features_map = get_features_map(experiments_map_object)
27-
{
27+
config = {
2828
'datafile' => @project_config.datafile,
2929
'experimentsMap' => experiments_map_object,
3030
'featuresMap' => features_map,
3131
'revision' => @project_config.revision
3232
}
33+
config['sdkKey'] = @project_config.sdk_key if @project_config.sdk_key
34+
config['environmentKey'] = @project_config.environment_key if @project_config.environment_key
35+
config
3336
end
3437

3538
private

lib/optimizely/project_config.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
# Copyright 2016-2020, Optimizely and contributors
3+
# Copyright 2016-2021, Optimizely and contributors
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.
@@ -46,6 +46,10 @@ def bot_filtering; end
4646

4747
def revision; end
4848

49+
def sdk_key; end
50+
51+
def environment_key; end
52+
4953
def send_flag_decisions; end
5054

5155
def rollouts; end

spec/config/datafile_project_config_spec.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
#
4-
# Copyright 2019-2020, Optimizely and contributors
4+
# Copyright 2019-2021, Optimizely and contributors
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -51,6 +51,8 @@
5151
expect(project_config.groups).to eq(config_body['groups'])
5252
expect(project_config.project_id).to eq(config_body['projectId'])
5353
expect(project_config.revision).to eq(config_body['revision'])
54+
expect(project_config.sdk_key).to eq(config_body['sdkKey'])
55+
expect(project_config.environment_key).to eq(config_body['environmentKey'])
5456
expect(project_config.send_flag_decisions).to eq(config_body['sendFlagDecisions'])
5557

5658
expected_attribute_key_map = {

spec/optimizely_config_spec.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
#
4-
# Copyright 2019-2020, Optimizely and contributors
4+
# Copyright 2019-2021, Optimizely and contributors
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -95,6 +95,14 @@
9595
expect(project_config.revision).to eq(optimizely_config['revision'])
9696
end
9797

98+
it 'should return correct sdk key' do
99+
expect(project_config.sdk_key).to eq(optimizely_config['sdkKey'])
100+
end
101+
102+
it 'should return correct environment key' do
103+
expect(project_config.environment_key).to eq(optimizely_config['environmentKey'])
104+
end
105+
98106
it 'should return correct datafile string' do
99107
expect(project_config.datafile).to eq(optimizely_config['datafile'])
100108
end

spec/spec_params.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
#
4-
# Copyright 2016-2020, Optimizely and contributors
4+
# Copyright 2016-2021, Optimizely and contributors
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -24,6 +24,8 @@ module OptimizelySpec
2424
'anonymizeIP' => false,
2525
'botFiltering' => true,
2626
'revision' => '42',
27+
'sdkKey' => 'VALID',
28+
'environmentKey' => 'VALID_ENVIRONMENT',
2729
'version' => '2',
2830
'sendFlagDecisions' => true,
2931
'events' => [{
@@ -1125,6 +1127,8 @@ module OptimizelySpec
11251127
}
11261128
],
11271129
'revision' => '3',
1130+
'sdkKey' => 'AUDIENCES',
1131+
'environmentKey' => 'AUDIENCES_ENVIRONMENT',
11281132
'sendFlagDecisions' => true
11291133
}.freeze
11301134

0 commit comments

Comments
 (0)