in src/Cli/ConfigGenerator.cs [956:1089]
private static bool TryUpdateConfiguredHostValues(
ConfigureOptions options,
ref HostOptions? updatedHostOptions)
{
object? updatedValue;
try
{
// Runtime.Host.Mode
updatedValue = options?.RuntimeHostMode;
if (updatedValue != null)
{
updatedHostOptions = updatedHostOptions! with { Mode = (HostMode)updatedValue };
_logger.LogInformation("Updated RuntimeConfig with Runtime.Host.Mode as '{updatedValue}'", updatedValue);
}
// Runtime.Host.Cors.Origins
IEnumerable<string>? updatedCorsOrigins = options?.RuntimeHostCorsOrigins;
if (updatedCorsOrigins != null && updatedCorsOrigins.Any())
{
CorsOptions corsOptions;
if (updatedHostOptions?.Cors == null)
{
corsOptions = new(Origins: updatedCorsOrigins.ToArray());
}
else
{
corsOptions = updatedHostOptions.Cors! with { Origins = updatedCorsOrigins.ToArray() };
}
updatedHostOptions = updatedHostOptions! with { Cors = corsOptions };
_logger.LogInformation("Updated RuntimeConfig with Runtime.Host.Cors.Origins as '{updatedValue}'", updatedCorsOrigins);
}
// Runtime.Host.Cors.Allow-Credentials
updatedValue = options?.RuntimeHostCorsAllowCredentials;
if (updatedValue != null)
{
CorsOptions corsOptions;
if (updatedHostOptions?.Cors == null)
{
corsOptions = new(new string[] { }, AllowCredentials: (bool)updatedValue);
}
else
{
corsOptions = updatedHostOptions.Cors! with { AllowCredentials = (bool)updatedValue };
}
updatedHostOptions = updatedHostOptions! with { Cors = corsOptions };
_logger.LogInformation("Updated RuntimeConfig with Runtime.Host.Cors.Allow-Credentials as '{updatedValue}'", updatedValue);
}
// Runtime.Host.Authentication.Provider
string? updatedProviderValue = options?.RuntimeHostAuthenticationProvider;
if (updatedProviderValue != null)
{
updatedValue = updatedProviderValue?.ToString() ?? nameof(EasyAuthType.StaticWebApps);
AuthenticationOptions AuthOptions;
if (updatedHostOptions?.Authentication == null)
{
AuthOptions = new(Provider: (string)updatedValue);
}
else
{
AuthOptions = updatedHostOptions.Authentication with { Provider = (string)updatedValue };
}
updatedHostOptions = updatedHostOptions! with { Authentication = AuthOptions };
_logger.LogInformation("Updated RuntimeConfig with Runtime.Host.Authentication.Provider as '{updatedValue}'", updatedValue);
}
// Runtime.Host.Authentication.Jwt.Audience
updatedValue = options?.RuntimeHostAuthenticationJwtAudience;
if (updatedValue != null)
{
JwtOptions jwtOptions;
AuthenticationOptions AuthOptions;
if (updatedHostOptions?.Authentication == null || updatedHostOptions.Authentication?.Jwt == null)
{
jwtOptions = new(Audience: (string)updatedValue, null);
}
else
{
jwtOptions = updatedHostOptions.Authentication.Jwt with { Audience = (string)updatedValue };
}
if (updatedHostOptions?.Authentication == null)
{
AuthOptions = new(Jwt: jwtOptions);
}
else
{
AuthOptions = updatedHostOptions.Authentication with { Jwt = jwtOptions };
}
updatedHostOptions = updatedHostOptions! with { Authentication = AuthOptions };
_logger.LogInformation("Updated RuntimeConfig with Runtime.Host.Authentication.Jwt.Audience as '{updatedValue}'", updatedValue);
}
// Runtime.Host.Authentication.Jwt.Issuer
updatedValue = options?.RuntimeHostAuthenticationJwtIssuer;
if (updatedValue != null)
{
JwtOptions jwtOptions;
AuthenticationOptions AuthOptions;
if (updatedHostOptions?.Authentication == null || updatedHostOptions.Authentication?.Jwt == null)
{
jwtOptions = new(null, Issuer: (string)updatedValue);
}
else
{
jwtOptions = updatedHostOptions.Authentication.Jwt with { Issuer = (string)updatedValue };
}
if (updatedHostOptions?.Authentication == null)
{
AuthOptions = new(Jwt: jwtOptions);
}
else
{
AuthOptions = updatedHostOptions.Authentication with { Jwt = jwtOptions };
}
updatedHostOptions = updatedHostOptions! with { Authentication = AuthOptions };
_logger.LogInformation("Updated RuntimeConfig with Runtime.Host.Authentication.Jwt.Issuer as '{updatedValue}'", updatedValue);
}
return true;
}
catch (Exception ex)
{
_logger.LogError("Failed to update RuntimeConfig.Host with exception message: {exceptionMessage}.", ex.Message);
return false;
}
}