diff --git a/Mac/MainWindow/MainWindowController.swift b/Mac/MainWindow/MainWindowController.swift index 5d0c2aee0..8ad54b745 100644 --- a/Mac/MainWindow/MainWindowController.swift +++ b/Mac/MainWindow/MainWindowController.swift @@ -1278,7 +1278,7 @@ private extension MainWindowController { func startArticleExtractorForCurrentLink() { let secrets = Secrets() - if let link = currentLink, let extractor = ArticleExtractor(link, clientID: secrets.mercuryClientId, clientSecret: secrets.mercuryClientSecret) { + if let link = currentLink, let extractor = ArticleExtractor(link, clientID: secrets.mercuryClientID, clientSecret: secrets.mercuryClientSecret) { extractor.delegate = self extractor.process() articleExtractor = extractor diff --git a/Modules/Feedly/Sources/Feedly/OAuth/OAuthAuthorizationClient+Feedly.swift b/Modules/Feedly/Sources/Feedly/OAuth/OAuthAuthorizationClient+Feedly.swift index e45bf92f4..d3e85217a 100644 --- a/Modules/Feedly/Sources/Feedly/OAuth/OAuthAuthorizationClient+Feedly.swift +++ b/Modules/Feedly/Sources/Feedly/OAuth/OAuthAuthorizationClient+Feedly.swift @@ -15,7 +15,7 @@ public extension OAuthAuthorizationClient { /// Models private NetNewsWire client secrets. /// These placeholders are substituted at build time using a Run Script phase with build settings. /// https://developer.feedly.com/v3/auth/#authenticating-a-user-and-obtaining-an-auth-code - return OAuthAuthorizationClient(id: secretsProvider.feedlyClientId, + return OAuthAuthorizationClient(id: secretsProvider.feedlyClientID, redirectURI: "netnewswire://auth/feedly", state: nil, secret: secretsProvider.feedlyClientSecret) diff --git a/Modules/ReaderAPI/Sources/ReaderAPI/ReaderAPICaller.swift b/Modules/ReaderAPI/Sources/ReaderAPI/ReaderAPICaller.swift index 3a1adc01f..492a8b115 100644 --- a/Modules/ReaderAPI/Sources/ReaderAPI/ReaderAPICaller.swift +++ b/Modules/ReaderAPI/Sources/ReaderAPI/ReaderAPICaller.swift @@ -543,7 +543,7 @@ private extension ReaderAPICaller { func addVariantHeaders(_ request: inout URLRequest) { if variant == .inoreader { - request.addValue(secretsProvider.inoreaderAppId, forHTTPHeaderField: "AppId") + request.addValue(secretsProvider.inoreaderAppID, forHTTPHeaderField: "AppId") request.addValue(secretsProvider.inoreaderAppKey, forHTTPHeaderField: "AppKey") } } diff --git a/Modules/Secrets/Sources/Secrets/SecretsProvider.swift b/Modules/Secrets/Sources/Secrets/SecretsProvider.swift index 26ed84410..0c15dd336 100644 --- a/Modules/Secrets/Sources/Secrets/SecretsProvider.swift +++ b/Modules/Secrets/Sources/Secrets/SecretsProvider.swift @@ -8,10 +8,10 @@ import Foundation public protocol SecretsProvider { - var mercuryClientId: String { get } + var mercuryClientID: String { get } var mercuryClientSecret: String { get } - var feedlyClientId: String { get } + var feedlyClientID: String { get } var feedlyClientSecret: String { get } - var inoreaderAppId: String { get } + var inoreaderAppID: String { get } var inoreaderAppKey: String { get } } diff --git a/Shared/Secrets.swift.gyb b/Shared/Secrets.swift.gyb index 6333296d1..235963f7a 100644 --- a/Shared/Secrets.swift.gyb +++ b/Shared/Secrets.swift.gyb @@ -13,39 +13,37 @@ def encode(string, salt): def snake_to_camel(snake_str): components = snake_str.split('_') - return components[0].lower() + ''.join(x.title() for x in components[1:]) + components = [components[0].lower()] + [x.title() if x != 'ID' else x for x in components[1:]] + camel_case_str = ''.join(components) + return camel_case_str salt = [byte for byte in os.urandom(64)] }% import Secrets -public final class Secrets: SecretsProvider { +public final class Secrets: SecretsProvider, Sendable { % for secret in secrets: - public lazy var ${snake_to_camel(secret)}: String = { + public let ${snake_to_camel(secret)}: String = { let encoded: [UInt8] = [ % for chunk in chunks(encode(os.environ.get(secret) or "", salt), 8): ${"".join(["0x%02x, " % byte for byte in chunk])} % end ] - return decode(encoded, salt: salt) + return decode(encoded) }() % end - - %{ - # custom example: static let myVariable = "${os.environ.get('MY_CUSTOM_VARIABLE')}" - }% - - private let salt: [UInt8] = [ - % for chunk in chunks(salt, 8): - ${"".join(["0x%02x, " % byte for byte in chunk])} - % end - ] - - private func decode(_ encoded: [UInt8], salt: [UInt8]) -> String { - String(decoding: encoded.enumerated().map { (offset, element) in - element ^ salt[offset % salt.count] - }, as: UTF8.self) - } +} + +private let salt: [UInt8] = [ +% for chunk in chunks(salt, 8): + ${"".join(["0x%02x, " % byte for byte in chunk])} +% end +] + +private func decode(_ encoded: [UInt8]) -> String { + String(decoding: encoded.enumerated().map { (offset, element) in + element ^ salt[offset % salt.count] + }, as: UTF8.self) }