Modern Apps git

← xtool.git

More DS data

Commit
fb80c3b525e43b4c548fac306f62e0b21e5b6104
Author
Kabir Oberai <[email protected]>
When
2024-12-30 21:30 UTC (1 year ago)
Parents
6222518

Diff

Sources/SupersignCLISupport/DSCommands/DSCertificatesCommand.swift
diff --git a/Sources/SupersignCLISupport/DSCommands/DSCertificatesCommand.swift b/Sources/SupersignCLISupport/DSCommands/DSCertificatesCommand.swiftindex eb6a55b..69e4b2a 100644--- a/Sources/SupersignCLISupport/DSCommands/DSCertificatesCommand.swift+++ b/Sources/SupersignCLISupport/DSCommands/DSCertificatesCommand.swift@@ -53,8 +53,11 @@ struct DSCertificatesListCommand: AsyncParsableCommand {                 print("  expiry: \(expirationDate.formatted(.dateTime))")             } -            if let contentString = attributes.certificateContent,-               let content = Data(base64Encoded: contentString) {+            if let contentString = attributes.certificateContent {+                guard let content = Data(base64Encoded: contentString) else {+                    print("  content: error: bad base64")+                    continue+                }                 do {                     let certificate = try Certificate(data: content)                     print("  content:")
Sources/SupersignCLISupport/DSCommands/DSCommand.swift
diff --git a/Sources/SupersignCLISupport/DSCommands/DSCommand.swift b/Sources/SupersignCLISupport/DSCommands/DSCommand.swiftindex 02e1ac9..3246516 100644--- a/Sources/SupersignCLISupport/DSCommands/DSCommand.swift+++ b/Sources/SupersignCLISupport/DSCommands/DSCommand.swift@@ -55,8 +55,10 @@ struct DSCommand: AsyncParsableCommand {         abstract: "Interact with Apple Developer Services",         subcommands: [             DSTeamsCommand.self,-            DSIdentifiersCommand.self,             DSCertificatesCommand.self,+            DSIdentifiersCommand.self,+            DSDevicesCommand.self,+            DSProfilesCommand.self,             DSAnisetteCommand.self,         ]     )
Sources/SupersignCLISupport/DSCommands/DSDevicesCommand.swift
diff --git a/Sources/SupersignCLISupport/DSCommands/DSDevicesCommand.swift b/Sources/SupersignCLISupport/DSCommands/DSDevicesCommand.swiftnew file mode 100644index 0000000..4e76d61--- /dev/null+++ b/Sources/SupersignCLISupport/DSCommands/DSDevicesCommand.swift@@ -0,0 +1,61 @@+import Foundation+import ArgumentParser+import Supersign+import DeveloperAPI++struct DSDevicesCommand: AsyncParsableCommand {+    static let configuration = CommandConfiguration(+        commandName: "devices",+        abstract: "Interact with devices",+        subcommands: [+            DSDevicesListCommand.self,+        ],+        defaultSubcommand: DSDevicesListCommand.self+    )+}++struct DSDevicesListCommand: AsyncParsableCommand {+    static let configuration = CommandConfiguration(+        commandName: "list",+        abstract: "List devices"+    )++    func run() async throws {+        let client = DeveloperAPIClient(auth: try AuthToken.saved().authData())+        let devices = try await client.devicesGetCollection().ok.body.json.data+        for device in devices {+            print("- id: \(device.id)")+            guard let attributes = device.attributes else {+                continue+            }++            if let name = attributes.name {+                print("  name: \(name)")+            }++            if let platform = attributes.platform {+                print("  platform: \(platform.rawValue)")+            }++            if let udid = attributes.udid {+                print("  udid: \(udid)")+            }++            if let deviceClass = attributes.deviceClass {+                print("  device class: \(deviceClass.rawValue)")+            }++            if let status = attributes.status {+                print("  status: \(status.rawValue)")+            }++            if let model = attributes.model {+                print("  model: \(model)")+            }++            if let addedDate = attributes.addedDate {+                print("  added date: \(addedDate.formatted(.dateTime))")+            }+        }+    }+}
Sources/SupersignCLISupport/DSCommands/DSProfilesCommand.swift
diff --git a/Sources/SupersignCLISupport/DSCommands/DSProfilesCommand.swift b/Sources/SupersignCLISupport/DSCommands/DSProfilesCommand.swiftnew file mode 100644index 0000000..e37559b--- /dev/null+++ b/Sources/SupersignCLISupport/DSCommands/DSProfilesCommand.swift@@ -0,0 +1,100 @@+import Foundation+import ArgumentParser+import Supersign+import DeveloperAPI++struct DSProfilesCommand: AsyncParsableCommand {+    static let configuration = CommandConfiguration(+        commandName: "profiles",+        abstract: "Interact with profiles",+        subcommands: [+            DSProfilesListCommand.self,+        ],+        defaultSubcommand: DSProfilesListCommand.self+    )+}++struct DSProfilesListCommand: AsyncParsableCommand {+    static let configuration = CommandConfiguration(+        commandName: "list",+        abstract: "List profiles"+    )++    private static let encoder = JSONEncoder()++    func run() async throws {+        let client = DeveloperAPIClient(auth: try AuthToken.saved().authData())+        let profiles = try await client.profilesGetCollection().ok.body.json.data+        for profile in profiles {+            print("- id: \(profile.id)")+            guard let attributes = profile.attributes else {+                continue+            }++            ///   - name:+            ///   - platform:+            ///   - profileType:+            ///   - profileState:+            ///   - profileContent:+            ///   - uuid:+            ///   - createdDate:+            ///   - expirationDate:++            if let name = attributes.name {+                print("  name: \(name)")+            }++            if let platform = attributes.platform {+                print("  platform: \(platform.rawValue)")+            }++            if let profileType = attributes.profileType {+                print("  profile type: \(profileType.rawValue)")+            }++            if let profileState = attributes.profileState {+                print("  profile state: \(profileState.rawValue)")+            }++            if let uuid = attributes.uuid {+                print("  uuid: \(uuid)")+            }++            if let createdDate = attributes.createdDate {+                print("  created date: \(createdDate.formatted(.dateTime))")+            }++            if let expirationDate = attributes.expirationDate {+                print("  expiration date: \(expirationDate.formatted(.dateTime))")+            }++            if let contentString = attributes.profileContent {+                guard let contentData = Data(base64Encoded: contentString) else {+                    print("  content: error: bad base64")+                    continue+                }++                do {+                    let profile = try Mobileprovision(data: contentData)+                    let digest = try profile.digest()+                    print("    team identifiers:")+                    for teamID in digest.teamIdentifiers {+                        print("      - \(teamID.rawValue)")+                    }+                    print("    certificates:")+                    for certificate in digest.certificates {+                        print("      - \(certificate.serialNumber())")+                    }+                    print("    devices:")+                    for device in digest.devices {+                        print("      - \(device)")+                    }+                    let entitlements = try? String(decoding: Self.encoder.encode(digest.entitlements), as: UTF8.self)+                    print("    entitlements: \(entitlements ?? "<error>")")+                } catch {+                    print("  content: error: \(error)")+                }+            }+        }+    }+}