Skip to content
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

v5 to v6 config JSON conversion #9

Merged
merged 8 commits into from
Sep 15, 2023
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
16 changes: 16 additions & 0 deletions src/ConfigCat.Cli.Models/ConfigFile/PrerequisiteComparator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.ComponentModel.DataAnnotations;

namespace ConfigCat.Cli.Models.ConfigFile
{
/// <summary>
/// The comparison operator used during the evaluation process.
/// </summary>
public enum PrerequisiteComparator : byte
{
[Display(Name = "EQUALS")]
Equals = 0,

[Display(Name = "NOT EQUALS")]
DoesNotEqual = 1
}
}
63 changes: 63 additions & 0 deletions src/ConfigCat.Cli.Models/ConfigFile/RolloutRuleComparator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.ComponentModel.DataAnnotations;

namespace ConfigCat.Cli.Models.ConfigFile
{
public enum RolloutRuleComparator
{
[Display(Name = "IS ONE OF")]
IsOneOf = 0,

[Display(Name = "IS NOT ONE OF")]
IsNotOneOf = 1,

[Display(Name = "CONTAINS")]
Contains = 2,

[Display(Name = "DOES NOT CONTAIN")]
DoesNotContain = 3,


[Display(Name = "SEMVER IS ONE OF")]
SemVerIsOneOf = 4,

[Display(Name = "SEMVER IS NOT ONE OF")]
SemVerIsNotOneOf = 5,

[Display(Name = "SEMVER LESS THAN")]
SemVerLess = 6,

[Display(Name = "SEMVER LESS THAN OR EQUALS TO")]
SemVerLessOrEquals = 7,

[Display(Name = "SEMVER GREATER THAN")]
SemVerGreater = 8,

[Display(Name = "SEMVER GREATER THAN OR EQUALS TO")]
SemVerGreaterOrEquals = 9,


[Display(Name = "NUMBER EQUALS TO")]
NumberEquals = 10,

[Display(Name = "NUMBER DOES NOT EQUAL TO")]
NumberDoesNotEqual = 11,

[Display(Name = "NUMBER LESS")]
NumberLess = 12,

[Display(Name = "NUMBER LESS THAN OR EQUALS TO")]
NumberLessOrEquals = 13,

[Display(Name = "NUMBER GREATER THAN")]
NumberGreater = 14,

[Display(Name = "NUMBER GREATER THAN OR EQUALS TO")]
NumberGreaterOrEquals = 15,

[Display(Name = "SENSITIVE IS ONE OF")]
SensitiveIsOneOf = 16,

[Display(Name = "SENSITIVE IS NOT ONE OF")]
SensitiveIsNotOneOf = 17,
}
}
16 changes: 16 additions & 0 deletions src/ConfigCat.Cli.Models/ConfigFile/SegmentComparator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.ComponentModel.DataAnnotations;

namespace ConfigCat.Cli.Models.ConfigFile
{
/// <summary>
/// The segment comparison operator used during the evaluation process.
/// </summary>
public enum SegmentComparator
{
[Display(Name = "IS IN SEGMENT")]
IsIn,

[Display(Name = "IS NOT IN SEGMENT")]
IsNotIn
}
}
19 changes: 19 additions & 0 deletions src/ConfigCat.Cli.Models/ConfigFile/SettingType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.ComponentModel.DataAnnotations;

namespace ConfigCat.Cli.Models.ConfigFile
{
public enum SettingType
{
[Display(Name = "On/Off Toggle (Boolean)")]
Boolean = 0,

[Display(Name = "Text (String)")]
String = 1,

[Display(Name = "Whole Number (Integer) - eg. 42")]
Int = 2,

[Display(Name = "Decimal Number (Double) - eg. 3.14")]
Double = 3,
}
}
96 changes: 96 additions & 0 deletions src/ConfigCat.Cli.Models/ConfigFile/UserComparator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using System.ComponentModel.DataAnnotations;

