Skip to content

Commit

Permalink
fix(management): prevent empty config creation
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashilzendegen authored and gingters committed Nov 9, 2023
1 parent 18cd826 commit 908b756
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,30 @@ public static TenantModel ToModel(this TenantEntity tenant)
/// <param name="tenant">The tenant instance to convert.</param>
/// <returns>A new instance of an <see cref="Thinktecture.Relay.Server.Persistence.Models.Tenant"/>.</returns>
public static TenantEntity ToEntity(this TenantModel tenant)
=> new TenantEntity()
{
var config = (ConfigEntity?)null;

if (tenant.KeepAliveInterval != null ||
tenant.EnableTracing != null ||
tenant.ReconnectMinimumDelay != null ||
tenant.ReconnectMaximumDelay != null)
{
Id = tenant.Id,
Name = tenant.Name,
DisplayName = tenant.DisplayName,
Description = tenant.Description,
Config = new ConfigEntity()
config = new ConfigEntity()
{
KeepAliveInterval = tenant.KeepAliveInterval,
EnableTracing = tenant.EnableTracing,
ReconnectMinimumDelay = tenant.ReconnectMinimumDelay,
ReconnectMaximumDelay = tenant.ReconnectMaximumDelay,
},
};
}

return new TenantEntity()
{
Id = tenant.Id,
Name = tenant.Name,
DisplayName = tenant.DisplayName,
Description = tenant.Description,
Config = config,
ClientSecrets = tenant.Credentials.Select(s =>
new ClientSecret()
{
Expand All @@ -75,8 +86,9 @@ public static TenantEntity ToEntity(this TenantModel tenant)
Value = s.Value ?? Sha512(s.PlainTextValue)!,
Expiration = s.Expiration,
}
).ToList(),
).ToList(),
};
}

/// <summary>
/// Converts an enumerable of <see cref="Thinktecture.Relay.Server.Persistence.Models.Tenant"/> to an
Expand Down

0 comments on commit 908b756

Please sign in to comment.