mirror of
https://github.com/bitwarden/server.git
synced 2025-06-25 13:18:48 -05:00

* [PM-17562] Update documentation for event integrations * Fix SonarQube suggestion, bring ASB event listener in line with integration listener * Apply suggestions from code review Co-authored-by: Matt Bishop <mbishop@bitwarden.com> * Updates to README - PR fixes, additional context, tense alignment * Fix the formatting for inlined code snippets * Add links to different sections; remove inline code formatting in favor of single bacticks for JSON --------- Co-authored-by: Matt Bishop <mbishop@bitwarden.com>
74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.Text.Json;
|
|
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.AdminConsole.Models.Data.EventIntegrations;
|
|
using Bit.Core.Enums;
|
|
|
|
#nullable enable
|
|
|
|
namespace Bit.Api.AdminConsole.Models.Request.Organizations;
|
|
|
|
public class OrganizationIntegrationConfigurationRequestModel
|
|
{
|
|
public string? Configuration { get; set; }
|
|
|
|
[Required]
|
|
public EventType EventType { get; set; }
|
|
|
|
public string? Template { get; set; }
|
|
|
|
public bool IsValidForType(IntegrationType integrationType)
|
|
{
|
|
switch (integrationType)
|
|
{
|
|
case IntegrationType.CloudBillingSync or IntegrationType.Scim:
|
|
return false;
|
|
case IntegrationType.Slack:
|
|
return !string.IsNullOrWhiteSpace(Template) && IsConfigurationValid<SlackIntegrationConfiguration>();
|
|
case IntegrationType.Webhook:
|
|
return !string.IsNullOrWhiteSpace(Template) && IsConfigurationValid<WebhookIntegrationConfiguration>();
|
|
default:
|
|
return false;
|
|
|
|
}
|
|
}
|
|
|
|
public OrganizationIntegrationConfiguration ToOrganizationIntegrationConfiguration(Guid organizationIntegrationId)
|
|
{
|
|
return new OrganizationIntegrationConfiguration()
|
|
{
|
|
OrganizationIntegrationId = organizationIntegrationId,
|
|
Configuration = Configuration,
|
|
EventType = EventType,
|
|
Template = Template
|
|
};
|
|
}
|
|
|
|
public OrganizationIntegrationConfiguration ToOrganizationIntegrationConfiguration(OrganizationIntegrationConfiguration currentConfiguration)
|
|
{
|
|
currentConfiguration.Configuration = Configuration;
|
|
currentConfiguration.EventType = EventType;
|
|
currentConfiguration.Template = Template;
|
|
|
|
return currentConfiguration;
|
|
}
|
|
|
|
private bool IsConfigurationValid<T>()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(Configuration))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
try
|
|
{
|
|
var config = JsonSerializer.Deserialize<T>(Configuration);
|
|
return config is not null;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|