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 { public final class NEProfileRepository: ProfileRepository {
private let repository: NETunnelManagerRepository private let repository: NETunnelManagerRepository
private let title: (Profile) -> String
private let profilesSubject: CurrentValueSubject<[Profile], Never> private let profilesSubject: CurrentValueSubject<[Profile], Never>
private var subscription: AnyCancellable? private var subscription: AnyCancellable?
public init(repository: NETunnelManagerRepository) { public init(repository: NETunnelManagerRepository, title: @escaping (Profile) -> String) {
self.repository = repository self.repository = repository
self.title = title
profilesSubject = CurrentValueSubject([]) profilesSubject = CurrentValueSubject([])
subscription = repository subscription = repository
@ -62,7 +65,7 @@ public final class NEProfileRepository: ProfileRepository {
} }
public func saveProfile(_ profile: Profile) async throws { 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 { public func removeProfiles(withIds profileIds: [Profile.ID]) async throws {

View File

@ -28,9 +28,15 @@ import PassepartoutKit
@MainActor @MainActor
public final class ProfileProcessor: ObservableObject { public final class ProfileProcessor: ObservableObject {
public let process: (Profile) throws -> Profile public let title: (Profile) -> String
public init(process: @escaping (Profile) throws -> Profile) { public let processed: (Profile) throws -> Profile
self.process = process
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 @MainActor
extension Tunnel { extension Tunnel {
func install(_ profile: Profile, processor: ProfileProcessor) async throws { func install(_ profile: Profile, processor: ProfileProcessor) async throws {
let newProfile = try processor.process(profile) let newProfile = try processor.processed(profile)
try await install(newProfile, connect: false, title: \.name) try await install(newProfile, connect: false, title: processor.title)
} }
func connect(with profile: Profile, processor: ProfileProcessor) async throws { func connect(with profile: Profile, processor: ProfileProcessor) async throws {
let newProfile = try processor.process(profile) let newProfile = try processor.processed(profile)
try await install(newProfile, connect: true, title: \.name) try await install(newProfile, connect: true, title: processor.title)
} }
func currentLog(parameters: Constants.Log) async -> [String] { func currentLog(parameters: Constants.Log) async -> [String] {

View File

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

View File

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