VaultSharp
VaultSharp copied to clipboard
Feature request : Patch a secret (real patch, not delete / post )
Due to security settings, we need to be able to patch a secret. The current Patch method in the library seems to do a delete / Post, and we don't have Post rights, so this Patch method cannot be used. Therefore we wrote a patch method ourselves, it would be nice to include this in the library.
` public const string VaultDataPath = "/v1/secret/data/";
private async Task PatchKey(string path, string key, string value)
{
_logger.LogDebug("Patch Vault key {Key} at {VaultPath}", key, path);
var requestUri = new Uri(VaultConstants.VaultDataPath + path, UriKind.Relative);
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Patch, requestUri);
httpRequestMessage.Headers.Add(VaultConstants.VaultRequestHeaderKey, "true");
httpRequestMessage.Headers.Add(VaultConstants.VaultTokenHeaderKey, _options.Token);
var postKey = new JObject();
postKey[key] = value;
var postData = new JObject();
postData["data"] = postKey;
httpRequestMessage.Content = new StringContent(JsonConvert.SerializeObject(postData), Encoding.UTF8, "application/merge-patch+json");
var httpResponseMessage = await _httpClient.SendAsync(httpRequestMessage);
if (httpResponseMessage.IsSuccessStatusCode)
{
_logger.LogDebug("Patched Vault key {Key} at {VaultPath} successfully", key, path);
}
else
{
_logger.LogError("Error patching Vault key {Key} at {VaultPath}, statusCode: {StatusCode}", key, path, httpResponseMessage.StatusCode);
throw new Exception($"Error patching Vault key {key} at {path}");
}
}
`
Hey @stephdep,
I've created a draft PR for this Issue. It needs to be reviewed and also tested.
Hi, Next week I'm on holidays, but I'll check your PR right away when I get back! Kind regards, StephDep
On Sun, Jul 24, 2022 at 7:59 PM Srigovind Nayak @.***> wrote:
Hey @stephdep https://github.com/stephdep,
I've created a draft PR for this Issue. It needs to be reviewed and also tested.
— Reply to this email directly, view it on GitHub https://github.com/rajanadar/VaultSharp/issues/269#issuecomment-1193366290, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEQKQX4BYJWVU3DG5HTWQDVVWAAJANCNFSM53RQBCCA . You are receiving this because you were mentioned.Message ID: @.***>
Hey @konidev20,
Any update on this?
Thanks.
Rick
Hey @ric-sec,
The review for the PR is still pending. You can take a build from the branch and check it out. Let me know if you want help with that.
Thanks, @konidev20
Available here: https://www.nuget.org/packages/VaultSharp/1.7.2