Skip to content

Commit

Permalink
refactor: change masterKey to primaryKey (#2)
Browse files Browse the repository at this point in the history
* refactor: change masterKey to primaryKey

* cover deprecated code

* fix links
  • Loading branch information
cbaker6 authored Oct 22, 2022
1 parent b9de57c commit 66aafe4
Show file tree
Hide file tree
Showing 139 changed files with 549 additions and 330 deletions.
3 changes: 1 addition & 2 deletions .github/ISSUE_TEMPLATE/---1-report-an-issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ assignees: ''
-->

- [ ] I am not disclosing a [vulnerability](https://github.com/netreconlab/Parse-Swift/security/policy).
- [ ] I am not just asking a [question](https://github.com/netreconlab/.github/blob/main/SUPPORT.md).
- [ ] I have searched through [existing issues](https://github.com/netreconlab/Parse-Swift/issues?q=is%3Aissue).
- [ ] I can reproduce the issue with the latest versions of [Parse Server](https://github.com/netreconlab/parse-server/releases) and the [Parse Swift SDK](https://github.com/netreconlab/Parse-Swift/releases). <!-- We don't investigate issues for outdated releases. -->
- [ ] I can reproduce the issue with the latest versions of [Parse Server](https://github.com/parse-community/parse-server/releases) and the [Parse Swift SDK](https://github.com/netreconlab/Parse-Swift/releases). <!-- We don't investigate issues for outdated releases. -->

### Issue Description
<!-- What is the specific issue? -->
Expand Down
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/---2-feature-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ assignees: ''
-->

- [ ] I am not disclosing a [vulnerability](https://github.com/netreconlab/Parse-Swift/security/policy).
- [ ] I am not just asking a [question](https://github.com/netreconlab/.github/blob/main/SUPPORT.md).
- [ ] I have searched through [existing issues](https://github.com/netreconlab/Parse-Swift/issues?q=is%3Aissue).

### Current Limitation
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Parse-Swift Changelog

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

### 4.14.2
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/4.14.2...4.15.0), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/4.15.0/documentation/parseswift)

__New features__
- Addressed an issue that prevented updating ParseObjects with saveAll ([#2](https://github.com/netrecolab/Parse-Swift/pull/2)), thanks to [Corey Baker](https://github.com/cbaker6).

### 4.14.2
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.14.1...4.14.2), [Documentation](https://swiftpackageindex.com/parse-community/Parse-Swift/4.14.2/documentation/parseswift)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ let query = ParsePushStatus<ParsePushPayloadAny>
Be sure to add the `.userMasterKey option when doing
anything with `ParsePushStatus` directly.
*/
query.findAll(options: [.useMasterKey]) { result in
query.findAll(options: [.usePrimaryKey]) { result in
switch result {
case .success(let pushStatus):
print("All matching statuses: \"\(pushStatus)\"")
Expand Down
2 changes: 1 addition & 1 deletion ParseSwift.playground/Sources/Common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ParseSwift
public func initializeParse(customObjectId: Bool = false) {
ParseSwift.initialize(applicationId: "applicationId",
clientKey: "clientKey",
masterKey: "masterKey",
primaryKey: "primaryKey",
serverURL: URL(string: "http://localhost:1337/1")!,
allowingCustomObjectIds: customObjectId,
usingEqualQueryConstraint: false,
Expand Down
9 changes: 6 additions & 3 deletions Sources/ParseSwift/API/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ public struct API {
/// Options available to send to Parse Server.
public enum Option: Hashable {

/// Use the primaryKey/masterKey if it was provided during initial configuraration.
case usePrimaryKey
/// Use the masterKey if it was provided during initial configuraration.
@available(*, deprecated, renamed: "usePrimaryKey")
case useMasterKey // swiftlint:disable:this inclusive_language
/// Use a specific session token.
/// - note: The session token of the current user is provided by default.
Expand Down Expand Up @@ -167,7 +170,7 @@ public struct API {

public func hash(into hasher: inout Hasher) {
switch self {
case .useMasterKey:
case .usePrimaryKey, .useMasterKey:
hasher.combine(1)
case .sessionToken:
hasher.combine(2)
Expand Down Expand Up @@ -216,8 +219,8 @@ public struct API {

options.forEach { (option) in
switch option {
case .useMasterKey:
headers["X-Parse-Master-Key"] = Parse.configuration.masterKey
case .usePrimaryKey, .useMasterKey:
headers["X-Parse-Master-Key"] = Parse.configuration.primaryKey
case .sessionToken(let sessionToken):
headers["X-Parse-Session-Token"] = sessionToken
case .installationId(let installationId):
Expand Down
14 changes: 12 additions & 2 deletions Sources/ParseSwift/LiveQuery/Messages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct StandardMessage: LiveQueryable, Codable {
var op: ClientOperation // swiftlint:disable:this identifier_name
var applicationId: String?
var clientKey: String?
var masterKey: String? // swiftlint:disable:this inclusive_language
var primaryKey: String?
var sessionToken: String?
var installationId: String?
var requestId: Int?
Expand All @@ -22,7 +22,7 @@ struct StandardMessage: LiveQueryable, Codable {
self.op = operation
if additionalProperties {
self.applicationId = Parse.configuration.applicationId
self.masterKey = Parse.configuration.masterKey
self.primaryKey = Parse.configuration.primaryKey
self.clientKey = Parse.configuration.clientKey
self.sessionToken = BaseParseUser.currentContainer?.sessionToken
self.installationId = BaseParseInstallation.currentContainer.installationId
Expand All @@ -33,6 +33,16 @@ struct StandardMessage: LiveQueryable, Codable {
self.init(operation: operation)
self.requestId = requestId.value
}

enum CodingKeys: String, CodingKey {
case op // swiftlint:disable:this identifier_name
case applicationId
case clientKey
case primaryKey = "masterKey"
case sessionToken
case installationId
case requestId
}
}

struct SubscribeQuery: Encodable {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Objects/ParsePushStatusable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
Objects that conform to the `ParsePushStatusable` protocol represent
PushStatus on the Parse Server.
- warning: These objects are only read-only.
- requires: `.useMasterKey` has to be available. It is recommended to only
- requires: `.usePrimaryKey` has to be available. It is recommended to only
use the master key in server-side applications where the key is kept secure and not
exposed to the public.
*/
Expand Down
112 changes: 102 additions & 10 deletions Sources/ParseSwift/Parse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal struct Parse {

internal func initialize(applicationId: String,
clientKey: String? = nil,
masterKey: String? = nil,
primaryKey: String? = nil,
serverURL: URL,
liveQueryServerURL: URL? = nil,
requiringCustomObjectIds: Bool = false,
Expand All @@ -36,7 +36,7 @@ internal func initialize(applicationId: String,
URLCredential?) -> Void) -> Void)? = nil) {
var configuration = ParseConfiguration(applicationId: applicationId,
clientKey: clientKey,
masterKey: masterKey,
primaryKey: primaryKey,
serverURL: serverURL,
liveQueryServerURL: liveQueryServerURL,
requiringCustomObjectIds: requiringCustomObjectIds,
Expand Down Expand Up @@ -86,7 +86,7 @@ public var configuration: ParseConfiguration {
Configure the Parse Swift client. This should only be used when starting your app. Typically in the
`application(... didFinishLaunchingWithOptions launchOptions...)`.
- parameter configuration: The Parse configuration.
- important: It is recomended to only specify `masterKey` when using the SDK on a server. Do not use this key on the client.
- important: It is recomended to only specify `primaryKey/masterKey` when using the SDK on a server. Do not use this key on the client.
- note: Setting `usingPostForQuery` to **true** will require all queries to access the server instead of following the `requestCachePolicy`.
- warning: `usingTransactions` is experimental.
- warning: Setting `usingDataProtectionKeychain` to **true** is known to cause issues in Playgrounds or in
Expand Down Expand Up @@ -179,8 +179,9 @@ public func initialize(configuration: ParseConfiguration) {
`application(... didFinishLaunchingWithOptions launchOptions...)`.
- parameter applicationId: The application id for your Parse application.
- parameter clientKey: The client key for your Parse application.
- parameter masterKey: The master key for your Parse application. This key should only be
specified when using the SDK on a server.
- parameter primaryKey: The primary key for your Parse application. This key should only be
specified when using the SDK on a server. This has been renamed from `masterKey` to reflect
inclusive language.
- parameter serverURL: The server URL to connect to Parse Server.
- parameter liveQueryServerURL: The live query server URL to connect to Parse Server.
- parameter requiringCustomObjectIds: Requires `objectId`'s to be created on the client
Expand Down Expand Up @@ -214,7 +215,7 @@ public func initialize(configuration: ParseConfiguration) {
It should have the following argument signature: `(challenge: URLAuthenticationChallenge,
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void`.
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
- important: It is recomended to only specify `masterKey` when using the SDK on a server. Do not use this key on the client.
- important: It is recomended to only specify `primaryKey/masterKey` when using the SDK on a server. Do not use this key on the client.
- note: Setting `usingPostForQuery` to **true** will require all queries to access the server instead of following the `requestCachePolicy`.
- warning: `usingTransactions` is experimental.
- warning: Setting `usingDataProtectionKeychain` to **true** is known to cause issues in Playgrounds or in
Expand All @@ -223,7 +224,7 @@ public func initialize(configuration: ParseConfiguration) {
public func initialize(
applicationId: String,
clientKey: String? = nil,
masterKey: String? = nil,
primaryKey: String? = nil,
serverURL: URL,
liveQueryServerURL: URL? = nil,
requiringCustomObjectIds: Bool = false,
Expand All @@ -245,7 +246,7 @@ public func initialize(
) {
let configuration = ParseConfiguration(applicationId: applicationId,
clientKey: clientKey,
masterKey: masterKey,
primaryKey: primaryKey,
serverURL: serverURL,
liveQueryServerURL: liveQueryServerURL,
requiringCustomObjectIds: requiringCustomObjectIds,
Expand All @@ -265,6 +266,97 @@ public func initialize(
initialize(configuration: configuration)
}

/**
Configure the Parse Swift client. This should only be used when starting your app. Typically in the
`application(... didFinishLaunchingWithOptions launchOptions...)`.
- parameter applicationId: The application id for your Parse application.
- parameter clientKey: The client key for your Parse application.
- parameter masterKey: The master key for your Parse application. This key should only be
specified when using the SDK on a server.
- parameter serverURL: The server URL to connect to Parse Server.
- parameter liveQueryServerURL: The live query server URL to connect to Parse Server.
- parameter requiringCustomObjectIds: Requires `objectId`'s to be created on the client
side for each object. Must be enabled on the server to work.
- parameter usingTransactions: Use transactions when saving/updating multiple objects.
- parameter usingEqualQueryConstraint: Use the **$eq** query constraint when querying.
- parameter usingPostForQuery: Use **POST** instead of **GET** when making query calls.
Defaults to **false**.
- parameter primitiveStore: A key/value store that conforms to the `ParseKeyValueStore`
protocol. Defaults to `nil` in which one will be created an memory, but never persisted. For Linux, this
this is the only store available since there is no Keychain. Linux, Android, and Windows users should
replace this store with an encrypted one.
- parameter requestCachePolicy: The default caching policy for all http requests that determines
when to return a response from the cache. Defaults to `useProtocolCachePolicy`. See Apple's [documentation](https://developer.apple.com/documentation/foundation/url_loading_system/accessing_cached_data)
for more info.
- parameter cacheMemoryCapacity: The memory capacity of the cache, in bytes. Defaults to 512KB.
- parameter cacheDiskCapacity: The disk capacity of the cache, in bytes. Defaults to 10MB.
- parameter usingDataProtectionKeychain: Sets `kSecUseDataProtectionKeychain` to **true**. See Apple's [documentation](https://developer.apple.com/documentation/security/ksecusedataprotectionkeychain)
for more info. Defaults to **false**.
- parameter deletingKeychainIfNeeded: Deletes the Parse Keychain when the app is running for the first time.
Defaults to **false**.
- parameter httpAdditionalHeaders: A dictionary of additional headers to send with requests. See Apple's
[documentation](https://developer.apple.com/documentation/foundation/urlsessionconfiguration/1411532-httpadditionalheaders)
for more info.
- parameter maxConnectionAttempts: Maximum number of times to try to connect to Parse Server.
Defaults to 5.
- parameter parseFileTransfer: Override the default transfer behavior for `ParseFile`'s.
Allows for direct uploads to other file storage providers.
- parameter authentication: A callback block that will be used to receive/accept/decline network challenges.
Defaults to `nil` in which the SDK will use the default OS authentication methods for challenges.
It should have the following argument signature: `(challenge: URLAuthenticationChallenge,
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void`.
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
- important: It is recomended to only specify `primaryKey/masterKey` when using the SDK on a server. Do not use this key on the client.
- note: Setting `usingPostForQuery` to **true** will require all queries to access the server instead of following the `requestCachePolicy`.
- warning: `usingTransactions` is experimental.
- warning: Setting `usingDataProtectionKeychain` to **true** is known to cause issues in Playgrounds or in
situtations when apps do not have credentials to setup a Keychain.
*/
@available(*, deprecated, message: "Change: masterKey->primaryKey")
public func initialize(
applicationId: String,
clientKey: String? = nil,
masterKey: String? = nil,
serverURL: URL,
liveQueryServerURL: URL? = nil,
requiringCustomObjectIds: Bool = false,
usingTransactions: Bool = false,
usingEqualQueryConstraint: Bool = false,
usingPostForQuery: Bool = false,
primitiveStore: ParsePrimitiveStorable? = nil,
requestCachePolicy: URLRequest.CachePolicy = .useProtocolCachePolicy,
cacheMemoryCapacity: Int = 512_000,
cacheDiskCapacity: Int = 10_000_000,
usingDataProtectionKeychain: Bool = false,
deletingKeychainIfNeeded: Bool = false,
httpAdditionalHeaders: [AnyHashable: Any]? = nil,
maxConnectionAttempts: Int = 5,
parseFileTransfer: ParseFileTransferable? = nil,
authentication: ((URLAuthenticationChallenge,
(URLSession.AuthChallengeDisposition,
URLCredential?) -> Void) -> Void)? = nil
) {
initialize(applicationId: applicationId,
clientKey: clientKey,
primaryKey: masterKey,
serverURL: serverURL,
liveQueryServerURL: liveQueryServerURL,
requiringCustomObjectIds: requiringCustomObjectIds,
usingTransactions: usingTransactions,
usingEqualQueryConstraint: usingEqualQueryConstraint,
usingPostForQuery: usingPostForQuery,
primitiveStore: primitiveStore,
requestCachePolicy: requestCachePolicy,
cacheMemoryCapacity: cacheMemoryCapacity,
cacheDiskCapacity: cacheDiskCapacity,
usingDataProtectionKeychain: usingDataProtectionKeychain,
deletingKeychainIfNeeded: deletingKeychainIfNeeded,
httpAdditionalHeaders: httpAdditionalHeaders,
maxConnectionAttempts: maxConnectionAttempts,
parseFileTransfer: parseFileTransfer,
authentication: authentication)
}

/**
Configure the Parse Swift client. This should only be used when starting your app. Typically in the
`application(... didFinishLaunchingWithOptions launchOptions...)`.
Expand Down Expand Up @@ -305,7 +397,7 @@ public func initialize(
It should have the following argument signature: `(challenge: URLAuthenticationChallenge,
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void`.
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
- important: It is recomended to only specify `masterKey` when using the SDK on a server. Do not use this key on the client.
- important: It is recomended to only specify `primaryKey/masterKey` when using the SDK on a server. Do not use this key on the client.
- note: Setting `usingPostForQuery` to **true** will require all queries to access the server instead of following the `requestCachePolicy`.
- warning: `usingTransactions` is experimental.
- warning: Setting `usingDataProtectionKeychain` to **true** is known to cause issues in Playgrounds or in
Expand Down Expand Up @@ -398,7 +490,7 @@ public func initialize(
It should have the following argument signature: `(challenge: URLAuthenticationChallenge,
completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) -> Void`.
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
- important: It is recomended to only specify `masterKey` when using the SDK on a server. Do not use this key on the client.
- important: It is recomended to only specify `primaryKey/masterKey` when using the SDK on a server. Do not use this key on the client.
- note: Setting `usingPostForQuery` to **true** will require all queries to access the server instead of following the `requestCachePolicy`.
- warning: `usingTransactions` is experimental.
- warning: Setting `usingDataProtectionKeychain` to **true** is known to cause issues in Playgrounds or in
Expand Down
Loading

0 comments on commit 66aafe4

Please sign in to comment.