Skip to content

Commit

Permalink
Fixing Issue #15 (#16)
Browse files Browse the repository at this point in the history
* Fixing ArgumentOutOfRangeException issue when no key exists.

* Bumping patch number on VersionPrefix.
  • Loading branch information
kevbite authored and adamhathcock committed Dec 8, 2017
1 parent c893cc2 commit 53f936a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
10 changes: 10 additions & 0 deletions misc/CredstashTester/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System;
using System.Collections.Generic;
using Amazon;
using Amazon.DynamoDBv2;
using Amazon.KeyManagementService;
using Amazon.Runtime;
using Microsoft.Extensions.Configuration;
using Narochno.Credstash;
using Narochno.Credstash.Configuration;

namespace CredstashTester
Expand All @@ -10,6 +14,12 @@ public class Program
{
public static void Main(string[] args)
{
var stash = new Credstash(new CredstashOptions(), new AmazonKeyManagementServiceClient(RegionEndpoint.EUWest1),
new AmazonDynamoDBClient(RegionEndpoint.EUWest1));

var noneExistingKey1 = stash.GetSecretAsync(Guid.NewGuid().ToString()).Result;
var noneExistingKey2 = stash.GetSecretAsync(Guid.NewGuid().ToString(), "1").Result;

//var creds = new StoredProfileAWSCredentials();
//var stash = new Credstash(new CredstashOptions(), new AmazonKeyManagementServiceClient(creds, RegionEndpoint.EUWest1),
// new AmazonDynamoDBClient(creds, RegionEndpoint.EUWest1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>2.1.0</VersionPrefix>
<VersionPrefix>2.1.1</VersionPrefix>
<Authors>adamhathcock</Authors>
<TargetFrameworks>netstandard1.3;netstandard2.0</TargetFrameworks>
<AssemblyName>Narochno.Credstash.Configuration</AssemblyName>
Expand Down
9 changes: 8 additions & 1 deletion src/Narochno.Credstash/Credstash.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -58,7 +59,8 @@ public async Task<Optional<string>> GetSecretAsync(string name, string version =
}
}
}).ConfigureAwait(false);
item = CredstashItem.From(response.Items[0]);

item = CredstashItem.From(response.Items.FirstOrDefault());
}
else
{
Expand All @@ -74,6 +76,11 @@ public async Task<Optional<string>> GetSecretAsync(string name, string version =
item = CredstashItem.From(response.Item);
}

if (item == null)
{
return null;
}

DecryptResponse decryptResponse;
try
{
Expand Down
5 changes: 5 additions & 0 deletions src/Narochno.Credstash/Internal/CredstashItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public class CredstashItem

public static CredstashItem From(Dictionary<string, AttributeValue> item)
{
if (item == null || item.Count == 0)
{
return null;
}

return new CredstashItem
{
Name = item["name"].S,
Expand Down
2 changes: 1 addition & 1 deletion src/Narochno.Credstash/Narochno.Credstash.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>2.1.0</VersionPrefix>
<VersionPrefix>2.1.1</VersionPrefix>
<Authors>adamhathcock</Authors>
<TargetFrameworks>netstandard1.3;netstandard2.0</TargetFrameworks>
<AssemblyName>Narochno.Credstash</AssemblyName>
Expand Down

0 comments on commit 53f936a

Please sign in to comment.