diff --git a/Sources/App/Authenticator.swift b/Sources/App/Authenticator.swift index b7eb71d..1959d9b 100644 --- a/Sources/App/Authenticator.swift +++ b/Sources/App/Authenticator.swift @@ -2,7 +2,7 @@ import Foundation import Clairvoyant import Vapor -final class Authenticator: MetricAccessAuthenticator { +final class Authenticator: MetricAccessManager { private var writers: Set @@ -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) } diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index 78f2dd9..05971f5 100755 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -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