mirror of
https://github.com/jcreek/Creek.FileRepository.git
synced 2026-07-12 18:33:43 +00:00
refactor(*): Use a strongly-typed options object for reading configuration for the SftpRepository
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Creek.HelpfulExtensions" Version="1.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Creek.FileRepository.Helpers;
|
||||
using Creek.FileRepository.Models;
|
||||
using Creek.FileRepository.RepositoryOptions;
|
||||
using Creek.HelpfulExtensions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Renci.SshNet;
|
||||
@@ -28,11 +29,14 @@ namespace Creek.FileRepository.Repositories
|
||||
/// <param name="config">The configuration to initialise the repository with.</param>
|
||||
internal SftpRepository(IConfiguration config)
|
||||
{
|
||||
this.host = config["SftpRepository:host"];
|
||||
this.port = int.Parse(config["SftpRepository:port"]);
|
||||
this.username = config["SftpRepository:username"].ToString();
|
||||
this.password = config["SftpRepository:password"].ToString();
|
||||
this.remoteDirectoryPath = config["SftpRepository:remoteDirectoryPath"].ToString();
|
||||
SftpRepositoryOptions sftpRepositoryOptions = config.GetSection(SftpRepositoryOptions.SftpRepository)
|
||||
.Get<SftpRepositoryOptions>();
|
||||
|
||||
this.host = sftpRepositoryOptions.Host;
|
||||
this.port = sftpRepositoryOptions.Port;
|
||||
this.username = sftpRepositoryOptions.Username;
|
||||
this.password = sftpRepositoryOptions.Password;
|
||||
this.remoteDirectoryPath = sftpRepositoryOptions.RemoteDirectoryPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Creek.FileRepository.RepositoryOptions
|
||||
{
|
||||
public class SftpRepositoryOptions
|
||||
{
|
||||
public const string SftpRepository = "SftpRepository";
|
||||
|
||||
public string Host { get; set; }
|
||||
public int Port { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string RemoteDirectoryPath { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"SftpRepository": {
|
||||
"host": "",
|
||||
"port": 22,
|
||||
"username": "",
|
||||
"password": "",
|
||||
"remoteDirectoryPath": "/"
|
||||
"Host": "",
|
||||
"Port": 22,
|
||||
"Username": "",
|
||||
"Password": "",
|
||||
"RemoteDirectoryPath": "/"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user