launchdarkly-server-sdk 7.0.0 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e189d76d654dbf73dc95e9cea758b81bc0df93d9012ebb6560d0994e6dff227c
4
- data.tar.gz: fc8bdc8b9affee0e51ef233c217cfa4a3c7fbdbceb4694c38c5a2e90155205ed
3
+ metadata.gz: 75f53c22b8da0f6ef2ae0c387ec0e0fa7f421995a4325e984bbf45cb71d0104c
4
+ data.tar.gz: 85341f03930799add9de607e744c04ad1553582bcd275aa0a78169ee7a8fc9fa
5
5
  SHA512:
6
- metadata.gz: 7fb89d48c3185f7019cd170f36f571b1ca2f7de130c624d6301fbfd30d46a0ae7a986494393ab290fa23b66511ce676b660533e1ad23d3a9e01fb037e20db6c4
7
- data.tar.gz: 7e706747d2fcd1ab299a76eca7bf26908dbe97972b8c1ea74cfae6bc6aaffe866ddfc157b26675eb44fb22044c74efff88e7c5c4bf8dc0e75fa93dfe0ddbea8a
6
+ metadata.gz: 147b8b4ca65428dda6dda31bf1a09da6a982087c6fddf16dcd31aa8ae35c289c4aa4e9b2366c3605b9b9f4642c3c0fde20bad4fa0a207d3a92eba8a72b420bbc
7
+ data.tar.gz: b624f93ba0ada0244e3080713c99d7f45a78d3670d7a7b6c1fe5036aaf37396d3185e4286c7f6d739edef4b21ccfe503e91b65cce589963cb557cfd203ba9988
@@ -10,9 +10,9 @@ module LaunchDarkly
10
10
  # @param flag [LaunchDarkly::Impl::Model::FeatureFlag]
11
11
  # @param reason [LaunchDarkly::EvaluationReason]
12
12
  #
13
- def self.evaluation_detail_for_off_variation(flag, reason, logger = nil)
13
+ def self.evaluation_detail_for_off_variation(flag, reason)
14
14
  index = flag.off_variation
15
- index.nil? ? EvaluationDetail.new(nil, nil, reason) : evaluation_detail_for_variation(flag, index, reason, logger)
15
+ index.nil? ? EvaluationDetail.new(nil, nil, reason) : evaluation_detail_for_variation(flag, index, reason)
16
16
  end
17
17
 
18
18
  #
@@ -20,11 +20,11 @@ module LaunchDarkly
20
20
  # @param index [Integer]
21
21
  # @param reason [LaunchDarkly::EvaluationReason]
22
22
  #
23
- def self.evaluation_detail_for_variation(flag, index, reason, logger = nil)
23
+ def self.evaluation_detail_for_variation(flag, index, reason)
24
24
  vars = flag.variations
25
25
  if index < 0 || index >= vars.length
26
- logger.error("[LDClient] Data inconsistency in feature flag \"#{flag.key}\": invalid variation index") unless logger.nil?
27
26
  EvaluationDetail.new(nil, nil, EvaluationReason::error(EvaluationReason::ERROR_MALFORMED_FLAG))
27
+ # This error condition has already been logged at the time we received the flag data - see model/feature_flag.rb
28
28
  else
29
29
  EvaluationDetail.new(vars[index], index, reason)
30
30
  end
@@ -1,3 +1,5 @@
1
+ require "ldclient-rb/reference"
2
+
1
3
 
2
4
  # See serialization.rb for implementation notes on the data model classes.
3
5
 
@@ -5,14 +7,18 @@ module LaunchDarkly
5
7
  module Impl
6
8
  module Model
7
9
  class Clause
8
- def initialize(data, logger)
10
+ def initialize(data, errors_out = nil)
9
11
  @data = data
10
12
  @context_kind = data[:contextKind]
11
- @attribute = (@context_kind.nil? || @context_kind.empty?) ? Reference.create_literal(data[:attribute]) : Reference.create(data[:attribute])
12
- unless logger.nil? || @attribute.error.nil?
13
- logger.error("[LDClient] Data inconsistency in feature flag: #{@attribute.error}")
14
- end
15
13
  @op = data[:op].to_sym
14
+ if @op == :segmentMatch
15
+ @attribute = nil
16
+ else
17
+ @attribute = (@context_kind.nil? || @context_kind.empty?) ? Reference.create_literal(data[:attribute]) : Reference.create(data[:attribute])
18
+ unless errors_out.nil? || @attribute.error.nil?
19
+ errors_out << "clause has invalid attribute: #{@attribute.error}"
20
+ end
21
+ end
16
22
  @values = data[:values] || []
17
23
  @negate = !!data[:negate]
18
24
  end
@@ -4,6 +4,14 @@ require "set"
4
4
 
5
5
  # See serialization.rb for implementation notes on the data model classes.
6
6
 
