Changes
This commit is contained in:
@@ -6,7 +6,17 @@ namespace Musify.Application.Configuration
|
|||||||
{
|
{
|
||||||
public const string SectionName = "Storage";
|
public const string SectionName = "Storage";
|
||||||
|
|
||||||
public string BucketName { get; set; } = "musify-S3";
|
public string ServiceUrl { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string AccessKey { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string SecretAccessKey { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string BucketName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public bool ForcePathStyle { get; set; }
|
||||||
|
|
||||||
|
public bool UseHttp { get; set; }
|
||||||
|
|
||||||
public StorageRoutes Routes { get; set; } = new StorageRoutes();
|
public StorageRoutes Routes { get; set; } = new StorageRoutes();
|
||||||
|
|
||||||
@@ -24,6 +34,10 @@ namespace Musify.Application.Configuration
|
|||||||
{
|
{
|
||||||
EnsureValue(configuration.BucketName, nameof(BucketName));
|
EnsureValue(configuration.BucketName, nameof(BucketName));
|
||||||
EnsureValue(configuration.Routes.Uploads, $"{SectionName}:Route:Upload");
|
EnsureValue(configuration.Routes.Uploads, $"{SectionName}:Route:Upload");
|
||||||
|
|
||||||
|
EnsureValue(configuration.ServiceUrl, nameof(ServiceUrl));
|
||||||
|
EnsureValue(configuration.AccessKey, nameof(AccessKey));
|
||||||
|
EnsureValue(configuration.SecretAccessKey, nameof(SecretAccessKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnsureValue(string value, string name)
|
static void EnsureValue(string value, string name)
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace Musify.Infrastructure.Identity
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
namespace Musify.Infrastructure.Identity
|
||||||
{
|
{
|
||||||
public class KeycloakConfiguration
|
public class KeycloakConfiguration
|
||||||
{
|
{
|
||||||
@@ -11,5 +13,29 @@
|
|||||||
public string Username { get; set; } = string.Empty;
|
public string Username { get; set; } = string.Empty;
|
||||||
|
|
||||||
public string Password { get; set; } = string.Empty;
|
public string Password { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public static KeycloakConfiguration Load(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
var keycloakConfiguration = configuration.GetSection(SectionName).Get<KeycloakConfiguration>()
|
||||||
|
?? throw new InvalidOperationException($"{SectionName} configuration section not found.");
|
||||||
|
|
||||||
|
Validate(keycloakConfiguration);
|
||||||
|
|
||||||
|
return keycloakConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Validate(KeycloakConfiguration configuration)
|
||||||
|
{
|
||||||
|
EnsureValue(configuration.BaseUrl, nameof(configuration.BaseUrl));
|
||||||
|
EnsureValue(configuration.Realm, nameof(configuration.Realm));
|
||||||
|
EnsureValue(configuration.Username, nameof(configuration.Username));
|
||||||
|
EnsureValue(configuration.Password, nameof(configuration.Password));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void EnsureValue(string value, string name)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(value))
|
||||||
|
throw new InvalidOperationException($"{name} configuration value not found.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Musify.Application.Contracts.Infrastructure;
|
||||||
|
|
||||||
|
namespace Musify.Infrastructure.Identity
|
||||||
|
{
|
||||||
|
public static class KeycloakDependencyInjection
|
||||||
|
{
|
||||||
|
public static void AddKeycloakAuthentication(this IServiceCollection serviceDescriptors, IConfiguration configuration)
|
||||||
|
{
|
||||||
|
var keycloakConfiguration = KeycloakConfiguration.Load(configuration);
|
||||||
|
|
||||||
|
serviceDescriptors.AddSingleton(keycloakConfiguration);
|
||||||
|
|
||||||
|
serviceDescriptors.AddScoped<IKeycloakUserClient, KeycloakIdentityService>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Amazon.S3;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Musify.Application.Configuration;
|
||||||
using Musify.Application.Contracts.Infrastructure;
|
using Musify.Application.Contracts.Infrastructure;
|
||||||
|
|
||||||
namespace Musify.Infrastructure.Storage
|
namespace Musify.Infrastructure.Storage
|
||||||
@@ -7,6 +9,20 @@ namespace Musify.Infrastructure.Storage
|
|||||||
{
|
{
|
||||||
public static void AddStorageHandler(this IServiceCollection serviceDescriptors)
|
public static void AddStorageHandler(this IServiceCollection serviceDescriptors)
|
||||||
{
|
{
|
||||||
|
serviceDescriptors.AddScoped<IAmazonS3>(serviceProvider =>
|
||||||
|
{
|
||||||
|
var configuration = serviceProvider.GetRequiredService<StorageConfiguration>();
|
||||||
|
|
||||||
|
var s3Configuration = new AmazonS3Config
|
||||||
|
{
|
||||||
|
ServiceURL = configuration.ServiceUrl,
|
||||||
|
ForcePathStyle = configuration.ForcePathStyle,
|
||||||
|
UseHttp = configuration.UseHttp,
|
||||||
|
};
|
||||||
|
|
||||||
|
return new AmazonS3Client(configuration.AccessKey, configuration.SecretAccessKey, s3Configuration);
|
||||||
|
} );
|
||||||
|
|
||||||
serviceDescriptors.AddScoped<IStorageHandler, StorageHandler>();
|
serviceDescriptors.AddScoped<IStorageHandler, StorageHandler>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user