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

Fix to connect Amazon S3 compatible endpoints with custom auth region #427

Open
wants to merge 2 commits into
base: master
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion KeeAnywhere/StorageProviders/AmazonS3/AmazonS3AccountForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private async Task TestConnection()

try
{
var config = this.IsAmazon ? AmazonS3Helper.GetConfig(this.AWSRegion) : AmazonS3Helper.GetConfig(this.EndpointUrl);
var config = this.IsAmazon ? AmazonS3Helper.GetConfig(this.AWSRegion) : AmazonS3Helper.GetConfig(this.EndpointUrl, authRegion: this.OverridedAuthRegion);

using (var api = AmazonS3Helper.GetApi(credentials, config))
{
Expand Down Expand Up @@ -112,6 +112,7 @@ public void ClearTestResult()
public string AccessKey { get { return m_txtAccessKey.Text.Trim(); } }
public string SecretKey { get { return m_txtSecretKey.Text.Trim(); } }
public string SessionToken { get { return m_txtSessionToken.Text.Trim(); } }
public string OverridedAuthRegion { get { return m_authRegion.Text.Trim(); } }
public bool UseSessionToken { get { return m_chkUseSessionToken.Checked; } }
public RegionEndpoint AWSRegion { get { return (RegionEndpoint) m_cmbRegion.SelectedItem; } }
public string EndpointUrl { get { return m_cmbEndpointUrl.Text.Trim(); } }
Expand Down Expand Up @@ -152,6 +153,8 @@ private void OnTypeChanged(object sender, EventArgs e)
{
m_cmbRegion.Enabled = m_rbTypeAmazon.Checked;
m_cmbEndpointUrl.Enabled = m_rbTypeOther.Checked;
m_authRegion.Enabled = m_rbTypeOther.Checked;
m_lblAuthRegion.Enabled = m_rbTypeOther.Checked;
ClearTestResult();
}
}
Expand Down
11 changes: 7 additions & 4 deletions KeeAnywhere/StorageProviders/AmazonS3/AmazonS3Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public static AmazonS3Client GetApi(AccountConfiguration account)
AmazonS3Config config;

if (account.AdditionalSettings.ContainsKey("EndpointURL")) {
config = GetConfig(account.AdditionalSettings["EndpointURL"]);
config = GetConfig(
account.AdditionalSettings["EndpointURL"],
authRegion: account.AdditionalSettings["OverridedAuthRegion"]
);
} else
{
var region = RegionEndpoint.USWest1;
Expand All @@ -48,16 +51,16 @@ public static AmazonS3Client GetApi(AccountConfiguration account)
return GetApi(credentials, config);
}

public static AmazonS3Config GetConfig(string endpointURL)
public static AmazonS3Config GetConfig(string endpointURL, string authRegion = "")
{
if (string.IsNullOrEmpty(endpointURL)) throw new ArgumentNullException("endpointURL");

var config = new AmazonS3Config
{
RegionEndpoint = RegionEndpoint.USEast1, // Required???
ServiceURL = endpointURL,
ForcePathStyle = true,
Timeout = Timeout.InfiniteTimeSpan
Timeout = Timeout.InfiniteTimeSpan,
AuthenticationRegion = String.IsNullOrWhiteSpace(authRegion) ? "" : authRegion
};

return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public async Task<AccountConfiguration> CreateAccount()
} else
{
account.AdditionalSettings.Add("EndpointURL", dlg.EndpointUrl);
account.AdditionalSettings.Add("OverridedAuthRegion", dlg.OverridedAuthRegion);
}

account.AdditionalSettings.Add("UseSessionToken", Convert.ToString(dlg.UseSessionToken));
Expand Down