From 600464b8895d44ff37f3f332921ea391d998ac40 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Mon, 30 Jan 2023 16:07:04 +0100 Subject: [PATCH] Update to new access management --- Sources/App/Authenticator.swift | 14 ++++++++++---- Sources/App/configure.swift | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) 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