Skip to content

Commit

Permalink
Add FOSSA and Exclude tests from Qodana scan (#120)
Browse files Browse the repository at this point in the history
qodana

---------

Co-authored-by: zingz0r <zingz0r@tothnet.hu>
  • Loading branch information
zingz0r and zingz0r authored Dec 27, 2024
1 parent 6876044 commit 96bdd1e
Show file tree
Hide file tree
Showing 23 changed files with 137 additions and 721 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/fossa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: '🐯 FOSSA: License & security scan'

on:
workflow_dispatch:
pull_request:
push:
branches:
- master

jobs:
scan:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: FOSSA Scan
uses: fossas/fossa-action@main
with:
api-key: ${{ secrets.FOSSA_API_KEY }}
File renamed without changes.
5 changes: 3 additions & 2 deletions CloudFlare.Client.Test/Accounts/RolesUnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CloudFlare.Client.Api.Display;
using CloudFlare.Client.Api.Parameters;
Expand Down Expand Up @@ -41,7 +42,7 @@ public async Task TestGetRolesAsync()

using var client = new CloudFlareClient(WireMockConnection.ApiKeyAuthentication, _connectionInfo);

var roles = await client.Accounts.Roles.GetAsync(accountId, default, displayOptions);
var roles = await client.Accounts.Roles.GetAsync(accountId, displayOptions, CancellationToken.None);

roles.Result.Should().BeEquivalentTo(RoleTestData.Roles);
}
Expand All @@ -63,4 +64,4 @@ public async Task TestGetRoleDetailsAsync()

roleDetails.Result.Should().BeEquivalentTo(role);
}
}
}
4 changes: 1 addition & 3 deletions CloudFlare.Client.Test/CloudFlare.Client.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<LangVersion>10.0</LangVersion>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector">
Expand Down
4 changes: 1 addition & 3 deletions CloudFlare.Client/Api/Parameters/Data/IData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
/// <summary>
/// Data type
/// </summary>
public interface IData
{
}
public interface IData;
4 changes: 1 addition & 3 deletions CloudFlare.Client/Attributes/DataTypeDnsRecordAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
namespace CloudFlare.Client.Attributes;

[AttributeUsage(AttributeTargets.Field)]
internal class DataTypeDnsRecordAttribute : Attribute
{
}
internal class DataTypeDnsRecordAttribute : Attribute;
2 changes: 1 addition & 1 deletion CloudFlare.Client/Client/Accounts/IRoles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IRoles
/// <param name="cancellationToken">Cancellation token</param>
/// <param name="displayOptions">Display Options</param>
/// <returns>The requested role</returns>
Task<CloudFlareResult<IReadOnlyList<Role>>> GetAsync(string accountId, CancellationToken cancellationToken = default, DisplayOptions displayOptions = null);
Task<CloudFlareResult<IReadOnlyList<Role>>> GetAsync(string accountId, DisplayOptions displayOptions = null, CancellationToken cancellationToken = default);

/// <summary>
/// Get information about a specific role for an account
Expand Down
2 changes: 1 addition & 1 deletion CloudFlare.Client/Client/Accounts/Roles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Roles(IConnection connection)
}

