Update to new access management

This commit is contained in:
Christoph Hagen 2023-01-30 16:07:04 +01:00
parent c5ce5414a9
commit 600464b889
2 changed files with 11 additions and 5 deletions

View File

@ -2,7 +2,7 @@ import Foundation
import Clairvoyant
import Vapor
final class Authenticator: MetricAccessAuthenticator {
final class Authenticator: MetricAccessManager {
private var writers: Set<String>
@ -20,11 +20,17 @@ final class Authenticator: MetricAccessAuthenticator {
writers.contains(key)
}
func metricAccess(isAllowedForToken accessToken: Data) -> Bool {
func metricListAccess(isAllowedForToken accessToken: AccessToken) throws {
guard let key = String(data: accessToken, encoding: .utf8) else {
return false
return
}
return hasAuthorization(for: key)
guard hasAuthorization(for: key) else {
throw MetricError.accessDenied
}
}
func metricAccess(to metric: MetricId, isAllowedForToken accessToken: AccessToken) throws {
try metricListAccess(isAllowedForToken: accessToken)
}

View File

@ -12,7 +12,7 @@ public func configure(_ app: Application) throws {
let monitor = MetricObserver(
logFolder: config.logURL,
authenticator: authenticator,
accessManager: authenticator,
logMetricId: "caps.log")
// All new metrics are automatically registered with the standard observer