mirror of
https://github.com/xtool-org/xtool.git
synced 2026-02-04 11:53:30 +01:00
We pull the list of App IDs in `upsertApp` to see if we already created the App ID. This broke when the user had too many App IDs, since DS returned a paginated response and we only looked at the first page. We could paginate the whole list (as seen in #89) but that's slow. Instead, just filter the query to the expected App ID. This is a prefix search so we might still receive multiple responses, but it's much less likely that the user has like 10(? I'm not sure what the default/max pagination limit is) apps registered with the XTL-ABC.com.foo.bar prefix (they could have PlugIns but usually just a small number of them.) This is a tentative fix for #87.
52 lines
1.7 KiB
Swift
52 lines
1.7 KiB
Swift
//
|
|
// ProvisioningIdentifiers.swift
|
|
// XKit
|
|
//
|
|
// Created by Kabir Oberai on 14/10/19.
|
|
// Copyright © 2019 Kabir Oberai. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
enum ProvisioningIdentifiers {}
|
|
|
|
extension ProvisioningIdentifiers {
|
|
|
|
static let idPrefix = "XTL-"
|
|
static let groupPrefix = "group."
|
|
static let namePrefix = "XTool "
|
|
|
|
static func sanitize(identifier: String) -> String {
|
|
guard identifier.hasPrefix(Self.idPrefix) else { return identifier }
|
|
return identifier.split(separator: ".").dropFirst().joined(separator: ".")
|
|
}
|
|
|
|
static func identifier(fromSanitized sanitized: String, context: SigningContext) -> String {
|
|
let uuid = context.auth.identityID.split(separator: "-")[0].uppercased()
|
|
return "\(Self.idPrefix)\(uuid).\(sanitized)"
|
|
}
|
|
|
|
static func safeify(identifier: String) -> String {
|
|
identifier.replacingOccurrences(of: ".", with: " ")
|
|
}
|
|
|
|
static func sanitize(groupID: DeveloperServicesAppGroup.GroupID) -> String {
|
|
var id = groupID.rawValue
|
|
if id.hasPrefix(Self.groupPrefix) { id.removeFirst(Self.groupPrefix.count) }
|
|
return sanitize(identifier: id)
|
|
}
|
|
|
|
static func groupID(fromSanitized sanitized: String, context: SigningContext) -> DeveloperServicesAppGroup.GroupID {
|
|
.init(rawValue: "\(Self.groupPrefix)\(identifier(fromSanitized: sanitized, context: context))")
|
|
}
|
|
|
|
static func groupName(fromSanitized sanitized: String) -> String {
|
|
"\(Self.namePrefix)group \(safeify(identifier: sanitized))"
|
|
}
|
|
|
|
static func appName(fromSanitized sanitized: String) -> String {
|
|
"\(Self.namePrefix)\(safeify(identifier: sanitized))"
|
|
}
|
|
|
|
}
|