Skip to content

Commit

Permalink
Add support for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
tinder-calebdavis committed Jun 7, 2023
1 parent b21fc1b commit a65880b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ internal struct CreateProvisioningProfileCommand: ParsableCommand {
case opensslPath = "opensslPath"
case intermediaryAppleCertificates = "intermediaryAppleCertificates"
case certificateSigningRequestSubject = "certificateSigningRequestSubject"
case platform = "platform"
}

@Option(help: "The key identifier of the private key (https://developer.apple.com/documentation/appstoreconnectapi/generating_tokens_for_api_requests)")
Expand All @@ -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 platform to filter bundle identifiers for")
internal var platform: Platform

@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: Platform
) {
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(Platform.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
14 changes: 14 additions & 0 deletions Sources/SignHereLibrary/Models/Platform.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Platform.swift
// Models
//
// Created by Caleb Davis on 06/07/23.
//

import ArgumentParser
import Foundation

enum Platform: String, Decodable, ExpressibleByArgument {
case iOS = "IOS"
case macOS = "MAC_OS"
}
8 changes: 5 additions & 3 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: Platform
) throws -> String
func fetchITCDeviceIDs(jsonWebToken: String) throws -> Set<String>
func createProfile(
Expand Down Expand Up @@ -226,15 +227,16 @@ internal class iTunesConnectServiceImp: iTunesConnectService {
func determineBundleIdITCId(
jsonWebToken: String,
bundleIdentifier: String,
bundleIdentifierName: String?
bundleIdentifierName: String?,
platform: Platform
) throws -> String {
var urlComponents: URLComponents = .init()
urlComponents.scheme = Constants.httpsScheme
urlComponents.host = Constants.itcHost
urlComponents.path = "/v1/bundleIds"
urlComponents.queryItems = [
.init(name: "filter[identifier]", value: bundleIdentifier),
.init(name: "filter[platform]", value: "IOS"),
.init(name: "filter[platform]", value: platform.rawValue),
.init(name: "limit", value: "200")
]
guard let url: URL = urlComponents.url
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: .iOS
)
}

Expand Down
9 changes: 9 additions & 0 deletions Tests/SignHereLibraryTests/PlatformTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation
import XCTestCase

final class PlatformTests: XCTestCase {
func test_rawValue() {
XCTAssertEqual(Platform.iOS.rawValue, "IOS")
XCTAssertEqual(Platform.macOS.rawValue, "MAC_OS")
}
}
12 changes: 8 additions & 4 deletions Tests/SignHereLibraryTests/iTunesConnectServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ final class iTunesConnectServiceTests: XCTestCase {
let value: String = try subject.determineBundleIdITCId(
jsonWebToken: "jsonWebToken",
bundleIdentifier: "bundleIdentifier",
bundleIdentifierName: nil
bundleIdentifierName: nil,
platform: .iOS
)

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

// THEN
Expand All @@ -431,7 +433,8 @@ final class iTunesConnectServiceTests: XCTestCase {
XCTAssertThrowsError(try subject.determineBundleIdITCId(
jsonWebToken: "jsonWebToken",
bundleIdentifier: "bundleIdentifier",
bundleIdentifierName: "invalid"
bundleIdentifierName: "invalid",
platform: .iOS
)) {
if case iTunesConnectServiceImp.Error.unableToDetermineITCIdForBundleId = $0 {
return
Expand All @@ -458,7 +461,8 @@ final class iTunesConnectServiceTests: XCTestCase {
XCTAssertThrowsError(try subject.determineBundleIdITCId(
jsonWebToken: "jsonWebToken",
bundleIdentifier: "bundleIdentifier",
bundleIdentifierName: nil
bundleIdentifierName: nil,
platform: .iOS
)) {
if case iTunesConnectServiceImp.Error.unableToDecodeResponse = $0 {
return
Expand Down

0 comments on commit a65880b

Please sign in to comment.