Skip to content
Snippets Groups Projects
SFTPService.swift 1.61 KiB
Newer Older
import Models
import Foundation

public typealias SFTPAuthParams = (String, String, String)
public typealias SFTPFetchResult = (Result<RestoreSettings?, Error>) -> Void
public typealias SFTPFetchParams = (SFTPAuthParams, SFTPFetchResult)

Bruno Muniz's avatar
Bruno Muniz committed
public struct SFTPService {
    public var isAuthorized: () -> Bool
    public var fetch: (SFTPFetchParams) -> Void
    public var justAuthenticate: (SFTPAuthParams) -> Void
Bruno Muniz's avatar
Bruno Muniz committed
}

public extension SFTPService {
    static var mock = SFTPService(
        isAuthorized: {
            false
        },
        fetch: { (authParams, completion) in
            print("^^^ RestoreSFTP Host: \(authParams.0)")
            print("^^^ RestoreSFTP Username: \(authParams.1)")
            print("^^^ RestoreSFTP Password: \(authParams.2)")

            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
                completion(.success(.init(
                    backup: .init(id: "ASDF", date: Date.distantPast, size: 100_000_000),
                    cloudService: .sftp
                )))
            }
        },
        justAuthenticate: { host, username, password in
            // TODO: Store these params on the keychain
        })

Bruno Muniz's avatar
Bruno Muniz committed
    static var live = SFTPService(
        isAuthorized: {
            /// If it has host/username/password on keychain
            /// means its authorized, not that is working
            ///
Bruno Muniz's avatar
Bruno Muniz committed
            true
        },
        fetch: { (authParams, completion) in
            // TODO: Store host/username/password on keychain
        },
        justAuthenticate: { host, username, password in
            // TODO: Store host/username/password on keychain
Bruno Muniz's avatar
Bruno Muniz committed
        }
    )
}