Commit 7ec00f71 authored by mohammad.salama's avatar mohammad.salama

Added Validation Data, Some Performance Enhancement , Tested

parent 94d078f8
......@@ -29,6 +29,14 @@ namespace ScheduledMessagesHandler.MongoMessages
collection = database.GetCollection<BsonDocument>(myCollection);
var keys = Builders<BsonDocument>.IndexKeys.Ascending("timestamp").Ascending("status");
var indexOptions = new CreateIndexOptions { Background = true };
var indexModel = new CreateIndexModel<BsonDocument>(keys, indexOptions);
collection.Indexes.CreateOne(indexModel);
return "ok";
}
catch (Exception ex)
......
using Validator.Initializer;
using MongoDB.Bson;
using MongoDB.Driver;
using Validator.Initializer;
using Validator.MongoMessages;
namespace Validator.MongoDBAccess
{
public class InformationHolder
{
private readonly string URL = AccountsDBParser.connection;
private readonly string DBName = AccountsDBParser.DBName;
private readonly string collection = AccountsDBParser.collection;
public void checkMessage(MessageMetaData metaData)
public string OK = "ok";
public string DBError = "Could Not Connect To Data Base";
public string Error = "Illegal Message";
public string checkMessage(MessageMetaData metaData)
{
//check for auther + authen + quota
string apiKey = metaData.ApiKey;
string clientId = metaData.ClientID;
string tag = metaData.Tag;
IMongoCollection<BsonDocument> collection = MongoSettingsInitializer.collection;
var filter = Builders<BsonDocument>.Filter.And(
Builders<BsonDocument>.Filter.Eq("api-key", apiKey),
Builders<BsonDocument>.Filter.Eq("client-id", clientId)
);
try
{
var docs = collection.Find(filter).ToList<BsonDocument>();
if (docs.Count == 0)
{
return Error;
}
foreach (var doc in docs)
{
var tags = (string)doc["providers"];
if (tags.Contains(tag, StringComparison.OrdinalIgnoreCase))
{
return OK;
}
}
return Error;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return DBError;
}
}
}
}
using MongoDB.Bson;
using MongoDB.Driver;
using Validator.Initializer;
namespace Validator.MongoMessages
{
public class MongoSettingsInitializer
{
private static string MongoURL = AccountsDBParser.connection;
private static string DataBaseName = AccountsDBParser.DBName;
private static string myCollection = AccountsDBParser.collection;
public static IMongoCollection<BsonDocument> collection;
public static string ConnectionError = "Error Connecting to MongoDB on : " + MongoURL;
/// <summary>
/// Connects to MongoDB to Store Messges and Set Things Up
/// </summary>
/// <returns>string : ok if all goes well , otherwise something else</returns>
public static string init()
{
var client = new MongoClient(MongoURL);
var database = client.GetDatabase(DataBaseName);
collection = database.GetCollection<BsonDocument>(myCollection);
var keys = Builders<BsonDocument>.IndexKeys.Ascending("api-key").Ascending("client-id");
var indexOptions = new CreateIndexOptions { Background = true };
var indexModel = new CreateIndexModel<BsonDocument>(keys, indexOptions);
collection.Indexes.CreateOne(indexModel);
return "ok";
}
}
}
......@@ -5,6 +5,7 @@ using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using Validator.Initializer;
using Validator.MongoMessages;
var builder = WebApplication.CreateBuilder(args);
......@@ -16,7 +17,7 @@ builder.Services.AddGrpc();
builder.Services.AddDiscoveryClient();
IConfiguration config = builder.Configuration;
Initializer.init(ref config);
MongoSettingsInitializer.init();
string serviceName = ServiceNameParser.serviceName;
builder.Services.AddOpenTelemetry()
......
using Grpc.Core;
using Validator;
using Validator.MongoDBAccess;
namespace Validator.Services
{
......@@ -13,12 +14,23 @@ namespace Validator.Services
public override Task<Reply> ValidateMessage(MessageMetaData messageMetaData , ServerCallContext context)
{
// do some work with /DataBase
InformationHolder informationHolder = new InformationHolder();
string res = informationHolder.checkMessage(messageMetaData);
if ( res == informationHolder.OK)
return Task.FromResult(new Reply
{
ReplyCode = "OK ok 200 + validated !! ",
AccountPriority = 0
}) ;
else
{
return Task.FromResult(new Reply
{
ReplyCode = res,
AccountPriority = -1
});
}
}
}
......
......@@ -20,6 +20,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MongoDB.Driver" Version="2.27.0" />
</ItemGroup>
<PropertyGroup>
......
......@@ -37,8 +37,8 @@
}
},
"AccountsDB": {
"Mongo": "localhost:6565",
"DBName": "accountsdb",
"collection": "accounts"
"Mongo": "mongodb://127.0.0.1:27020",
"DBName": "AccountsDB",
"collection": "Accounts"
}
}
......@@ -37,8 +37,8 @@
}
},
"AccountsDB": {
"Mongo": "localhost:6565",
"DBName": "accountsdb",
"collection": "accounts"
"Mongo": "mongodb://127.0.0.1:27020",
"DBName": "AccountsDB",
"collection": "Accounts"
}
}
98231ec169cc750a6381f6c66189c3f13eb16fa0
2c3d7b69161262ba12efc8937415d40e2dd22606
......@@ -70,3 +70,16 @@ D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\o
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\obj\Debug\net6.0\ref\Validator.dll
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\obj\Debug\net6.0\Validator.pdb
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\obj\Debug\net6.0\Validator.genruntimeconfig.cache
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\bin\Debug\net6.0\AWSSDK.Core.dll
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\bin\Debug\net6.0\AWSSDK.SecurityToken.dll
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\bin\Debug\net6.0\DnsClient.dll
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\bin\Debug\net6.0\MongoDB.Bson.dll
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\bin\Debug\net6.0\MongoDB.Driver.dll
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\bin\Debug\net6.0\MongoDB.Driver.Core.dll
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\bin\Debug\net6.0\MongoDB.Libmongocrypt.dll
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\bin\Debug\net6.0\SharpCompress.dll
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\bin\Debug\net6.0\Snappier.dll
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\bin\Debug\net6.0\ZstdSharp.dll
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\bin\Debug\net6.0\runtimes\linux\native\libmongocrypt.so
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\bin\Debug\net6.0\runtimes\osx\native\libmongocrypt.dylib
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\Validator\bin\Debug\net6.0\runtimes\win\native\mongocrypt.dll
......@@ -62,6 +62,10 @@
"target": "Package",
"version": "[2.64.0, )"
},
"MongoDB.Driver": {
"target": "Package",
"version": "[2.27.0, )"
},
"OpenTelemetry.Collector.AspNetCore": {
"target": "Package",
"version": "[0.2.0-alpha.179, )"
......
......@@ -20,6 +20,8 @@
</ImportGroup>
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<PkgMicrosoft_Extensions_ApiDescription_Server Condition=" '$(PkgMicrosoft_Extensions_ApiDescription_Server)' == '' ">C:\Users\moham\.nuget\packages\microsoft.extensions.apidescription.server\6.0.5</PkgMicrosoft_Extensions_ApiDescription_Server>
<PkgAWSSDK_Core Condition=" '$(PkgAWSSDK_Core)' == '' ">C:\Users\moham\.nuget\packages\awssdk.core\3.7.100.14</PkgAWSSDK_Core>
<PkgAWSSDK_SecurityToken Condition=" '$(PkgAWSSDK_SecurityToken)' == '' ">C:\Users\moham\.nuget\packages\awssdk.securitytoken\3.7.100.14</PkgAWSSDK_SecurityToken>
<PkgGrpc_Tools Condition=" '$(PkgGrpc_Tools)' == '' ">C:\Users\moham\.nuget\packages\grpc.tools\2.64.0</PkgGrpc_Tools>
</PropertyGroup>
</Project>
\ No newline at end of file
This diff is collapsed.
{
"version": 2,
"dgSpecHash": "JbVejI7mhkfsNgMbwddd7RZft1bTvDTdvaaZafxy87DwMSbGwJ2QcarVArYgvCwpctN+o+XW2hSdfhVENruXVQ==",
"dgSpecHash": "6/yb1D0tb1X7sSpKf70ilh+W+GpvLvTQvdhvvITaFkf7ejJw9ChB3WbK2HFL9LvSjSU/BxDKYtszq3LnJn111Q==",
"success": true,
"projectFilePath": "D:\\HIAST\\FIY\\Project-MSGPriorityQ\\GrpcMessage\\message-priority-queue\\Validator\\Validator.csproj",
"expectedPackageFiles": [
"C:\\Users\\moham\\.nuget\\packages\\awssdk.core\\3.7.100.14\\awssdk.core.3.7.100.14.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\awssdk.securitytoken\\3.7.100.14\\awssdk.securitytoken.3.7.100.14.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\dnsclient\\1.6.1\\dnsclient.1.6.1.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\google.protobuf\\3.27.1\\google.protobuf.3.27.1.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\grpc.aspnetcore\\2.40.0\\grpc.aspnetcore.2.40.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\grpc.aspnetcore.server\\2.40.0\\grpc.aspnetcore.server.2.40.0.nupkg.sha512",
......@@ -47,9 +50,14 @@
"C:\\Users\\moham\\.nuget\\packages\\microsoft.extensions.options\\8.0.0\\microsoft.extensions.options.8.0.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\microsoft.extensions.options.configurationextensions\\8.0.0\\microsoft.extensions.options.configurationextensions.8.0.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\microsoft.extensions.primitives\\8.0.0\\microsoft.extensions.primitives.8.0.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\microsoft.netcore.platforms\\1.1.0\\microsoft.netcore.platforms.1.1.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\microsoft.netcore.platforms\\5.0.0\\microsoft.netcore.platforms.5.0.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\microsoft.netcore.targets\\1.1.0\\microsoft.netcore.targets.1.1.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\microsoft.openapi\\1.2.3\\microsoft.openapi.1.2.3.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\microsoft.win32.registry\\5.0.0\\microsoft.win32.registry.5.0.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\mongodb.bson\\2.27.0\\mongodb.bson.2.27.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\mongodb.driver\\2.27.0\\mongodb.driver.2.27.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\mongodb.driver.core\\2.27.0\\mongodb.driver.core.2.27.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\mongodb.libmongocrypt\\1.10.0\\mongodb.libmongocrypt.1.10.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\opentelemetry\\1.9.0\\opentelemetry.1.9.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\opentelemetry.api\\1.9.0\\opentelemetry.api.1.9.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\opentelemetry.api.providerbuilderextensions\\1.9.0\\opentelemetry.api.providerbuilderextensions.1.9.0.nupkg.sha512",
......@@ -61,6 +69,8 @@
"C:\\Users\\moham\\.nuget\\packages\\opentelemetry.extensions.hosting\\1.9.0\\opentelemetry.extensions.hosting.1.9.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\opentelemetry.instrumentation.aspnetcore\\1.9.0\\opentelemetry.instrumentation.aspnetcore.1.9.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\opentelemetry.instrumentation.grpcnetclient\\1.9.0-beta.1\\opentelemetry.instrumentation.grpcnetclient.1.9.0-beta.1.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\sharpcompress\\0.30.1\\sharpcompress.0.30.1.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\snappier\\1.0.0\\snappier.1.0.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\steeltoe.common\\3.2.6\\steeltoe.common.3.2.6.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\steeltoe.common.abstractions\\3.2.6\\steeltoe.common.abstractions.3.2.6.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\steeltoe.common.http\\3.2.6\\steeltoe.common.http.3.2.6.nupkg.sha512",
......@@ -75,9 +85,11 @@
"C:\\Users\\moham\\.nuget\\packages\\swashbuckle.aspnetcore.swagger\\6.4.0\\swashbuckle.aspnetcore.swagger.6.4.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\swashbuckle.aspnetcore.swaggergen\\6.4.0\\swashbuckle.aspnetcore.swaggergen.6.4.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\swashbuckle.aspnetcore.swaggerui\\6.4.0\\swashbuckle.aspnetcore.swaggerui.6.4.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.buffers\\4.5.1\\system.buffers.4.5.1.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.diagnostics.diagnosticsource\\8.0.0\\system.diagnostics.diagnosticsource.8.0.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.diagnostics.eventlog\\6.0.0\\system.diagnostics.eventlog.6.0.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.io\\4.3.0\\system.io.4.3.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.memory\\4.5.5\\system.memory.4.5.5.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.net.http.json\\3.2.1\\system.net.http.json.3.2.1.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.reflection\\4.3.0\\system.reflection.4.3.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.reflection.metadataloadcontext\\4.6.0\\system.reflection.metadataloadcontext.4.6.0.nupkg.sha512",
......@@ -86,11 +98,14 @@
"C:\\Users\\moham\\.nuget\\packages\\system.runtime.compilerservices.unsafe\\6.0.0\\system.runtime.compilerservices.unsafe.6.0.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.runtime.handles\\4.3.0\\system.runtime.handles.4.3.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.runtime.interopservices\\4.3.0\\system.runtime.interopservices.4.3.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.security.accesscontrol\\5.0.0\\system.security.accesscontrol.5.0.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.security.principal.windows\\5.0.0\\system.security.principal.windows.5.0.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.text.encoding\\4.3.0\\system.text.encoding.4.3.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.text.encodings.web\\6.0.0\\system.text.encodings.web.6.0.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.text.json\\6.0.0\\system.text.json.6.0.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.threading.tasks\\4.3.0\\system.threading.tasks.4.3.0.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\system.threading.tasks.extensions\\4.5.4\\system.threading.tasks.extensions.4.5.4.nupkg.sha512"
"C:\\Users\\moham\\.nuget\\packages\\system.threading.tasks.extensions\\4.5.4\\system.threading.tasks.extensions.4.5.4.nupkg.sha512",
"C:\\Users\\moham\\.nuget\\packages\\zstdsharp.port\\0.7.3\\zstdsharp.port.0.7.3.nupkg.sha512"
],
"logs": []
}
\ No newline at end of file
......@@ -35,3 +35,7 @@
2.0
2.0
2.0
2.0
2.0
2.0
2.0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment