Add meaningful prefix to keychain entries (#724)
Hard to find in keychain, add "Passepartout: " prefix to profile name.
This commit is contained in:
parent
a0b9529870
commit
9449a02b77
|
@ -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 {
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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] {
|
||||||
|
|
|
@ -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)),
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue