Skip to content

Commit

Permalink
NuGet v1.3.2, new constructor for S3-compatible storage
Browse files Browse the repository at this point in the history
  • Loading branch information
jchristn committed Aug 17, 2019
1 parent 00efd1a commit fa5dee3
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
39 changes: 32 additions & 7 deletions BlobHelper/AwsSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AwsSettings
/// Override the AWS S3 endpoint (if using non-Amazon storage), otherwise leave null.
/// Use the form http://localhost:8000/
/// </summary>
public string Hostname { get; set; }
public string Endpoint { get; set; }

/// <summary>
/// Enable or disable SSL (only if using non-Amazon storage).
Expand Down Expand Up @@ -72,7 +72,7 @@ public AwsSettings(string accessKey, string secretKey, AwsRegion region, string
if (String.IsNullOrEmpty(accessKey)) throw new ArgumentNullException(nameof(accessKey));
if (String.IsNullOrEmpty(secretKey)) throw new ArgumentNullException(nameof(secretKey));
if (String.IsNullOrEmpty(bucket)) throw new ArgumentNullException(nameof(bucket));
Hostname = null;
Endpoint = null;
Ssl = true;
AccessKey = accessKey;
SecretKey = secretKey;
Expand Down Expand Up @@ -114,7 +114,7 @@ public AwsSettings(string accessKey, string secretKey, AwsRegion region, string
if (String.IsNullOrEmpty(accessKey)) throw new ArgumentNullException(nameof(accessKey));
if (String.IsNullOrEmpty(secretKey)) throw new ArgumentNullException(nameof(secretKey));
if (String.IsNullOrEmpty(bucket)) throw new ArgumentNullException(nameof(bucket));
Hostname = null;
Endpoint = null;
Ssl = true;
AccessKey = accessKey;
SecretKey = secretKey;
Expand Down Expand Up @@ -148,26 +148,51 @@ public AwsSettings(string accessKey, string secretKey, string region, string buc
/// <summary>
/// Initialize the object.
/// </summary>
/// <param name="hostname">Override the AWS S3 endpoint (if using non-Amazon storage). Use the form http://localhost:8000/.</param>
/// <param name="endpoint">Override the AWS S3 endpoint (if using non-Amazon storage). Use the form http://localhost:8000/.</param>
/// <param name="ssl">Enable or disable SSL.</param>
/// <param name="accessKey">Access key with which to access AWS S3.</param>
/// <param name="secretKey">Secret key with which to access AWS S3.</param>
/// <param name="region">AWS region.</param>
/// <param name="bucket">Bucket in which to store BLOBs.</param>
public AwsSettings(string hostname, bool ssl, string accessKey, string secretKey, AwsRegion region, string bucket)
public AwsSettings(string endpoint, bool ssl, string accessKey, string secretKey, AwsRegion region, string bucket)
{
if (String.IsNullOrEmpty(hostname)) throw new ArgumentNullException(nameof(hostname));
if (String.IsNullOrEmpty(endpoint)) throw new ArgumentNullException(nameof(endpoint));
if (String.IsNullOrEmpty(accessKey)) throw new ArgumentNullException(nameof(accessKey));
if (String.IsNullOrEmpty(secretKey)) throw new ArgumentNullException(nameof(secretKey));
if (String.IsNullOrEmpty(bucket)) throw new ArgumentNullException(nameof(bucket));
Hostname = hostname;
Endpoint = endpoint;
Ssl = ssl;
AccessKey = accessKey;
SecretKey = secretKey;
Region = region;
Bucket = bucket;
}

/// <summary>
/// Initialize the object.
/// </summary>
/// <param name="endpoint">Override the AWS S3 endpoint (if using non-Amazon storage). Use the form http://localhost:8000/.</param>
/// <param name="ssl">Enable or disable SSL.</param>
/// <param name="accessKey">Access key with which to access AWS S3.</param>
/// <param name="secretKey">Secret key with which to access AWS S3.</param>
/// <param name="region">AWS region.</param>
/// <param name="bucket">Bucket in which to store BLOBs.</param>
public AwsSettings(string endpoint, bool ssl, string accessKey, string secretKey, string region, string bucket)
{
if (String.IsNullOrEmpty(endpoint)) throw new ArgumentNullException(nameof(endpoint));
if (String.IsNullOrEmpty(accessKey)) throw new ArgumentNullException(nameof(accessKey));
if (String.IsNullOrEmpty(secretKey)) throw new ArgumentNullException(nameof(secretKey));
if (String.IsNullOrEmpty(bucket)) throw new ArgumentNullException(nameof(bucket));
Endpoint = endpoint;
Ssl = ssl;
AccessKey = accessKey;
SecretKey = secretKey;
Bucket = bucket;

if (!ValidateRegion(region)) throw new ArgumentException("Unable to validate region: " + region);
Region = GetRegionFromString(region);
}

#endregion

#region Public-Methods
Expand Down
4 changes: 2 additions & 2 deletions BlobHelper/BlobHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.3.1</Version>
<Version>1.3.2</Version>
<Authors>Joel Christner</Authors>
<Description>BLOB storage wrapper for Microsoft Azure, Amazon S3, Kvpbase, and local filesystem written in C#.</Description>
<Copyright>(c)2019 Joel Christner</Copyright>
<PackageProjectUrl>https://github.com/jchristn/BlobHelper</PackageProjectUrl>
<RepositoryUrl>https://github.com/jchristn/BlobHelper</RepositoryUrl>
<RepositoryType>Github</RepositoryType>
<PackageLicenseUrl>https://github.com/jchristn/BlobHelper/blob/master/LICENSE.TXT</PackageLicenseUrl>
<PackageReleaseNotes>Fix to allow connection to S3 without SSL.</PackageReleaseNotes>
<PackageReleaseNotes>Modify test app and constructors to support S3 and S3-compatible storage.</PackageReleaseNotes>
<PackageIconUrl>https://raw.githubusercontent.com/jchristn/BlobHelper/master/assets/icon.ico</PackageIconUrl>
<PackageTags>blob azure storage s3 object rest</PackageTags>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions BlobHelper/Blobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ private void InitializeClients()
_S3Region = _AwsSettings.GetAwsRegion();
_S3Credentials = new Amazon.Runtime.BasicAWSCredentials(_AwsSettings.AccessKey, _AwsSettings.SecretKey);

if (String.IsNullOrEmpty(_AwsSettings.Hostname))
if (String.IsNullOrEmpty(_AwsSettings.Endpoint))
{
_S3Config = new AmazonS3Config
{
Expand All @@ -359,7 +359,7 @@ private void InitializeClients()
_S3Config = new AmazonS3Config
{
RegionEndpoint = _S3Region,
ServiceURL = _AwsSettings.Hostname,
ServiceURL = _AwsSettings.Endpoint,
ForcePathStyle = true,
UseHttp = !_AwsSettings.Ssl
};
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This project was built to provide a simple interface over external storage to he

## New in v1.3.x

- New constructor to better support S3-compatible storage, update to test app
- Fix to allow non-SSL connections to S3
- Added enumeration capabilities to list contents of a bucket or container
- Added metadata capabilities to retrieve metadata for a given BLOB
Expand Down
9 changes: 6 additions & 3 deletions Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ static void InitializeClient()
switch (_StorageType)
{
case StorageType.AwsS3:
Console.WriteLine("For S3-compatible storage, endpoint should be of the form http://[hostname]:[port]/");
_AwsSettings = new AwsSettings(
InputString("Endpoint :", null, true),
InputBoolean("SSL :", true),
InputString("Access key :", null, false),
InputString("Secret key :", null, false),
InputString("Secret key :", null, false),
InputString("Region :", "USWest1", false),
InputString("Bucket :", null, false),
InputBoolean("SSL :", true));
InputString("Bucket :", null, false)
);
_Blobs = new Blobs(_AwsSettings);
break;
case StorageType.Azure:
Expand Down

0 comments on commit fa5dee3

Please sign in to comment.