Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ _textdb/
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore

# .NET C#
appsettings.json


# User-specific files
*.rsuser
*.suo
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Deployment/images/services/tester_app_ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions Services/testapp/Choice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT License.
using System.ComponentModel;

namespace Tester.ConsoleApp
{
enum Choice
{
[Description("1. List Registered Documents")]
ListRegisteredDocuments,
[Description("2. Register Documents")]
RegisterDocuments,
[Description("3. Delete Registered Documents in Azure")]
DeleteDocuments,
[Description("4. Perform Gap Analysis")]
GapAnalysis,
[Description("5. Get All Gap Analysis Results")]
GetAllGapAnalysisResults,
[Description("6. Perform Benchmark Analysis")]
BenchMarks,
[Description("7. Get All Benchmark Analysis Results")]
GetAllBenchMarksResults,
[Description("8. Test API Connection")]
TestApiConnection,
[Description("9. Exit")]
Exit
}
}
91 changes: 91 additions & 0 deletions Services/testapp/Functions/ApiConnection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT License.

using System.Security.Cryptography.X509Certificates;
using Spectre.Console;

namespace Tester.ConsoleApp.Functions
{
public static class ApiConnection
{
public static async void TestConnection(Uri uri)
{
// Create a custom HttpClientHandler to handle SSL certificate validation
var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) =>
{
// Here you can add custom logic to validate the certificate
// For example, you can check the certificate thumbprint, issuer, etc.
// Returning true will bypass the SSL certificate validation
if (cert == null)
{
AnsiConsole.WriteLine("No Server Certificate Found");
return false;
}
return ValidateCertificate(cert);
}
};

// Create an HttpClient using the custom handler
using (var client = new HttpClient(handler))
{
// Set the base address of the API
client.BaseAddress = uri;
try
{
// Make a GET request to the API
HttpResponseMessage response = await client.GetAsync("/api/endpoint");
// Check if the response is successful
if (response.IsSuccessStatusCode)
{
// Read the response content
string content = await response.Content.ReadAsStringAsync();
//AnsiConsole.WriteLine("\nTest Connection Response Content: " + content);
}
AnsiConsole.WriteLine("API Connection is successful.");
}
catch (Exception ex)
{
//AnsiConsole.WriteLine("\nTest Connection Failed with Exception (check your appsettings.json and services): " + ex.Message);
AnsiConsole.WriteLine("Test Connection Failed with Exceptions. Check your appsettings.json and API services.");
}
}
}

// Validate the SSL certificate
static bool ValidateCertificate(X509Certificate2 cert)
{
// Add custom validation logic here
// For example, check the certificate thumbprint, issuer, expiration date, etc.
//AnsiConsole.WriteLine("Certificate Subject: " + cert.Subject);
//AnsiConsole.WriteLine("Certificate Issuer: " + cert.Issuer);
//AnsiConsole.WriteLine("Certificate Thumbprint: " + cert.Thumbprint);
//AnsiConsole.WriteLine("Certificate Expiration: " + cert.NotAfter);
//AnsiConsole.WriteLine(); // Write a new line

// Example: Validate the certificate thumbprint. This is just an example, you should use a valid thumbprint.
string expectedThumbprint = "B89BB8B0BEF4B6CF59A472284B4F8F234525302B";
if (cert.Thumbprint == expectedThumbprint)
{
return true;
}

// Example: Validate the certificate issuer. This is just an example, you should use a valid issuer.
string expectedIssuer = "Kubernetes Ingress Controller Fake Certificate";
if (cert.Issuer == expectedIssuer)
{
return true;
}

// Example: Validate the certificate expiration date
if (DateTime.Now < cert.NotAfter)
{
return true;
}

// If none of the validation checks pass, return false
return false;
}
}
}
40 changes: 40 additions & 0 deletions Services/testapp/Functions/AppConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT License.

namespace Tester.ConsoleApp.Functions
{
public class AppConfig
{
public string JobOwner { get; set; }
public string Type { get; set; }
public string disclosureNumber { get; set; }
public string disclosureName { get; set; }
public string disclosureRequirement { get; set; }
public string disclosureRequirementDetail { get; set; }
public string disclosureAnnex { get; set; }

// Constructor to initialize properties
public AppConfig(string myJobOwner, string myType, string myDisclosureNumber, string myDisclosureName, string myDisclosureRequirement, string myDisclosureRequirementDetail, string myDisclosureAnnex)
{
JobOwner = myJobOwner;
Type = myType;
disclosureNumber = myDisclosureNumber;
disclosureName = myDisclosureName;
disclosureRequirement = myDisclosureRequirement;
disclosureRequirementDetail = myDisclosureRequirementDetail;
disclosureAnnex = myDisclosureAnnex;
}

// Parameterless constructor for deserialization
public AppConfig()
{
JobOwner = string.Empty;
Type = string.Empty;
disclosureNumber = string.Empty;
disclosureName = string.Empty;
disclosureRequirement = string.Empty;
disclosureRequirementDetail = string.Empty;
disclosureAnnex = string.Empty;
}
}
}
100 changes: 100 additions & 0 deletions Services/testapp/Functions/BenchMarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using RestSharp;
using Spectre.Console;
using System.Text;

