Skip to content

Commit

Permalink
Fixed build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tobihagemann committed Jan 2, 2025
1 parent d76c000 commit afec091
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 39 deletions.
16 changes: 6 additions & 10 deletions Cryptomator/Common/CloudAccountList/AccountListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class AccountListViewModel: AccountListViewModelProtocol {
}
}

// swiftlint:disable:next cyclomatic_complexity
func createAccountCellContent(from accountInfo: AccountInfo) throws -> AccountCellContent {
switch cloudProviderType {
case .box:
Expand All @@ -87,10 +88,7 @@ class AccountListViewModel: AccountListViewModelProtocol {
case .localFileSystem:
throw AccountListError.unsupportedCloudProviderType
case .oneDrive:
let credential = try OneDriveCredential(with: accountInfo.accountUID)
return try createAccountCellContent(for: credential)
case .sharePoint:
let credential = try SharePointCredential(with: accountInfo.accountUID)
let credential = MicrosoftGraphCredential.createForOneDrive(with: accountInfo.accountUID)
return try createAccountCellContent(for: credential)
case .pCloud:
return createAccountCellContentPlaceholder()
Expand All @@ -100,6 +98,9 @@ class AccountListViewModel: AccountListViewModelProtocol {
}
let displayName = try S3CredentialManager.shared.getDisplayName(for: credential)
return createAccountCellContent(for: credential, displayName: displayName)
case .sharePoint:
let credential = MicrosoftGraphCredential.createForSharePoint(with: accountInfo.accountUID)
return try createAccountCellContent(for: credential)
case .webDAV:
guard let credential = WebDAVCredentialManager.shared.getCredentialFromKeychain(with: accountInfo.accountUID) else {
throw CloudProviderAccountError.accountNotFoundError
Expand All @@ -123,12 +124,7 @@ class AccountListViewModel: AccountListViewModelProtocol {
return AccountCellContent(mainLabelText: username, detailLabelText: nil)
}

func createAccountCellContent(for credential: OneDriveCredential) throws -> AccountCellContent {
let username = try credential.getUsername()
return AccountCellContent(mainLabelText: username, detailLabelText: nil)
}

func createAccountCellContent(for credential: SharePointCredential) throws -> AccountCellContent {
func createAccountCellContent(for credential: MicrosoftGraphCredential) throws -> AccountCellContent {
let username = try credential.getUsername()
return AccountCellContent(mainLabelText: username, detailLabelText: nil)
}
Expand Down
25 changes: 13 additions & 12 deletions Cryptomator/Common/CloudAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ class CloudAuthenticator {
}
}

func authenticateMicrosoftGraph(from viewController: UIViewController, providerType: CloudProviderType) -> Promise<CloudProviderAccount> {
return MicrosoftGraphAuthenticator.authenticate(from: viewController, for: providerType).then { credential -> CloudProviderAccount in
let account = CloudProviderAccount(accountUID: credential.identifier, cloudProviderType: providerType)
func authenticateOneDrive(from viewController: UIViewController) -> Promise<CloudProviderAccount> {
return MicrosoftGraphAuthenticator.authenticateForOneDrive(from: viewController).then { credential -> CloudProviderAccount in
let account = CloudProviderAccount(accountUID: credential.identifier, cloudProviderType: .oneDrive)
try self.accountManager.saveNewAccount(account)
return account
}
}

func authenticateOneDrive(from viewController: UIViewController) -> Promise<CloudProviderAccount> {
return authenticateMicrosoftGraph(from: viewController, providerType: .oneDrive)
}

func authenticateSharePoint(from viewController: UIViewController) -> Promise<CloudProviderAccount> {
return authenticateMicrosoftGraph(from: viewController, providerType: .sharePoint)
return MicrosoftGraphAuthenticator.authenticateForSharePoint(from: viewController).then { credential -> CloudProviderAccount in
let account = CloudProviderAccount(accountUID: credential.identifier, cloudProviderType: .sharePoint)
try self.accountManager.saveNewAccount(account)
return account
}
}

func authenticatePCloud(from viewController: UIViewController) -> Promise<CloudProviderAccount> {
Expand Down Expand Up @@ -120,6 +120,7 @@ class CloudAuthenticator {
}
}

// swiftlint:disable:next cyclomatic_complexity
func deauthenticate(account: CloudProviderAccount) throws {
switch account.cloudProviderType {
case .box:
Expand All @@ -135,16 +136,16 @@ class CloudAuthenticator {
case .localFileSystem:
break
case .oneDrive:
let credential = try OneDriveCredential(with: account.accountUID)
try credential.deauthenticate()
case .sharePoint:
let credential = try SharePointCredential(with: account.accountUID)
let credential = MicrosoftGraphCredential.createForOneDrive(with: account.accountUID)
try credential.deauthenticate()
case .pCloud:
let credential = try PCloudCredential(userID: account.accountUID)
try credential.deauthenticate()
case .s3:
try S3CredentialManager.shared.removeCredential(with: account.accountUID)
case .sharePoint:
let credential = MicrosoftGraphCredential.createForSharePoint(with: account.accountUID)
try credential.deauthenticate()
case .webDAV:
try WebDAVCredentialManager.shared.removeCredentialFromKeychain(with: account.accountUID)
}
Expand Down
11 changes: 6 additions & 5 deletions Cryptomator/VaultDetail/VaultDetailInfoFooterViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class VaultDetailInfoFooterViewModel: BindableAttributedTextHeaderFooterViewMode
return String(format: LocalizedString.getValue("vaultDetail.info.footer.accountInfo"), username, vault.cloudProviderType.localizedString()) + " "
}

// swiftlint:disable:next cyclomatic_complexity
func getUsername() -> String? {
switch vault.cloudProviderType {
case .box:
Expand All @@ -59,22 +60,22 @@ class VaultDetailInfoFooterViewModel: BindableAttributedTextHeaderFooterViewMode
case .localFileSystem:
return nil
case .oneDrive:
let credential = try? OneDriveCredential(with: vault.delegateAccountUID)
return try? credential?.getUsername()
let credential = MicrosoftGraphCredential.createForOneDrive(with: vault.delegateAccountUID)
return try? credential.getUsername()
case .pCloud:
guard let credential = try? PCloudCredential(userID: vault.delegateAccountUID) else {
return nil
}
getUsername(for: credential)
return "(…)"
case .sharePoint:
let credential = try? SharePointCredential(with: vault.delegateAccountUID)
return try? credential?.getUsername()
case .s3:
guard let displayName = try? S3CredentialManager.shared.getDisplayName(for: vault.delegateAccountUID) else {
return nil
}
return displayName
case .sharePoint:
let credential = MicrosoftGraphCredential.createForSharePoint(with: vault.delegateAccountUID)
return try? credential.getUsername()
case .webDAV:
let credential = WebDAVCredentialManager.shared.getCredentialFromKeychain(with: vault.delegateAccountUID)
return credential?.username
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ public class CloudProviderDBManager: CloudProviderManager, CloudProviderUpdating
}
provider = try LocalFileSystemProvider(rootURL: rootURL, maxPageSize: .max)
case .oneDrive:
let credential = try OneDriveCredential(with: accountUID)
provider = try OneDriveCloudProvider(credential: credential, maxPageSize: .max)
case .sharePoint:
let credential = try SharePointCredential(with: accountUID)
let credential = MicrosoftGraphCredential.createForOneDrive(with: accountUID)
provider = try MicrosoftGraphCloudProvider(credential: credential, maxPageSize: .max)
case .pCloud:
let credential = try PCloudCredential(userID: accountUID)
Expand All @@ -90,6 +87,9 @@ public class CloudProviderDBManager: CloudProviderManager, CloudProviderUpdating
case .s3:
let credential = try getS3Credential(for: accountUID)
provider = try S3CloudProvider(credential: credential)
case .sharePoint:
let credential = MicrosoftGraphCredential.createForSharePoint(with: accountUID)
provider = try MicrosoftGraphCloudProvider(credential: credential, maxPageSize: .max)
case .webDAV:
let credential = try getWebDAVCredential(for: accountUID)
let client = WebDAVClient(credential: credential)
Expand Down Expand Up @@ -132,18 +132,18 @@ public class CloudProviderDBManager: CloudProviderManager, CloudProviderUpdating
}
provider = try LocalFileSystemProvider(rootURL: rootURL, maxPageSize: maxPageSizeForFileProvider)
case .oneDrive:
let credential = try OneDriveCredential(with: accountUID)
provider = try OneDriveCloudProvider.withBackgroundSession(credential: credential, maxPageSize: maxPageSizeForFileProvider, sessionIdentifier: sessionIdentifier)
case .sharePoint:
let credential = try SharePointCredential(with: accountUID)
provider = try OneDriveCloudProvider.withBackgroundSession(credential: credential, maxPageSize: maxPageSizeForFileProvider, sessionIdentifier: sessionIdentifier)
let credential = MicrosoftGraphCredential.createForOneDrive(with: accountUID)
provider = try MicrosoftGraphCloudProvider.withBackgroundSession(credential: credential, maxPageSize: maxPageSizeForFileProvider, sessionIdentifier: sessionIdentifier)
case .pCloud:
let credential = try PCloudCredential(userID: accountUID)
let client = PCloud.createBackgroundClient(with: credential.user, sessionIdentifier: sessionIdentifier)
provider = try PCloudCloudProvider(client: client)
case .s3:
let credential = try getS3Credential(for: accountUID)
provider = try S3CloudProvider.withBackgroundSession(credential: credential, sharedContainerIdentifier: CryptomatorConstants.appGroupName)
case .sharePoint:
let credential = MicrosoftGraphCredential.createForSharePoint(with: accountUID)
provider = try MicrosoftGraphCloudProvider.withBackgroundSession(credential: credential, maxPageSize: maxPageSizeForFileProvider, sessionIdentifier: sessionIdentifier)
case .webDAV:
let credential = try getWebDAVCredential(for: accountUID)
let client = WebDAVClient.withBackgroundSession(credential: credential, sessionIdentifier: sessionIdentifier, sharedContainerIdentifier: CryptomatorConstants.appGroupName)
Expand Down
6 changes: 3 additions & 3 deletions fastlane/scripts/create-cloud-access-secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public enum CloudAccessSecrets {
public static let googleDriveClientId = "${GOOGLE_DRIVE_CLIENT_ID}"
public static let googleDriveRedirectURLScheme = "${GOOGLE_DRIVE_REDIRECT_URL_SCHEME}"
public static let googleDriveRedirectURL = URL(string: "${GOOGLE_DRIVE_REDIRECT_URL_SCHEME}:/oauthredirect")
public static let oneDriveClientId = "${ONEDRIVE_CLIENT_ID}"
public static let oneDriveRedirectURIScheme = "${ONEDRIVE_REDIRECT_URI_SCHEME}"
public static let oneDriveRedirectURI = "${ONEDRIVE_REDIRECT_URI_SCHEME}://auth"
public static let microsoftGraphClientId = "${MICROSOFT_GRAPH_CLIENT_ID}"
public static let microsoftGraphRedirectURIScheme = "${MICROSOFT_GRAPH_REDIRECT_URI_SCHEME}"
public static let microsoftGraphRedirectURI = "${MICROSOFT_GRAPH_REDIRECT_URI_SCHEME}://auth"
public static let pCloudAppKey = "${PCLOUD_APP_KEY}"
}
EOM

0 comments on commit afec091

Please sign in to comment.