diff --git a/Package.swift b/Package.swift index 7974942..6e91515 100644 --- a/Package.swift +++ b/Package.swift @@ -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 diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index 6a2e9a1..a8595d6 100755 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -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("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) {