-
-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
…5208) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Text; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Storage; | ||
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal; | ||
using Ombi.Core.Models; | ||
using Polly; | ||
using Pomelo.EntityFrameworkCore.MySql.Storage.Internal; | ||
|
||
namespace Ombi.Core.Helpers; | ||
|
||
public static class DatabaseConfigurationSetup | ||
{ | ||
public static void ConfigurePostgres(DbContextOptionsBuilder options, PerDatabaseConfiguration config) | ||
{ | ||
options.UseNpgsql(config.ConnectionString, b => | ||
{ | ||
b.EnableRetryOnFailure(); | ||
}).ReplaceService<ISqlGenerationHelper, NpgsqlCaseInsensitiveSqlGenerationHelper>(); | ||
} | ||
|
||
public static void ConfigureMySql(DbContextOptionsBuilder options, PerDatabaseConfiguration config) | ||
{ | ||
if (string.IsNullOrEmpty(config.ConnectionString)) | ||
{ | ||
throw new ArgumentNullException("ConnectionString for the MySql/Mariadb database is empty"); | ||
} | ||
|
||
options.UseMySql(config.ConnectionString, GetServerVersion(config.ConnectionString), b => | ||
{ | ||
//b.CharSetBehavior(Pomelo.EntityFrameworkCore.MySql.Infrastructure.CharSetBehavior.NeverAppend); // ##ISSUE, link to migrations? | ||
b.EnableRetryOnFailure(); | ||
}); | ||
} | ||
|
||
private static ServerVersion GetServerVersion(string connectionString) | ||
{ | ||
// Workaround Windows bug, that can lead to the following exception: | ||
// | ||
// MySqlConnector.MySqlException (0x80004005): SSL Authentication Error | ||
// ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception. | ||
// ---> System.ComponentModel.Win32Exception (0x8009030F): The message or signature supplied for verification has been altered | ||
// | ||
// See https://github.com/dotnet/runtime/issues/17005#issuecomment-305848835 | ||
// | ||
// Also workaround for the fact, that ServerVersion.AutoDetect() does not use any retrying strategy. | ||
ServerVersion serverVersion = null; | ||
#pragma warning disable EF1001 | ||
var retryPolicy = Policy.Handle<Exception>(exception => MySqlTransientExceptionDetector.ShouldRetryOn(exception)) | ||
#pragma warning restore EF1001 | ||
.WaitAndRetry(3, (count, context) => TimeSpan.FromMilliseconds(count * 250)); | ||
|
||
serverVersion = retryPolicy.Execute(() => serverVersion = ServerVersion.AutoDetect(connectionString)); | ||
|
||
return serverVersion; | ||
} | ||
public class NpgsqlCaseInsensitiveSqlGenerationHelper : NpgsqlSqlGenerationHelper | ||
Check warning on line 57 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / unit-test
Check warning on line 57 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (linux-arm, tar.gz, tar)
Check warning on line 57 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (win-x86, zip, zip)
Check warning on line 57 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (win-x64, zip, zip)
Check warning on line 57 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (osx-x64, tar, tar.gz)
Check warning on line 57 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (linux-x64, tar.gz, tar)
Check warning on line 57 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (linux-arm64, tar, tar.gz)
|
||
{ | ||
const string EFMigrationsHisory = "__EFMigrationsHistory"; | ||
public NpgsqlCaseInsensitiveSqlGenerationHelper(RelationalSqlGenerationHelperDependencies dependencies) | ||
: base(dependencies) { } | ||
Check warning on line 61 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / unit-test
Check warning on line 61 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (linux-arm, tar.gz, tar)
Check warning on line 61 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (win-x86, zip, zip)
Check warning on line 61 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (win-x64, zip, zip)
Check warning on line 61 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (osx-x64, tar, tar.gz)
Check warning on line 61 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (linux-x64, tar.gz, tar)
Check warning on line 61 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (linux-arm64, tar, tar.gz)
|
||
public override string DelimitIdentifier(string identifier) => | ||
base.DelimitIdentifier(identifier == EFMigrationsHisory ? identifier : identifier.ToLower()); | ||
Check warning on line 63 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / unit-test
Check warning on line 63 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (linux-arm, tar.gz, tar)
Check warning on line 63 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (win-x86, zip, zip)
Check warning on line 63 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (win-x64, zip, zip)
Check warning on line 63 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (osx-x64, tar, tar.gz)
Check warning on line 63 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (linux-x64, tar.gz, tar)
Check warning on line 63 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (linux-arm64, tar, tar.gz)
|
||
public override void DelimitIdentifier(StringBuilder builder, string identifier) | ||
=> base.DelimitIdentifier(builder, identifier == EFMigrationsHisory ? identifier : identifier.ToLower()); | ||
Check warning on line 65 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / unit-test
Check warning on line 65 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (linux-arm, tar.gz, tar)
Check warning on line 65 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (win-x86, zip, zip)
Check warning on line 65 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (win-x64, zip, zip)
Check warning on line 65 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (osx-x64, tar, tar.gz)
Check warning on line 65 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (linux-x64, tar.gz, tar)
Check warning on line 65 in src/Ombi.Core/Helpers/DatabaseConfigurationSetup.cs GitHub Actions / publish (linux-arm64, tar, tar.gz)
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Ombi.Core.Helpers; | ||
|
||
public class FileSystem : IFileSystem | ||
{ | ||
public bool FileExists(string path) | ||
{ | ||
return System.IO.File.Exists(path); | ||
} | ||
// Implement other file system operations as needed | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Ombi.Core.Helpers; | ||
|
||
public interface IFileSystem | ||
{ | ||
bool FileExists(string path); | ||
// Add other file system operations as needed | ||
} |