Skip to content

Commit

Permalink
Support client version prerelease flag in context and LD targeting (#…
Browse files Browse the repository at this point in the history
…4994)

* Support client version prerelease flag in context and LD targeting

* Use integer instead of Boolean
  • Loading branch information
withinfocus authored Nov 7, 2024
1 parent d6e624d commit 21b7c3b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Core/Context/CurrentContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class CurrentContext : ICurrentContext
public virtual int? BotScore { get; set; }
public virtual string ClientId { get; set; }
public virtual Version ClientVersion { get; set; }
public virtual bool ClientVersionIsPrerelease { get; set; }
public virtual IdentityClientType IdentityClientType { get; set; }
public virtual Guid? ServiceAccountOrganizationId { get; set; }

Expand Down Expand Up @@ -97,6 +98,11 @@ public async virtual Task BuildAsync(HttpContext httpContext, GlobalSettings glo
{
ClientVersion = cVersion;
}

if (httpContext.Request.Headers.TryGetValue("Is-Prerelease", out var clientVersionIsPrerelease))
{
ClientVersionIsPrerelease = clientVersionIsPrerelease == "1";
}
}

public async virtual Task BuildAsync(ClaimsPrincipal user, GlobalSettings globalSettings)
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Context/ICurrentContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ public interface ICurrentContext
int? BotScore { get; set; }
string ClientId { get; set; }
Version ClientVersion { get; set; }
bool ClientVersionIsPrerelease { get; set; }

Task BuildAsync(HttpContext httpContext, GlobalSettings globalSettings);
Task BuildAsync(ClaimsPrincipal user, GlobalSettings globalSettings);

Task SetContextAsync(ClaimsPrincipal user);


Task<bool> OrganizationUser(Guid orgId);
Task<bool> OrganizationAdmin(Guid orgId);
Task<bool> OrganizationOwner(Guid orgId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class LaunchDarklyFeatureService : IFeatureService
private const string _contextKindServiceAccount = "service-account";

private const string _contextAttributeClientVersion = "client-version";
private const string _contextAttributeClientVersionIsPrerelease = "client-version-is-prerelease";
private const string _contextAttributeDeviceType = "device-type";
private const string _contextAttributeClientType = "client-type";
private const string _contextAttributeOrganizations = "organizations";
Expand Down Expand Up @@ -145,6 +146,7 @@ void SetCommonContextAttributes(ContextBuilder builder)
if (_currentContext.ClientVersion != null)
{
builder.Set(_contextAttributeClientVersion, _currentContext.ClientVersion.ToString());
builder.Set(_contextAttributeClientVersionIsPrerelease, _currentContext.ClientVersionIsPrerelease);
}

if (_currentContext.DeviceType.HasValue)
Expand Down
1 change: 1 addition & 0 deletions test/Core.Test/Services/LaunchDarklyFeatureServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private static SutProvider<LaunchDarklyFeatureService> GetSutProvider(IGlobalSet
var currentContext = Substitute.For<ICurrentContext>();
currentContext.UserId.Returns(Guid.NewGuid());
currentContext.ClientVersion.Returns(new Version(AssemblyHelpers.GetVersion()));
currentContext.ClientVersionIsPrerelease.Returns(true);
currentContext.DeviceType.Returns(Enums.DeviceType.ChromeBrowser);

var client = Substitute.For<ILdClient>();
Expand Down

0 comments on commit 21b7c3b

Please sign in to comment.