diff --git a/Sources/SignHereLibrary/Commands/CreateProvisioningProfileCommand.swift b/Sources/SignHereLibrary/Commands/CreateProvisioningProfileCommand.swift index ad8b25b..d82c7dc 100644 --- a/Sources/SignHereLibrary/Commands/CreateProvisioningProfileCommand.swift +++ b/Sources/SignHereLibrary/Commands/CreateProvisioningProfileCommand.swift @@ -121,6 +121,7 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand { case opensslPath = "opensslPath" case intermediaryAppleCertificates = "intermediaryAppleCertificates" case certificateSigningRequestSubject = "certificateSigningRequestSubject" + case profileName = "profileName" } @Option(help: "The key identifier of the private key (https://developer.apple.com/documentation/appstoreconnectapi/generating_tokens_for_api_requests)") @@ -165,6 +166,9 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand { @Option(help: "Intermediary Apple Certificates that should also be added to the keychain (https://www.apple.com/certificateauthority/)") internal var intermediaryAppleCertificates: [String] = [] + @Option(help: "The name that you would like to assign to the created provisioning profile (optional)") + internal var profileName: String? + @Option(help: """ Subject for the Certificate Signing Request when creating certificates. @@ -223,7 +227,8 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand { intermediaryAppleCertificates: [String], certificateSigningRequestSubject: String, bundleIdentifierName: String?, - platform: String + platform: String, + profileName: String? ) { self.files = files self.log = log @@ -246,6 +251,7 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand { self.certificateSigningRequestSubject = certificateSigningRequestSubject self.bundleIdentifierName = bundleIdentifierName self.platform = platform + self.profileName = profileName } internal init(from decoder: Decoder) throws { @@ -279,7 +285,8 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand { intermediaryAppleCertificates: try container.decodeIfPresent([String].self, forKey: .intermediaryAppleCertificates) ?? [], certificateSigningRequestSubject: try container.decode(String.self, forKey: .certificateSigningRequestSubject), bundleIdentifierName: try container.decodeIfPresent(String.self, forKey: .bundleIdentifierName), - platform: try container.decode(String.self, forKey: .platform) + platform: try container.decode(String.self, forKey: .platform), + profileName: try container.decode(String.self, forKey: .profileName) ) } @@ -315,7 +322,8 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand { ), certificateId: certificateId, deviceIDs: deviceIDs, - profileType: profileType + profileType: profileType, + profileName: profileName ) guard let profileData: Data = .init(base64Encoded: profileResponse.data.attributes.profileContent) else { diff --git a/Sources/SignHereLibrary/Services/iTunesConnectService.swift b/Sources/SignHereLibrary/Services/iTunesConnectService.swift index 68e3337..4180f1b 100644 --- a/Sources/SignHereLibrary/Services/iTunesConnectService.swift +++ b/Sources/SignHereLibrary/Services/iTunesConnectService.swift @@ -35,7 +35,8 @@ internal protocol iTunesConnectService { bundleId: String, certificateId: String, deviceIDs: Set, - profileType: String + profileType: String, + profileName: String? ) throws -> CreateProfileResponse func deleteProvisioningProfile( jsonWebToken: String, @@ -352,7 +353,8 @@ internal class iTunesConnectServiceImp: iTunesConnectService { bundleId: String, certificateId: String, deviceIDs: Set, - profileType: String + profileType: String, + profileName: String? = nil ) throws -> CreateProfileResponse { let urlString: String = "https://api.appstoreconnect.apple.com/v1/profiles" guard let url: URL = .init(string: urlString) @@ -364,7 +366,7 @@ internal class iTunesConnectServiceImp: iTunesConnectService { request.setValue(Constants.applicationJSONHeaderValue, forHTTPHeaderField: Constants.contentTypeHeaderName) request.setValue("Bearer \(jsonWebToken)", forHTTPHeaderField: "Authorization") request.httpMethod = "POST" - let profileName: String = "\(certificateId)_\(profileType)_\(clock.now().timeIntervalSince1970)" + let profileName = profileName ?? "\(certificateId)_\(profileType)_\(clock.now().timeIntervalSince1970)" var devices: CreateProfileRequest.CreateProfileRequestData.Relationships.Devices? = nil // ME: App Store profiles cannot use UDIDs if !["IOS_APP_STORE", "MAC_APP_STORE", "TVOS_APP_STORE", "MAC_CATALYST_APP_STORE"].contains(profileType) { diff --git a/Tests/SignHereLibraryTests/CreateProvisioningProfileCommandTests.swift b/Tests/SignHereLibraryTests/CreateProvisioningProfileCommandTests.swift index 0974396..6ca9190 100644 --- a/Tests/SignHereLibraryTests/CreateProvisioningProfileCommandTests.swift +++ b/Tests/SignHereLibraryTests/CreateProvisioningProfileCommandTests.swift @@ -56,7 +56,8 @@ final class CreateProvisioningProfileCommandTests: XCTestCase { intermediaryAppleCertificates: ["/intermediaryAppleCertificate"], certificateSigningRequestSubject: "certificateSigningRequestSubject", bundleIdentifierName: "bundleIdentifierName", - platform: "platform" + platform: "platform", + profileName: "profileName" ) isRecording = false } @@ -210,7 +211,7 @@ final class CreateProvisioningProfileCommandTests: XCTestCase { iTunesConnectService.createCertificateHandler = { _, _, _ in self.createCreateCertificateResponse() } - iTunesConnectService.createProfileHandler = { _, _, _, _, _ in + iTunesConnectService.createProfileHandler = { _, _, _, _, _, _ in self.createCreateProfileResponse() } @@ -253,7 +254,7 @@ final class CreateProvisioningProfileCommandTests: XCTestCase { iTunesConnectService.createCertificateHandler = { _, _, _ in self.createCreateCertificateResponse() } - iTunesConnectService.createProfileHandler = { _, _, _, _, _ in + iTunesConnectService.createProfileHandler = { _, _, _, _, _, _ in self.createCreateProfileResponse() } diff --git a/Tests/SignHereLibraryTests/iTunesConnectServiceTests.swift b/Tests/SignHereLibraryTests/iTunesConnectServiceTests.swift index 08a10da..26e0dea 100644 --- a/Tests/SignHereLibraryTests/iTunesConnectServiceTests.swift +++ b/Tests/SignHereLibraryTests/iTunesConnectServiceTests.swift @@ -567,7 +567,8 @@ final class iTunesConnectServiceTests: XCTestCase { bundleId: "bundleId", certificateId: "certificateId", deviceIDs: .init(["deviceId"]), - profileType: "profileType" + profileType: "profileType", + profileName: "profileName" ) // THEN @@ -596,7 +597,8 @@ final class iTunesConnectServiceTests: XCTestCase { bundleId: "bundleId", certificateId: "certificateId", deviceIDs: .init(["deviceId"]), - profileType: "IOS_APP_STORE" + profileType: "IOS_APP_STORE", + profileName: "profileName" ) // THEN @@ -624,7 +626,8 @@ final class iTunesConnectServiceTests: XCTestCase { bundleId: "bundleId", certificateId: "certificateId", deviceIDs: .init(["deviceId"]), - profileType: "profileType" + profileType: "profileType", + profileName: "profileName" )) { if case iTunesConnectServiceImp.Error.unableToDecodeResponse = $0 { return