xtool.git
Publicgit clone https://git.maproj.org/xtool.gitxtool.git / Sources / XKit / DeveloperServices / App IDs / Entitlements / EntitlementWithTeamOrBundleID.swift
EntitlementWithTeamOrBundleID.swift46 lines · 1.5 KiBRaw
| 1 | // |
| 2 | // EntitlementWithTeamOrBundleID.swift |
| 3 | // XKit |
| 4 | // |
| 5 | // Created by Kabir Oberai on 12/10/19. |
| 6 | // Copyright © 2019 Kabir Oberai. All rights reserved. |
| 7 | // |
| 8 | |
| 9 | import Foundation |
| 10 | |
| 11 | protocol EntitlementWithTeamOrBundleID: Entitlement { |
| 12 | init(teamID: DeveloperServicesTeam.ID, bundleID: String) |
| 13 | } |
| 14 | |
| 15 | extension ApplicationIdentifierEntitlement: EntitlementWithTeamOrBundleID { |
| 16 | init(teamID: DeveloperServicesTeam.ID, bundleID: String) { |
| 17 | self.rawValue = "\(teamID.rawValue).\(bundleID)" |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | extension TeamIdentifierEntitlement: EntitlementWithTeamOrBundleID { |
| 22 | init(teamID: DeveloperServicesTeam.ID, bundleID: String) { |
| 23 | self.rawValue = teamID.rawValue |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | extension KeychainAccessGroupsEntitlement: EntitlementWithTeamOrBundleID { |
| 28 | init(teamID: DeveloperServicesTeam.ID, bundleID: String) { |
| 29 | rawValue = ["\(teamID.rawValue).\(bundleID)"] |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | extension Entitlements { |
| 34 | |
| 35 | public mutating func update(teamID: DeveloperServicesTeam.ID, bundleID: String) throws { |
| 36 | let teamOrBundleIDTypes = EntitlementContainer.supportedTypes |
| 37 | .compactMap { $0 as? EntitlementWithTeamOrBundleID.Type } |
| 38 | let teamOrBundleIDSet = Set(teamOrBundleIDTypes.map(ObjectIdentifier.init)) |
| 39 | |
| 40 | try updateEntitlements { entitlements in |
| 41 | entitlements.removeAll { teamOrBundleIDSet.contains(ObjectIdentifier(type(of: $0))) } |
| 42 | entitlements += teamOrBundleIDTypes.map { $0.init(teamID: teamID, bundleID: bundleID) } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | } |