Skip to content

Commit

Permalink
Extend V4Authenticator constructor to take region (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
krisis authored and nitisht committed Dec 27, 2018
1 parent c2a7468 commit 64bf0b4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Minio/MinioClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ internal void initClient()
restClient = new RestSharp.RestClient(this.uri);
restClient.UserAgent = this.FullUserAgent;

authenticator = new V4Authenticator(this.Secure,this.AccessKey, this.SecretKey);
authenticator = new V4Authenticator(this.Secure,this.AccessKey, this.SecretKey, this.Region);
restClient.Authenticator = authenticator;
}

Expand Down
22 changes: 21 additions & 1 deletion Minio/V4Authenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,36 @@ internal class V4Authenticator : IAuthenticator
/// <param name="secure"></param>
/// <param name="accessKey">Access key id</param>
/// <param name="secretKey">Secret access key</param>
public V4Authenticator(bool secure,string accessKey, string secretKey)
public V4Authenticator(bool secure, string accessKey, string secretKey)
{
this.isSecure = secure;
this.accessKey = accessKey;
this.secretKey = secretKey;
this.isAnonymous = String.IsNullOrEmpty(accessKey) && String.IsNullOrEmpty(secretKey);
}

/// <summary>
/// Authenticator constructor with region specified.
/// </summary>
/// <param name="secure"></param>
/// <param name="accessKey">Access key id</param>
/// <param name="secretKey">Secret access key</param>
/// <param name="region">Region</param>
public V4Authenticator(bool secure, string accessKey, string secretKey, string region)
{
this.isSecure = secure;
this.accessKey = accessKey;
this.secretKey = secretKey;
this.isAnonymous = String.IsNullOrEmpty(accessKey) && String.IsNullOrEmpty(secretKey);
this.Region = region;
}

private String getRegion(string url)
{
if (!string.IsNullOrEmpty(this.Region))
{
return this.Region;
}
string region = Regions.GetRegionFromEndpoint(url);
return (region == "") ? "us-east-1" : region;
}
Expand Down

0 comments on commit 64bf0b4

Please sign in to comment.