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

Bump HIC.RDMP.Plugin.Test, Microsoft.CodeCoverage, NLog and NUnit #1985

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
<PackageVersion Include="HIC.DicomTypeTranslation" Version="4.1.3" />
<PackageVersion Include="HIC.FAnsiSql" Version="3.2.7" />
<PackageVersion Include="HIC.RDMP.Dicom" Version="7.1.0" />
<PackageVersion Include="HIC.RDMP.Plugin" Version="8.3.0" />
<PackageVersion Include="HIC.RDMP.Plugin" Version="8.3.1" />
<PackageVersion Include="IsIdentifiable" Version="0.4.0" />
<PackageVersion Include="LibArchive.Net" Version="0.1.5" />
<PackageVersion Include="LineReader" Version="0.1.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.11.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageVersion Include="MongoDB.Bson" Version="2.30.0" />
<PackageVersion Include="MongoDB.Driver" Version="2.30.0" />
<PackageVersion Include="MongoDB.Bson" Version="3.0.0" />
<PackageVersion Include="MongoDB.Driver" Version="3.0.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NLog" Version="5.3.4" />
<PackageVersion Include="RabbitMQ.Client" Version="6.8.1" />
Expand All @@ -30,7 +30,7 @@
<PackageVersion Include="YamlDotNet" Version="16.1.3" />
<!-- Test Packages -->
<PackageVersion Include="HIC.BadMedicine.Dicom" Version="0.1.1" />
<PackageVersion Include="HIC.RDMP.Plugin.Test" Version="8.3.0" />
<PackageVersion Include="HIC.RDMP.Plugin.Test" Version="8.3.1" />
<PackageVersion Include="Microsoft.CodeCoverage" Version="17.11.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Moq" Version="4.20.72" />
Expand Down
51 changes: 29 additions & 22 deletions src/SmiServices/Common/MongoDB/MongoClientHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using NLog;
using SmiServices.Common.Options;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;

namespace SmiServices.Common.MongoDB
Expand All @@ -16,6 +18,8 @@ public static class MongoClientHelpers

private static readonly ListCollectionNamesOptions _listOptions = new();

private static readonly ConcurrentDictionary<(MongoDbOptions options, string applicationName, bool skipAuthentication, bool skipJournal), MongoClient> _clientCache = new();

/// <summary>
/// Creates a <see cref="MongoClient"/> from the given options, and checks that the user has the "readWrite" role for the given database
/// </summary>
Expand All @@ -24,48 +28,51 @@ public static class MongoClientHelpers
/// <param name="skipAuthentication"></param>
/// <param name="skipJournal"></param>
/// <returns></returns>
public static MongoClient GetMongoClient(MongoDbOptions options, string applicationName, bool skipAuthentication = false, bool skipJournal = false)
public static MongoClient GetMongoClient(MongoDbOptions options, string applicationName,
bool skipAuthentication = false, bool skipJournal = false)
{
var args = (options, applicationName, skipAuthentication, skipJournal);
return _clientCache.GetOrAdd(args, static args => CreateMongoClient(args.options, args.applicationName,
args.skipAuthentication, args.skipJournal));
}

