Skip to content

Commit

Permalink
Add optional profileName parameter to create-provisioning-profile sub…
Browse files Browse the repository at this point in the history
…command
  • Loading branch information
andres97medrano committed Jan 24, 2024
1 parent b4426cc commit 7a78066
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
)
}

Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions Sources/SignHereLibrary/Services/iTunesConnectService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ internal protocol iTunesConnectService {
bundleId: String,
certificateId: String,
deviceIDs: Set<String>,
profileType: String
profileType: String,
profileName: String?
) throws -> CreateProfileResponse
func deleteProvisioningProfile(
jsonWebToken: String,
Expand Down Expand Up @@ -352,7 +353,8 @@ internal class iTunesConnectServiceImp: iTunesConnectService {
bundleId: String,
certificateId: String,
deviceIDs: Set<String>,
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)
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ final class CreateProvisioningProfileCommandTests: XCTestCase {
intermediaryAppleCertificates: ["/intermediaryAppleCertificate"],
certificateSigningRequestSubject: "certificateSigningRequestSubject",
bundleIdentifierName: "bundleIdentifierName",
platform: "platform"
platform: "platform",
profileName: "profileName"
)
isRecording = false
}
Expand Down Expand Up @@ -210,7 +211,7 @@ final class CreateProvisioningProfileCommandTests: XCTestCase {
iTunesConnectService.createCertificateHandler = { _, _, _ in
self.createCreateCertificateResponse()
}
iTunesConnectService.createProfileHandler = { _, _, _, _, _ in
iTunesConnectService.createProfileHandler = { _, _, _, _, _, _ in
self.createCreateProfileResponse()
}

Expand Down Expand Up @@ -253,7 +254,7 @@ final class CreateProvisioningProfileCommandTests: XCTestCase {
iTunesConnectService.createCertificateHandler = { _, _, _ in
self.createCreateCertificateResponse()
}
iTunesConnectService.createProfileHandler = { _, _, _, _, _ in
iTunesConnectService.createProfileHandler = { _, _, _, _, _, _ in
self.createCreateProfileResponse()
}

Expand Down
9 changes: 6 additions & 3 deletions Tests/SignHereLibraryTests/iTunesConnectServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,8 @@ final class iTunesConnectServiceTests: XCTestCase {
bundleId: "bundleId",
certificateId: "certificateId",
deviceIDs: .init(["deviceId"]),
profileType: "profileType"
profileType: "profileType",
profileName: "profileName"
)

// THEN
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7a78066

Please sign in to comment.