Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
UninstallPackage.cs
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Threading.Tasks;
9
11{
13 {
14 public UninstallPackage()
15 : base("/UninstallPackage")
16 {
17 }
18
19 public override bool HandlesSubPaths => false;
20 public override bool UserSessions => true;
21 public bool AllowsPOST => true;
22
23 public async Task POST(HttpRequest Request, HttpResponse Response)
24 {
25 Gateway.AssertUserAuthenticated(Request, "Admin.Software.Upload");
26
27 if (!Request.HasData || !(await Request.DecodeDataAsync() is Dictionary<string, object> Obj) ||
28 !Obj.TryGetValue("package", out object Value) || !(Value is string FileName))
29 {
30 throw new BadRequestException();
31 }
32
33 string FullFileName = Path.Combine(XmppServerModule.PackagesFolder, FileName);
34 if (!File.Exists(FullFileName))
35 throw new NotFoundException("Package file not found.");
36
37 Package Package = await Provisioning.ProvisioningComponent.GetPackage(FileName);
38 if (Package is null)
39 throw new NotFoundException("Package not found.");
40
42 throw new BadRequestException("Reserved package.");
43
44 if (Package.Installed == DateTime.MinValue)
45 throw new BadRequestException("Package not installed.");
46
47 byte[] Key = Package.AesKey;
48
49 Package.Installed = DateTime.MinValue;
50 Package.PublicKey = null;
51 Package.AesKey = null;
52
53 await Database.Update(Package);
54 await XmppServerModule.Instance.UninstallSoftware(Package.FileName, Key);
55 }
56 }
57}
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:126
static IUser AssertUserAuthenticated(HttpRequest Request, string Privilege)
Makes sure a request is being made from a session with a successful user login.
Definition: Gateway.cs:3041
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Represents an HTTP request.
Definition: HttpRequest.cs:18
bool HasData
If the request has data.
Definition: HttpRequest.cs:74
async Task< object > DecodeDataAsync()
Decodes data sent in request.
Definition: HttpRequest.cs:95
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:21
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
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:19
static async Task Update(object Object)
Updates an object in the database.
Definition: Database.cs:626
Identity of the IoT Broker package.
Definition: BrokerPackage.cs:7
const string FileName
IoTBroker.package
Contains information about a software package.
Definition: Package.cs:18
DateTime Installed
When package was installed (if installed).
Definition: Package.cs:94
CaseInsensitiveString FileName
Filename of package.
Definition: Package.cs:40
byte[] AesKey
Symmetric cipher used to encrypt package file.
Definition: Package.cs:58
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
bool AllowsPOST
If the POST method is allowed.
Service Module hosting the XMPP broker and its components.
POST Interface for HTTP resources.