Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

Store teamID instead of team in SigningContext

kabiroberai305131c3b7a7
diff --git a/Supersign/DeveloperServices/App Groups/DeveloperServicesAssignAppGroupsOperation.swift b/Supersign/DeveloperServices/App Groups/DeveloperServicesAssignAppGroupsOperation.swift
index ee7cacf..fba52a9 100644
--- a/Supersign/DeveloperServices/App Groups/DeveloperServicesAssignAppGroupsOperation.swift
+++ b/Supersign/DeveloperServices/App Groups/DeveloperServicesAssignAppGroupsOperation.swift
@@ -25,7 +25,7 @@ public struct DeveloperServicesAssignAppGroupsOperation: DeveloperServicesOperat
completion: @escaping (Result<DeveloperServicesAppGroup.GroupID, Swift.Error>) -> Void
) {
let request = DeveloperServicesAssignAppGroupRequest(
- platform: context.platform, teamID: context.team.id, appIDID: appID.id, groupID: group.id
+ platform: context.platform, teamID: context.teamID, appIDID: appID.id, groupID: group.id
)
context.client.send(request) { result in
guard result.get(withErrorHandler: completion) != nil else { return }
@@ -48,7 +48,7 @@ public struct DeveloperServicesAssignAppGroupsOperation: DeveloperServicesOperat
let groupID = ProvisioningIdentifiers.groupID(fromSanitized: sanitized)
let name = ProvisioningIdentifiers.groupName(fromSanitized: sanitized)
let request = DeveloperServicesAddAppGroupRequest(
- platform: context.platform, teamID: context.team.id, name: name, groupID: groupID
+ platform: context.platform, teamID: context.teamID, name: name, groupID: groupID
)
context.client.send(request) { result in
guard let group = result.get(withErrorHandler: completion) else { return }
@@ -58,7 +58,7 @@ public struct DeveloperServicesAssignAppGroupsOperation: DeveloperServicesOperat
}
public func perform(completion: @escaping (Result<[DeveloperServicesAppGroup.GroupID], Error>) -> Void) {
- let request = DeveloperServicesListAppGroupsRequest(platform: context.platform, teamID: context.team.id)
+ let request = DeveloperServicesListAppGroupsRequest(platform: context.platform, teamID: context.teamID)
context.client.send(request) { result in
guard let existingGroups = result.get(withErrorHandler: completion) else { return }
diff --git a/Supersign/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swift b/Supersign/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swift
index 90f0351..6ebbf47 100644
--- a/Supersign/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swift
+++ b/Supersign/DeveloperServices/App IDs/DeveloperServicesAddAppOperation.swift
@@ -12,15 +12,24 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
public enum Error: LocalizedError {
case invalidApp(URL)
+ case teamNotFound(DeveloperServicesTeam.ID)
public var errorDescription: String? {
switch self {
case .invalidApp(let url):
return String.localizedStringWithFormat(
NSLocalizedString(
- "app_id_request_helper.error.invalid_app", value: "Invalid app: %@", comment: ""
+ "add_app_operation.error.invalid_app", value: "Invalid app: %@", comment: ""
), url.path
)
+ case .teamNotFound(let id):
+ return String.localizedStringWithFormat(
+ NSLocalizedString(
+ "add_app_operation.error.team_not_found",
+ value: "A team with the ID '%@' could not be found. Please select another team.",
+ comment: ""
+ ), id.rawValue
+ )
}
}
}
@@ -36,9 +45,10 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
private func addOrFetchApp(
bundleID: String,
entitlements: Entitlements,
+ team: DeveloperServicesTeam,
completion: @escaping (Result<DeveloperServicesAppID, Swift.Error>) -> Void
) {
- let request = DeveloperServicesListAppIDsRequest(platform: context.platform, teamID: context.team.id)
+ let request = DeveloperServicesListAppIDsRequest(platform: context.platform, teamID: context.teamID)
context.client.send(request) { result in
guard let appIDs = result.get(withErrorHandler: completion) else { return }
if let appID = appIDs.first(where: {
@@ -46,11 +56,11 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
}) {
let request = DeveloperServicesUpdateAppIDRequest(
platform: self.context.platform,
- teamID: self.context.team.id,
+ teamID: self.context.teamID,
appIDID: appID.id,
entitlements: entitlements,
additionalFeatures: [],
- isFree: self.context.team.isFree
+ isFree: team.isFree
)
self.context.client.send(request, completion: completion)
} else {
@@ -58,12 +68,12 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
let name = ProvisioningIdentifiers.appName(fromSanitized: bundleID)
let request = DeveloperServicesAddAppIDRequest(
platform: self.context.platform,
- teamID: self.context.team.id,
+ teamID: self.context.teamID,
bundleID: newBundleID,
appName: name,
entitlements: entitlements,
additionalFeatures: [],
- isFree: self.context.team.isFree
+ isFree: team.isFree
)
self.context.client.send(request, completion: completion)
}
@@ -73,6 +83,7 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
/// Registers the app and returns the resultant entitlements
private func addAppAndGetEntitlements(
app: URL,
+ team: DeveloperServicesTeam,
// old bundle id, app id, ents
completion: @escaping (Result<(DeveloperServicesAppID, Entitlements), Swift.Error>) -> Void
) {
@@ -91,7 +102,7 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
let decodedEntitlements = try? PropertyListDecoder().decode(Entitlements.self, from: entitlementsData) {
entitlements = decodedEntitlements
- if context.team.isFree {
+ if team.isFree {
do {
// re-assign rather than using updateEntitlements since the latter will
// retain unrecognized entitlements
@@ -109,11 +120,11 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
}
}
- addOrFetchApp(bundleID: bundleID, entitlements: entitlements) { result in
+ addOrFetchApp(bundleID: bundleID, entitlements: entitlements, team: team) { result in
guard let appID = result.get(withErrorHandler: completion) else { return }
do {
- try entitlements.update(teamID: self.context.team.id, bundleID: appID.bundleID)
+ try entitlements.update(teamID: self.context.teamID, bundleID: appID.bundleID)
} catch {
return completion(.failure(error))
}
@@ -150,9 +161,10 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
/// that the app has).
private func addApp(
_ app: URL,
+ with team: DeveloperServicesTeam,
completion: @escaping (Result<ProvisioningInfo, Swift.Error>) -> Void
) {
- addAppAndGetEntitlements(app: app) { result in
+ addAppAndGetEntitlements(app: app, team: team) { result in
guard let (appID, entitlements) = result.get(withErrorHandler: completion) else { return }
DeveloperServicesFetchProfileOperation(context: self.context, appID: appID).perform { result in
guard let profile = result.get(withErrorHandler: completion) else { return }
@@ -165,8 +177,10 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
}
}
- /// Registers the app + its extensions, returning the profile and entitlements of each
- public func perform(completion: @escaping (Result<[URL: ProvisioningInfo], Swift.Error>) -> Void) {
+ private func perform(
+ with team: DeveloperServicesTeam,
+ completion: @escaping (Result<[URL: ProvisioningInfo], Swift.Error>) -> Void
+ ) {
var apps: [URL] = [root]
let plugins = root.appendingPathComponent("PlugIns")
if plugins.dirExists {
@@ -176,10 +190,21 @@ public struct DeveloperServicesAddAppOperation: DeveloperServicesOperation {
let grouper = RequestGrouper<(URL, ProvisioningInfo), Swift.Error>()
for app in apps {
grouper.add { completion in
- addApp(app) { completion($0.map { (app, $0) }) }
+ addApp(app, with: team) { completion($0.map { (app, $0) }) }
}
}
grouper.onComplete { completion($0.map(Dictionary.init(uniqueKeysWithValues:))) }
}
+ /// Registers the app + its extensions, returning the profile and entitlements of each
+ public func perform(completion: @escaping (Result<[URL: ProvisioningInfo], Swift.Error>) -> Void) {
+ let request = DeveloperServicesListTeamsRequest()
+ context.client.send(request) { result in
+ guard let teams = result.get(withErrorHandler: completion) else { return }
+ guard let team = teams.first(where: { $0.id == self.context.teamID })
+ else { return completion(.failure(Error.teamNotFound(self.context.teamID))) }
+ self.perform(with: team, completion: completion)
+ }
+ }
+
}
diff --git a/Supersign/DeveloperServices/Certificates/DeveloperServicesFetchCertificateOperation.swift b/Supersign/DeveloperServices/Certificates/DeveloperServicesFetchCertificateOperation.swift
index 7fda131..d0e67c3 100644
--- a/Supersign/DeveloperServices/Certificates/DeveloperServicesFetchCertificateOperation.swift
+++ b/Supersign/DeveloperServices/Certificates/DeveloperServicesFetchCertificateOperation.swift
@@ -17,7 +17,7 @@ public struct DeveloperServicesFetchCertificateOperation: DeveloperServicesOpera
switch self {
case .csrFailed:
return NSLocalizedString(
- "certificate_request_helper.error.csr_failed", value: "CSR request failed", comment: ""
+ "fetch_certificate_operation.error.csr_failed", value: "CSR request failed", comment: ""
)
}
}
@@ -43,7 +43,7 @@ public struct DeveloperServicesFetchCertificateOperation: DeveloperServicesOpera
let request = DeveloperServicesSubmitCSRRequest(
platform: context.platform,
- teamID: context.team.id,
+ teamID: context.teamID,
csr: csr,
machineName: context.deviceName,
machineID: context.udid
@@ -53,7 +53,7 @@ public struct DeveloperServicesFetchCertificateOperation: DeveloperServicesOpera
let serialNumber = partialCert.serialNumber
let request = DeveloperServicesListCertificatesRequest(
- teamID: self.context.team.id, certificateKind: .init(platform: self.context.platform)
+ teamID: self.context.teamID, certificateKind: .init(platform: self.context.platform)
)
self.context.client.send(request) { result in
guard let certificates = result.get(withErrorHandler: completion) else { return }
@@ -69,7 +69,7 @@ public struct DeveloperServicesFetchCertificateOperation: DeveloperServicesOpera
) {
createCertificate { result in
guard let value = result.get(withErrorHandler: completion) else { return }
- self.context.signingInfoManager[self.context.team.id] = value
+ self.context.signingInfoManager[self.context.teamID] = value
completion(.success(value))
}
}
@@ -78,7 +78,7 @@ public struct DeveloperServicesFetchCertificateOperation: DeveloperServicesOpera
certificate: DeveloperServicesCertificate,
completion: @escaping (Result<SigningInfo, Swift.Error>) -> Void
) {
- let request = DeveloperServicesRevokeCertificateRequest(teamID: context.team.id, certificateID: certificate.id)
+ let request = DeveloperServicesRevokeCertificateRequest(teamID: context.teamID, certificateID: certificate.id)
context.client.send(request) { result in
guard result.get(withErrorHandler: completion) != nil else { return }
self.createAndSaveCertificate(completion: completion)
@@ -87,7 +87,7 @@ public struct DeveloperServicesFetchCertificateOperation: DeveloperServicesOpera
public func perform(completion: @escaping (Result<SigningInfo, Swift.Error>) -> Void) {
let request = DeveloperServicesListCertificatesRequest(
- teamID: context.team.id, certificateKind: .init(platform: context.platform)
+ teamID: context.teamID, certificateKind: .init(platform: context.platform)
)
context.client.send(request) { result in
guard let certificates = result.get(withErrorHandler: completion) else { return }
@@ -96,7 +96,7 @@ public struct DeveloperServicesFetchCertificateOperation: DeveloperServicesOpera
return self.createAndSaveCertificate(completion: completion)
}
- guard let signingInfo = self.context.signingInfoManager[self.context.team.id],
+ guard let signingInfo = self.context.signingInfoManager[self.context.teamID],
let serialNumber = try? signingInfo.certificate.serialNumber(),
certificate.attributes.serialNumber.rawValue == serialNumber,
certificate.attributes.expiry > Date()
diff --git a/Supersign/DeveloperServices/Devices/DeveloperServicesFetchDeviceOperation.swift b/Supersign/DeveloperServices/Devices/DeveloperServicesFetchDeviceOperation.swift
index 00e48bd..d3e6d61 100644
--- a/Supersign/DeveloperServices/Devices/DeveloperServicesFetchDeviceOperation.swift
+++ b/Supersign/DeveloperServices/Devices/DeveloperServicesFetchDeviceOperation.swift
@@ -16,7 +16,7 @@ public struct DeveloperServicesFetchDeviceOperation: DeveloperServicesOperation
}
public func perform(completion: @escaping (Result<DeveloperServicesDevice, Error>) -> Void) {
- let request = DeveloperServicesListDevicesRequest(platform: context.platform, teamID: context.team.id)
+ let request = DeveloperServicesListDevicesRequest(platform: context.platform, teamID: context.teamID)
context.client.send(request) { result in
guard let devices = result.get(withErrorHandler: completion) else { return }
if let device = devices.first(where: { $0.udid == self.context.udid }) {
@@ -25,7 +25,7 @@ public struct DeveloperServicesFetchDeviceOperation: DeveloperServicesOperation
let addRequest = DeveloperServicesAddDeviceRequest(
platform: self.context.platform,
- teamID: self.context.team.id,
+ teamID: self.context.teamID,
udid: self.context.udid,
name: self.context.deviceName
)
diff --git a/Supersign/DeveloperServices/Profiles/DeveloperServicesFetchProfileOperation.swift b/Supersign/DeveloperServices/Profiles/DeveloperServicesFetchProfileOperation.swift
index eb58ad3..773bacc 100644
--- a/Supersign/DeveloperServices/Profiles/DeveloperServicesFetchProfileOperation.swift
+++ b/Supersign/DeveloperServices/Profiles/DeveloperServicesFetchProfileOperation.swift
@@ -22,18 +22,18 @@ public struct DeveloperServicesFetchProfileOperation: DeveloperServicesOperation
completion: @escaping (Result<DeveloperServicesProfile, Swift.Error>) -> Void
) {
let request = DeveloperServicesGetProfileRequest(
- platform: context.platform, teamID: context.team.id, appIDID: appID.id
+ platform: context.platform, teamID: context.teamID, appIDID: appID.id
)
context.client.send(request, completion: completion)
}
public func perform(completion: @escaping (Result<DeveloperServicesProfile, Error>) -> Void) {
- let request = DeveloperServicesListProfilesRequest(platform: context.platform, teamID: context.team.id)
+ let request = DeveloperServicesListProfilesRequest(platform: context.platform, teamID: context.teamID)
context.client.send(request) { result in
guard let profiles = result.get(withErrorHandler: completion) else { return }
if let profile = profiles.first(where: { $0.appID.id == self.appID.id }) {
let request = DeveloperServicesDeleteProfileRequest(
- platform: self.context.platform, teamID: self.context.team.id, profileID: profile.id
+ platform: self.context.platform, teamID: self.context.teamID, profileID: profile.id
)
self.context.client.send(request) { result in
guard result.get(withErrorHandler: completion) != nil else { return }
diff --git a/Supersign/Signer/SigningContext.swift b/Supersign/Signer/SigningContext.swift
index 96d1bce..2f90296 100644
--- a/Supersign/Signer/SigningContext.swift
+++ b/Supersign/Signer/SigningContext.swift
@@ -11,7 +11,7 @@ import Foundation
public struct SigningContext {
public let udid: String
- public let team: DeveloperServicesTeam
+ public let teamID: DeveloperServicesTeam.ID
public let client: DeveloperServicesClient
public let signingInfoManager: SigningInfoManager
public let platform: DeveloperServicesPlatform
@@ -19,14 +19,14 @@ public struct SigningContext {
public init(
udid: String,
- team: DeveloperServicesTeam,
+ teamID: DeveloperServicesTeam.ID,
client: DeveloperServicesClient,
signingInfoManager: SigningInfoManager,
platform: DeveloperServicesPlatform = .current,
signerImpl: SignerImpl? = nil
) throws {
self.udid = udid
- self.team = team
+ self.teamID = teamID
self.client = client
self.signingInfoManager = signingInfoManager
self.platform = platform
diff --git a/SupersignTests/Tests/SupersignDeveloperServicesTests.swift b/SupersignTests/Tests/SupersignDeveloperServicesTests.swift
index 33cb890..de5ad87 100644
--- a/SupersignTests/Tests/SupersignDeveloperServicesTests.swift
+++ b/SupersignTests/Tests/SupersignDeveloperServicesTests.swift
@@ -34,7 +34,7 @@ class SupersignDeveloperServicesTests: XCTestCase {
let context = try XCTTry(SigningContext(
udid: Config.current.udid,
- team: team,
+ teamID: team.id,
client: client,
signingInfoManager: TestSigningInfoManager()
))
diff --git a/SupersignTests/Tests/SupersignSigningTests.swift b/SupersignTests/Tests/SupersignSigningTests.swift
index 9102e60..ed774f6 100644
--- a/SupersignTests/Tests/SupersignSigningTests.swift
+++ b/SupersignTests/Tests/SupersignSigningTests.swift
@@ -48,7 +48,7 @@ class SupersignSigningTests: XCTestCase {
let context = try XCTTry(SigningContext(
udid: Config.current.udid,
- team: team,
+ teamID: team.id,
client: client,
signingInfoManager: TestSigningInfoManager(),
signerImpl: signerImpl