From f326d2714837fe99fbf6e807061874c242d8229b Mon Sep 17 00:00:00 2001 From: Erik Doernenburg Date: Fri, 16 Aug 2024 14:59:43 +0200 Subject: [PATCH] Added logging to help diagnose issue #13. --- CCMenu/Resources/Info.plist | 4 ++-- CCMenu/Source/Miscellaneous/Keychain.swift | 10 +++++++++- .../CCTray Sheets/CCTrayPipelineBuilder.swift | 5 +++-- CCMenu/Source/Server Monitor/CCTrayAPI.swift | 7 ++++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CCMenu/Resources/Info.plist b/CCMenu/Resources/Info.plist index f869fe9..0b218e6 100644 --- a/CCMenu/Resources/Info.plist +++ b/CCMenu/Resources/Info.plist @@ -19,7 +19,7 @@ CFBundlePackageType $(PRODUCT_BUNDLE_PACKAGE_TYPE) CFBundleShortVersionString - 25.1 + 25.2d1 CFBundleURLTypes @@ -34,7 +34,7 @@ CFBundleVersion - 2251.3 + 2252.1 LSApplicationCategoryType public.app-category.developer-tools LSMinimumSystemVersion diff --git a/CCMenu/Source/Miscellaneous/Keychain.swift b/CCMenu/Source/Miscellaneous/Keychain.swift index adee6ea..06e0fd7 100644 --- a/CCMenu/Source/Miscellaneous/Keychain.swift +++ b/CCMenu/Source/Miscellaneous/Keychain.swift @@ -6,7 +6,7 @@ import Foundation import Security - +import os enum KeychainAccessError: Error { case passwordEncodingErr @@ -50,9 +50,12 @@ class Keychain { } func getPassword(forURL url: URL) throws -> String? { + let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "keychain") if let password = cache[url.absoluteString] { + logger.log("Using cached password for \(url)") return password } + logger.log("Retrieving password for \(url) from keychain") let query = [ kSecClass: kSecClassInternetPassword, kSecAttrServer: try getOrThrow(error: .missingHostErr) { url.host() }, @@ -62,6 +65,11 @@ class Keychain { kSecReturnData: true ] as NSDictionary let password = try getStringForQuery(query) + if let password { + logger.log("Got password (length = \(password.count))") + } else { + logger.log("Didn't get a password") + } cache[url.absoluteString] = password return password } diff --git a/CCMenu/Source/Pipeline Window/CCTray Sheets/CCTrayPipelineBuilder.swift b/CCMenu/Source/Pipeline Window/CCTray Sheets/CCTrayPipelineBuilder.swift index 1aa5683..e7cec56 100644 --- a/CCMenu/Source/Pipeline Window/CCTray Sheets/CCTrayPipelineBuilder.swift +++ b/CCMenu/Source/Pipeline Window/CCTray Sheets/CCTrayPipelineBuilder.swift @@ -4,8 +4,8 @@ * not use these files except in compliance with the License. */ - import Foundation +import os class CCTrayPipelineBuilder: ObservableObject { @@ -49,7 +49,8 @@ class CCTrayPipelineBuilder: ObservableObject { let newUrl = components.url?.absoluteURL ?? url try Keychain.standard.setPassword(credential.password, forURL: newUrl.absoluteString) } catch { - // TODO: Figure out what to do here – so many errors... + let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "keychain") + logger.error("Error when storing password in keychain: \(error.localizedDescription)") } } } else { diff --git a/CCMenu/Source/Server Monitor/CCTrayAPI.swift b/CCMenu/Source/Server Monitor/CCTrayAPI.swift index bce80bc..a0fd1bc 100644 --- a/CCMenu/Source/Server Monitor/CCTrayAPI.swift +++ b/CCMenu/Source/Server Monitor/CCTrayAPI.swift @@ -5,7 +5,7 @@ */ import Foundation - +import os struct HTTPCredential { var user: String @@ -19,11 +19,16 @@ struct HTTPCredential { class CCTrayAPI { static func requestForProjects(url: URL, credential: HTTPCredential?) -> URLRequest { + let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "network") var request = URLRequest(url: url) if let credential { let v = URLRequest.basicAuthValue(user: credential.user, password: credential.password) request.setValue(v, forHTTPHeaderField: "Authorization") + let redacted = v.replacingOccurrences(of: "[A-Za-z0-9=]", with: "*", options: [.regularExpression]) + logger.log("Making request for url \(url) with authorization \(redacted)") + } else { + logger.log("Making request for url \(url)") } return request