Skip to content

Feat: added SDKkey and environmentKey in datafile #281

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 10 commits into from
Jun 22, 2021
6 changes: 5 additions & 1 deletion lib/optimizely/config/datafile_project_config.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# 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 @@ -38,6 +38,8 @@ class DatafileProjectConfig < ProjectConfig
attr_reader :anonymize_ip
attr_reader :bot_filtering
attr_reader :revision
attr_reader :sdk_key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update header.

attr_reader :environment_key
attr_reader :rollouts
attr_reader :version
attr_reader :send_flag_decisions
Expand Down Expand Up @@ -83,6 +85,8 @@ def initialize(datafile, logger, error_handler)
@anonymize_ip = config.key?('anonymizeIP') ? config['anonymizeIP'] : false
@bot_filtering = config['botFiltering']
@revision = config['revision']
@sdk_key = config.fetch('sdkKey', nil)
@environment_key = config.fetch('environmentKey', nil)
@rollouts = config.fetch('rollouts', [])
@send_flag_decisions = config.fetch('sendFlagDecisions', false)

Expand Down
7 changes: 5 additions & 2 deletions lib/optimizely/optimizely_config.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# 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 All @@ -24,12 +24,15 @@ def initialize(project_config)
def config
experiments_map_object = experiments_map
features_map = get_features_map(experiments_map_object)
{
config = {
'datafile' => @project_config.datafile,
'experimentsMap' => experiments_map_object,
'featuresMap' => features_map,
'revision' => @project_config.revision
}
config['sdkKey'] = @project_config.sdk_key if @project_config.sdk_key
config['environmentKey'] = @project_config.environment_key if @project_config.environment_key
config
end

private
Expand Down
6 changes: 5 additions & 1 deletion lib/optimizely/project_config.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# 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 @@ -46,6 +46,10 @@ def bot_filtering; end

def revision; end

def sdk_key; end

def environment_key; end

def send_flag_decisions; end

def rollouts; end
Expand Down
4 changes: 3 additions & 1 deletion spec/config/datafile_project_config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

#
# 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 @@ -51,6 +51,8 @@
expect(project_config.groups).to eq(config_body['groups'])
expect(project_config.project_id).to eq(config_body['projectId'])
expect(project_config.revision).to eq(config_body['revision'])
expect(project_config.sdk_key).to eq(config_body['sdkKey'])
expect(project_config.environment_key).to eq(config_body['environmentKey'])
expect(project_config.send_flag_decisions).to eq(config_body['sendFlagDecisions'])

expected_attribute_key_map = {
Expand Down
10 changes: 9 additions & 1 deletion spec/optimizely_config_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

#
# 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 @@ -95,6 +95,14 @@
expect(project_config.revision).to eq(optimizely_config['revision'])
end

it 'should return correct sdk key' do
expect(project_config.sdk_key).to eq(optimizely_config['sdkKey'])
end

it 'should return correct environment key' do
expect(project_config.environment_key).to eq(optimizely_config['environmentKey'])
end

it 'should return correct datafile string' do
expect(project_config.datafile).to eq(optimizely_config['datafile'])
end
Expand Down
6 changes: 5 additions & 1 deletion spec/spec_params.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

#
# 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 All @@ -24,6 +24,8 @@ module OptimizelySpec
'anonymizeIP' => false,
'botFiltering' => true,
'revision' => '42',
'sdkKey' => 'VALID',
'environmentKey' => 'VALID_ENVIRONMENT',
'version' => '2',
'sendFlagDecisions' => true,
'events' => [{
Expand Down Expand Up @@ -1125,6 +1127,8 @@ module OptimizelySpec
}
],
'revision' => '3',
'sdkKey' => 'AUDIENCES',
'environmentKey' => 'AUDIENCES_ENVIRONMENT',
'sendFlagDecisions' => true
}.freeze

Expand Down