Add meaningful prefix to keychain entries (#724)

Hard to find in keychain, add "Passepartout: " prefix to profile name.
This commit is contained in:
Davide 2024-10-11 00:31:32 +02:00 committed by GitHub
parent a0b9529870
commit 9449a02b77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 32 additions and 13 deletions

View File

@ -31,12 +31,15 @@ import PassepartoutKit
public final class NEProfileRepository: ProfileRepository {
private let repository: NETunnelManagerRepository
private let title: (Profile) -> String
private let profilesSubject: CurrentValueSubject<[Profile], Never>
private var subscription: AnyCancellable?
public init(repository: NETunnelManagerRepository) {
public init(repository: NETunnelManagerRepository, title: @escaping (Profile) -> String) {
self.repository = repository
self.title = title
profilesSubject = CurrentValueSubject([])
subscription = repository
@ -62,7 +65,7 @@ public final class NEProfileRepository: ProfileRepository {
}
public func saveProfile(_ profile: Profile) async throws {
try await repository.save(profile, connect: false, title: \.name)
try await repository.save(profile, connect: false, title: title)
}
public func removeProfiles(withIds profileIds: [Profile.ID]) async throws {

View File

@ -28,9 +28,15 @@ import PassepartoutKit
@MainActor
public final class ProfileProcessor: ObservableObject {
public let process: (Profile) throws -> Profile
public let title: (Profile) -> String
public init(process: @escaping (Profile) throws -> Profile) {
self.process = process
public let processed: (Profile) throws -> Profile
public init(
title: @escaping (Profile) -> String,
processed: @escaping (Profile) throws -> Profile
) {
self.title = title
self.processed = processed
}
}

View File

@ -30,13 +30,13 @@ import PassepartoutKit
@MainActor
extension Tunnel {
func install(_ profile: Profile, processor: ProfileProcessor) async throws {
let newProfile = try processor.process(profile)
try await install(newProfile, connect: false, title: \.name)
let newProfile = try processor.processed(profile)
try await install(newProfile, connect: false, title: processor.title)
}
func connect(with profile: Profile, processor: ProfileProcessor) async throws {
let newProfile = try processor.process(profile)
try await install(newProfile, connect: true, title: \.name)
let newProfile = try processor.processed(profile)
try await install(newProfile, connect: true, title: processor.title)
}
func currentLog(parameters: Constants.Log) async -> [String] {

View File

@ -55,6 +55,8 @@ extension AppContext {
return ProfileManager(profiles: profiles)
}(),
profileProcessor: ProfileProcessor {
"Passepartout.Mock: \($0.name)"
} processed: {
try $0.withProviderModules()
},
tunnel: Tunnel(strategy: FakeTunnelStrategy(environment: env)),

View File

@ -118,7 +118,9 @@ extension IAPManager {
}
extension ProfileProcessor {
static let shared = ProfileProcessor { profile in
static let shared = ProfileProcessor {
sharedProfileTitle($0)
} processed: { profile in
var builder = profile.builder()
// suppress on-demand rules if not eligible
@ -155,7 +157,7 @@ extension Tunnel {
)
}
private var localProfileRepository: any ProfileRepository {
private var localProfileRepository: ProfileRepository {
let store = CoreDataPersistentStore(
logger: .default,
containerName: Constants.shared.containers.local,
@ -182,8 +184,10 @@ extension Tunnel {
)
}
private var localProfileRepository: any ProfileRepository {
NEProfileRepository(repository: neRepository)
private var localProfileRepository: ProfileRepository {
NEProfileRepository(repository: neRepository) {
sharedProfileTitle($0)
}
}
private var neRepository: NETunnelManagerRepository {
@ -208,6 +212,10 @@ extension ProviderFactory {
// MARK: -
private let sharedProfileTitle: (Profile) -> String = {
"Passepartout: \($0.name)"
}
extension CoreDataPersistentStoreLogger where Self == DefaultCoreDataPersistentStoreLogger {
static var `default`: CoreDataPersistentStoreLogger {
DefaultCoreDataPersistentStoreLogger()