Skip to content

Commit

Permalink
Extend V4Authenticator constructor to take region
Browse files Browse the repository at this point in the history
  • Loading branch information
krisis committed Dec 27, 2018
1 parent 1f271e5 commit a72601e
Show file tree
Hide file tree
Showing 2 changed files with 21 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
21 changes: 20 additions & 1 deletion Minio/V4Authenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,35 @@ 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 (this.Region != "")
return this.Region;

string region = Regions.GetRegionFromEndpoint(url);
return (region == "") ? "us-east-1" : region;
}
Expand Down

0 comments on commit a72601e

Please sign in to comment.