private static MongoClient CreateMongoClient(MongoDbOptions options, string applicationName,
bool skipAuthentication, bool skipJournal)
{
if (!options.AreValid(skipAuthentication))
throw new ApplicationException($"Invalid MongoDB options: {options}");

var settings = new MongoClientSettings
{
ApplicationName = applicationName,
Servers = new List<MongoServerAddress>([new MongoServerAddress(options.HostName, options.Port)]),
WriteConcern = new WriteConcern(journal: !skipJournal),
DirectConnection = true,
HeartbeatInterval = TimeSpan.FromSeconds(10)
};

if (skipAuthentication || options.UserName == string.Empty)
return new MongoClient(new MongoClientSettings
{
ApplicationName = applicationName,
Server = new MongoServerAddress(options.HostName, options.Port),
WriteConcern = new WriteConcern(journal: !skipJournal)
});
return new MongoClient(settings);

if (string.IsNullOrWhiteSpace(options.Password))
throw new ApplicationException($"MongoDB password must be set");

MongoCredential credentials = MongoCredential.CreateCredential(AuthDatabase, options.UserName, options.Password);

var mongoClientSettings = new MongoClientSettings
{
ApplicationName = applicationName,
Credential = credentials,
Server = new MongoServerAddress(options.HostName, options.Port),
WriteConcern = new WriteConcern(journal: !skipJournal)
};
settings.Credential = MongoCredential.CreateCredential(AuthDatabase, options.UserName, options.Password);

var client = new MongoClient(mongoClientSettings);
var client = new MongoClient(settings);

try
{
IMongoDatabase db = client.GetDatabase(AuthDatabase);
var db = client.GetDatabase(AuthDatabase);
var queryResult = db.RunCommand<BsonDocument>(new BsonDocument("usersInfo", options.UserName));

if (!(queryResult["ok"] == 1))
throw new ApplicationException($"Could not check authentication for user \"{options.UserName}\"");

var roles = (BsonArray)queryResult[0][0]["roles"];

var hasReadWrite = false;
foreach (BsonDocument role in roles.Select(x => x.AsBsonDocument))
if (role["db"].AsString == options.DatabaseName && role["role"].AsString == "readWrite")
hasReadWrite = true;
var hasReadWrite = roles.Select(static x => x.AsBsonDocument).Any(role =>
role["db"].AsString == options.DatabaseName && role["role"].AsString == "readWrite");

if (!hasReadWrite)
throw new ApplicationException($"User \"{options.UserName}\" does not have readWrite permissions on database \"{options.DatabaseName}\"");
Expand Down
107 changes: 37 additions & 70 deletions src/SmiServices/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@
},
"HIC.RDMP.Plugin": {
"type": "Direct",
"requested": "[8.3.0, )",
"resolved": "8.3.0",
"contentHash": "iKM27C/qJoXECOtdyPmXRTxKvAcEx/EgXsg9D4kMRIZi0V4nlRh8a+PxAHTbfn+0BzfBrmKuEzikF4lyN8tmEQ==",
"dependencies": {
"AWSSDK.S3": "3.7.403.1",
"AWSSDK.SSO": "3.7.400.22",
"AWSSDK.SSOOIDC": "3.7.400.22",
"AWSSDK.SecurityToken": "3.7.400.22",
"requested": "[8.3.1, )",
"resolved": "8.3.1",
"contentHash": "o3iFnwBV+vdiAOq9JpQc7FHtzaUNGgWCBZgFIy2OE7HFGqXFUY/B8MD9FgY4VhJSHBe0T/rlSVmyHT/eqHG5uA==",
"dependencies": {
"AWSSDK.S3": "3.7.405",
"AWSSDK.SSO": "3.7.400.36",
"AWSSDK.SSOOIDC": "3.7.400.36",
"AWSSDK.SecurityToken": "3.7.400.36",
"CommandLineParser": "2.9.1",
"ExcelNumberFormat": "1.1.0",
"FluentFTP": "51.1.0",
"HIC.FAnsiSql": "3.2.6",
"HIC.FAnsiSql": "3.2.7",
"HIC.SynthEHR": "2.0.1",
"LibArchive.Net": "0.1.5",
"MongoDB.Driver": "2.29.0",
"MongoDB.Driver": "3.0.0",
"NLog": "5.3.4",
"NPOI": "2.7.1",
"Newtonsoft.Json": "13.0.3",
Expand All @@ -85,7 +85,7 @@
"Spectre.Console": "0.49.1",
"System.Resources.Extensions": "8.0.0",
"Terminal.Gui": "1.17.1",
"YamlDotNet": "16.1.2"
"YamlDotNet": "16.1.3"
}
},
"IsIdentifiable": {
Expand Down Expand Up @@ -152,24 +152,27 @@
},
"MongoDB.Bson": {
"type": "Direct",
"requested": "[2.30.0, )",
"resolved": "2.30.0",
"contentHash": "Gg0TQUT3IEntcqdug5a9P6d8iwL5CqOpQjVBCq1hxTbkjxdGdY6a2CPv7II44AO9GYUnORYsS6dDME2b7aqYyg==",
"requested": "[3.0.0, )",
"resolved": "3.0.0",
"contentHash": "qnPRJ58HXDh7C4oxTf6YB7BJhlCGJIa6TMXhzImw6zk44lrAomQXTB6AtoQ5lNJbkyrgQcT7+smsKFMnXmLXhw==",
"dependencies": {
"System.Memory": "4.5.5",
"System.Runtime.CompilerServices.Unsafe": "5.0.0"
}
},
"MongoDB.Driver": {
"type": "Direct",
"requested": "[2.30.0, )",
"resolved": "2.30.0",
"contentHash": "BCG8cNF0+U3h5f/O9fu3ktrYhoESBDems1w06PExfYrn2KjHBHCBdvBRY1cIbysnZVjQAJjGtFV9XgW+hXt7Hg==",
"requested": "[3.0.0, )",
"resolved": "3.0.0",
"contentHash": "udcP8rOhyuhLDn3sGVdNUgQSXfKGPaIP4w09XVKf4xdy66YSXinhkIuQSuOeZVHdTFsG2PpUbRx2wyFm7E0EMg==",
"dependencies": {
"DnsClient": "1.6.1",
"Microsoft.Extensions.Logging.Abstractions": "2.0.0",
"MongoDB.Bson": "2.30.0",
"MongoDB.Driver.Core": "2.30.0",
"MongoDB.Libmongocrypt": "1.12.0"
"MongoDB.Bson": "3.0.0",
"SharpCompress": "0.30.1",
"Snappier": "1.0.0",
"System.Buffers": "4.5.1",
"ZstdSharp.Port": "0.7.3"
}
},
"Newtonsoft.Json": {
Expand Down Expand Up @@ -222,39 +225,39 @@
},
"AWSSDK.Core": {
"type": "Transitive",
"resolved": "3.7.400.22",
"contentHash": "v1Pm6lFSkAufm7WtiwE+2laHSj330cVUzTRTXZ50YXNgT0jDu1OryJrTqxPxlbiv6jFEkTutvM9rImuvDSpaeg=="
"resolved": "3.7.400.36",
"contentHash": "K4iJjzwI8VfkjxvLhjpODiZvVk5frjqHJ69rWIxk6xPWglHBLYAN4DhSZO/GpKJpNWjtHB+VlCvgWGZA8JnEHQ=="
},
"AWSSDK.S3": {
"type": "Transitive",
"resolved": "3.7.403.1",
"contentHash": "5eVV+I7gHNz38WRvY8w2jEoHbQ+wIdOwSzS5MtD/I072vVJs/IL5lgjylgmA0t044JczLV9FmbPrPehKeEhHtQ==",
"resolved": "3.7.405",
"contentHash": "QW5lTOMGnPzjoP/3klZS5/ErTRrYcDz6s/smL0bBmpNSLTXJrp1vDC0AZZxDFxyI3GoLoYcgHfxDdDptzYEqVA==",
"dependencies": {
"AWSSDK.Core": "[3.7.400.22, 4.0.0)"
"AWSSDK.Core": "[3.7.400.36, 4.0.0)"
}
},
"AWSSDK.SecurityToken": {
"type": "Transitive",
"resolved": "3.7.400.22",
"contentHash": "R9laqYSFi3DCvVqSATDB1fTG7r1AApl2DLD97Nv3jO+oCd93whK9B/ZO7UVGfOfl+eMDMYC/0Ik+iaJYZy0Q+Q==",
"resolved": "3.7.400.36",
"contentHash": "0mEBp3RixKN/QWRpLimIvpHe97RtbD312G/le9ph0Jx8bEUeVkHbQms66VUnllj+yZwTWfm9ZP7xLJQt7QaydQ==",
"dependencies": {
"AWSSDK.Core": "[3.7.400.22, 4.0.0)"
"AWSSDK.Core": "[3.7.400.36, 4.0.0)"
}
},
"AWSSDK.SSO": {
"type": "Transitive",
"resolved": "3.7.400.22",
"contentHash": "YOMWgiief6tMn54GraNnrpUbjgPjM1a+Iq3M7Pf/zQUxkh4A/fIQedqBTJde4xaS/y/GcBf7t/3HZkNA9Xdxbw==",
"resolved": "3.7.400.36",
"contentHash": "8RLgfkYavYSonAC7B4k1qbatZHtSxHnB2ToG59uK1iGzjl4GvHgJTVbP6hFJsmI6d3v4wj3GQdNUtXfULfFpGA==",
"dependencies": {
"AWSSDK.Core": "[3.7.400.22, 4.0.0)"
"AWSSDK.Core": "[3.7.400.36, 4.0.0)"
}
},
"AWSSDK.SSOOIDC": {
"type": "Transitive",
"resolved": "3.7.400.22",
"contentHash": "vVRYOTQPsHarmxFTtAnnxVRNLteRVam1Ko/RyPjTdDAAxtxjqRL00DrLsyH5/EXycDVyRIw0Fp2I6EWUm6IhYw==",
"resolved": "3.7.400.36",
"contentHash": "BizxNQKLFaHChC4qzEDwTqVdR0sz6R2gEq3ZqmO5zHI/W/xuJypu3+eJ4qJGFuFnW0v/ngnR75flw9QYcvopjg==",
"dependencies": {
"AWSSDK.Core": "[3.7.400.22, 4.0.0)"
"AWSSDK.Core": "[3.7.400.36, 4.0.0)"
}
},
"Azure.Core": {
Expand Down Expand Up @@ -614,27 +617,6 @@
"System.Security.Principal.Windows": "5.0.0"
}
},
"MongoDB.Driver.Core": {
"type": "Transitive",
"resolved": "2.30.0",
"contentHash": "oepDgu24lo44SljuHmIQ99x6jHISnMC4tLfzQGniQg39xiMD8nxalm1HM9RDZcuZbbWa4F6YLt2AIhWkny3XWA==",
"dependencies": {
"AWSSDK.SecurityToken": "3.7.100.14",
"DnsClient": "1.6.1",
"Microsoft.Extensions.Logging.Abstractions": "2.0.0",
"MongoDB.Bson": "2.30.0",
"MongoDB.Libmongocrypt": "1.12.0",
"SharpCompress": "0.30.1",
"Snappier": "1.0.0",
"System.Buffers": "4.5.1",
"ZstdSharp.Port": "0.7.3"
}
},
"MongoDB.Libmongocrypt": {
"type": "Transitive",
"resolved": "1.12.0",
"contentHash": "B1X51jrtNacKvxKoaqWeknYeJfQS5aWf6BmVLT5JZerz3AUXFzv8edPskJYqBc3kLy1J2PWzMqqsnyb9g8FtcA=="
},
"MySqlConnector": {
"type": "Transitive",
"resolved": "2.3.7",
Expand Down Expand Up @@ -1099,11 +1081,6 @@
"System.Security.Principal.Windows": "5.0.0"
}
},
"MongoDB.Libmongocrypt": {
"type": "Transitive",
"resolved": "1.12.0",
"contentHash": "B1X51jrtNacKvxKoaqWeknYeJfQS5aWf6BmVLT5JZerz3AUXFzv8edPskJYqBc3kLy1J2PWzMqqsnyb9g8FtcA=="
},
"runtime.any.System.Collections": {
"type": "Transitive",
"resolved": "4.3.0",
Expand Down Expand Up @@ -1605,11 +1582,6 @@
"System.Security.Principal.Windows": "5.0.0"
}
},
"MongoDB.Libmongocrypt": {
"type": "Transitive",
"resolved": "1.12.0",
"contentHash": "B1X51jrtNacKvxKoaqWeknYeJfQS5aWf6BmVLT5JZerz3AUXFzv8edPskJYqBc3kLy1J2PWzMqqsnyb9g8FtcA=="
},
"runtime.any.System.Collections": {
"type": "Transitive",
"resolved": "4.3.0",
Expand Down Expand Up @@ -2111,11 +2083,6 @@
"System.Security.Principal.Windows": "5.0.0"
}
},
"MongoDB.Libmongocrypt": {
"type": "Transitive",
"resolved": "1.12.0",
"contentHash": "B1X51jrtNacKvxKoaqWeknYeJfQS5aWf6BmVLT5JZerz3AUXFzv8edPskJYqBc3kLy1J2PWzMqqsnyb9g8FtcA=="
},
"runtime.any.System.Collections": {
"type": "Transitive",
"resolved": "4.3.0",
Expand Down
Loading
Loading