Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListFiles - Major changes #36

Merged
merged 17 commits into from
Dec 21, 2023
11 changes: 3 additions & 8 deletions .github/workflows/ListFiles_build_and_test_on_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ on:

jobs:
build:
uses: FrendsPlatform/FrendsTasks/.github/workflows/build_main.yml@main
uses: FrendsPlatform/FrendsTasks/.github/workflows/linux_build_main.yml@main
with:
workdir: Frends.FTP.ListFiles
env_var_name_1: HiQ_FTP_Host
env_var_name_2: HiQ_FTP_User
env_var_name_3: HiQ_FTP_Password
prebuild_command: docker-compose -f Frends.FTP.ListFiles.Tests/docker-compose.yml up -d
secrets:
badge_service_api_key: ${{ secrets.BADGE_SERVICE_API_KEY }}
env_var_value_1: ${{ secrets.HIQ_FTP_HOST }}
env_var_value_2: ${{ secrets.HIQ_FTP_USER }}
env_var_value_3: ${{ secrets.HIQ_FTP_PASSWORD }}
badge_service_api_key: ${{ secrets.BADGE_SERVICE_API_KEY }}
11 changes: 3 additions & 8 deletions .github/workflows/ListFiles_build_and_test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@ on:

jobs:
build:
uses: FrendsPlatform/FrendsTasks/.github/workflows/build_test.yml@main
uses: FrendsPlatform/FrendsTasks/.github/workflows/linux_build_test.yml@main
with:
workdir: Frends.FTP.ListFiles
env_var_name_1: HiQ_FTP_Host
env_var_name_2: HiQ_FTP_User
env_var_name_3: HiQ_FTP_Password
prebuild_command: docker-compose -f Frends.FTP.ListFiles.Tests/docker-compose.yml up -d
secrets:
badge_service_api_key: ${{ secrets.BADGE_SERVICE_API_KEY }}
test_feed_api_key: ${{ secrets.TASKS_TEST_FEED_API_KEY }}
env_var_value_1: ${{ secrets.HIQ_FTP_HOST }}
env_var_value_2: ${{ secrets.HIQ_FTP_USER }}
env_var_value_3: ${{ secrets.HIQ_FTP_PASSWORD }}
test_feed_api_key: ${{ secrets.TASKS_TEST_FEED_API_KEY }}
20 changes: 20 additions & 0 deletions Frends.FTP.ListFiles/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## [2.0.0] - 2022-12-20
### Fixed
- Fixed documentation
- Fixed Tests and change the Tests to use docker container.
- Fixed error handling to throw specific errors from the library and not custom.

### Added
- Created Connection class for connection parameters.
- Added FTPS options.
- Added FtpMode and FtpsSslMode
- Added feature which enables the Task to get files, directories or both.
- Added feature which enables the Task to get files from subdirectories.
- Added possibility to use certificates.

### Changed
- Changed return object to a List of FileItems.
- Renamed most of the parameters.
- Changed the target framework to .net6.
- Changed the Task to async method.

## [1.0.0] - 2022-05-18
### Added
- Initial implementation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN X9.42 DH PARAMETERS-----
MIICLAKCAQEAw2Vi3DlhlltVCbM+vrY7qXBL62xIsyYGWHDVRiQR1CxfdPpy7AVG
lPc1FWsFBrUMVmhKBwsktlQmCzT7Hf6DdBFLU4V2erCER1IkEkwuC1IC61j8NTFq
59jVNjgy7RFTN3n0eFvaT7U/PQIyC7gGqlYHJpPnBb8nul3AF5aGdrlHvuvattwY
6P6PtpJCpGypZi352nGMkMFhA/tcBfi3jp9hFA7o6HJi89/UZzeO1ks1uEUf3EFv
rx7ckWBW9Rr85bTNsAcOn1q9h2BVoY8RjRHNTtzwpiygE31BRovShVL4UL+uYZ+E
1qKBdfV8KLyGT6IEdxEwHD+JC+3oMA1TfQKCAQB+2MtPTMZDRLJfy//8DbEajAK4
SyBzv7OHjZ/Oin4we1tE9FtLUDNwXNocGVPyHLK+cYhhDOcVWI3LdCyY38abSnhE
XWUA5q28OQsfsoDT/6EOx8NZ5A69UgNtzUyHfacnWCtVZ+WCUO6qb/XreqFZhuJD
tt4wwwitl2xU2C29CNqd3mTVukDypkHhBZZosMn6r4Jyw6V98xoZx9pvSqk8ts84
4bfTAgcfbWW7IH5C4ah6yVWfEkCbYIs5NPgAha0qumWPwpvMQSAXihYKKF3MgYWm
n+va+f6/GG3lIIbuvea/ESh9W7mSytAgwqd27JXtxcNd9D+Yu3f8khefBcvYAiEA
u4TEb+qo7uxkHl/8p1q6t7fLGqtomQCJTxufjVjkJUM=
-----END X9.42 DH PARAMETERS-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCU0FaMrsBVqfPd
ZncSFilS3JcOR6nZZE7mKDTo868Nz016yJXwBSEjg3z81tSTkNhocrQPvxWJAobV
TXy0h0yXhJMlKV4wQKyRXsdSrS5nn2NTA+fj3kx+Gtz+4yADiDB/egkOGKAm3RZM
grhjglR94BZRQk1/00Wen2B+EbCCKs4qx7uRiFbB9WPEIGkmd1e4z1zBsP2wTkWD
M+6wD+Fu02nAS9eo/JVYNVcw5XVlMWy6igsvfVEtcZObHxgJj3tpRYmfsVBsDZNi
rLGoraZtNSGBEVc2KTSIVsekOTNyFJ7Is8lXrUBTj5pVhdCQ3jcjfwXqHOPzu0Mb
x/tTDF2lAgMBAAECggEAQYeYhSyyn0ZOj7D+P+WoXseqcOxXu9Xy9GDCI86iyEcA
DFBlziLEG/pbwI7tXunKkfvolIKFfiaxrx4HCwwFSzdjAFs+Eat5Ei6VQS/nnlPO
jhDLPUl3j5ROuqLTRxrimE/pyt5HL7XtitWJUrBiemeCDFhQ/jfPkXEHMZyiiD6b
UnjtgmmMlsZ/6bwSyu9cTKGM9SOhCpowYBb8TEbh8HakVU+KEklsOqNCFho8ED/a
dsFi9nx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pEeNesnn+FZu8k3HpIknlm2b3J5WzZK8
-----END CERTIFICATE-----
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Frends.FTP.ListFiles\Frends.FTP.ListFiles.csproj" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Frends.FTP.ListFiles\Frends.FTP.ListFiles.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="DockerVolumes\data\ftp\test\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Usage", "CA2211:Non-constant fields should not be visible", Justification = "<Pending>", Scope = "member", Target = "~F:Frends.FTP.ListFiles.Tests.Lib.ListFilesTestBase.FtpHelper")]
78 changes: 78 additions & 0 deletions Frends.FTP.ListFiles/Frends.FTP.ListFiles.Tests/Lib/FtpHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System.Text;
using FluentFTP;
using Frends.FTP.ListFiles.Definitions;

namespace Frends.FTP.ListFiles.Tests;

public class FtpHelper : IDisposable
{
// Those values are taken directly from docker compose (see docker-compose.yml)
internal static readonly string FtpHost = "localhost";
internal static readonly int FtpPort = 21;
internal static readonly int FtpsPort = 21;
internal static readonly string FtpUsername = "frendsuser";
internal static readonly string FtpPassword = "frendspass";
internal static readonly string Sha1Hash = "D911262984DE9CC32A3518A1094CD24249EA5C49";
readonly FtpClient client = new();

public FtpHelper()
{
client = new FtpClient(FtpHost, FtpPort, FtpUsername, FtpPassword);
client.Connect();
}

internal static Connection GetFtpsConnection()
{
var connection = new Connection
{
UseFTPS = true,
Address = FtpHost,
UserName = FtpUsername,
Password = FtpPassword,
Port = FtpsPort,
SslMode = FtpsSslMode.Explicit,
CertificateHashStringSHA1 = Sha1Hash
};

return connection;
}

internal static Connection GetFtpConnection()
{
var connection = new Connection
{
Address = FtpHost,
UserName = FtpUsername,
Password = FtpPassword,
Port = FtpPort,
SslMode = FtpsSslMode.None
};

return connection;
}

internal void CreateFileOnFTP(string subDir, string fileName, string content = "hello")
{
client.CreateDirectory(subDir);
client.SetWorkingDirectory(subDir);
client.Upload(Encoding.UTF8.GetBytes(content), fileName);
client.SetWorkingDirectory("/");
}

internal void CreateDirectoryOnFTP(string subDir)
{
client.CreateDirectory(subDir);
}

public void Dispose()
{
GC.SuppressFinalize(this);
client.Disconnect();
if (!client.IsDisposed) client.Dispose();
}

public void DeleteDirectoryOnFTP(string ftpDir)
{
client.DeleteDirectory(ftpDir, FtpListOption.Recursive);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using NUnit.Framework;
using Frends.FTP.ListFiles.Definitions;

namespace Frends.FTP.ListFiles.Tests.Lib;

public class ListFilesTestBase
{
protected string LocalDirFullPath = string.Empty;
protected static FtpHelper FtpHelper = new();
protected string FtpDir = string.Empty;

protected Input input = new();

[OneTimeSetUp]
public void OneTimeSetUp()
{
FtpHelper = new FtpHelper();
}

[OneTimeTearDown]
public void OneTimeTearDown()
{
if (FtpHelper != null)
FtpHelper.Dispose();
}

[SetUp]
public void SetUp()
{
FtpDir = Guid.NewGuid().ToString();
var files = new string[]
{
$"Test1.txt",
$"Test1.xlsx",
$"Test1.xml",
$"testfile.txt",
$"DemoTest.txt"
};

foreach (var file in files)
{
FtpHelper.CreateFileOnFTP(FtpDir, file);
}

input = new Input
{
FileMask = "*",
Directory = FtpDir,
IncludeSubdirectories = false,
IncludeType = IncludeType.File
};
}

[TearDown]
public void TearDown()
{
FtpHelper.DeleteDirectoryOnFTP(FtpDir);
}
}
Loading
Loading