mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-18 05:21:38 +03:00
FetchDeviceOperation: account for pagination
This commit is contained in:
@@ -39,7 +39,7 @@ public struct DeveloperServicesProvisioningOperation: DeveloperServicesOperation
|
||||
|
||||
public func perform() async throws -> Response {
|
||||
progress(0/3)
|
||||
_ = try await DeveloperServicesFetchDeviceOperation(context: context).perform()
|
||||
try await DeveloperServicesAddDeviceOperation(context: context).perform()
|
||||
|
||||
progress(1/3)
|
||||
let signingInfo = try await DeveloperServicesFetchCertificateOperation(
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import Foundation
|
||||
import DeveloperAPI
|
||||
|
||||
public struct DeveloperServicesAddDeviceOperation: DeveloperServicesOperation {
|
||||
public let context: SigningContext
|
||||
public init(context: SigningContext) {
|
||||
self.context = context
|
||||
}
|
||||
|
||||
public func perform() async throws {
|
||||
guard let targetDevice = context.targetDevice else { return }
|
||||
|
||||
// try to register the device
|
||||
let response = try await context.developerAPIClient.devicesCreateInstance(
|
||||
body: .json(.init(data: .init(
|
||||
_type: .devices,
|
||||
attributes: .init(
|
||||
name: targetDevice.name,
|
||||
platform: .init(.ios),
|
||||
udid: targetDevice.udid
|
||||
)
|
||||
)))
|
||||
)
|
||||
|
||||
// we get a 409 CONFLICT if the device was already registered.
|
||||
// handle this by returning gracefully.
|
||||
if (try? response.conflict) != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// otherwise, we should get a 201 CREATED to indicate that the device
|
||||
// was added. any other case is unexpected, and this will throw.
|
||||
_ = try response.created
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
//
|
||||
// DeveloperServicesFetchDeviceOperation.swift
|
||||
// XKit
|
||||
//
|
||||
// Created by Kabir Oberai on 13/10/19.
|
||||
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import DeveloperAPI
|
||||
|
||||
public struct DeveloperServicesFetchDeviceOperation: DeveloperServicesOperation {
|
||||
public let context: SigningContext
|
||||
public init(context: SigningContext) {
|
||||
self.context = context
|
||||
}
|
||||
|
||||
public func perform() async throws -> Components.Schemas.Device {
|
||||
let devices = try await context.developerAPIClient.devicesGetCollection().ok.body.json.data
|
||||
|
||||
if let device = devices.first(where: { $0.attributes?.udid == self.context.udid }) {
|
||||
return device
|
||||
}
|
||||
|
||||
let response = try await context.developerAPIClient.devicesCreateInstance(
|
||||
body: .json(.init(data: .init(
|
||||
_type: .devices,
|
||||
attributes: .init(
|
||||
name: self.context.deviceName,
|
||||
platform: .init(.ios),
|
||||
udid: self.context.udid
|
||||
)
|
||||
)))
|
||||
)
|
||||
|
||||
return try response.created.body.json.data
|
||||
}
|
||||
|
||||
}
|
||||
@@ -270,9 +270,8 @@ public actor IntegratedInstaller {
|
||||
try await updateProgress(to: 1)
|
||||
|
||||
let context = try SigningContext(
|
||||
udid: udid,
|
||||
deviceName: deviceName,
|
||||
auth: auth
|
||||
auth: auth,
|
||||
targetDevice: .init(udid: udid, name: deviceName)
|
||||
)
|
||||
|
||||
let signer = AutoSigner(context: context) { certs in
|
||||
|
||||
@@ -11,24 +11,26 @@ import DeveloperAPI
|
||||
|
||||
public struct SigningContext: Sendable {
|
||||
|
||||
public let udid: String
|
||||
public let deviceName: String
|
||||
public let auth: DeveloperAPIAuthData
|
||||
public let signer: Signer
|
||||
public struct TargetDevice: Sendable, Hashable {
|
||||
public var udid: String
|
||||
public var name: String
|
||||
}
|
||||
|
||||
public var auth: DeveloperAPIAuthData
|
||||
public var targetDevice: TargetDevice?
|
||||
public var signer: Signer
|
||||
|
||||
public var developerAPIClient: DeveloperAPIClient {
|
||||
DeveloperAPIClient(auth: auth)
|
||||
}
|
||||
|
||||
public init(
|
||||
udid: String,
|
||||
deviceName: String,
|
||||
auth: DeveloperAPIAuthData,
|
||||
targetDevice: TargetDevice? = nil,
|
||||
signer: Signer? = nil
|
||||
) throws {
|
||||
self.udid = udid
|
||||
self.deviceName = deviceName
|
||||
self.auth = auth
|
||||
self.targetDevice = targetDevice
|
||||
self.signer = try signer ?? .first()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user