Skip to content

Commit

Permalink
Update keychain
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Nov 9, 2024
1 parent 4d43a19 commit 057d39f
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 207 deletions.
18 changes: 11 additions & 7 deletions Sources/OversizeAppStoreServices/Auth/EnvAuthenticator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
//

import AppStoreConnect
import Factory
import Foundation
import OversizeServices

public struct EnvAuthenticator: Authenticator {
private let secureStorage: KeychainService = .init()

private let storage: SecureStorageService = .init()
private var jwt: JWT

public var api: API { jwt.api }

public init(
Expand All @@ -21,16 +21,20 @@ public struct EnvAuthenticator: Authenticator {
throw Error.missingEnvironmentVariable("AppStore.Account")
}

guard let appStoreCertificate = secureStorage.getAppStoreCertificate(with: keyLabel) else {
guard let appStoreCertificate = storage.getPassword(for: "AppConnector-Certificate-" + keyLabel) else {
throw Error.missingEnvironmentVariable("AppStore.Key.Default")
}

guard let appStoreCredentials = storage.getCredentials(with: "AppConnector-" + keyLabel) else {
throw Error.missingEnvironmentVariable("AppStore.Key.Default")
}

let privateKey = try JWT.PrivateKey(pemRepresentation: appStoreCertificate.privateKey)
let privateKey = try JWT.PrivateKey(pemRepresentation: appStoreCertificate)

jwt = JWT(
api: api,
keyID: appStoreCertificate.keyId,
issuerID: appStoreCertificate.issuerId,
keyID: appStoreCredentials.password,
issuerID: appStoreCredentials.login,
expiryDuration: 20 * 60,
privateKey: privateKey
)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 4 additions & 0 deletions Sources/OversizeAppStoreServices/Models/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public extension App {
public let builds: [Build]
public let prereleaseVersions: [PrereleaseVersion]

public var appStoreVersion: AppStoreVersion? {
appStoreVersions.last
}

public var macOsAppStoreVersions: [AppStoreVersion] {
appStoreVersions.filter { $0.platform == .macOs }
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/OversizeAppStoreServices/Models/Build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public struct Build: Sendable, Identifiable, Equatable {
}
}

private func parseURL(from urlString: String) -> URL? {
func parseURL(from urlString: String) -> URL? {
if let url = URL(string: urlString), let components = URLComponents(url: url, resolvingAgainstBaseURL: true) {
if let scheme = components.scheme, let host = components.host {
if !scheme.isEmpty && !host.isEmpty {
Expand All @@ -66,7 +66,7 @@ private func parseURL(from urlString: String) -> URL? {
return nil
}

private func constructURLString(baseURL: String, width: Int, height: Int, format: String) -> String {
func constructURLString(baseURL: String, width: Int, height: Int, format: String) -> String {
let replacedURL = baseURL.replacingOccurrences(of: "{w}", with: "\(width)")
.replacingOccurrences(of: "{h}", with: "\(height)")
.replacingOccurrences(of: "{f}", with: format)
Expand Down
13 changes: 0 additions & 13 deletions Sources/OversizeAppStoreServices/Models/Typs/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,5 @@ public enum Platform: String, CaseIterable, Codable, Sendable, Identifiable {
}
}

private var title: String {
switch self {
case .ios:
return "iOS"
case .macOs:
return "macOS"
case .tvOs:
return "tvOS"
case .visionOs:
return "visionOS"
}
}

public var id: String { rawValue }
}
6 changes: 3 additions & 3 deletions Sources/OversizeAppStoreServices/ServiceRegistering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import Factory

public extension Container {
var keychainService: Factory<KeychainService> {
self { KeychainService() }
}
// var keychainService: Factory<KeychainService> {
// self { KeychainService() }
// }

var appsService: Factory<AppsService> {
self { AppsService() }
Expand Down
31 changes: 31 additions & 0 deletions Sources/OversizeAppStoreServices/Services/AppsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,37 @@ public actor AppsService {
}
}

public func fetchAppsIncludeAppStoreVersionsAndPreReleaseVersions() async -> Result<[App], AppError> {
do {
guard let client = client else {
return .failure(.network(type: .unauthorized))
}
let request = Resources.v1.apps.get(
include: [
.appStoreVersions,
.preReleaseVersions,
]
)
let result = try await client.send(request)
let apps: [App] = result.data.compactMap { schema in
let filteredIncluded = result.included?.filter { includedItem in
switch includedItem {
case let .appStoreVersion(appStoreVersion):
return schema.relationships?.appStoreVersions?.data?.first(where: { $0.id == appStoreVersion.id }) != nil
case let .prereleaseVersion(prereleaseVersion):
return schema.relationships?.preReleaseVersions?.data?.first(where: { $0.id == prereleaseVersion.id }) != nil
default:
return false
}
}
return App(schema: schema, included: filteredIncluded)
}
return .success(apps)
} catch {
return .failure(.network(type: .noResponse))
}
}

public func fetchAppsIncludeAppStoreVersionsAndBuildsAndPreReleaseVersions() async -> Result<[App], AppError> {
do {
guard let client = client else {
Expand Down
24 changes: 24 additions & 0 deletions Sources/OversizeAppStoreServices/Services/BuildsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,28 @@ public actor BuildsService {
return .failure(.network(type: .noResponse))
}
}

public func fetchAppStoreVersionsBuildImageUrl(versionId: String) async -> Result<URL?, AppError> {
guard let client = client else { return .failure(.network(type: .unauthorized)) }
let request = Resources.v1.appStoreVersions.id(versionId).build.get(
fieldsBuilds: [.iconAssetToken]
)
do {
let iconAssetToken = try await client.send(request).data.attributes?.iconAssetToken
guard let templateURL = iconAssetToken?.templateURL else {
return .success(nil)
}
let url = parseURL(
from: constructURLString(
baseURL: templateURL,
width: iconAssetToken?.width ?? 100,
height: iconAssetToken?.height ?? 100,
format: "png"
)
)
return .success(url)
} catch {
return .failure(.network(type: .noResponse))
}
}
}

0 comments on commit 057d39f

Please sign in to comment.