namespace ConfigCat.Cli.Models.ConfigFile
{
/// <summary>
/// The comparison operator the evaluation process must use when it compares the given user attribute's value with the comparison value.
/// </summary>
public enum UserComparator
{
/* [Display(Name = "IS ONE OF")]
IsOneOf = 0,

[Display(Name = "IS NOT ONE OF")]
IsNotOneOf = 1, */

[Display(Name = "CONTAINS ANY OF")]
ContainsAnyOf = 2,

[Display(Name = "NOT CONTAINS ANY OF")]
DoesNotContainAnyOf = 3,


[Display(Name = "SEMVER IS ONE OF")]
SemVerIsOneOf = 4,

[Display(Name = "SEMVER IS NOT ONE OF")]
SemVerIsNotOneOf = 5,

[Display(Name = "SEMVER LESS THAN")]
SemVerLess = 6,

[Display(Name = "SEMVER LESS THAN OR EQUALS TO")]
SemVerLessOrEquals = 7,

[Display(Name = "SEMVER GREATER THAN")]
SemVerGreater = 8,

[Display(Name = "SEMVER GREATER THAN OR EQUALS TO")]
SemVerGreaterOrEquals = 9,


[Display(Name = "NUMBER EQUALS TO")]
NumberEquals = 10,

[Display(Name = "NUMBER NOT EQUALS TO")]
NumberDoesNotEqual = 11,

[Display(Name = "NUMBER LESS THAN")]
NumberLess = 12,

[Display(Name = "NUMBER LESS THAN OR EQUALS TO")]
NumberLessOrEquals = 13,

[Display(Name = "NUMBER GREATER THAN")]
NumberGreater = 14,

[Display(Name = "NUMBER GREATER THAN OR EQUALS TO")]
NumberGreaterOrEquals = 15,

[Display(Name = "SENSITIVE IS ONE OF")]
SensitiveIsOneOf = 16,

[Display(Name = "SENSITIVE IS NOT ONE OF")]
SensitiveIsNotOneOf = 17,

[Display(Name = "DATETIME BEFORE")]
DateTimeBefore = 18,

[Display(Name = "DATETIME AFTER")]
DateTimeAfter = 19,

[Display(Name = "SENSITIVE TEXT EQUALS TO")]
SensitiveTextEquals = 20,

[Display(Name = "SENSITIVE TEXT NOT EQUALS TO")]
SensitiveTextDoesNotEqual = 21,

[Display(Name = "SENSITIVE TEXT STARTS WITH ANY OF")]
SensitiveTextStartsWithAnyOf = 22,

[Display(Name = "SENSITIVE TEXT NOT STARTS WITH ANY OF")]
SensitiveTextNotStartsWithAnyOf = 23,

[Display(Name = "SENSITIVE TEXT ENDS WITH ANY OF")]
SensitiveTextEndsWithAnyOf = 24,

[Display(Name = "SENSITIVE TEXT NOT ENDS WITH ANY OF")]
SensitiveTextNotEndsWithAnyOf = 25,

[Display(Name = "ARRAY CONTAINS ANY OF")]
ArrayContainsAnyOf = 26,

[Display(Name = "ARRAY NOT CONTAINS ANY OF")]
ArrayDoesNotContainAnyOf = 27,
}
}
14 changes: 14 additions & 0 deletions src/ConfigCat.Cli.Models/ConfigFile/V5/ConfigV5.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace ConfigCat.Cli.Models.ConfigFile.V5
{
public class ConfigV5
{
[JsonPropertyName("f")]
public Dictionary<string, SettingV5> Settings { get; set; }

[JsonPropertyName("p")]
public PreferencesV5 Preferences { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/ConfigCat.Cli.Models/ConfigFile/V5/PreferencesV5.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Text.Json.Serialization;

namespace ConfigCat.Cli.Models.ConfigFile.V5
{
public class PreferencesV5
{
[JsonPropertyName("u")]
public string Url { get; set; }

[JsonPropertyName("r")]
public int RedirectMode { get; set; }
}
}
20 changes: 20 additions & 0 deletions src/ConfigCat.Cli.Models/ConfigFile/V5/RolloutPercentageItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace ConfigCat.Cli.Models.ConfigFile.V5
{
public class RolloutPercentageItem
{
[JsonPropertyName("o")]
public short Order { get; set; }

[JsonPropertyName("v")]
public JsonElement Value { get; set; }

[JsonPropertyName("p")]
public int Percentage { get; set; }

[JsonPropertyName("i")]
public string VariationId { get; set; }
}
}
26 changes: 26 additions & 0 deletions src/ConfigCat.Cli.Models/ConfigFile/V5/RolloutRuleV5.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace ConfigCat.Cli.Models.ConfigFile.V5
{
public class RolloutRuleV5
{
[JsonPropertyName("o")]
public short Order { get; set; }

[JsonPropertyName("a")]
public string ComparisonAttribute { get; set; }

[JsonPropertyName("t")]
public RolloutRuleComparator Comparator { get; set; }

[JsonPropertyName("c")]
public string ComparisonValue { get; set; }

[JsonPropertyName("v")]
public JsonElement Value { get; set; }

[JsonPropertyName("i")]
public string VariationId { get; set; }
}
}
23 changes: 23 additions & 0 deletions src/ConfigCat.Cli.Models/ConfigFile/V5/SettingV5.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace ConfigCat.Cli.Models.ConfigFile.V5
{
public class SettingV5
{
[JsonPropertyName("v")]
public JsonElement Value { get; set; }

[JsonPropertyName("t")]
public SettingType? SettingType { get; set; }

[JsonPropertyName("p")]
public RolloutPercentageItem[] RolloutPercentageItems { get; set; }

[JsonPropertyName("r")]
public RolloutRuleV5[] RolloutRules { get; set; }

[JsonPropertyName("i")]
public string VariationId { get; set; }
}
}
26 changes: 26 additions & 0 deletions src/ConfigCat.Cli.Models/ConfigFile/V6/ComparisonRuleV6.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace ConfigCat.Cli.Models.ConfigFile.V6
{
public class ComparisonRuleV6
{
/// <summary>
/// The attribute of the user object that should be used to evaluate this rule
/// </summary>
[JsonPropertyName("a")]
public string ComparisonAttribute { get; set; }

[JsonPropertyName("c")]
public UserComparator Comparator { get; set; }

[JsonPropertyName("s")]
public string StringValue { get; set; }

[JsonPropertyName("d")]
public double? DoubleValue { get; set; }

[JsonPropertyName("l")]
public List<string> StringListValue { get; set; }
}
}
25 changes: 25 additions & 0 deletions src/ConfigCat.Cli.Models/ConfigFile/V6/ConditionV6.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Text.Json.Serialization;

namespace ConfigCat.Cli.Models.ConfigFile.V6
{
public class ConditionV6
{
/// <summary>
/// Classic targeting rule
/// </summary>
[JsonPropertyName("t")]
public ComparisonRuleV6 ComparisonRule { get; set; }

/// <summary>
/// Segment targeting rule
/// </summary>
[JsonPropertyName("s")]
public SegmentConditionV6 SegmentCondition { get; set; }

/// <summary>
/// Prerequisite targeting rule
/// </summary>
[JsonPropertyName("d")]
public PrerequisiteFlagConditionV6 PrerequisiteFlagCondition { get; set; }
}
}
17 changes: 17 additions & 0 deletions src/ConfigCat.Cli.Models/ConfigFile/V6/ConfigV6.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace ConfigCat.Cli.Models.ConfigFile.V6
{
public class ConfigV6
{
[JsonPropertyName("p")]
public PreferenceV6 Preferences { get; set; }

[JsonPropertyName("s")]
public List<SegmentV6> Segments { get; set; }

[JsonPropertyName("f")]
public Dictionary<string, EvaluationFormulaV6> FeatureFlags { get; set; }
}
}
Loading
Loading