From 645d135312664155207620a56da1aa8e86e9eb20 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 31 Mar 2020 12:29:38 -0700 Subject: [PATCH 1/2] Option for app authentication key --- .../RDMUICManager/BuildController.swift | 2 +- Manager/Sources/RDMUICManager/CLI.swift | 19 ++++++++++++++++++- Manager/Sources/RDMUICManager/Device.swift | 6 +++++- .../RealDeviceMap-UIControl.xcscheme | 5 +++++ RealDeviceMap-UIControl/Config.swift | 2 ++ .../RealDeviceMap_UIControlUITests.swift | 19 +++++++++++++++++++ 6 files changed, 50 insertions(+), 3 deletions(-) diff --git a/Manager/Sources/RDMUICManager/BuildController.swift b/Manager/Sources/RDMUICManager/BuildController.swift index 29221f36..32ad0120 100644 --- a/Manager/Sources/RDMUICManager/BuildController.swift +++ b/Manager/Sources/RDMUICManager/BuildController.swift @@ -197,7 +197,7 @@ class BuildController { "startupLocationLon=\(device.startupLocationLon)", "encounterMaxWait=\(device.encounterMaxWait)", "encounterDelay=\(device.encounterDelay)", "fastIV=\(device.fastIV)", "ultraIV=\(device.ultraIV)", "deployEggs=\(device.deployEggs)", "token=\(device.token)", "ultraQuests=\(device.ultraQuests)", - "attachScreenshots=\(device.attachScreenshots)" + "attachScreenshots=\(device.attachScreenshots)", "appKey=\(device.appKey)" ) var contains = true diff --git a/Manager/Sources/RDMUICManager/CLI.swift b/Manager/Sources/RDMUICManager/CLI.swift index cecf2698..667879a3 100644 --- a/Manager/Sources/RDMUICManager/CLI.swift +++ b/Manager/Sources/RDMUICManager/CLI.swift @@ -168,6 +168,7 @@ class CLI { Ultra Quests: \(device.ultraQuests.toBool()) Enabled: \(device.enabled.toBool()) AttachScreenshots: \(device.attachScreenshots.toBool()) + App Key: \(device.appKey) """ print(row + "\n") @@ -316,6 +317,11 @@ class CLI { if attachScreenshots != nil { defaultDevice.attachScreenshots = attachScreenshots!.toInt() } + + let appKey = askInput("Default App Key (empty = \(defaultDevice.appKey))") + if appKey != "" { + defaultDevice.appKey = appKey + } do { try defaultDevice.save() @@ -472,6 +478,11 @@ class CLI { if attachScreenshots == nil { attachScreenshots = defaultDevice.attachScreenshots } + + var appKey = askInput("App Key (empty = \(defaultDevice.appKey))") + if appKey == "" { + appKey = defaultDevice.appKey + } device.uuid = uuid device.name = name @@ -502,6 +513,7 @@ class CLI { device.ultraQuests = ultraQuests! device.enabled = enabled! device.attachScreenshots = attachScreenshots! + device.appKey = appKey do { try device.create() @@ -673,7 +685,12 @@ class CLI { if attachScreenshots != nil { device.attachScreenshots = attachScreenshots!.toInt() } - + + let appKey = askInput("App Key (empty = \(device.appKey))") + if appKey != "" { + device.appKey = appKey + } + do { try device.save() clear() diff --git a/Manager/Sources/RDMUICManager/Device.swift b/Manager/Sources/RDMUICManager/Device.swift index b3b3cd22..6078bc4a 100644 --- a/Manager/Sources/RDMUICManager/Device.swift +++ b/Manager/Sources/RDMUICManager/Device.swift @@ -53,6 +53,7 @@ class Device: SQLiteStORM, Equatable, Hashable { var ultraQuests: Int var enabled: Int var attachScreenshots: Int + var appKey: String override init() { self.uuid = "" @@ -84,6 +85,7 @@ class Device: SQLiteStORM, Equatable, Hashable { self.ultraQuests = 0 self.enabled = 1 self.attachScreenshots = 0 + self.appKey = "" super.init() } @@ -92,7 +94,7 @@ class Device: SQLiteStORM, Equatable, Hashable { targetMaxDistance: Double, itemFullCount: Int, questFullCount: Int, itemsPerStop: Int, minDelayLogout: Double, maxNoQuestCount: Int, maxFailedCount: Int, maxEmptyGMO: Int, startupLocationLat: Double, startupLocationLon: Double, encounterMaxWait: Int, encounterDelay: Double, fastIV: Int, ultraIV: Int, - deployEggs: Int, token: String, ultraQuests: Int, enabled: Int, attachScreenshots: Int) { + deployEggs: Int, token: String, ultraQuests: Int, enabled: Int, attachScreenshots: Int, appKey: String) { self.uuid = uuid self.name = name self.backendURL = backendURL @@ -122,6 +124,7 @@ class Device: SQLiteStORM, Equatable, Hashable { self.ultraQuests = ultraQuests self.enabled = enabled self.attachScreenshots = attachScreenshots + self.appKey = appKey super.init() } @@ -159,6 +162,7 @@ class Device: SQLiteStORM, Equatable, Hashable { ultraQuests = this.data["ultraQuests"] as? Int ?? 0 enabled = this.data["enabled"] as? Int ?? 1 attachScreenshots = this.data["attachScreenshots"] as? Int ?? 0 + appKey = this.data["appKey"] as? String ?? "" } static func getAll() -> [Device] { diff --git a/RealDeviceMap-UIControl.xcodeproj/xcshareddata/xcschemes/RealDeviceMap-UIControl.xcscheme b/RealDeviceMap-UIControl.xcodeproj/xcshareddata/xcschemes/RealDeviceMap-UIControl.xcscheme index 6158c29b..64dfee2b 100644 --- a/RealDeviceMap-UIControl.xcodeproj/xcshareddata/xcschemes/RealDeviceMap-UIControl.xcscheme +++ b/RealDeviceMap-UIControl.xcodeproj/xcshareddata/xcschemes/RealDeviceMap-UIControl.xcscheme @@ -208,6 +208,11 @@ value = "$(attachScreenshots)" isEnabled = "YES"> + + diff --git a/RealDeviceMap-UIControl/Config.swift b/RealDeviceMap-UIControl/Config.swift index 7982e5a9..d9bfae1c 100644 --- a/RealDeviceMap-UIControl/Config.swift +++ b/RealDeviceMap-UIControl/Config.swift @@ -39,6 +39,7 @@ class Config { var ultraQuests: Bool var enabled: Bool var attachScreenshots: Bool + var appKey: String init() { @@ -74,6 +75,7 @@ class Config { ultraQuests = enviroment["ultraQuests"]?.toBool() ?? false enabled = enviroment["enabled"]?.toBool() ?? true attachScreenshots = enviroment["attachScreenshots"]?.toBool() ?? false + appKey = enviroment["appKey"] ?? "" } } diff --git a/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift b/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift index b3b48c62..51605310 100644 --- a/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift +++ b/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift @@ -986,6 +986,23 @@ class RealDeviceMap_UIControlUITests: XCTestCase { return HTTPResponse(.ok) } + + func handleConfigRequest(request: HTTPRequest) -> HTTPResponse { + let responseData: [String: Any] = [ + "key": self.config.appKey ?? "", + "loc": "", // optional + "endpoints": [""] // optional + ] + do { + let jsonData = try JSONSerialization.data(withJSONObject: responseData, options: .prettyPrinted) + let jsonString = String(data: jsonData, encoding: .utf8) ?? "" + let response = HTTPResponse(content: jsonString) + response.headers = ["Content-Type": "application/json"] + return response + } catch { + return HTTPResponse(.internalServerError) + } + } func part8Main() { @@ -1969,6 +1986,8 @@ class RealDeviceMap_UIControlUITests: XCTestCase { self.server.route(.post, "loc", self.handleLocRequest) self.server.route(.get, "data", self.handleDataRequest) self.server.route(.post, "data", self.handleDataRequest) + self.server.route(.get, "config", self.handleConfigRequest) + self.server.route(.post, "config", self.handleConfigRequest) self.lock.lock() self.currentLocation = self.config.startupLocation From 6b349b347b42ec45ac39cfb5c7f08c2e0b9cfe90 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 31 Mar 2020 13:05:15 -0700 Subject: [PATCH 2/2] Linting --- Manager/Sources/RDMUICManager/CLI.swift | 8 ++++---- .../RealDeviceMap_UIControlUITests.swift | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Manager/Sources/RDMUICManager/CLI.swift b/Manager/Sources/RDMUICManager/CLI.swift index 667879a3..fa1de7a6 100644 --- a/Manager/Sources/RDMUICManager/CLI.swift +++ b/Manager/Sources/RDMUICManager/CLI.swift @@ -317,7 +317,7 @@ class CLI { if attachScreenshots != nil { defaultDevice.attachScreenshots = attachScreenshots!.toInt() } - + let appKey = askInput("Default App Key (empty = \(defaultDevice.appKey))") if appKey != "" { defaultDevice.appKey = appKey @@ -478,7 +478,7 @@ class CLI { if attachScreenshots == nil { attachScreenshots = defaultDevice.attachScreenshots } - + var appKey = askInput("App Key (empty = \(defaultDevice.appKey))") if appKey == "" { appKey = defaultDevice.appKey @@ -685,12 +685,12 @@ class CLI { if attachScreenshots != nil { device.attachScreenshots = attachScreenshots!.toInt() } - + let appKey = askInput("App Key (empty = \(device.appKey))") if appKey != "" { device.appKey = appKey } - + do { try device.save() clear() diff --git a/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift b/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift index 51605310..5da98ed1 100644 --- a/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift +++ b/RealDeviceMap-UIControl/RealDeviceMap_UIControlUITests.swift @@ -986,7 +986,7 @@ class RealDeviceMap_UIControlUITests: XCTestCase { return HTTPResponse(.ok) } - + func handleConfigRequest(request: HTTPRequest) -> HTTPResponse { let responseData: [String: Any] = [ "key": self.config.appKey ?? "",