-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathClient.cs
More file actions
76 lines (67 loc) · 1.99 KB
/
Client.cs
File metadata and controls
76 lines (67 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
namespace NeoSmart.SecureStore.Client
{
class Client
{
private SecretsManager _sman;
public Client(SecretsManager sman)
{
_sman = sman;
}
public void Create()
{
//no-op
}
public void Update(string key, string value)
{
// Force validation to avoid loss of sensitive data
if (_sman.TryGetBytes(key, out var buffer))
{
}
_sman.Set(key, value);
}
public void Delete(string key)
{
if (!_sman.Delete(key))
{
throw new ExitCodeException(1, $"Key \"{key}\" not found in secrets store!");
}
}
public void Decrypt(string key)
{
if (!_sman.TryGetValue(key, out string? retrieved))
{
throw new ExitCodeException(1, $"Key \"{key}\" not found in secrets store!");
}
else
{
Console.WriteLine(retrieved);
}
}
public void DecryptAll(DecryptFormat format)
{
// This is going to stdout out, don't bother securing the memory here
var decrypted = new Dictionary<string, dynamic>();
foreach (var k in _sman.Keys)
{
var v = _sman.Get(k);
decrypted[k] = v;
}
switch (format)
{
case DecryptFormat.PlainText:
foreach (var k in decrypted.Keys)
{
Console.WriteLine($"{k}: { decrypted[k].ToString() }");
}
break;
default:
var serializerOptions = JsonConvert.SerializeObject(decrypted, Formatting.Indented);
Console.WriteLine(serializerOptions);
break;
}
}
}
}