Make Secrets Sendable. Rename Id to ID.

This commit is contained in:
Brent Simmons 2024-07-07 12:14:14 -07:00
parent 5b4cf235d7
commit 90311f0e70
5 changed files with 24 additions and 26 deletions

View File

@ -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

View File

@ -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)

View File

@ -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")
}
}

View File

@ -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 }
}

View File

@ -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)
}