7
+ def check_variation_range(flag, errors_out, variation, description)
8
+ unless flag.nil? || errors_out.nil? || variation.nil?
9
+ if variation < 0 || variation >= flag.variations.length
10
+ errors_out << "#{description} has invalid variation index"
11
+ end
12
+ end
13
+ end
14
+
7
15
  module LaunchDarkly
8
16
  module Impl
9
17
  module Model
@@ -12,6 +20,7 @@ module LaunchDarkly
12
20
  # @param logger [Logger|nil]
13
21
  def initialize(data, logger = nil)
14
22
  raise ArgumentError, "expected hash but got #{data.class}" unless data.is_a?(Hash)
23
+ errors = []
15
24
  @data = data
16
25
  @key = data[:key]
17
26
  @version = data[:version]
@@ -20,24 +29,30 @@ module LaunchDarkly
20
29
  @variations = data[:variations] || []
21
30
  @on = !!data[:on]
22
31
  fallthrough = data[:fallthrough] || {}
23
- @fallthrough = VariationOrRollout.new(fallthrough[:variation], fallthrough[:rollout])
32
+ @fallthrough = VariationOrRollout.new(fallthrough[:variation], fallthrough[:rollout], self, errors, "fallthrough")
24
33
  @off_variation = data[:offVariation]
34
+ check_variation_range(self, errors, @off_variation, "off variation")
25
35
  @prerequisites = (data[:prerequisites] || []).map do |prereq_data|
26
- Prerequisite.new(prereq_data, self, logger)
36
+ Prerequisite.new(prereq_data, self, errors)
27
37
  end
28
38
  @targets = (data[:targets] || []).map do |target_data|
29
- Target.new(target_data, self, logger)
39
+ Target.new(target_data, self, errors)
30
40
  end
31
41
  @context_targets = (data[:contextTargets] || []).map do |target_data|
32
- Target.new(target_data, self, logger)
42
+ Target.new(target_data, self, errors)
33
43
  end
34
44
  @rules = (data[:rules] || []).map.with_index do |rule_data, index|
35
- FlagRule.new(rule_data, index, self, logger)
45
+ FlagRule.new(rule_data, index, self, errors)
36
46
  end
37
47
  @salt = data[:salt]
38
- @off_result = EvaluatorHelpers.evaluation_detail_for_off_variation(self, EvaluationReason::off, logger)
48
+ @off_result = EvaluatorHelpers.evaluation_detail_for_off_variation(self, EvaluationReason::off)
39
49
  @fallthrough_results = Preprocessor.precompute_multi_variation_results(self,
40
50
  EvaluationReason::fallthrough(false), EvaluationReason::fallthrough(true))
51
+ unless logger.nil?
52
+ errors.each do |message|
53
+ logger.error("[LDClient] Data inconsistency in feature flag \"#{@key}\": #{message}")
54
+ end
55
+ end
41
56
  end
42
57
 
43
58
  # @return [Hash]
@@ -93,12 +108,13 @@ module LaunchDarkly
93
108
  end
94
109
 
95
110
  class Prerequisite
96
- def initialize(data, flag, logger)
111
+ def initialize(data, flag, errors_out = nil)
97
112
  @data = data
98
113
  @key = data[:key]
99
114
  @variation = data[:variation]
100
115
  @failure_result = EvaluatorHelpers.evaluation_detail_for_off_variation(flag,
101
- EvaluationReason::prerequisite_failed(@key), logger)
116
+ EvaluationReason::prerequisite_failed(@key))
117
+ check_variation_range(flag, errors_out, @variation, "prerequisite")
102
118
  end
103
119
 
104
120
  # @return [Hash]
@@ -112,13 +128,14 @@ module LaunchDarkly
112
128
  end
113
129
 
114
130
  class Target
115
- def initialize(data, flag, logger)
131
+ def initialize(data, flag, errors_out = nil)
116
132
  @kind = data[:contextKind] || LDContext::KIND_DEFAULT
117
133
  @data = data
118
134
  @values = Set.new(data[:values] || [])
119
135
  @variation = data[:variation]
120
136
  @match_result = EvaluatorHelpers.evaluation_detail_for_variation(flag,
121
- data[:variation], EvaluationReason::target_match, logger)
137
+ data[:variation], EvaluationReason::target_match)
138
+ check_variation_range(flag, errors_out, @variation, "target")
122
139
  end
123
140
 
124
141
  # @return [String]
@@ -134,12 +151,12 @@ module LaunchDarkly
134
151
  end
135
152
 
136
153
  class FlagRule
137
- def initialize(data, rule_index, flag, logger)
154
+ def initialize(data, rule_index, flag, errors_out = nil)
138
155
  @data = data
139
156
  @clauses = (data[:clauses] || []).map do |clause_data|
140
- Clause.new(clause_data, logger)
157
+ Clause.new(clause_data, errors_out)
141
158
  end
142
- @variation_or_rollout = VariationOrRollout.new(data[:variation], data[:rollout])
159
+ @variation_or_rollout = VariationOrRollout.new(data[:variation], data[:rollout], flag, errors_out, 'rule')
143
160
  rule_id = data[:id]
