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 {
|
||||
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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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] {
|
||||
|
|
|
@ -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)),
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue