Update to new access management
This commit is contained in:
parent
c5ce5414a9
commit
600464b889
@ -2,7 +2,7 @@ import Foundation
|
|||||||
import Clairvoyant
|
import Clairvoyant
|
||||||
import Vapor
|
import Vapor
|
||||||
|
|
||||||
final class Authenticator: MetricAccessAuthenticator {
|
final class Authenticator: MetricAccessManager {
|
||||||
|
|
||||||
private var writers: Set<String>
|
private var writers: Set<String>
|
||||||
|
|
||||||
@ -20,11 +20,17 @@ final class Authenticator: MetricAccessAuthenticator {
|
|||||||
writers.contains(key)
|
writers.contains(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func metricAccess(isAllowedForToken accessToken: Data) -> Bool {
|
func metricListAccess(isAllowedForToken accessToken: AccessToken) throws {
|
||||||
guard let key = String(data: accessToken, encoding: .utf8) else {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ public func configure(_ app: Application) throws {
|
|||||||
|
|
||||||
let monitor = MetricObserver(
|
let monitor = MetricObserver(
|
||||||
logFolder: config.logURL,
|
logFolder: config.logURL,
|
||||||
authenticator: authenticator,
|
accessManager: authenticator,
|
||||||
logMetricId: "caps.log")
|
logMetricId: "caps.log")
|
||||||
|
|
||||||
// All new metrics are automatically registered with the standard observer
|
// All new metrics are automatically registered with the standard observer
|
||||||
|
Loading…
Reference in New Issue
Block a user