Skip to content

Commit

Permalink
Added logging to help diagnose issue #13.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdoe committed Aug 16, 2024
1 parent 69c8259 commit f326d27
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions CCMenu/Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>25.1</string>
<string>25.2d1</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand All @@ -34,7 +34,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>2251.3</string>
<string>2252.1</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
Expand Down
10 changes: 9 additions & 1 deletion CCMenu/Source/Miscellaneous/Keychain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import Foundation
import Security

import os

enum KeychainAccessError: Error {
case passwordEncodingErr
Expand Down Expand Up @@ -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() },
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* not use these files except in compliance with the License.
*/


import Foundation
import os

class CCTrayPipelineBuilder: ObservableObject {

Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion CCMenu/Source/Server Monitor/CCTrayAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import Foundation

import os

struct HTTPCredential {
var user: String
Expand All @@ -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
Expand Down

0 comments on commit f326d27

Please sign in to comment.