Skip to content

Commit

Permalink
Merge pull request #9 from tinder-cwybranowski/cwybranowski/add-platform
Browse files Browse the repository at this point in the history
Add Platform Option
  • Loading branch information
tinder-maxwellelliott authored Oct 11, 2023
2 parents d7af7f7 + 3428713 commit 99f4a1d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand {
case keychainPassword = "keychainPassword"
case bundleIdentifier = "bundleIdentifier"
case bundleIdentifierName = "bundleIdentifierName"
case platform = "platform"
case profileType = "profileType"
case certificateType = "certificateType"
case outputPath = "outputPath"
Expand Down Expand Up @@ -146,6 +147,9 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand {
@Option(help: "The bundle identifier name for the desired bundle identifier, this is optional but if it is not set the logic will select the first bundle id it finds that matches `--bundle-identifier`")
internal var bundleIdentifierName: String?

@Option(help: "The intended operating system for the target (https://developer.apple.com/documentation/appstoreconnectapi/bundleidplatform)")
internal var platform: String

@Option(help: "The profile type which you wish to create (https://developer.apple.com/documentation/appstoreconnectapi/profilecreaterequest/data/attributes)")
internal var profileType: String

Expand Down Expand Up @@ -218,7 +222,8 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand {
opensslPath: String,
intermediaryAppleCertificates: [String],
certificateSigningRequestSubject: String,
bundleIdentifierName: String?
bundleIdentifierName: String?,
platform: String
) {
self.files = files
self.log = log
Expand All @@ -240,6 +245,7 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand {
self.intermediaryAppleCertificates = intermediaryAppleCertificates
self.certificateSigningRequestSubject = certificateSigningRequestSubject
self.bundleIdentifierName = bundleIdentifierName
self.platform = platform
}

internal init(from decoder: Decoder) throws {
Expand Down Expand Up @@ -272,7 +278,8 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand {
opensslPath: try container.decode(String.self, forKey: .opensslPath),
intermediaryAppleCertificates: try container.decodeIfPresent([String].self, forKey: .intermediaryAppleCertificates) ?? [],
certificateSigningRequestSubject: try container.decode(String.self, forKey: .certificateSigningRequestSubject),
bundleIdentifierName: try container.decodeIfPresent(String.self, forKey: .bundleIdentifierName)
bundleIdentifierName: try container.decodeIfPresent(String.self, forKey: .bundleIdentifierName),
platform: try container.decode(String.self, forKey: .platform)
)
}

Expand Down Expand Up @@ -303,7 +310,8 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand {
bundleId: try iTunesConnectService.determineBundleIdITCId(
jsonWebToken: jsonWebToken,
bundleIdentifier: bundleIdentifier,
bundleIdentifierName: bundleIdentifierName
bundleIdentifierName: bundleIdentifierName,
platform: platform
),
certificateId: certificateId,
deviceIDs: deviceIDs,
Expand Down
24 changes: 16 additions & 8 deletions Sources/SignHereLibrary/Services/iTunesConnectService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ internal protocol iTunesConnectService {
func determineBundleIdITCId(
jsonWebToken: String,
bundleIdentifier: String,
bundleIdentifierName: String?
bundleIdentifierName: String?,
platform: String
) throws -> String
func fetchITCDeviceIDs(jsonWebToken: String) throws -> Set<String>
func createProfile(
Expand All @@ -46,7 +47,7 @@ internal class iTunesConnectServiceImp: iTunesConnectService {
enum Error: Swift.Error, CustomStringConvertible {
case invalidURL(string: String)
case unableToCreateURL(urlComponents: URLComponents)
case unableToDetermineITCIdForBundleId(bundleIdentifier: String)
case unableToDetermineITCIdForBundleId(bundleIdentifier: String, platform: String)
case unableToDetermineModulusForCertificate(output: ShellOutput)
case unableToDetermineModulusForPrivateKey(privateKeyPath: String, output: ShellOutput)
case unableToBase64DecodeCertificate(displayName: String)
Expand All @@ -64,10 +65,11 @@ internal class iTunesConnectServiceImp: iTunesConnectService {
return """
[iTunesConnectServiceImp] Unable to create url for itunes connect request from url components: \(urlComponents.description)
"""
case let .unableToDetermineITCIdForBundleId(bundleIdentifier: bundleIdentifier):
case let .unableToDetermineITCIdForBundleId(bundleIdentifier: bundleIdentifier, platform: platform):
return """
[iTunesConnectServiceImp] Unable to determine iTunesConnect API ID for bundle identifier
- Bundle Identifier: \(bundleIdentifier)
- Platform: \(platform)
"""
case let .unableToDetermineModulusForCertificate(output: output):
return """
Expand Down Expand Up @@ -226,7 +228,8 @@ internal class iTunesConnectServiceImp: iTunesConnectService {
func determineBundleIdITCId(
jsonWebToken: String,
bundleIdentifier: String,
bundleIdentifierName: String?
bundleIdentifierName: String?,
platform: String
) throws -> String {
var urlComponents: URLComponents = .init()
urlComponents.scheme = Constants.httpsScheme
Expand All @@ -250,20 +253,22 @@ internal class iTunesConnectServiceImp: iTunesConnectService {
return try makeFirstITCIdForBundleId(
data: data,
bundleIdentifier: bundleIdentifier,
bundleIdentifierName: bundleIdentifierName
bundleIdentifierName: bundleIdentifierName,
platform: platform
)
}

private func makeFirstITCIdForBundleId(
data: Data,
bundleIdentifier: String,
bundleIdentifierName: String?
bundleIdentifierName: String?,
platform: String
) throws -> String {
do {
let listBundleIDsResponse: ListBundleIDsResponse = try createITCApiJSONDecoder().decode(ListBundleIDsResponse.self, from: data)
guard let bundleIdITCId: String = listBundleIDsResponse.data.compactMap({ bundleData in
guard bundleData.attributes.identifier == bundleIdentifier,
bundleData.attributes.platform == "IOS"
bundleData.attributes.platform == platform
else {
return nil
}
Expand All @@ -276,7 +281,10 @@ internal class iTunesConnectServiceImp: iTunesConnectService {
return bundleData.id
}).first
else {
throw Error.unableToDetermineITCIdForBundleId(bundleIdentifier: bundleIdentifier)
throw Error.unableToDetermineITCIdForBundleId(
bundleIdentifier: bundleIdentifier,
platform: platform
)
}
return bundleIdITCId
} catch let decodingError as DecodingError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ final class CreateProvisioningProfileCommandTests: XCTestCase {
opensslPath: "/opensslPath",
intermediaryAppleCertificates: ["/intermediaryAppleCertificate"],
certificateSigningRequestSubject: "certificateSigningRequestSubject",
bundleIdentifierName: "bundleIdentifierName"
bundleIdentifierName: "bundleIdentifierName",
platform: "platform"
)
isRecording = false
}
Expand Down Expand Up @@ -158,7 +159,8 @@ final class CreateProvisioningProfileCommandTests: XCTestCase {
"outputPath": "/outputPath",
"opensslPath": "/opensslPath",
"certificateSigningRequestSubject": "certificateSigningRequestSubject",
"bundleIdentifierName": "bundleIdentifierName"
"bundleIdentifierName": "bundleIdentifierName",
"platform": "platform"
}
""".utf8)

Expand All @@ -177,6 +179,7 @@ final class CreateProvisioningProfileCommandTests: XCTestCase {
XCTAssertEqual(subject.certificateType, "certificateType")
XCTAssertEqual(subject.outputPath, "/outputPath")
XCTAssertEqual(subject.bundleIdentifierName, "bundleIdentifierName")
XCTAssertEqual(subject.platform, "platform")
}

func test_execute_alreadyActiveCertificate() throws {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[iTunesConnectServiceImp] Unable to determine iTunesConnect API ID for bundle identifier
- Bundle Identifier: bundleIdentifier
- Bundle Identifier: bundleIdentifier
- Platform: platform
37 changes: 23 additions & 14 deletions Tests/SignHereLibraryTests/iTunesConnectServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ final class iTunesConnectServiceTests: XCTestCase {
func testErrors() {
assertSnapshot(
matching: iTunesConnectServiceImp.Error.unableToDetermineITCIdForBundleId(
bundleIdentifier: "bundleIdentifier"
bundleIdentifier: "bundleIdentifier",
platform: "platform"
).description,
as: .lines
)
Expand Down Expand Up @@ -383,7 +384,8 @@ final class iTunesConnectServiceTests: XCTestCase {
let value: String = try subject.determineBundleIdITCId(
jsonWebToken: "jsonWebToken",
bundleIdentifier: "bundleIdentifier",
bundleIdentifierName: nil
bundleIdentifierName: nil,
platform: "platform"
)

// THEN
Expand All @@ -407,7 +409,8 @@ final class iTunesConnectServiceTests: XCTestCase {
let value: String = try subject.determineBundleIdITCId(
jsonWebToken: "jsonWebToken",
bundleIdentifier: "bundleIdentifier",
bundleIdentifierName: "name"
bundleIdentifierName: "name",
platform: "platform"
)

// THEN
Expand All @@ -428,11 +431,14 @@ final class iTunesConnectServiceTests: XCTestCase {
}

// WHEN
XCTAssertThrowsError(try subject.determineBundleIdITCId(
jsonWebToken: "jsonWebToken",
bundleIdentifier: "bundleIdentifier",
bundleIdentifierName: "invalid"
)) {
XCTAssertThrowsError(
try subject.determineBundleIdITCId(
jsonWebToken: "jsonWebToken",
bundleIdentifier: "bundleIdentifier",
bundleIdentifierName: "invalid",
platform: "platform"
)
) {
if case iTunesConnectServiceImp.Error.unableToDetermineITCIdForBundleId = $0 {
return
}
Expand All @@ -455,11 +461,14 @@ final class iTunesConnectServiceTests: XCTestCase {
}

// WHEN
XCTAssertThrowsError(try subject.determineBundleIdITCId(
jsonWebToken: "jsonWebToken",
bundleIdentifier: "bundleIdentifier",
bundleIdentifierName: nil
)) {
XCTAssertThrowsError(
try subject.determineBundleIdITCId(
jsonWebToken: "jsonWebToken",
bundleIdentifier: "bundleIdentifier",
bundleIdentifierName: nil,
platform: "platform"
)
) {
if case iTunesConnectServiceImp.Error.unableToDecodeResponse = $0 {
return
}
Expand Down Expand Up @@ -757,7 +766,7 @@ final class iTunesConnectServiceTests: XCTestCase {
attributes: ListBundleIDsResponse.BundleId.Attributes(
name: "name",
identifier: "bundleIdentifier",
platform: "IOS"
platform: "platform"
)
)
]
Expand Down

0 comments on commit 99f4a1d

Please sign in to comment.