0.6.5.b Arroyo Toad
Git commit fixes
This commit is contained in:
5
Sources/App/CustomCode/Errors/ParsingError.swift
Normal file
5
Sources/App/CustomCode/Errors/ParsingError.swift
Normal file
@@ -0,0 +1,5 @@
|
||||
public enum ParsingError : Error {
|
||||
case MalformedJSON(reason: String)
|
||||
case ConfigFileNotExistent
|
||||
case ImpossibleToWriteKeyToFileSystem
|
||||
}
|
||||
@@ -36,6 +36,7 @@ public func fetchPrivateP256Key(deviceID: UInt) async throws -> P256.Signing.Pri
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
|
||||
let key = createPrivateP256Key()
|
||||
|
||||
@@ -57,6 +58,31 @@ public func fetchPrivateP256Key(deviceID: UInt) async throws -> P256.Signing.Pri
|
||||
let _ = try await URLSession.shared.upload(for: httpRequest, from: data)
|
||||
return key
|
||||
|
||||
=======
|
||||
do {
|
||||
let key = createPrivateP256Key()
|
||||
|
||||
let publicKey = key.publicKey.pemRepresentation
|
||||
|
||||
try privateP256_2_pem(privateKey: key).write(to: URL(filePath: keyFilePath), atomically: true, encoding: String.Encoding.utf8)
|
||||
|
||||
|
||||
// UGLY: hardcoded
|
||||
var httpRequest = URLRequest(url: URL(string: "http://public-key-db.internal/key")!)
|
||||
httpRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
||||
httpRequest.httpMethod = "POST"
|
||||
|
||||
let message = PublicKeyMessage(deviceID: deviceID, publicKey: publicKey)
|
||||
let encoder = JSONEncoder()
|
||||
let data = try encoder.encode(message)
|
||||
httpRequest.httpBody = data
|
||||
|
||||
let _ = try await URLSession.shared.upload(for: httpRequest, from: data)
|
||||
return key
|
||||
} catch {
|
||||
throw ParsingError.ImpossibleToWriteKeyToFileSystem
|
||||
}
|
||||
>>>>>>> 5d78c9be5855d5541dd07b24d8331c018ddd2c70
|
||||
|
||||
|
||||
|
||||
|
||||
4
Sources/App/CustomCode/Utils/PublicKeyMessage.swift
Normal file
4
Sources/App/CustomCode/Utils/PublicKeyMessage.swift
Normal file
@@ -0,0 +1,4 @@
|
||||
public struct PublicKeyMessage : Codable {
|
||||
public let deviceID: UInt
|
||||
public let publicKey: String
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import Vapor
|
||||
|
||||
// configures your application
|
||||
public func configure(_ app: Application) async throws {
|
||||
// uncomment to serve files from /Public folder
|
||||
// app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
|
||||
// register routes
|
||||
try routes(app)
|
||||
}
|
||||
import Vapor
|
||||
|
||||
// configures your application
|
||||
public func configure(_ app: Application) async throws {
|
||||
// uncomment to serve files from /Public folder
|
||||
// app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
|
||||
// register routes
|
||||
try routes(app)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import Vapor
|
||||
|
||||
func routes(_ app: Application) throws {
|
||||
app.get { req async in
|
||||
"It works!"
|
||||
}
|
||||
|
||||
app.get("hello") { req async -> String in
|
||||
"Hello, world!"
|
||||
}
|
||||
}
|
||||
import Foundation
|
||||
import Vapor
|
||||
|
||||
func routes(_ app: Application) throws {
|
||||
app.get { req async in
|
||||
"It works!"
|
||||
}
|
||||
|
||||
app.get("hello") { req async -> String in
|
||||
return "Hello, world!"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import Crypto
|
||||
import Foundation
|
||||
<<<<<<< HEAD
|
||||
import FoundationNetworking
|
||||
=======
|
||||
>>>>>>> 5d78c9be5855d5541dd07b24d8331c018ddd2c70
|
||||
import IoT_Simulator_Core
|
||||
import MessageUtils
|
||||
|
||||
@@ -49,6 +52,7 @@ private func jsonConfigurationParser(_ json: [String: Any]) async throws {
|
||||
try IoTSimulatorCore.addDevice(location: env.location, device: dev) { msg in
|
||||
// UGLY: But fast
|
||||
// TODO: add sending code here
|
||||
<<<<<<< HEAD
|
||||
let backendURL = ProcessInfo.processInfo.environment["BACKEND_URL"]!
|
||||
|
||||
var httpRequest = URLRequest(url: URL(string: backendURL)!)
|
||||
@@ -58,6 +62,8 @@ private func jsonConfigurationParser(_ json: [String: Any]) async throws {
|
||||
httpRequest.httpBody = msg
|
||||
let _ = try await URLSession.shared.upload(for: httpRequest, from: msg)
|
||||
|
||||
=======
|
||||
>>>>>>> 5d78c9be5855d5541dd07b24d8331c018ddd2c70
|
||||
} failure: {
|
||||
print("Failed")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user