Add server status

This commit is contained in:
Christoph Hagen 2023-01-31 19:10:57 +01:00
parent 52cb76d4c8
commit 21a4f4ecae
2 changed files with 21 additions and 2 deletions

View File

@ -4,16 +4,19 @@ import PackageDescription
let package = Package(
name: "SesameServer",
platforms: [
.macOS(.v10_15)
.macOS(.v12)
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
.package(url: "https://github.com/christophhagen/clairvoyant.git", from: "0.3.0"),
],
targets: [
.target(
name: "App",
dependencies: [
.product(name: "Vapor", package: "vapor")
.product(name: "Vapor", package: "vapor"),
.product(name: "Clairvoyant", package: "Clairvoyant"),
],
swiftSettings: [
// Enable better optimizations when building in Release configuration. Despite the use of

View File

@ -1,4 +1,5 @@
import Vapor
import Clairvoyant
var deviceManager: DeviceManager!
@ -12,10 +13,23 @@ public func configure(_ app: Application) throws {
let storageFolder = URL(fileURLWithPath: app.directory.resourcesDirectory)
let logFolder = storageFolder.appendingPathComponent("logs")
let accessManager = AccessTokenManager([])
let monitor = MetricObserver(
logFolder: logFolder,
accessManager: accessManager,
logMetricId: "sesame.log")
MetricObserver.standard = monitor
let status = Metric<ServerStatus>("sesame.status")
status.update(.initializing)
monitor.registerRoutes(app)
let configUrl = storageFolder.appendingPathComponent("config.json")
let config = try Config(loadFrom: configUrl)
config.authenticationTokens.map { $0.data(using: .utf8)! }.forEach(accessManager.add)
app.http.server.configuration.port = config.port
let keyFile = storageFolder.appendingPathComponent(config.keyFileName)
@ -30,6 +44,8 @@ public func configure(_ app: Application) throws {
deviceManager.removeDeviceConnection()
}
}
status.update(.nominal)
}
private func loadKeys(at url: URL) throws -> (deviceKey: Data, remoteKey: Data) {