144
161
  match_reason = EvaluationReason::rule_match(rule_index, rule_id)
145
162
  match_reason_in_experiment = EvaluationReason::rule_match(rule_index, rule_id, true)
@@ -157,9 +174,10 @@ module LaunchDarkly
157
174
  end
158
175
 
159
176
  class VariationOrRollout
160
- def initialize(variation, rollout_data)
177
+ def initialize(variation, rollout_data, flag = nil, errors_out = nil, description = nil)
161
178
  @variation = variation
162
- @rollout = rollout_data.nil? ? nil : Rollout.new(rollout_data)
179
+ check_variation_range(flag, errors_out, variation, description)
180
+ @rollout = rollout_data.nil? ? nil : Rollout.new(rollout_data, flag, errors_out, description)
163
181
  end
164
182
 
165
183
  # @return [Integer|nil]
@@ -169,9 +187,9 @@ module LaunchDarkly
169
187
  end
170
188
 
171
189
  class Rollout
172
- def initialize(data)
190
+ def initialize(data, flag = nil, errors_out = nil, description = nil)
173
191
  @context_kind = data[:contextKind]
174
- @variations = (data[:variations] || []).map { |v| WeightedVariation.new(v) }
192
+ @variations = (data[:variations] || []).map { |v| WeightedVariation.new(v, flag, errors_out, description) }
175
193
  @bucket_by = data[:bucketBy]
176
194
  @kind = data[:kind]
177
195
  @is_experiment = @kind == "experiment"
@@ -193,10 +211,11 @@ module LaunchDarkly
193
211
  end
194
212
 
195
213
  class WeightedVariation
196
- def initialize(data)
214
+ def initialize(data, flag = nil, errors_out = nil, description = nil)
197
215
  @variation = data[:variation]
198
216
  @weight = data[:weight]
199
217
  @untracked = !!data[:untracked]
218
+ check_variation_range(flag, errors_out, @variation, description)
200
219
  end
201
220
 
202
221
  # @return [Integer]
@@ -12,6 +12,7 @@ module LaunchDarkly
12
12
  # @param logger [Logger|nil]
13
13
  def initialize(data, logger = nil)
14
14
  raise ArgumentError, "expected hash but got #{data.class}" unless data.is_a?(Hash)
15
+ errors = []
15
16
  @data = data
16
17
  @key = data[:key]
17
18
  @version = data[:version]
@@ -26,12 +27,17 @@ module LaunchDarkly
26
27
  SegmentTarget.new(target_data)
27
28
  end
28
29
  @rules = (data[:rules] || []).map do |rule_data|
29
- SegmentRule.new(rule_data, logger)
30
+ SegmentRule.new(rule_data, errors)
30
31
  end
31
32
  @unbounded = !!data[:unbounded]
32
33
  @unbounded_context_kind = data[:unboundedContextKind] || LDContext::KIND_DEFAULT
33
34
  @generation = data[:generation]
34
35
  @salt = data[:salt]
36
+ unless logger.nil?
37
+ errors.each do |message|
38
+ logger.error("[LDClient] Data inconsistency in segment \"#{@key}\": #{message}")
39
+ end
40
+ end
35
41
  end
36
42
 
37
43
  # @return [Hash]
@@ -98,10 +104,10 @@ module LaunchDarkly
98
104
  end
99
105
 
100
106
  class SegmentRule
101
- def initialize(data, logger)
107
+ def initialize(data, errors_out = nil)
102
108
  @data = data
103
109
  @clauses = (data[:clauses] || []).map do |clause_data|
104
- Clause.new(clause_data, logger)
110
+ Clause.new(clause_data, errors_out)
105
111
  end
106
112
  @weight = data[:weight]
107
113
  @bucket_by = data[:bucketBy]
@@ -37,7 +37,7 @@ module LaunchDarkly
37
37
  # @param kind [Hash] normally either FEATURES or SEGMENTS
38
38
  # @param input [object] a JSON string or a parsed hash (or a data model object, in which case
39
39
  # we'll just return the original object)
40
- # @param logger [Logger|nil] logs warnings if there are any data validation problems
40
+ # @param logger [Logger|nil] logs errors if there are any data validation problems
41
41
  # @return [Object] the flag or segment (or, for an unknown data kind, the data as a hash)
42
42
  def self.deserialize(kind, input, logger = nil)
43
43
  return nil if input.nil?
@@ -1,3 +1,3 @@
1
1
  module LaunchDarkly
2
- VERSION = "7.0.0"
2
+ VERSION = "7.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: launchdarkly-server-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - LaunchDarkly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-30 00:00:00.000000000 Z
11
+ date: 2023-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-dynamodb
@@ -338,7 +338,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
338
338
  - !ruby/object:Gem::Version
339
339
  version: '0'
340
340
  requirements: []
341
- rubygems_version: 3.4.1
341
+ rubygems_version: 3.4.4
342
342
  signing_key:
343
343
  specification_version: 4
344
344
  summary: LaunchDarkly SDK for Ruby