Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GetFromVault.cs
1using System;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Content;
11using Waher.Script;
14
16{
21 {
25 public GetFromVault()
26 : base("Storage/GetFromVault",
27 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
28 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
29 {
30 }
31
32 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(StoreInVault).Namespace + ".JSON.GetFromVault.req");
33 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(StoreInVault).Namespace + ".XML.GetFromVault.req");
34
43 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
44 {
46
47 string VaultId = (string)Parameters["PVaultId"]?.AssociatedObjectValue;
48 bool Masked = (bool)(Parameters["PMasked"]?.AssociatedObjectValue ?? true);
49 byte[] VaultIdBin;
50
51 try
52 {
53 VaultIdBin = Convert.FromBase64String(VaultId);
54 }
55 catch (Exception)
56 {
57 throw new BadRequestException("Invalid Vault ID.");
58 }
59
60 VaultItem Item = await Database.FindFirstIgnoreRest<VaultItem>(
61 new FilterFieldEqualTo("VaultId", VaultIdBin))
62 ?? throw new NotFoundException("Vault item not found.");
63
64 if (Item.Account != User.UserName)
65 throw new ForbiddenException(Request, "Access to vault item denied.");
66
67 await Response.Return(EncodeVaultItem(Item, Masked));
68 }
69
70 internal static NamedDictionary<string,object> EncodeVaultItem(VaultItem Item, bool Masked)
71 {
73
74 foreach (VaultTag Tag in Item.Tags)
75 {
76 Tags.Add(new NamedDictionary<string, object>("Tag", string.Empty)
77 {
78 { "name", Tag.Name },
79 { "value", Masked ? (Tag.MaskedValue ?? Tag.Value) : Tag.Value }
80 });
81 }
82
83 return new NamedDictionary<string, object>("VaultItem", AgentNamespace)
84 {
85 { "vaultId", Convert.ToBase64String(Item.VaultId) },
86 { "type", Item.Type },
87 { "clientId", Item.ClientId },
88 { "created", Item.Created },
89 { "updated", Item.Updated },
90 { "Tags", Tags.ToArray() }
91 };
92 }
93 }
94}
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
This filter selects objects that have a named field equal to a given value.
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
void Add(T Item)
Adds an item to the collection.
Definition: ChunkedList.cs:272
T[] ToArray()
Returns an array containing all elements of the collection.
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
Gets information from the Encrypted Vault.
Definition: GetFromVault.cs:21
GetFromVault()
> Gets information from the Encrypted Vault.
Definition: GetFromVault.cs:25
override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary< string, IElement > Parameters)
Executes the POST method on the resource.
Definition: GetFromVault.cs:43
Stores information in the Encrypted Vault.
Definition: StoreInVault.cs:22
Contains information about an item in the Vault.
Definition: VaultItem.cs:16
VaultTag[] Tags
Tags containing information about the item.
Definition: VaultItem.cs:84
Contains information about a tag in a vault item.
Definition: VaultTag.cs:7