Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DeleteFromVault.cs
1using System;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Content;
10using Waher.Script;
13
15{
20 {
25 : base("Storage/DeleteFromVault",
26 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
27 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
28 {
29 }
30
31 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(StoreInVault).Namespace + ".JSON.DeleteFromVault.req");
32 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(StoreInVault).Namespace + ".XML.DeleteFromVault.req");
33
42 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
43 {
45
46 string VaultId = (string)Parameters["PVaultId"]?.AssociatedObjectValue;
47 byte[] VaultIdBin;
48
49 try
50 {
51 VaultIdBin = Convert.FromBase64String(VaultId);
52 }
53 catch (Exception)
54 {
55 throw new BadRequestException("Invalid Vault ID.");
56 }
57
58 VaultItem Item = await Database.FindFirstIgnoreRest<VaultItem>(
59 new FilterFieldEqualTo("VaultId", VaultIdBin))
60 ?? throw new NotFoundException("Vault item not found.");
61
62 if (Item.Account != User.UserName)
63 throw new ForbiddenException(Request, "Access to vault item denied.");
64
65 await Database.Delete(Item);
66
67 await Response.Return(new NamedDictionary<string, object>("AckResponse", AgentNamespace));
68 }
69 }
70}
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
The server understood the request, but is refusing to fulfill it. Authorization will not help and the...
Represents an HTTP request.
Definition: HttpRequest.cs:22
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:23
Task Return(Exception ex)
Returns an error to the client.
The server has not found anything matching the Request-URI. No indication is given of whether the con...
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:21
static async Task Delete(object Object)
Deletes an object in the database.
Definition: Database.cs:1291
This filter selects objects that have a named field equal to a given value.
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:13
static string LoadResourceAsText(string ResourceName)
Loads a text resource from an embedded resource.
Definition: Resources.cs:55
Class managing a script expression.
Definition: Expression.cs:41
Abstract base class for agent resources supporting the POST method.
static AccountUser AssertUserAuthenticated(HttpRequest Request)
Makes sure the request is made by an authenticated API user.
const string AgentNamespace
https://waher.se/Schema/BrokerAgent.xsd
override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary< string, IElement > Parameters)
Executes the POST method on the resource.
DeleteFromVault()
> Deletes an item from the Encrypted Vault.
Stores information in the Encrypted Vault.
Definition: StoreInVault.cs:22
Contains information about an item in the Vault.
Definition: VaultItem.cs:16