Skip to content

Commit fa5dee3

Browse files
committed
NuGet v1.3.2, new constructor for S3-compatible storage
1 parent 00efd1a commit fa5dee3

File tree

5 files changed

+43
-14
lines changed

5 files changed

+43
-14
lines changed

BlobHelper/AwsSettings.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class AwsSettings
1717
/// Override the AWS S3 endpoint (if using non-Amazon storage), otherwise leave null.
1818
/// Use the form http://localhost:8000/
1919
/// </summary>
20-
public string Hostname { get; set; }
20+
public string Endpoint { get; set; }
2121

2222
/// <summary>
2323
/// Enable or disable SSL (only if using non-Amazon storage).
@@ -72,7 +72,7 @@ public AwsSettings(string accessKey, string secretKey, AwsRegion region, string
7272
if (String.IsNullOrEmpty(accessKey)) throw new ArgumentNullException(nameof(accessKey));
7373
if (String.IsNullOrEmpty(secretKey)) throw new ArgumentNullException(nameof(secretKey));
7474
if (String.IsNullOrEmpty(bucket)) throw new ArgumentNullException(nameof(bucket));
75-
Hostname = null;
75+
Endpoint = null;
7676
Ssl = true;
7777
AccessKey = accessKey;
7878
SecretKey = secretKey;
@@ -114,7 +114,7 @@ public AwsSettings(string accessKey, string secretKey, AwsRegion region, string
114114
if (String.IsNullOrEmpty(accessKey)) throw new ArgumentNullException(nameof(accessKey));
115115
if (String.IsNullOrEmpty(secretKey)) throw new ArgumentNullException(nameof(secretKey));
116116
if (String.IsNullOrEmpty(bucket)) throw new ArgumentNullException(nameof(bucket));
117-
Hostname = null;
117+
Endpoint = null;
118118
Ssl = true;
119119
AccessKey = accessKey;
120120
SecretKey = secretKey;
@@ -148,26 +148,51 @@ public AwsSettings(string accessKey, string secretKey, string region, string buc
148148
/// <summary>
149149
/// Initialize the object.
150150
/// </summary>
151-
/// <param name="hostname">Override the AWS S3 endpoint (if using non-Amazon storage). Use the form http://localhost:8000/.</param>
151+
/// <param name="endpoint">Override the AWS S3 endpoint (if using non-Amazon storage). Use the form http://localhost:8000/.</param>
152152
/// <param name="ssl">Enable or disable SSL.</param>
153153
/// <param name="accessKey">Access key with which to access AWS S3.</param>
154154
/// <param name="secretKey">Secret key with which to access AWS S3.</param>
155155
/// <param name="region">AWS region.</param>
156156
/// <param name="bucket">Bucket in which to store BLOBs.</param>
157-
public AwsSettings(string hostname, bool ssl, string accessKey, string secretKey, AwsRegion region, string bucket)
157+
public AwsSettings(string endpoint, bool ssl, string accessKey, string secretKey, AwsRegion region, string bucket)
158158
{
159-
if (String.IsNullOrEmpty(hostname)) throw new ArgumentNullException(nameof(hostname));
159+
if (String.IsNullOrEmpty(endpoint)) throw new ArgumentNullException(nameof(endpoint));
160160
if (String.IsNullOrEmpty(accessKey)) throw new ArgumentNullException(nameof(accessKey));
161161
if (String.IsNullOrEmpty(secretKey)) throw new ArgumentNullException(nameof(secretKey));
162162
if (String.IsNullOrEmpty(bucket)) throw new ArgumentNullException(nameof(bucket));
163-
Hostname = hostname;
163+
Endpoint = endpoint;
164164
Ssl = ssl;
165165
AccessKey = accessKey;
166166
SecretKey = secretKey;
167167
Region = region;
168168
Bucket = bucket;
169169
}
170170

171+
/// <summary>
172+
/// Initialize the object.
173+
/// </summary>
174+
/// <param name="endpoint">Override the AWS S3 endpoint (if using non-Amazon storage). Use the form http://localhost:8000/.</param>
175+
/// <param name="ssl">Enable or disable SSL.</param>
176+
/// <param name="accessKey">Access key with which to access AWS S3.</param>
177+
/// <param name="secretKey">Secret key with which to access AWS S3.</param>
178+
/// <param name="region">AWS region.</param>
179+
/// <param name="bucket">Bucket in which to store BLOBs.</param>
180+
public AwsSettings(string endpoint, bool ssl, string accessKey, string secretKey, string region, string bucket)
181+
{
182+
if (String.IsNullOrEmpty(endpoint)) throw new ArgumentNullException(nameof(endpoint));
183+
if (String.IsNullOrEmpty(accessKey)) throw new ArgumentNullException(nameof(accessKey));
184+
if (String.IsNullOrEmpty(secretKey)) throw new ArgumentNullException(nameof(secretKey));
185+
if (String.IsNullOrEmpty(bucket)) throw new ArgumentNullException(nameof(bucket));
186+
Endpoint = endpoint;
187+
Ssl = ssl;
188+
AccessKey = accessKey;
189+
SecretKey = secretKey;
190+
Bucket = bucket;
191+
192+
if (!ValidateRegion(region)) throw new ArgumentException("Unable to validate region: " + region);
193+
Region = GetRegionFromString(region);
194+
}
195+
171196
#endregion
172197

173198
#region Public-Methods

BlobHelper/BlobHelper.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
<PropertyGroup>
44
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
<Version>1.3.1</Version>
6+
<Version>1.3.2</Version>
77
<Authors>Joel Christner</Authors>
88
<Description>BLOB storage wrapper for Microsoft Azure, Amazon S3, Kvpbase, and local filesystem written in C#.</Description>
99
<Copyright>(c)2019 Joel Christner</Copyright>
1010
<PackageProjectUrl>https://github.com/jchristn/BlobHelper</PackageProjectUrl>
1111
<RepositoryUrl>https://github.com/jchristn/BlobHelper</RepositoryUrl>
1212
<RepositoryType>Github</RepositoryType>
1313
<PackageLicenseUrl>https://github.com/jchristn/BlobHelper/blob/master/LICENSE.TXT</PackageLicenseUrl>
14-
<PackageReleaseNotes>Fix to allow connection to S3 without SSL.</PackageReleaseNotes>
14+
<PackageReleaseNotes>Modify test app and constructors to support S3 and S3-compatible storage.</PackageReleaseNotes>
1515
<PackageIconUrl>https://raw.githubusercontent.com/jchristn/BlobHelper/master/assets/icon.ico</PackageIconUrl>
1616
<PackageTags>blob azure storage s3 object rest</PackageTags>
1717
</PropertyGroup>

BlobHelper/Blobs.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ private void InitializeClients()
343343
_S3Region = _AwsSettings.GetAwsRegion();
344344
_S3Credentials = new Amazon.Runtime.BasicAWSCredentials(_AwsSettings.AccessKey, _AwsSettings.SecretKey);
345345

346-
if (String.IsNullOrEmpty(_AwsSettings.Hostname))
346+
if (String.IsNullOrEmpty(_AwsSettings.Endpoint))
347347
{
348348
_S3Config = new AmazonS3Config
349349
{
@@ -359,7 +359,7 @@ private void InitializeClients()
359359
_S3Config = new AmazonS3Config
360360
{
361361
RegionEndpoint = _S3Region,
362-
ServiceURL = _AwsSettings.Hostname,
362+
ServiceURL = _AwsSettings.Endpoint,
363363
ForcePathStyle = true,
364364
UseHttp = !_AwsSettings.Ssl
365365
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This project was built to provide a simple interface over external storage to he
1717

1818
## New in v1.3.x
1919

20+
- New constructor to better support S3-compatible storage, update to test app
2021
- Fix to allow non-SSL connections to S3
2122
- Added enumeration capabilities to list contents of a bucket or container
2223
- Added metadata capabilities to retrieve metadata for a given BLOB

Test/Program.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,15 @@ static void InitializeClient()
103103
switch (_StorageType)
104104
{
105105
case StorageType.AwsS3:
106+
Console.WriteLine("For S3-compatible storage, endpoint should be of the form http://[hostname]:[port]/");
106107
_AwsSettings = new AwsSettings(
108+
InputString("Endpoint :", null, true),
109+
InputBoolean("SSL :", true),
107110
InputString("Access key :", null, false),
108-
InputString("Secret key :", null, false),
111+
InputString("Secret key :", null, false),
109112
InputString("Region :", "USWest1", false),
110-
InputString("Bucket :", null, false),
111-
InputBoolean("SSL :", true));
113+
InputString("Bucket :", null, false)
114+
);
112115
_Blobs = new Blobs(_AwsSettings);
113116
break;
114117
case StorageType.Azure:

0 commit comments

Comments
 (0)