1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-21 12:05:42 +01:00

Set proper context for service accounts (#4765)

This commit is contained in:
Matt Bishop 2024-09-11 15:41:06 -04:00 committed by GitHub
parent bee76732b4
commit df61edbce7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -181,7 +181,7 @@ public class LaunchDarklyFeatureService : IFeatureService
if (_currentContext.Organizations?.Any() ?? false) if (_currentContext.Organizations?.Any() ?? false)
{ {
var ldOrgs = _currentContext.Organizations.Select(o => LdValue.Of(o.Id.ToString())); var ldOrgs = _currentContext.Organizations.Select(o => LdValue.Of(o.Id.ToString()));
ldUser.Set(_contextAttributeOrganizations, LaunchDarkly.Sdk.LdValue.ArrayFrom(ldOrgs)); ldUser.Set(_contextAttributeOrganizations, LdValue.ArrayFrom(ldOrgs));
} }
builder.Add(ldUser.Build()); builder.Add(ldUser.Build());
@ -213,15 +213,14 @@ public class LaunchDarklyFeatureService : IFeatureService
builder.Add(ldServiceAccount.Build()); builder.Add(ldServiceAccount.Build());
} }
else if (_currentContext.OrganizationId.HasValue)
if (_currentContext.OrganizationId.HasValue)
{ {
var ldOrg = LaunchDarkly.Sdk.Context.Builder(_currentContext.OrganizationId.Value.ToString()); var ldServiceAccount = LaunchDarkly.Sdk.Context.Builder(_currentContext.OrganizationId.Value.ToString());
ldOrg.Kind(_contextKindOrganization); ldServiceAccount.Kind(_contextKindServiceAccount);
SetCommonContextAttributes(ldOrg); SetCommonContextAttributes(ldServiceAccount);
builder.Add(ldOrg.Build()); builder.Add(ldServiceAccount.Build());
} }
} }
break; break;
@ -235,17 +234,17 @@ public class LaunchDarklyFeatureService : IFeatureService
var source = TestData.DataSource(); var source = TestData.DataSource();
foreach (var kvp in values) foreach (var kvp in values)
{ {
if (bool.TryParse(kvp.Value, out bool boolValue)) if (bool.TryParse(kvp.Value, out var boolValue))
{ {
source.Update(source.Flag(kvp.Key).ValueForAll(LaunchDarkly.Sdk.LdValue.Of(boolValue))); source.Update(source.Flag(kvp.Key).ValueForAll(LdValue.Of(boolValue)));
} }
else if (int.TryParse(kvp.Value, out int intValue)) else if (int.TryParse(kvp.Value, out var intValue))
{ {
source.Update(source.Flag(kvp.Key).ValueForAll(LaunchDarkly.Sdk.LdValue.Of(intValue))); source.Update(source.Flag(kvp.Key).ValueForAll(LdValue.Of(intValue)));
} }
else else
{ {
source.Update(source.Flag(kvp.Key).ValueForAll(LaunchDarkly.Sdk.LdValue.Of(kvp.Value))); source.Update(source.Flag(kvp.Key).ValueForAll(LdValue.Of(kvp.Value)));
} }
} }