-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
691 additions
and
695 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,88 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Foundatio | ||
namespace Foundatio; | ||
|
||
public class MinioConnectionStringBuilder | ||
{ | ||
public class MinioConnectionStringBuilder | ||
{ | ||
public string AccessKey { get; set; } | ||
public string AccessKey { get; set; } | ||
|
||
public string SecretKey { get; set; } | ||
public string SecretKey { get; set; } | ||
|
||
public string Region { get; set; } | ||
public string Region { get; set; } | ||
|
||
public string EndPoint { get; set; } | ||
public string EndPoint { get; set; } | ||
|
||
protected MinioConnectionStringBuilder() { } | ||
protected MinioConnectionStringBuilder() { } | ||
|
||
protected MinioConnectionStringBuilder(string connectionString) | ||
{ | ||
if (String.IsNullOrEmpty(connectionString)) | ||
throw new ArgumentNullException(nameof(connectionString)); | ||
Parse(connectionString); | ||
} | ||
protected MinioConnectionStringBuilder(string connectionString) | ||
{ | ||
if (String.IsNullOrEmpty(connectionString)) | ||
throw new ArgumentNullException(nameof(connectionString)); | ||
Parse(connectionString); | ||
} | ||
|
||
private void Parse(string connectionString) | ||
private void Parse(string connectionString) | ||
{ | ||
foreach (var option in connectionString | ||
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) | ||
.Where(kvp => kvp.Contains('=')) | ||
.Select(kvp => kvp.Split(new[] { '=' }, 2))) | ||
{ | ||
foreach (var option in connectionString | ||
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) | ||
.Where(kvp => kvp.Contains('=')) | ||
.Select(kvp => kvp.Split(new[] { '=' }, 2))) | ||
var optionKey = option[0].Trim(); | ||
var optionValue = option[1].Trim(); | ||
if (!ParseItem(optionKey, optionValue)) | ||
{ | ||
var optionKey = option[0].Trim(); | ||
var optionValue = option[1].Trim(); | ||
if (!ParseItem(optionKey, optionValue)) | ||
{ | ||
throw new ArgumentException($"The option '{optionKey}' cannot be recognized in connection string.", nameof(connectionString)); | ||
} | ||
throw new ArgumentException($"The option '{optionKey}' cannot be recognized in connection string.", nameof(connectionString)); | ||
} | ||
} | ||
} | ||
|
||
protected virtual bool ParseItem(string key, string value) | ||
protected virtual bool ParseItem(string key, string value) | ||
{ | ||
if (String.Equals(key, "AccessKey", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "Access Key", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "AccessKeyId", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "Access Key Id", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "Id", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
if (String.Equals(key, "AccessKey", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "Access Key", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "AccessKeyId", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "Access Key Id", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "Id", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
AccessKey = value; | ||
return true; | ||
} | ||
if (String.Equals(key, "SecretKey", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "Secret Key", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "SecretAccessKey", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "Secret Access Key", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "Secret", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
SecretKey = value; | ||
return true; | ||
} | ||
if (String.Equals(key, "Region", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
Region = value; | ||
return true; | ||
} | ||
if (String.Equals(key, "EndPoint", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "End Point", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
EndPoint = value; | ||
return true; | ||
} | ||
return false; | ||
AccessKey = value; | ||
return true; | ||
} | ||
|
||
public override string ToString() | ||
if (String.Equals(key, "SecretKey", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "Secret Key", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "SecretAccessKey", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "Secret Access Key", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "Secret", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
SecretKey = value; | ||
return true; | ||
} | ||
if (String.Equals(key, "Region", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
Region = value; | ||
return true; | ||
} | ||
if (String.Equals(key, "EndPoint", StringComparison.OrdinalIgnoreCase) || | ||
String.Equals(key, "End Point", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
var connectionString = string.Empty; | ||
if (!string.IsNullOrEmpty(AccessKey)) | ||
connectionString += "AccessKey=" + AccessKey + ";"; | ||
if (!string.IsNullOrEmpty(SecretKey)) | ||
connectionString += "SecretKey=" + SecretKey + ";"; | ||
if (!string.IsNullOrEmpty(Region)) | ||
connectionString += "Region=" + Region + ";"; | ||
if (!string.IsNullOrEmpty(EndPoint)) | ||
connectionString += "EndPoint=" + EndPoint + ";"; | ||
return connectionString; | ||
EndPoint = value; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
var connectionString = string.Empty; | ||
if (!string.IsNullOrEmpty(AccessKey)) | ||
connectionString += "AccessKey=" + AccessKey + ";"; | ||
if (!string.IsNullOrEmpty(SecretKey)) | ||
connectionString += "SecretKey=" + SecretKey + ";"; | ||
if (!string.IsNullOrEmpty(Region)) | ||
connectionString += "Region=" + Region + ";"; | ||
if (!string.IsNullOrEmpty(EndPoint)) | ||
connectionString += "EndPoint=" + EndPoint + ";"; | ||
return connectionString; | ||
} | ||
} |
Oops, something went wrong.