namespace Tester.ConsoleApp.Functions
{
public static class BenchMarks
{
public static async Task PerformBenchmarks(Uri baseUri, IConfiguration config)
{

var standardType = string.Empty;
while (standardType != "CSRD" && standardType != "GRI")
{
standardType = AnsiConsole.Ask<string>("CSRD or GRI?:");
if (standardType != "CSRD" && standardType != "GRI")
{
AnsiConsole.MarkupLine("[red]Invalid input. Valid values: 'CSRD' or 'GRI'.[/]");
}
}

AppConfig appConfig = new AppConfig();
appConfig = Helpers.ConfigHelper.GetAppConfig(standardType, config);

var client = new HttpClient();
client.BaseAddress = baseUri;

var myJobName = AnsiConsole.Ask<string>("Enter a Job Name for Benchmarks Analysis:");

// user input for documentIds
var myDocumentIds = new List<string>();
while (true)
{
var myDocumentId = AnsiConsole.Ask<string>("Enter a document ID or the word 'Finished' to end:");
if (myDocumentId.Equals("Finished", StringComparison.OrdinalIgnoreCase))
{
break;
}
myDocumentIds.Add(myDocumentId);
}
var requestBody = new
{
jobName = myJobName,
documentIds = myDocumentIds,
jobOwner = config["AppConfig:JobOwner"] ?? string.Empty,
disclosureNumber = config["AppConfig:disclosureNumber"] ?? string.Empty,
disclosureName = config["AppConfig:disclosureName"] ?? string.Empty,
disclosureRequirement = config["AppConfig:disclosureRequirement"] ?? string.Empty,
disclosureRequirementDetail = config["AppConfig:disclosureRequirementDetail"] ?? string.Empty,
disclosureAnnex = config["AppConfig:disclosureAnnex"] ?? string.Empty
};

var json = JsonConvert.SerializeObject(requestBody);
var content = new StringContent(json, Encoding.UTF8, "application/json");

var response = await client.PostAsync("ESRS/ESRSDisclosureBenchmarkOnQueue", content);

if (response.IsSuccessStatusCode)
{
var responseContent = await response.Content.ReadAsStringAsync();
AnsiConsole.MarkupLine("[green]Benchmark documents request was successful.[/]");
AnsiConsole.WriteLine(responseContent);
}
else
{
AnsiConsole.MarkupLine("[red]Benchmark documents request failed.[/]");
AnsiConsole.WriteLine(response.ReasonPhrase ?? "No reason phrase provided.");
}
}

public static void GetAllBenchmarksResults(Uri uri)
{
var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
};

var client = new RestClient(new RestClientOptions(uri)
{
ConfigureMessageHandler = _ => handler
});

//BaseUrl/ESRS/GetAllESRSBenchmarkResults
var request = new RestRequest("ESRS/GetAllESRSBenchmarkResults", Method.Get);

RestResponse response = client.Execute(request);
var content = response.Content;

AnsiConsole.WriteLine("GetAllESRSBenchmarkResults Response Status: " + response.StatusCode);
AnsiConsole.WriteLine("GetAllESRSBenchmarkResults Response Content: " + content);

}

}
}
42 changes: 42 additions & 0 deletions Services/testapp/Functions/ConfigHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Extensions.Configuration;
using Tester.ConsoleApp.Functions;

namespace Tester.ConsoleApp.Helpers
{
public static class ConfigHelper
{
public static AppConfig GetAppConfig(string standardType, IConfiguration config)
{
var appConfig = new AppConfig();

if (standardType.Equals("CSRD", StringComparison.OrdinalIgnoreCase))
{
appConfig.JobOwner = config["CSRD:JobOwner"] ?? string.Empty;
appConfig.Type = config["CSRD:Type"] ?? string.Empty;
appConfig.disclosureName = config["CSRD:disclosureName"] ?? string.Empty;
appConfig.disclosureNumber = config["CSRD:disclosureNumber"] ?? string.Empty;
appConfig.disclosureRequirement = config["CSRD:disclosureRequirement"] ?? string.Empty;
appConfig.disclosureRequirementDetail = config["CSRD:disclosureRequirementDetail"] ?? string.Empty;
}
else if (standardType.Equals("GRI", StringComparison.OrdinalIgnoreCase))
{
appConfig.JobOwner = config["GRI:JobOwner"] ?? string.Empty;
appConfig.Type = config["GRI:Type"] ?? string.Empty;
appConfig.disclosureName = config["GRI:disclosureName"] ?? string.Empty;
appConfig.disclosureNumber = config["GRI:disclosureNumber"] ?? string.Empty;
appConfig.disclosureRequirement = config["GRI:disclosureRequirement"] ?? string.Empty;
appConfig.disclosureRequirementDetail = config["GRI:disclosureRequirementDetail"] ?? string.Empty;
appConfig.disclosureAnnex = config["GRI:disclosureAnnex"] ?? string.Empty;
}
else
{
throw new ArgumentException($"Invalid input {standardType}. Valid values: 'CSRD' or 'GRI'.");
}

return appConfig;
}
}
}
Loading
Loading