Skip to content

[PM-17562] Add feature flag for event-based organization integrations #5710

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

Merged
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
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
๏ปฟusing Bit.Api.AdminConsole.Models.Request.Organizations;
using Bit.Api.AdminConsole.Models.Response.Organizations;
using Bit.Core;
using Bit.Core.Context;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Bit.Api.AdminConsole.Controllers;

[RequireFeature(FeatureFlagKeys.EventBasedOrganizationIntegrations)]
[Route("organizations/{organizationId:guid}/integrations/{integrationId:guid}/configurations")]
[Authorize("Application")]
public class OrganizationIntegrationConfigurationController(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
๏ปฟusing Bit.Api.AdminConsole.Models.Request.Organizations;
using Bit.Api.AdminConsole.Models.Response.Organizations;
using Bit.Core;
using Bit.Core.Context;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

#nullable enable

namespace Bit.Api.AdminConsole.Controllers;

[RequireFeature(FeatureFlagKeys.EventBasedOrganizationIntegrations)]
[Route("organizations/{organizationId:guid}/integrations")]
[Authorize("Application")]
public class OrganizationIntegrationController(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
๏ปฟusing System.Text.Json;
using Bit.Api.AdminConsole.Models.Response.Organizations;
using Bit.Core;
using Bit.Core.AdminConsole.Entities;
using Bit.Core.Context;
using Bit.Core.Enums;
using Bit.Core.Exceptions;
using Bit.Core.Models.Data.Integrations;
using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Bit.Api.AdminConsole.Controllers;

[RequireFeature(FeatureFlagKeys.EventBasedOrganizationIntegrations)]
[Route("organizations/{organizationId:guid}/integrations/slack")]
[Authorize("Application")]
public class SlackIntegrationController(
Expand Down
1 change: 1 addition & 0 deletions src/Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public static class FeatureFlagKeys
public const string PolicyRequirements = "pm-14439-policy-requirements";
public const string SsoExternalIdVisibility = "pm-18630-sso-external-id-visibility";
public const string ScimInviteUserOptimization = "pm-16811-optimize-invite-user-flow-to-fail-fast";
public const string EventBasedOrganizationIntegrations = "event-based-organization-integrations";

/* Auth Team */
public const string PM9112DeviceApprovalPersistence = "pm-9112-device-approval-persistence";
Expand Down
23 changes: 18 additions & 5 deletions src/Events/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
๏ปฟusing System.Globalization;
using Bit.Core;
using Bit.Core.AdminConsole.Services.Implementations;
using Bit.Core.AdminConsole.Services.NoopImplementations;
using Bit.Core.Context;
Expand Down Expand Up @@ -62,33 +63,45 @@
{
services.AddSingleton<IApplicationCacheService, InMemoryApplicationCacheService>();
}
services.AddScoped<IEventService, EventService>();

if (!globalSettings.SelfHosted && CoreHelpers.SettingHasValue(globalSettings.Events.ConnectionString))
{
services.AddKeyedSingleton<IEventWriteService, AzureQueueEventWriteService>("storage");

Check warning on line 69 in src/Events/Startup.cs

View check run for this annotation

Codecov / codecov/patch

src/Events/Startup.cs#L69

Added line #L69 was not covered by tests

if (CoreHelpers.SettingHasValue(globalSettings.EventLogging.AzureServiceBus.ConnectionString) &&
CoreHelpers.SettingHasValue(globalSettings.EventLogging.AzureServiceBus.TopicName))
{
services.AddSingleton<IEventWriteService, AzureServiceBusEventWriteService>();
services.AddKeyedSingleton<IEventWriteService, AzureServiceBusEventWriteService>("broadcast");

Check warning on line 74 in src/Events/Startup.cs

View check run for this annotation

Codecov / codecov/patch

src/Events/Startup.cs#L74

Added line #L74 was not covered by tests
}
else
{
services.AddSingleton<IEventWriteService, AzureQueueEventWriteService>();
services.AddKeyedSingleton<IEventWriteService, NoopEventWriteService>("broadcast");

Check warning on line 78 in src/Events/Startup.cs

View check run for this annotation

Codecov / codecov/patch

src/Events/Startup.cs#L78

Added line #L78 was not covered by tests
}
}
else
{
services.AddKeyedSingleton<IEventWriteService, RepositoryEventWriteService>("storage");

if (CoreHelpers.SettingHasValue(globalSettings.EventLogging.RabbitMq.HostName) &&
CoreHelpers.SettingHasValue(globalSettings.EventLogging.RabbitMq.Username) &&
CoreHelpers.SettingHasValue(globalSettings.EventLogging.RabbitMq.Password) &&
CoreHelpers.SettingHasValue(globalSettings.EventLogging.RabbitMq.ExchangeName))
{
services.AddSingleton<IEventWriteService, RabbitMqEventWriteService>();
services.AddKeyedSingleton<IEventWriteService, RabbitMqEventWriteService>("broadcast");

Check warning on line 90 in src/Events/Startup.cs

View check run for this annotation

Codecov / codecov/patch

src/Events/Startup.cs#L90

Added line #L90 was not covered by tests
}
else
{
services.AddSingleton<IEventWriteService, RepositoryEventWriteService>();
services.AddKeyedSingleton<IEventWriteService, NoopEventWriteService>("broadcast");
}
}
services.AddScoped<IEventWriteService>(sp =>
{
var featureService = sp.GetRequiredService<IFeatureService>();

Check warning on line 99 in src/Events/Startup.cs

View check run for this annotation

Codecov / codecov/patch

src/Events/Startup.cs#L98-L99

Added lines #L98 - L99 were not covered by tests
var key = featureService.IsEnabled(FeatureFlagKeys.EventBasedOrganizationIntegrations)
? "broadcast" : "storage";
return sp.GetRequiredKeyedService<IEventWriteService>(key);

Check warning on line 102 in src/Events/Startup.cs

View check run for this annotation

Codecov / codecov/patch

src/Events/Startup.cs#L101-L102

Added lines #L101 - L102 were not covered by tests
});
services.AddScoped<IEventService, EventService>();

services.AddOptionality();

Expand Down
23 changes: 18 additions & 5 deletions src/SharedWeb/Utilities/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Security.Cryptography.X509Certificates;
using AspNetCoreRateLimit;
using Azure.Storage.Queues;
using Bit.Core;
using Bit.Core.AdminConsole.Models.Business.Tokenables;
using Bit.Core.AdminConsole.OrganizationFeatures.Policies;
using Bit.Core.AdminConsole.Services;
Expand Down Expand Up @@ -332,34 +333,46 @@

if (!globalSettings.SelfHosted && CoreHelpers.SettingHasValue(globalSettings.Events.ConnectionString))
{
services.AddKeyedSingleton<IEventWriteService, AzureQueueEventWriteService>("storage");

Check warning on line 336 in src/SharedWeb/Utilities/ServiceCollectionExtensions.cs

View check run for this annotation

Codecov / codecov/patch

src/SharedWeb/Utilities/ServiceCollectionExtensions.cs#L336

Added line #L336 was not covered by tests

if (CoreHelpers.SettingHasValue(globalSettings.EventLogging.AzureServiceBus.ConnectionString) &&
CoreHelpers.SettingHasValue(globalSettings.EventLogging.AzureServiceBus.TopicName))
{
services.AddSingleton<IEventWriteService, AzureServiceBusEventWriteService>();
services.AddKeyedSingleton<IEventWriteService, AzureServiceBusEventWriteService>("broadcast");

Check warning on line 341 in src/SharedWeb/Utilities/ServiceCollectionExtensions.cs

View check run for this annotation

Codecov / codecov/patch

src/SharedWeb/Utilities/ServiceCollectionExtensions.cs#L341

Added line #L341 was not covered by tests
}
else
{
services.AddSingleton<IEventWriteService, AzureQueueEventWriteService>();
services.AddKeyedSingleton<IEventWriteService, NoopEventWriteService>("broadcast");

Check warning on line 345 in src/SharedWeb/Utilities/ServiceCollectionExtensions.cs

View check run for this annotation

Codecov / codecov/patch

src/SharedWeb/Utilities/ServiceCollectionExtensions.cs#L345

Added line #L345 was not covered by tests
}
}
else if (globalSettings.SelfHosted)
{
services.AddKeyedSingleton<IEventWriteService, RepositoryEventWriteService>("storage");

Check warning on line 350 in src/SharedWeb/Utilities/ServiceCollectionExtensions.cs

View check run for this annotation

Codecov / codecov/patch

src/SharedWeb/Utilities/ServiceCollectionExtensions.cs#L350

Added line #L350 was not covered by tests

if (CoreHelpers.SettingHasValue(globalSettings.EventLogging.RabbitMq.HostName) &&
CoreHelpers.SettingHasValue(globalSettings.EventLogging.RabbitMq.Username) &&
CoreHelpers.SettingHasValue(globalSettings.EventLogging.RabbitMq.Password) &&
CoreHelpers.SettingHasValue(globalSettings.EventLogging.RabbitMq.ExchangeName))
{
services.AddSingleton<IEventWriteService, RabbitMqEventWriteService>();
services.AddKeyedSingleton<IEventWriteService, RabbitMqEventWriteService>("broadcast");

Check warning on line 357 in src/SharedWeb/Utilities/ServiceCollectionExtensions.cs

View check run for this annotation

Codecov / codecov/patch

src/SharedWeb/Utilities/ServiceCollectionExtensions.cs#L357

Added line #L357 was not covered by tests
}
else
{
services.AddSingleton<IEventWriteService, RepositoryEventWriteService>();
services.AddKeyedSingleton<IEventWriteService, NoopEventWriteService>("broadcast");

Check warning on line 361 in src/SharedWeb/Utilities/ServiceCollectionExtensions.cs

View check run for this annotation

Codecov / codecov/patch

src/SharedWeb/Utilities/ServiceCollectionExtensions.cs#L361

Added line #L361 was not covered by tests
}
}
else
{
services.AddSingleton<IEventWriteService, NoopEventWriteService>();
services.AddKeyedSingleton<IEventWriteService, NoopEventWriteService>("storage");
services.AddKeyedSingleton<IEventWriteService, NoopEventWriteService>("broadcast");
}
services.AddScoped<IEventWriteService>(sp =>
{
var featureService = sp.GetRequiredService<IFeatureService>();

Check warning on line 371 in src/SharedWeb/Utilities/ServiceCollectionExtensions.cs

View check run for this annotation

Codecov / codecov/patch

src/SharedWeb/Utilities/ServiceCollectionExtensions.cs#L370-L371

Added lines #L370 - L371 were not covered by tests
var key = featureService.IsEnabled(FeatureFlagKeys.EventBasedOrganizationIntegrations)
? "broadcast" : "storage";
return sp.GetRequiredKeyedService<IEventWriteService>(key);

Check warning on line 374 in src/SharedWeb/Utilities/ServiceCollectionExtensions.cs

View check run for this annotation

Codecov / codecov/patch

src/SharedWeb/Utilities/ServiceCollectionExtensions.cs#L373-L374

Added lines #L373 - L374 were not covered by tests
});

if (CoreHelpers.SettingHasValue(globalSettings.Attachment.ConnectionString))
{
Expand Down
Loading