|
5 | 5 | using Microsoft.Extensions.Configuration.AzureAppConfiguration.Extensions;
|
6 | 6 | using System;
|
7 | 7 | using System.Collections.Generic;
|
8 |
| -using System.Diagnostics; |
9 | 8 | using System.Linq;
|
10 | 9 | using System.Net.Mime;
|
11 | 10 | using System.Security.Cryptography;
|
@@ -324,98 +323,12 @@ private List<KeyValuePair<string, string>> ProcessMicrosoftSchemaFeatureFlag(Fea
|
324 | 323 | keyValues.Add(new KeyValuePair<string, string>($"{telemetryPath}:{FeatureManagementConstants.Metadata}:{FeatureManagementConstants.ETag}", setting.ETag.ToString()));
|
325 | 324 |
|
326 | 325 | keyValues.Add(new KeyValuePair<string, string>($"{telemetryPath}:{FeatureManagementConstants.Enabled}", telemetry.Enabled.ToString()));
|
327 |
| - |
328 |
| - if (featureFlag.Allocation != null) |
329 |
| - { |
330 |
| - string allocationId = CalculateAllocationId(featureFlag); |
331 |
| - |
332 |
| - if (allocationId != null) |
333 |
| - { |
334 |
| - keyValues.Add(new KeyValuePair<string, string>($"{telemetryPath}:{FeatureManagementConstants.Metadata}:{FeatureManagementConstants.AllocationId}", allocationId)); |
335 |
| - } |
336 |
| - } |
337 | 326 | }
|
338 | 327 | }
|
339 | 328 |
|
340 | 329 | return keyValues;
|
341 | 330 | }
|
342 | 331 |
|
343 |
| - private string CalculateAllocationId(FeatureFlag flag) |
344 |
| - { |
345 |
| - Debug.Assert(flag.Allocation != null); |
346 |
| - |
347 |
| - StringBuilder inputBuilder = new StringBuilder(); |
348 |
| - |
349 |
| - // Seed |
350 |
| - inputBuilder.Append($"seed={flag.Allocation.Seed ?? string.Empty}"); |
351 |
| - |
352 |
| - var allocatedVariants = new HashSet<string>(); |
353 |
| - |
354 |
| - // DefaultWhenEnabled |
355 |
| - if (flag.Allocation.DefaultWhenEnabled != null) |
356 |
| - { |
357 |
| - allocatedVariants.Add(flag.Allocation.DefaultWhenEnabled); |
358 |
| - } |
359 |
| - |
360 |
| - inputBuilder.Append($"\ndefault_when_enabled={flag.Allocation.DefaultWhenEnabled ?? string.Empty}"); |
361 |
| - |
362 |
| - // Percentiles |
363 |
| - inputBuilder.Append("\npercentiles="); |
364 |
| - |
365 |
| - if (flag.Allocation.Percentile != null && flag.Allocation.Percentile.Any()) |
366 |
| - { |
367 |
| - IEnumerable<FeaturePercentileAllocation> sortedPercentiles = flag.Allocation.Percentile |
368 |
| - .Where(p => p.From != p.To) |
369 |
| - .OrderBy(p => p.From) |
370 |
| - .ToList(); |
371 |
| - |
372 |
| - allocatedVariants.UnionWith(sortedPercentiles.Select(p => p.Variant)); |
373 |
| - |
374 |
| - inputBuilder.Append(string.Join(";", sortedPercentiles.Select(p => $"{p.From},{p.Variant.ToBase64String()},{p.To}"))); |
375 |
| - } |
376 |
| - |
377 |
| - // If there's no custom seed and no variants allocated, stop now and return null |
378 |
| - if (flag.Allocation.Seed == null && |
379 |
| - !allocatedVariants.Any()) |
380 |
| - { |
381 |
| - return null; |
382 |
| - } |
383 |
| - |
384 |
| - // Variants |
385 |
| - inputBuilder.Append("\nvariants="); |
386 |
| - |
387 |
| - if (allocatedVariants.Any() && flag.Variants != null && flag.Variants.Any()) |
388 |
| - { |
389 |
| - IEnumerable<FeatureVariant> sortedVariants = flag.Variants |
390 |
| - .Where(variant => allocatedVariants.Contains(variant.Name)) |
391 |
| - .OrderBy(variant => variant.Name) |
392 |
| - .ToList(); |
393 |
| - |
394 |
| - inputBuilder.Append(string.Join(";", sortedVariants.Select(v => |
395 |
| - { |
396 |
| - var variantValue = string.Empty; |
397 |
| - |
398 |
| - if (v.ConfigurationValue.ValueKind != JsonValueKind.Null && v.ConfigurationValue.ValueKind != JsonValueKind.Undefined) |
399 |
| - { |
400 |
| - variantValue = v.ConfigurationValue.SerializeWithSortedKeys(); |
401 |
| - } |
402 |
| - |
403 |
| - return $"{v.Name.ToBase64String()},{(variantValue)}"; |
404 |
| - }))); |
405 |
| - } |
406 |
| - |
407 |
| - // Example input string |
408 |
| - // input == "seed=123abc\ndefault_when_enabled=Control\npercentiles=0,Blshdk,20;20,Test,100\nvariants=TdLa,standard;Qfcd,special" |
409 |
| - string input = inputBuilder.ToString(); |
410 |
| - |
411 |
| - using (SHA256 sha256 = SHA256.Create()) |
412 |
| - { |
413 |
| - byte[] truncatedHash = new byte[15]; |
414 |
| - Array.Copy(sha256.ComputeHash(Encoding.UTF8.GetBytes(input)), truncatedHash, 15); |
415 |
| - return truncatedHash.ToBase64Url(); |
416 |
| - } |
417 |
| - } |
418 |
| - |
419 | 332 | private FormatException CreateFeatureFlagFormatException(string jsonPropertyName, string settingKey, string foundJsonValueKind, string expectedJsonValueKind)
|
420 | 333 | {
|
421 | 334 | return new FormatException(string.Format(
|
|
0 commit comments