/// <inheritdoc />
public async Task<CloudFlareResult<IReadOnlyList<Role>>> GetAsync(string accountId, CancellationToken cancellationToken = default, DisplayOptions displayOptions = null)
public async Task<CloudFlareResult<IReadOnlyList<Role>>> GetAsync(string accountId, DisplayOptions displayOptions = null, CancellationToken cancellationToken = default)
{
var requestUri =
$"{AccountEndpoints.Base}/{accountId}/{AccountEndpoints.Roles}";
Expand Down
2 changes: 1 addition & 1 deletion CloudFlare.Client/Client/Accounts/TurnStileWidgets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task<CloudFlareResult<TurnstileWidget>> UpdateAsync(string accountI
Domains = turnstileWidget.Domains,
Mode = turnstileWidget.Mode,
Name = turnstileWidget.Name,
OffLabel = turnstileWidget.OffLabel,
OffLabel = turnstileWidget.OffLabel
};

var requestUri = $"{AccountEndpoints.Base}/{accountId}/{AccountEndpoints.TurnstileWidgets}/{turnstileWidget.Id}";
Expand Down
6 changes: 3 additions & 3 deletions CloudFlare.Client/Client/Users/Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ public Users(IConnection connection)
/// <inheritdoc />
public async Task<CloudFlareResult<User>> GetDetailsAsync(CancellationToken cancellationToken = default)
{
var requestUri = $"{UserEndpoints.Base}";
const string requestUri = $"{UserEndpoints.Base}";
return await Connection.GetAsync<User>(requestUri, cancellationToken).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<CloudFlareResult<User>> UpdateAsync(User editedUser, CancellationToken cancellationToken = default)
{
var requestUri = $"{UserEndpoints.Base}";
const string requestUri = $"{UserEndpoints.Base}";
return await Connection.PatchAsync(requestUri, editedUser, cancellationToken).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<CloudFlareResult<VerifyToken>> VerifyAsync(CancellationToken cancellationToken = default)
{
var requestUri = $"{UserEndpoints.Base}/{TokenEndpoints.Base}/{TokenEndpoints.Verify}";
const string requestUri = $"{UserEndpoints.Base}/{TokenEndpoints.Base}/{TokenEndpoints.Verify}";
return await Connection.GetAsync<VerifyToken>(requestUri, cancellationToken).ConfigureAwait(false);
}
}
2 changes: 1 addition & 1 deletion CloudFlare.Client/Client/Zones/Zones.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Zones(IConnection connection)
/// <inheritdoc />
public async Task<CloudFlareResult<Zone>> AddAsync(NewZone newZone, CancellationToken cancellationToken = default)
{
var requestUri = $"{ZoneEndpoints.Base}";
const string requestUri = $"{ZoneEndpoints.Base}";
return await Connection.PostAsync<Zone, NewZone>(requestUri, newZone, cancellationToken).ConfigureAwait(false);
}

Expand Down
52 changes: 6 additions & 46 deletions CloudFlare.Client/CloudFlare.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,67 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;</TargetFrameworks>
<PackageLicenseExpression>
</PackageLicenseExpression>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>nuget_logo.png</PackageIcon>
<PackageIconUrl>https://raw.githubusercontent.com/zingz0r/CloudFlare.Client/master/CloudFlare.Client/Resources/nuget_logo.png</PackageIconUrl>
<LangVersion>10.0</LangVersion>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<CodeAnalysisRuleSet>StyleCop/stylecop.ruleset</CodeAnalysisRuleSet>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>
<PropertyGroup>
<IsPackable>true</IsPackable>
<Authors>Tamás Tóth</Authors>
<Company>TothNET</Company>
<Description>.NET library for communication with the Cloudflare service API.</Description>
<Copyright>Copyright © 2019 - CC BY-NC-ND 4.0</Copyright>
<PackageProjectUrl>https://github.com/zingz0r/CloudFlare.Client</PackageProjectUrl>
<RepositoryUrl>https://github.com/zingz0r/CloudFlare.Client</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<PackageTags>CloudFlare, DNS, DDNS,</PackageTags>
<PackageReleaseNotes/>
<NeutralLanguage>en</NeutralLanguage>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup>
<MajorVersion Condition="'$(MajorVersion)' == ''">1</MajorVersion>
<MinorVersion Condition="'$(MinorVersion)' == ''">0</MinorVersion>
<PatchVersion Condition="'$(PatchVersion)' == ''">0</PatchVersion>
<PreReleaseSuffix Condition="'$(PreReleaseLabel)' != ''">-$(PreReleaseLabel)</PreReleaseSuffix>
<BuildMetadataSuffix Condition="'$(BuildMetadata)' != ''">+$(BuildMetadata)</BuildMetadataSuffix>

<AssemblyVersion>$(MajorVersion).$(MinorVersion).0.0</AssemblyVersion>
<InformationalVersion>$(MajorVersion).$(MinorVersion).$(PatchVersion).0</InformationalVersion>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<FileVersion>$(MajorVersion).$(MinorVersion).$(PatchVersion)</FileVersion>
<PackageVersion>$(FileVersion)$(PreReleaseSuffix)$(BuildMetadataSuffix)</PackageVersion>
</PropertyGroup>
<PropertyGroup>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1701;1702</NoWarn>
<PackageTags>CloudFlare, DNS, DDNS</PackageTags>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" />
<PackageReference Include="Microsoft.CSharp" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="StyleCop.Analyzers">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CSharp" />
<PackageReference Include="Newtonsoft.Json" />
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>$(AssemblyName).Test</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
<None Include="..\LICENSE" Pack="True" PackagePath="" />
<None Include="..\CloudFlare.Client\Resources\nuget_logo.png" Pack="True" PackagePath="" />
<None Include="..\LICENSE" Pack="true" PackagePath="" />
<None Include="..\CloudFlare.Client\Resources\nuget_logo.png" Pack="true" PackagePath="" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion CloudFlare.Client/CloudFlareClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace CloudFlare.Client;
/// <inheritdoc />
public class CloudFlareClient : ICloudFlareClient
{
private readonly IConnection _connection;
private readonly ApiConnection _connection;

/// <summary>
/// Initializes a new instance of the <see cref="CloudFlareClient"/> class
Expand Down
9 changes: 2 additions & 7 deletions CloudFlare.Client/Contexts/ApiConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@

namespace CloudFlare.Client.Contexts;

internal class ApiConnection : Connection
{
public ApiConnection(IAuthentication authentication, ConnectionInfo connectionInfo)
: base(authentication, connectionInfo)
{
}
}
internal class ApiConnection(IAuthentication authentication, ConnectionInfo connectionInfo)
: Connection(authentication, connectionInfo);
6 changes: 4 additions & 2 deletions CloudFlare.Client/Contexts/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ private static HttpClient CreateHttpClient(IAuthentication authentication, Conne
{
BaseAddress = connectionInfo.Address
};
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("CloudFlareClient", "1.0.0"));

var version = typeof(CloudFlareClient).Assembly.GetName().Version;
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(nameof(CloudFlareClient), version.ToString()));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(HttpContentTypesHelper.Json));
client.DefaultRequestHeaders.ExpectContinue = connectionInfo.ExpectContinue;

Expand All @@ -156,7 +158,7 @@ private static HttpClient CreateHttpClient(IAuthentication authentication, Conne
return client;
}

private static HttpMessageHandler CreateHttpClientHandler(ConnectionInfo connectionInfo)
private static HttpClientHandler CreateHttpClientHandler(ConnectionInfo connectionInfo)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion CloudFlare.Client/Enumerators/SslSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ public enum SslSetting
/// Encrypts end-to-end, but requires a trusted CA or CloudFlare Origin CA certificate on the server
/// </summary>
[EnumMember(Value = "strict")]
Strict,
Strict
}
14 changes: 6 additions & 8 deletions CloudFlare.Client/Extensions/HttpResponseMessageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ internal static async Task<CloudFlareResult<T>> GetCloudFlareResultAsync<T>(this
{
return JsonConvert.DeserializeObject<CloudFlareResult<T>>(content);
}
else
{
if (typeof(T) != typeof(string))
{
throw new PersistenceUnavailableException("Unexpected result from CloudFlare");
}

dynamic cast = content.Replace("\\n", Environment.NewLine);
return new CloudFlareResult<T>((T)cast, new ResultInfo(), true, new List<ErrorDetails>(), new List<ApiError>(), new TimingInfo());
if (typeof(T) != typeof(string))
{
throw new PersistenceUnavailableException("Unexpected result from CloudFlare");
}

dynamic cast = content.Replace("\\n", Environment.NewLine);
return new CloudFlareResult<T>((T)cast, new ResultInfo(), true, new List<ErrorDetails>(), new List<ApiError>(), new TimingInfo());
}
}
catch (Exception ex)
Expand Down
10 changes: 4 additions & 6 deletions CloudFlare.Client/Helpers/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ internal static class FileHelper
{
internal static async Task<byte[]> ReadAsync(string path, CancellationToken cancellationToken)
{

#if NETSTANDARD2_0
using var sourceStream = File.Open(path, FileMode.Open);
var result = new byte[sourceStream.Length];

#if NETSTANDARD2_0
await sourceStream.ReadAsync(result, 0, (int)sourceStream.Length, cancellationToken).ConfigureAwait(false);
return result;
#else
using var memoryStream = new MemoryStream(result, 0, result.Length, true, true);
await sourceStream.ReadAsync(memoryStream.GetBuffer(), cancellationToken).ConfigureAwait(false);
return await File.ReadAllBytesAsync(path, cancellationToken).ConfigureAwait(false);
#endif

return result;
}
}
51 changes: 0 additions & 51 deletions CloudFlare.Client/StyleCop/stylecop.json

This file was deleted.

Loading

0 comments on commit 96bdd1e

Please sign in to comment.