mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-22 07:34:09 +01:00
Make Secrets Sendable. Rename Id to ID.
This commit is contained in:
parent
5b4cf235d7
commit
90311f0e70
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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 }
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user