Skip to content

Commit 7a06604

Browse files
authored
feat: Add maintenance key to configuration (#195)
* feat: Add maintenance key to configuration * nits * nit * test live query
1 parent 157401b commit 7a06604

10 files changed

+215
-134
lines changed

.github/pull_request_template.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
Thanks for contributing to Parse-Swift!
66
-->
77

8-
- [ ] I am not disclosing a [vulnerability](https://github.com/netreconlab/Parse-Swift/security/policy).
9-
- [ ] I am creating this PR in reference to an [issue](https://github.com/netreconlab/Parse-Swift/issues?q=is%3Aissue).
8+
- Disclose a [vulnerability](https://github.com/netreconlab/Parse-Swift/security/policy).
9+
- Link this PR to an [issue](https://github.com/netreconlab/Parse-Swift/issues?q=is%3Aissue).
1010

1111
### Issue Description
1212
<!-- Add a brief description of the issue this PR solves. -->
1313

14+
Closes: FILL_THIS_OUT
15+
1416
### Approach
1517
<!-- Add a description of the approach in this PR. -->
1618

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
# Parse-Swift Changelog
33

44
### main
5-
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.11.5...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
5+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.12.0...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
66
* _Contributing to this repo? Add info about your change here to be included in the next release_
77

8+
### 5.12.0
9+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.11.5...5.12.0), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.12.0/documentation/parseswift)
10+
11+
__New features__
12+
* Add maintenance key that can be used on server-side ([#194](https://github.com/netreconlab/Parse-Swift/pull/194)), thanks to [Corey Baker](https://github.com/cbaker6).
13+
814
### 5.11.5
915
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.11.4...5.11.5), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.11.5/documentation/parseswift)
1016

Sources/ParseSwift/API/API.swift

+18-11
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ public struct API {
141141
/// Options available to send to Parse Server.
142142
public enum Option: Hashable, Sendable {
143143

144+
/// Use the maintenanceKey if it was provided during initial configuraration.
145+
case useMaintenanceKey
144146
/// Use the primaryKey/masterKey if it was provided during initial configuraration.
145147
case usePrimaryKey
146148
/// Use a specific session token.
@@ -178,34 +180,37 @@ public struct API {
178180
// swiftlint:disable:next cyclomatic_complexity
179181
public func hash(into hasher: inout Hasher) {
180182
switch self {
181-
case .usePrimaryKey:
183+
case .useMaintenanceKey:
182184
hasher.combine(1)
183-
case .sessionToken:
185+
case .usePrimaryKey:
184186
hasher.combine(2)
185-
case .installationId:
187+
case .sessionToken:
186188
hasher.combine(3)
187-
case .mimeType:
189+
case .installationId:
188190
hasher.combine(4)
189-
case .fileSize:
191+
case .mimeType:
190192
hasher.combine(5)
191-
case .removeMimeType:
193+
case .fileSize:
192194
hasher.combine(6)
193-
case .metadata:
195+
case .removeMimeType:
194196
hasher.combine(7)
195-
case .tags:
197+
case .metadata:
196198
hasher.combine(8)
197-
case .context:
199+
case .tags:
198200
hasher.combine(9)
199-
case .cachePolicy:
201+
case .context:
200202
hasher.combine(10)
201-
case .serverURL:
203+
case .cachePolicy:
202204
hasher.combine(11)
205+
case .serverURL:
206+
hasher.combine(12)
203207
}
204208
}
205209

206210
// swiftlint:disable:next cyclomatic_complexity
207211
public static func == (lhs: API.Option, rhs: API.Option) -> Bool {
208212
switch (lhs, rhs) {
213+
case (.useMaintenanceKey, .useMaintenanceKey): return true
209214
case (.usePrimaryKey, .usePrimaryKey): return true
210215
case (.removeMimeType, .removeMimeType): return true
211216
case (.sessionToken(let object1), .sessionToken(let object2)): return object1 == object2
@@ -244,6 +249,8 @@ public struct API {
244249

245250
options.forEach { option in
246251
switch option {
252+
case .useMaintenanceKey:
253+
headers["X-Parse-Maintenance-Key"] = Parse.configuration.maintenanceKey
247254
case .usePrimaryKey:
248255
headers["X-Parse-Master-Key"] = Parse.configuration.primaryKey
249256
case .sessionToken(let sessionToken):

Sources/ParseSwift/LiveQuery/Messages.swift

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct StandardMessage: LiveQueryable, Codable {
1414
var applicationId: String?
1515
var clientKey: String?
1616
var primaryKey: String?
17+
var maintenanceKey: String?
1718
var sessionToken: String?
1819
var installationId: String?
1920
var requestId: Int?
@@ -24,6 +25,7 @@ struct StandardMessage: LiveQueryable, Codable {
2425
case .connect:
2526
self.applicationId = Parse.configuration.applicationId
2627
self.primaryKey = Parse.configuration.primaryKey
28+
self.maintenanceKey = Parse.configuration.maintenanceKey
2729
self.clientKey = Parse.configuration.clientKey
2830
self.sessionToken = await BaseParseUser.currentContainer()?.sessionToken
2931
if additionalProperties {
@@ -33,6 +35,7 @@ struct StandardMessage: LiveQueryable, Codable {
3335
if additionalProperties {
3436
self.applicationId = Parse.configuration.applicationId
3537
self.primaryKey = Parse.configuration.primaryKey
38+
self.maintenanceKey = Parse.configuration.maintenanceKey
3639
self.clientKey = Parse.configuration.clientKey
3740
self.sessionToken = await BaseParseUser.currentContainer()?.sessionToken
3841
self.installationId = await BaseParseInstallation.currentContainer().installationId
@@ -50,6 +53,7 @@ struct StandardMessage: LiveQueryable, Codable {
5053
case applicationId
5154
case clientKey
5255
case primaryKey = "masterKey"
56+
case maintenanceKey
5357
case sessionToken
5458
case installationId
5559
case requestId

Sources/ParseSwift/Parse.swift

+81-69
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,59 @@ internal struct Parse {
1212
static var sessionDelegate: ParseURLSessionDelegate!
1313
}
1414

15-
internal func initialize(applicationId: String,
16-
clientKey: String? = nil,
17-
primaryKey: String? = nil,
18-
serverURL: URL,
19-
liveQueryServerURL: URL? = nil,
20-
requiringCustomObjectIds: Bool = false,
21-
usingTransactions: Bool = false,
22-
usingEqualQueryConstraint: Bool = false,
23-
usingPostForQuery: Bool = false,
24-
primitiveStore: ParsePrimitiveStorable? = nil,
25-
requestCachePolicy: URLRequest.CachePolicy = .useProtocolCachePolicy,
26-
cacheMemoryCapacity: Int = 512_000,
27-
cacheDiskCapacity: Int = 10_000_000,
28-
migratingFromObjcSDK: Bool = false,
29-
usingDataProtectionKeychain: Bool = false,
30-
deletingKeychainIfNeeded: Bool = false,
31-
httpAdditionalHeaders: [AnyHashable: Any]? = nil,
32-
usingAutomaticLogin: Bool = false,
33-
maxConnectionAttempts: Int = 5,
34-
liveQueryConnectionAdditionalProperties: Bool = true,
35-
liveQueryMaxConnectionAttempts: Int = 20,
36-
testing: Bool = false,
37-
testLiveQueryDontCloseSocket: Bool = false,
38-
authentication: ((URLAuthenticationChallenge,
39-
(URLSession.AuthChallengeDisposition,
40-
URLCredential?) -> Void) -> Void)? = nil) async throws {
41-
var configuration = ParseConfiguration(applicationId: applicationId,
42-
clientKey: clientKey,
43-
primaryKey: primaryKey,
44-
serverURL: serverURL,
45-
liveQueryServerURL: liveQueryServerURL,
46-
requiringCustomObjectIds: requiringCustomObjectIds,
47-
usingTransactions: usingTransactions,
48-
usingEqualQueryConstraint: usingEqualQueryConstraint,
49-
usingPostForQuery: usingPostForQuery,
50-
primitiveStore: primitiveStore,
51-
requestCachePolicy: requestCachePolicy,
52-
cacheMemoryCapacity: cacheMemoryCapacity,
53-
cacheDiskCapacity: cacheDiskCapacity,
54-
usingDataProtectionKeychain: usingDataProtectionKeychain,
55-
deletingKeychainIfNeeded: deletingKeychainIfNeeded,
56-
httpAdditionalHeaders: httpAdditionalHeaders,
57-
usingAutomaticLogin: usingAutomaticLogin,
58-
maxConnectionAttempts: maxConnectionAttempts,
59-
liveQueryConnectionAdditionalProperties: liveQueryConnectionAdditionalProperties,
60-
liveQueryMaxConnectionAttempts: liveQueryMaxConnectionAttempts,
61-
authentication: authentication)
15+
internal func initialize(
16+
applicationId: String,
17+
clientKey: String? = nil,
18+
primaryKey: String? = nil,
19+
maintenanceKey: String? = nil,
20+
serverURL: URL,
21+
liveQueryServerURL: URL? = nil,
22+
requiringCustomObjectIds: Bool = false,
23+
usingTransactions: Bool = false,
24+
usingEqualQueryConstraint: Bool = false,
25+
usingPostForQuery: Bool = false,
26+
primitiveStore: ParsePrimitiveStorable? = nil,
27+
requestCachePolicy: URLRequest.CachePolicy = .useProtocolCachePolicy,
28+
cacheMemoryCapacity: Int = 512_000,
29+
cacheDiskCapacity: Int = 10_000_000,
30+
migratingFromObjcSDK: Bool = false,
31+
usingDataProtectionKeychain: Bool = false,
32+
deletingKeychainIfNeeded: Bool = false,
33+
httpAdditionalHeaders: [AnyHashable: Any]? = nil,
34+
usingAutomaticLogin: Bool = false,
35+
maxConnectionAttempts: Int = 5,
36+
liveQueryConnectionAdditionalProperties: Bool = true,
37+
liveQueryMaxConnectionAttempts: Int = 20,
38+
testing: Bool = false,
39+
testLiveQueryDontCloseSocket: Bool = false,
40+
authentication: ((URLAuthenticationChallenge,
41+
(URLSession.AuthChallengeDisposition,
42+
URLCredential?) -> Void) -> Void)? = nil
43+
) async throws {
44+
var configuration = ParseConfiguration(
45+
applicationId: applicationId,
46+
clientKey: clientKey,
47+
primaryKey: primaryKey,
48+
maintenanceKey: maintenanceKey,
49+
serverURL: serverURL,
50+
liveQueryServerURL: liveQueryServerURL,
51+
requiringCustomObjectIds: requiringCustomObjectIds,
52+
usingTransactions: usingTransactions,
53+
usingEqualQueryConstraint: usingEqualQueryConstraint,
54+
usingPostForQuery: usingPostForQuery,
55+
primitiveStore: primitiveStore,
56+
requestCachePolicy: requestCachePolicy,
57+
cacheMemoryCapacity: cacheMemoryCapacity,
58+
cacheDiskCapacity: cacheDiskCapacity,
59+
usingDataProtectionKeychain: usingDataProtectionKeychain,
60+
deletingKeychainIfNeeded: deletingKeychainIfNeeded,
61+
httpAdditionalHeaders: httpAdditionalHeaders,
62+
usingAutomaticLogin: usingAutomaticLogin,
63+
maxConnectionAttempts: maxConnectionAttempts,
64+
liveQueryConnectionAdditionalProperties: liveQueryConnectionAdditionalProperties,
65+
liveQueryMaxConnectionAttempts: liveQueryMaxConnectionAttempts,
66+
authentication: authentication
67+
)
6268
configuration.isMigratingFromObjcSDK = migratingFromObjcSDK
6369
configuration.isTestingSDK = testing
6470
configuration.isTestingLiveQueryDontCloseSocket = testLiveQueryDontCloseSocket
@@ -215,6 +221,8 @@ public func initialize(configuration: ParseConfiguration) async throws { // swif
215221
- parameter primaryKey: The primary key for your Parse application. This key should only be
216222
specified when using the SDK on a server. This has been renamed from `masterKey` to reflect
217223
inclusive language.
224+
- parameter maintenanceKey: The maintenance key for your Parse application. This key should only be
225+
specified when using the SDK on a server.
218226
- parameter serverURL: The server URL to connect to Parse Server.
219227
- parameter liveQueryServerURL: The live query server URL to connect to Parse Server.
220228
- parameter requiringCustomObjectIds: Requires `objectId`'s to be created on the client
@@ -265,6 +273,7 @@ public func initialize(
265273
applicationId: String,
266274
clientKey: String? = nil,
267275
primaryKey: String? = nil,
276+
maintenanceKey: String? = nil,
268277
serverURL: URL,
269278
liveQueryServerURL: URL? = nil,
270279
requiringCustomObjectIds: Bool = false,
@@ -287,28 +296,31 @@ public func initialize(
287296
(URLSession.AuthChallengeDisposition,
288297
URLCredential?) -> Void) -> Void)? = nil
289298
) async throws {
290-
let configuration = ParseConfiguration(applicationId: applicationId,
291-
clientKey: clientKey,
292-
primaryKey: primaryKey,
293-
serverURL: serverURL,
294-
liveQueryServerURL: liveQueryServerURL,
295-
requiringCustomObjectIds: requiringCustomObjectIds,
296-
usingTransactions: usingTransactions,
297-
usingEqualQueryConstraint: usingEqualQueryConstraint,
298-
usingPostForQuery: usingPostForQuery,
299-
primitiveStore: primitiveStore,
300-
requestCachePolicy: requestCachePolicy,
301-
cacheMemoryCapacity: cacheMemoryCapacity,
302-
cacheDiskCapacity: cacheDiskCapacity,
303-
usingDataProtectionKeychain: usingDataProtectionKeychain,
304-
deletingKeychainIfNeeded: deletingKeychainIfNeeded,
305-
httpAdditionalHeaders: httpAdditionalHeaders,
306-
usingAutomaticLogin: usingAutomaticLogin,
307-
maxConnectionAttempts: maxConnectionAttempts,
308-
liveQueryConnectionAdditionalProperties: liveQueryConnectionAdditionalProperties,
309-
liveQueryMaxConnectionAttempts: liveQueryMaxConnectionAttempts,
310-
parseFileTransfer: parseFileTransfer,
311-
authentication: authentication)
299+
let configuration = ParseConfiguration(
300+
applicationId: applicationId,
301+
clientKey: clientKey,
302+
primaryKey: primaryKey,
303+
maintenanceKey: maintenanceKey,
304+
serverURL: serverURL,
305+
liveQueryServerURL: liveQueryServerURL,
306+
requiringCustomObjectIds: requiringCustomObjectIds,
307+
usingTransactions: usingTransactions,
308+
usingEqualQueryConstraint: usingEqualQueryConstraint,
309+
usingPostForQuery: usingPostForQuery,
310+
primitiveStore: primitiveStore,
311+
requestCachePolicy: requestCachePolicy,
312+
cacheMemoryCapacity: cacheMemoryCapacity,
313+
cacheDiskCapacity: cacheDiskCapacity,
314+
usingDataProtectionKeychain: usingDataProtectionKeychain,
315+
deletingKeychainIfNeeded: deletingKeychainIfNeeded,
316+
httpAdditionalHeaders: httpAdditionalHeaders,
317+
usingAutomaticLogin: usingAutomaticLogin,
318+
maxConnectionAttempts: maxConnectionAttempts,
319+
liveQueryConnectionAdditionalProperties: liveQueryConnectionAdditionalProperties,
320+
liveQueryMaxConnectionAttempts: liveQueryMaxConnectionAttempts,
321+
parseFileTransfer: parseFileTransfer,
322+
authentication: authentication
323+
)
312324
try await initialize(configuration: configuration)
313325
}
314326

Sources/ParseSwift/ParseConstants.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
enum ParseConstants {
1212
static let sdk = "swift"
13-
static let version = "5.11.5"
13+
static let version = "5.12.0"
1414
static let fileManagementDirectory = "parse/"
1515
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
1616
static let fileManagementLibraryDirectory = "Library/"

0 commit comments

Comments
 (0)