Reduce footprint of Account credentials API
This commit is contained in:
parent
2756e8f204
commit
1ac1144b2d
|
@ -295,34 +295,40 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func retrieveBasicCredentials() throws -> Credentials? {
|
public func retrieveCredentials() throws -> Credentials? {
|
||||||
|
switch type {
|
||||||
|
case .feedbin:
|
||||||
guard let username = self.username, let server = delegate.server else {
|
guard let username = self.username, let server = delegate.server else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return try CredentialsManager.retrieveBasicCredentials(server: server, username: username)
|
return try CredentialsManager.retrieveBasicCredentials(server: server, username: username)
|
||||||
|
case .freshRSS:
|
||||||
|
guard let username = self.username, let server = delegate.server else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return try CredentialsManager.retrieveReaderAPIAuthCredentials(server: server, username: username)
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func removeBasicCredentials() throws {
|
public func removeCredentials() throws {
|
||||||
|
switch type {
|
||||||
|
case .feedbin:
|
||||||
guard let username = self.username, let server = delegate.server else {
|
guard let username = self.username, let server = delegate.server else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try CredentialsManager.removeBasicCredentials(server: server, username: username)
|
try CredentialsManager.removeBasicCredentials(server: server, username: username)
|
||||||
self.username = nil
|
self.username = nil
|
||||||
}
|
case .freshRSS:
|
||||||
|
|
||||||
public func retrieveReaderAPIAuthCredentials() throws -> Credentials? {
|
|
||||||
guard let username = self.username, let server = delegate.server else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return try CredentialsManager.retrieveReaderAPIAuthCredentials(server: server, username: username)
|
|
||||||
}
|
|
||||||
|
|
||||||
public func removeReaderAPIAuthCredentials() throws {
|
|
||||||
guard let username = self.username, let server = delegate.server else {
|
guard let username = self.username, let server = delegate.server else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try CredentialsManager.removeReaderAPIAuthCredentials(server: server, username: username)
|
try CredentialsManager.removeReaderAPIAuthCredentials(server: server, username: username)
|
||||||
self.username = nil
|
self.username = nil
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func validateCredentials(transport: Transport = URLSession.webserviceTransport(), type: AccountType, credentials: Credentials, endpoint: URL? = nil, completion: @escaping (Result<Credentials?, Error>) -> Void) {
|
public static func validateCredentials(transport: Transport = URLSession.webserviceTransport(), type: AccountType, credentials: Credentials, endpoint: URL? = nil, completion: @escaping (Result<Credentials?, Error>) -> Void) {
|
||||||
|
|
|
@ -510,7 +510,7 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
func accountDidInitialize(_ account: Account) {
|
func accountDidInitialize(_ account: Account) {
|
||||||
credentials = try? account.retrieveBasicCredentials()
|
credentials = try? account.retrieveCredentials()
|
||||||
accountMetadata = account.metadata
|
accountMetadata = account.metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -411,7 +411,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||||
|
|
||||||
func accountDidInitialize(_ account: Account) {
|
func accountDidInitialize(_ account: Account) {
|
||||||
accountMetadata = account.metadata
|
accountMetadata = account.metadata
|
||||||
credentials = try? account.retrieveReaderAPIAuthCredentials()
|
credentials = try? account.retrieveCredentials()
|
||||||
}
|
}
|
||||||
|
|
||||||
static func validateCredentials(transport: Transport, credentials: Credentials, endpoint: URL?, completion: @escaping (Result<Credentials?, Error>) -> Void) {
|
static func validateCredentials(transport: Transport, credentials: Credentials, endpoint: URL?, completion: @escaping (Result<Credentials?, Error>) -> Void) {
|
||||||
|
|
|
@ -27,10 +27,9 @@ class AccountsFeedbinWindowController: NSWindowController {
|
||||||
}
|
}
|
||||||
|
|
||||||
override func windowDidLoad() {
|
override func windowDidLoad() {
|
||||||
if let account = account, let credentials = try? account.retrieveBasicCredentials() {
|
if let account = account, let credentials = try? account.retrieveCredentials() {
|
||||||
if case .basic(let username, let password) = credentials {
|
if case .basic(let username, _) = credentials {
|
||||||
usernameTextField.stringValue = username
|
usernameTextField.stringValue = username
|
||||||
passwordTextField.stringValue = password
|
|
||||||
}
|
}
|
||||||
actionButton.title = NSLocalizedString("Update", comment: "Update")
|
actionButton.title = NSLocalizedString("Update", comment: "Update")
|
||||||
} else {
|
} else {
|
||||||
|
@ -87,7 +86,7 @@ class AccountsFeedbinWindowController: NSWindowController {
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try self.account?.removeBasicCredentials()
|
try self.account?.removeCredentials()
|
||||||
try self.account?.storeCredentials(validatedCredentials)
|
try self.account?.storeCredentials(validatedCredentials)
|
||||||
if newAccount {
|
if newAccount {
|
||||||
self.account?.refreshAll() { result in
|
self.account?.refreshAll() { result in
|
||||||
|
|
|
@ -42,10 +42,9 @@ class AccountsReaderAPIWindowController: NSWindowController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let account = account, let credentials = try? account.retrieveBasicCredentials() {
|
if let account = account, let credentials = try? account.retrieveCredentials() {
|
||||||
if case .basic(let username, let password) = credentials {
|
if case .basic(let username, _) = credentials {
|
||||||
usernameTextField.stringValue = username
|
usernameTextField.stringValue = username
|
||||||
passwordTextField.stringValue = password
|
|
||||||
}
|
}
|
||||||
actionButton.title = NSLocalizedString("Update", comment: "Update")
|
actionButton.title = NSLocalizedString("Update", comment: "Update")
|
||||||
} else {
|
} else {
|
||||||
|
@ -110,7 +109,7 @@ class AccountsReaderAPIWindowController: NSWindowController {
|
||||||
do {
|
do {
|
||||||
self.account?.endpointURL = apiURL
|
self.account?.endpointURL = apiURL
|
||||||
|
|
||||||
try self.account?.removeReaderAPIAuthCredentials()
|
try self.account?.removeCredentials()
|
||||||
try self.account?.storeCredentials(validatedCredentials)
|
try self.account?.storeCredentials(validatedCredentials)
|
||||||
|
|
||||||
if newAccount {
|
if newAccount {
|
||||||
|
|
Loading…
Reference in New Issue