Add server status
This commit is contained in:
parent
52cb76d4c8
commit
21a4f4ecae
@ -4,16 +4,19 @@ import PackageDescription
|
|||||||
let package = Package(
|
let package = Package(
|
||||||
name: "SesameServer",
|
name: "SesameServer",
|
||||||
platforms: [
|
platforms: [
|
||||||
.macOS(.v10_15)
|
.macOS(.v12)
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
|
.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: [
|
targets: [
|
||||||
.target(
|
.target(
|
||||||
name: "App",
|
name: "App",
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.product(name: "Vapor", package: "vapor")
|
.product(name: "Vapor", package: "vapor"),
|
||||||
|
.product(name: "Clairvoyant", package: "Clairvoyant"),
|
||||||
|
|
||||||
],
|
],
|
||||||
swiftSettings: [
|
swiftSettings: [
|
||||||
// Enable better optimizations when building in Release configuration. Despite the use of
|
// Enable better optimizations when building in Release configuration. Despite the use of
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import Vapor
|
import Vapor
|
||||||
|
import Clairvoyant
|
||||||
|
|
||||||
var deviceManager: DeviceManager!
|
var deviceManager: DeviceManager!
|
||||||
|
|
||||||
@ -12,10 +13,23 @@ public func configure(_ app: Application) throws {
|
|||||||
let storageFolder = URL(fileURLWithPath: app.directory.resourcesDirectory)
|
let storageFolder = URL(fileURLWithPath: app.directory.resourcesDirectory)
|
||||||
let logFolder = storageFolder.appendingPathComponent("logs")
|
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 configUrl = storageFolder.appendingPathComponent("config.json")
|
||||||
let config = try Config(loadFrom: configUrl)
|
let config = try Config(loadFrom: configUrl)
|
||||||
|
|
||||||
|
config.authenticationTokens.map { $0.data(using: .utf8)! }.forEach(accessManager.add)
|
||||||
|
|
||||||
app.http.server.configuration.port = config.port
|
app.http.server.configuration.port = config.port
|
||||||
|
|
||||||
let keyFile = storageFolder.appendingPathComponent(config.keyFileName)
|
let keyFile = storageFolder.appendingPathComponent(config.keyFileName)
|
||||||
@ -30,6 +44,8 @@ public func configure(_ app: Application) throws {
|
|||||||
deviceManager.removeDeviceConnection()
|
deviceManager.removeDeviceConnection()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status.update(.nominal)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func loadKeys(at url: URL) throws -> (deviceKey: Data, remoteKey: Data) {
|
private func loadKeys(at url: URL) throws -> (deviceKey: Data, remoteKey: Data) {
|
||||||
|
Loading…
Reference in New Issue
Block a user