Allow absolute key path
This commit is contained in:
parent
c9d13bb150
commit
e0e2a1cb06
@ -5,7 +5,11 @@ struct Config {
|
||||
/// The port where the server runs
|
||||
let port: Int
|
||||
|
||||
/// The name of the file in the `Resources` folder containing the device authentication token
|
||||
/**
|
||||
The path to the file containing the containing the device authentication token.
|
||||
|
||||
If the path is relative, then it is relative to the `Resources` folder.
|
||||
*/
|
||||
let keyFileName: String
|
||||
|
||||
/// The seconds to wait for a response from the device
|
||||
@ -14,20 +18,30 @@ struct Config {
|
||||
/// The authentication tokens to use for monitoring of the service
|
||||
let authenticationTokens: Set<String>
|
||||
|
||||
/// The path to the folder where the metric logs are stored
|
||||
///
|
||||
/// If no path is provided, then a folder `logs` in the resources directory is created
|
||||
/// If the path is relative, then it is assumed relative to the resources directory
|
||||
/**
|
||||
The path to the folder where the metric logs are stored
|
||||
|
||||
If no path is provided, then a folder `logs` in the resources directory is created.
|
||||
If the path is relative, then it is assumed relative to the resources directory.
|
||||
*/
|
||||
let logPath: String?
|
||||
|
||||
func logURL(possiblyRelativeTo resourcesDirectory: URL) -> URL {
|
||||
guard let logPath else {
|
||||
return resourcesDirectory.appendingPathComponent("logs")
|
||||
}
|
||||
guard !logPath.hasPrefix("/") else {
|
||||
return .init(fileURLWithPath: logPath)
|
||||
return Config.url(logPath, possiblyRelativeTo: resourcesDirectory)
|
||||
}
|
||||
return resourcesDirectory.appendingPathComponent(logPath)
|
||||
|
||||
func keyURL(possiblyRelativeTo resourcesDirectory: URL) -> URL {
|
||||
Config.url(keyFileName, possiblyRelativeTo: resourcesDirectory)
|
||||
}
|
||||
|
||||
private static func url(_ name: String, possiblyRelativeTo resourcesDirectory: URL) -> URL {
|
||||
guard !name.hasPrefix("/") else {
|
||||
return .init(fileURLWithPath: name)
|
||||
}
|
||||
return resourcesDirectory.appendingPathComponent(name)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public func configure(_ app: Application) async throws {
|
||||
|
||||
app.http.server.configuration.port = config.port
|
||||
|
||||
let keyFile = storageFolder.appendingPathComponent(config.keyFileName)
|
||||
let keyFile = config.keyURL(possiblyRelativeTo: storageFolder)
|
||||
|
||||
let (deviceKey, remoteKey) = try loadKeys(at: keyFile)
|
||||
deviceManager = DeviceManager(deviceKey: deviceKey, remoteKey: remoteKey, deviceTimeout: config.deviceTimeout, serverStatus: status)
|
||||
|
Loading…
Reference in New Issue
Block a user