From 9ef32067ce0b1c3e5e5e307df54ee13a35a88b51 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Sun, 10 May 2020 14:31:15 -0500 Subject: [PATCH 01/12] Remove numerous unnecessary code stanzas. --- .../Environment/Environment+Process.swift | 12 ++----- Sources/Vapor/Environment/Environment.swift | 33 ++++++------------- 2 files changed, 12 insertions(+), 33 deletions(-) diff --git a/Sources/Vapor/Environment/Environment+Process.swift b/Sources/Vapor/Environment/Environment+Process.swift index ae14f6f897..6f0e61efc0 100644 --- a/Sources/Vapor/Environment/Environment+Process.swift +++ b/Sources/Vapor/Environment/Environment+Process.swift @@ -17,11 +17,7 @@ extension Environment { /// Environment.process.DATABASE_PORT // 3306 public subscript(dynamicMember member: String) -> T? where T: LosslessStringConvertible { get { - guard let raw = self._info.environment[member], let value = T(raw) else { - return nil - } - - return value + return self._info.environment[member].flatMap { T($0) } } nonmutating set (value) { if let raw = value?.description { @@ -38,11 +34,7 @@ extension Environment { /// Environment.process.DATABASE_USER // "root" public subscript(dynamicMember member: String) -> String? { get { - guard let value = self._info.environment[member] else { - return nil - } - - return value + return self._info.environment[member] } nonmutating set (value) { if let raw = value { diff --git a/Sources/Vapor/Environment/Environment.swift b/Sources/Vapor/Environment/Environment.swift index 067054b29c..f4e4ecd117 100644 --- a/Sources/Vapor/Environment/Environment.swift +++ b/Sources/Vapor/Environment/Environment.swift @@ -29,18 +29,15 @@ public struct Environment: Equatable { struct EnvironmentSignature: CommandSignature { @Option(name: "env", short: "e", help: "Change the application's environment") var environment: String? - init() { } } var env: Environment - if let value = try EnvironmentSignature(from: &commandInput).environment { - switch value { + switch try EnvironmentSignature(from: &commandInput).environment ?? + Environment.process.VAPOR_ENV + { case "prod", "production": env = .production - case "dev", "development": env = .development + case "dev", "development", .none: env = .development case "test", "testing": env = .testing - default: env = .init(name: value) - } - } else { - env = .development + case .some(let name): env = .init(name: name) } env.commandInput = commandInput return env @@ -49,24 +46,16 @@ public struct Environment: Equatable { // MARK: Presets /// An environment for deploying your application to consumers. - public static var production: Environment { - return .init(name: "production") - } + public static var production: Environment { .init(name: "production") } /// An environment for developing your application. - public static var development: Environment { - return .init(name: "development", arguments: ["vapor"]) - } + public static var development: Environment { .init(name: "development") } /// An environment for testing your application. - public static var testing: Environment { - return .init(name: "testing", arguments: ["vapor"]) - } + public static var testing: Environment { .init(name: "testing") } /// Creates a custom environment. - public static func custom(name: String) -> Environment { - return .init(name: name, arguments: ["vapor"]) - } + public static func custom(name: String) -> Environment { .init(name: name) } // MARK: Env @@ -96,9 +85,7 @@ public struct Environment: Equatable { /// /// This usually means reducing logging, disabling debug information, and sometimes /// providing warnings about configuration states that are not suitable for production. - public var isRelease: Bool { - return !_isDebugAssertConfiguration() - } + public var isRelease: Bool { !_isDebugAssertConfiguration() } /// The command-line arguments for this `Environment`. public var arguments: [String] From 5c9fcd9431e304008d0b7102018e567d5efdd52b Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Sun, 10 May 2020 14:31:46 -0500 Subject: [PATCH 02/12] Whitespace cleanup --- Sources/Vapor/Environment/Environment+Process.swift | 5 +++++ Sources/Vapor/Environment/Environment+Secret.swift | 2 +- Sources/Vapor/Environment/Environment.swift | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/Vapor/Environment/Environment+Process.swift b/Sources/Vapor/Environment/Environment+Process.swift index 6f0e61efc0..0ca7559f85 100644 --- a/Sources/Vapor/Environment/Environment+Process.swift +++ b/Sources/Vapor/Environment/Environment+Process.swift @@ -1,6 +1,8 @@ extension Environment { + /// The process information of an environment. Wraps `ProcessInto.processInfo`. @dynamicMemberLookup public struct Process { + /// The process information of the environment. private let _info: ProcessInfo @@ -19,6 +21,7 @@ extension Environment { get { return self._info.environment[member].flatMap { T($0) } } + nonmutating set (value) { if let raw = value?.description { setenv(member, raw, 1) @@ -36,6 +39,7 @@ extension Environment { get { return self._info.environment[member] } + nonmutating set (value) { if let raw = value { setenv(member, raw, 1) @@ -45,4 +49,5 @@ extension Environment { } } } + } diff --git a/Sources/Vapor/Environment/Environment+Secret.swift b/Sources/Vapor/Environment/Environment+Secret.swift index 4855301227..bdcf928a98 100644 --- a/Sources/Vapor/Environment/Environment+Secret.swift +++ b/Sources/Vapor/Environment/Environment+Secret.swift @@ -39,5 +39,5 @@ extension Environment { nil }) } -} +} diff --git a/Sources/Vapor/Environment/Environment.swift b/Sources/Vapor/Environment/Environment.swift index f4e4ecd117..e61e6056dc 100644 --- a/Sources/Vapor/Environment/Environment.swift +++ b/Sources/Vapor/Environment/Environment.swift @@ -30,6 +30,7 @@ public struct Environment: Equatable { @Option(name: "env", short: "e", help: "Change the application's environment") var environment: String? } + var env: Environment switch try EnvironmentSignature(from: &commandInput).environment ?? Environment.process.VAPOR_ENV From 08bea6a1e83f32308a0a10b17bc493472a3ce5f3 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Sun, 10 May 2020 14:32:50 -0500 Subject: [PATCH 03/12] Don't check isRelease Environment.==, it will always be equal because the value is effectively a compile-time constant. Also improve the use of MARK comments so Xcode renders the intended divisions nicely. --- Sources/Vapor/Environment/Environment.swift | 25 ++++++++++++--------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Sources/Vapor/Environment/Environment.swift b/Sources/Vapor/Environment/Environment.swift index e61e6056dc..97cb6860bf 100644 --- a/Sources/Vapor/Environment/Environment.swift +++ b/Sources/Vapor/Environment/Environment.swift @@ -12,6 +12,9 @@ /// print(Environment.get("DB_PASSWORD")) /// public struct Environment: Equatable { + + // MARK: - Detection + /// Detects the environment from `CommandLine.arguments`. Invokes `detect(from:)`. /// - parameters: /// - arguments: Command line arguments to detect environment from. @@ -44,7 +47,7 @@ public struct Environment: Equatable { return env } - // MARK: Presets + // MARK: - Presets /// An environment for deploying your application to consumers. public static var production: Environment { .init(name: "production") } @@ -58,26 +61,26 @@ public struct Environment: Equatable { /// Creates a custom environment. public static func custom(name: String) -> Environment { .init(name: name) } - // MARK: Env + // MARK: - Env /// Gets a key from the process environment public static func get(_ key: String) -> String? { return ProcessInfo.processInfo.environment[key] } - // MARK: Equatable - - /// See `Equatable` - public static func ==(lhs: Environment, rhs: Environment) -> Bool { - return lhs.name == rhs.name && lhs.isRelease == rhs.isRelease - } - /// The current process of the environment. public static var process: Process { return Process() } - // MARK: Properties + // MARK: - Equatable + + /// See `Equatable` + public static func ==(lhs: Environment, rhs: Environment) -> Bool { + return lhs.name == rhs.name + } + + // MARK: - Properties /// The environment's unique name. public let name: String @@ -97,7 +100,7 @@ public struct Environment: Equatable { set { arguments = newValue.executablePath + newValue.arguments } } - // MARK: Init + // MARK: - Init /// Create a new `Environment`. public init(name: String, arguments: [String] = CommandLine.arguments) { From 459516981a5f7fdd3414f6a8e87e4f19f83d195a Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Sun, 10 May 2020 14:33:13 -0500 Subject: [PATCH 04/12] Add warning to `Environment.isRelease` explaining the seemingly unusual behavior of its value. --- Sources/Vapor/Environment/Environment.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/Vapor/Environment/Environment.swift b/Sources/Vapor/Environment/Environment.swift index 97cb6860bf..5cbfdc2c75 100644 --- a/Sources/Vapor/Environment/Environment.swift +++ b/Sources/Vapor/Environment/Environment.swift @@ -89,6 +89,12 @@ public struct Environment: Equatable { /// /// This usually means reducing logging, disabling debug information, and sometimes /// providing warnings about configuration states that are not suitable for production. + /// + /// - Warning: This value is determined at compile time by configuration; it is not + /// based on the actual environment name. This can lead to unxpected results, such + /// as `Environment.production.isRelease == false`. This is done intentionally to + /// allow scenarios, such as testing production environment behaviors while retaining + /// availability of debug information. public var isRelease: Bool { !_isDebugAssertConfiguration() } /// The command-line arguments for this `Environment`. From 740241d0e9350ce1b2f61c34ff1f3e760c078bb9 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Sun, 10 May 2020 14:34:16 -0500 Subject: [PATCH 05/12] Redo the documentation comments for `Environment.secret()` (both versions). Significantly simplify the implementation of the path-taking version. IMPORTANT NOTE: This is an interim step of cleanup while a much more complete revamping of this API is worked on. --- .../Environment/Environment+Secret.swift | 74 ++++++++++++------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/Sources/Vapor/Environment/Environment+Secret.swift b/Sources/Vapor/Environment/Environment+Secret.swift index bdcf928a98..bb6cb9f539 100644 --- a/Sources/Vapor/Environment/Environment+Secret.swift +++ b/Sources/Vapor/Environment/Environment+Secret.swift @@ -1,43 +1,63 @@ extension Environment { - /// Reads a file's content for a secret. The secret key represents the name of the environment variable that holds the path for the file containing the secret + + /// Reads a file's content for a secret. The secret key is the name of the environment variable that is expected to + /// specify the path of the file containing the secret. + /// /// - Parameters: - /// - key: Environment name for the path to the file containing the secret - /// - fileIO: FileIO handler provided by NIO - /// - on: EventLoop to operate on while opening the file - /// - Throws: Error.environmentVariableNotFound if the environment variable with the key name does not exist + /// - key: The environment variable name + /// - fileIO: `NonBlockingFileIO` handler provided by NIO + /// - eventLoop: `EventLoop` for NIO to use for working with the file + /// + /// Example usage: + /// + /// ```` + /// func configure(_ app: Application) { + /// // ... + /// + /// let databasePassword = try Environment.secret( + /// key: "DATABASE_PASSWORD_FILE", + /// fileIO: app.fileio, + /// on: app.eventLoopGroup.next() + /// ).wait() + /// + /// ```` + /// + /// - Important: Do _not_ use `.wait()` if loading a secret at any time after the app has booted, such as while + /// handling a `Request`. Chain the result as you would any other future instead. public static func secret(key: String, fileIO: NonBlockingFileIO, on eventLoop: EventLoop) -> EventLoopFuture { - guard let filePath = self.get(key) else { return eventLoop.future(nil) } + guard let filePath = self.get(key) else { + return eventLoop.future(nil) + } return self.secret(path: filePath, fileIO: fileIO, on: eventLoop) } - /// Reads a file's content for a secret. The path is a file path to the file that contains the secret in plain text + /// Load the content of a file at a given path as a secret. + /// /// - Parameters: - /// - path: Path to the file that contains the secret - /// - fileIO: FileIO handler provided by NIO - /// - on: EventLoop to operate on while opening the file - /// - Throws: Error.environmentVariableNotFound if the environment variable with the key name does not exist + /// - path: Path to the file containing the secret + /// - fileIO: `NonBlockingFileIO` handler provided by NIO + /// - eventLoop: `EventLoop` for NIO to use for working with the file + /// + /// - Returns: + /// - On success, a succeeded future with the loaded content of the file. + /// - On any kind of error, a succeeded future with a value of `nil`. It is not currently possible to get error details. public static func secret(path: String, fileIO: NonBlockingFileIO, on eventLoop: EventLoop) -> EventLoopFuture { return fileIO .openFile(path: path, eventLoop: eventLoop) - .flatMap({ (arg) -> EventLoopFuture in + .flatMap { handle, region in return fileIO - .read(fileRegion: arg.1, allocator: .init(), eventLoop: eventLoop) - .flatMapThrowing({ (buffer) -> ByteBuffer in - try arg.0.close() - return buffer - }) - }) - .map({ (buffer) -> (String) in - var buffer = buffer - return buffer.readString(length: buffer.writerIndex) ?? "" - }) - .map({ (secret) -> (String) in - secret.trimmingCharacters(in: .whitespacesAndNewlines) - }) - .recover ({ (_) -> String? in + .read(fileRegion: region, allocator: .init(), eventLoop: eventLoop) + .always { _ in try? handle.close() } + } + .map { buffer -> String in + return buffer + .getString(at: buffer.readerIndex, length: buffer.readableBytes)! + .trimmingCharacters(in: .whitespacesAndNewlines) + } + .recover { _ -> String? in nil - }) + } } } From a690e5cbeb38e614a6f98d618b9e155ac994025f Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Sun, 10 May 2020 15:38:24 -0500 Subject: [PATCH 06/12] Correctly sanitize the excess arguments Xcode passes to test invocations for the testing environment. I forgot to mention in a previous commit that support was added for `VAPOR_ENV` too... --- Sources/Vapor/Environment/Environment.swift | 39 +++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/Sources/Vapor/Environment/Environment.swift b/Sources/Vapor/Environment/Environment.swift index 5cbfdc2c75..8b05881d8e 100644 --- a/Sources/Vapor/Environment/Environment.swift +++ b/Sources/Vapor/Environment/Environment.swift @@ -1,3 +1,5 @@ +import ConsoleKit + /// The environment the application is running in, i.e., production, dev, etc. All `Container`s will have /// an `Environment` that can be used to dynamically register and configure services. /// @@ -24,11 +26,14 @@ public struct Environment: Equatable { return try Environment.detect(from: &commandInput) } - /// Detects the environment from `CommandInput`. Parses the `--env` flag. + /// Detects the environment from `CommandInput`. Parses the `--env` flag, with the + /// `VAPOR_ENV` environment variable as a fallback. /// - parameters: /// - arguments: `CommandInput` to parse `--env` flag from. /// - returns: The detected environment, or default env. public static func detect(from commandInput: inout CommandInput) throws -> Environment { + self.sanitize(commandInput: &commandInput) + struct EnvironmentSignature: CommandSignature { @Option(name: "env", short: "e", help: "Change the application's environment") var environment: String? @@ -47,6 +52,32 @@ public struct Environment: Equatable { return env } + /// Performs stripping of user defaults overrides where and when appropriate. + private static func sanitize(commandInput: inout CommandInput) { + #if Xcode + // Strip all leading arguments matching the pattern for assignment to the `NSArgumentsDomain` + // of `UserDefaults`. Matching this pattern means being prefixed by `-NS` or `-Apple` and being + // followed by a value argument. Since this is mainly just to get around Xcode's habit of + // passing a bunch of these when no other arguments are specified in a test scheme, we ignore + // any that don't match the Apple patterns and assume the app knows what it's doing. + // + // Note that we also perform this behavior more forcefully when the `.testing` environment is + // constructed, even if it means + while (commandInput.arguments.first?.prefix(6) == "-Apple" || commandInput.arguments.first?.prefix(3) == "-NS"), + commandInput.arguments.count > 1 { + commandInput.arguments.removeFirst(2) + } + #endif + } + + /// Invokes `sanitize(commandInput:)` over a set of raw arguments and returns the + /// resulting arguments, including the executable path. + private static func sanitizeArguments(_ arguments: [String] = CommandLine.arguments) -> [String] { + var commandInput = CommandInput(arguments: arguments) + sanitize(commandInput: &commandInput) + return commandInput.executablePath + commandInput.arguments + } + // MARK: - Presets /// An environment for deploying your application to consumers. @@ -56,7 +87,11 @@ public struct Environment: Equatable { public static var development: Environment { .init(name: "development") } /// An environment for testing your application. - public static var testing: Environment { .init(name: "testing") } + /// + /// Performs an explicit sanitization step because this preset is often used directly in unit tests, without the + /// benefit of the logic usually invoked through either form of `detect()`. This means that when `--env test` is + /// explicitly specified, the sanitize logic is run twice, but this should be harmless. + public static var testing: Environment { .init(name: "testing", arguments: sanitizeArguments()) } /// Creates a custom environment. public static func custom(name: String) -> Environment { .init(name: name) } From ebb4da557deb2ce59e4d47950bbdc606467a13a9 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Sun, 10 May 2020 16:46:55 -0500 Subject: [PATCH 07/12] Add sanitization of raw SwiftPM's invocation of the xctest runner binary. This is necessarily a little specific to the version of SwiftPM and Xcode involved, but should at least be specific enough a check to not interfere with normal operations if the call sequence changes. --- Sources/Vapor/Environment/Environment.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sources/Vapor/Environment/Environment.swift b/Sources/Vapor/Environment/Environment.swift index 8b05881d8e..4e21878db2 100644 --- a/Sources/Vapor/Environment/Environment.swift +++ b/Sources/Vapor/Environment/Environment.swift @@ -67,6 +67,19 @@ public struct Environment: Equatable { commandInput.arguments.count > 1 { commandInput.arguments.removeFirst(2) } + #elseif os(macOS) || os(iOS) || os(tvOS) || os(watchOS) + // When tests are invoked directly through SwiftPM using `--filter`, SwiftPM will pass `-XCTest ` to the + // runner binary, and also the test bundle path unconditionally. These must be stripped for Vapor to be satisifed + // with the validity of the arguments. We detect this case reliably the hard way, by looking for the `xctest` + // runner executable and a leading argument with the `.xctest` bundle suffix. + if commandInput.executable.hasSuffix("/usr/bin/xctest") { + if commandInput.arguments.first?.lowercased() == "-xctest" && commandInput.arguments.count > 1 { + commandInput.arguments.removeFirst(2) + } + if commandInput.arguments.first?.hasSuffix(".xctest") ?? false { + commandInput.arguments.removeFirst() + } + } #endif } From 426907c4d044611baaca614d0fea309c8697f32a Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Sun, 10 May 2020 16:57:36 -0500 Subject: [PATCH 08/12] There is no need to hardcode all the logger levels for LosslessStringConvertible conformance. Logger.Level is already RawRepresentable as String and that conformance can be used transparently. (And it has CaseIterable for good measure, which provides yet another way to scale this particular elevation.) --- .../Logging/LoggingSystem+Environment.swift | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/Sources/Vapor/Logging/LoggingSystem+Environment.swift b/Sources/Vapor/Logging/LoggingSystem+Environment.swift index 4c685ec721..64e5ab5fb9 100644 --- a/Sources/Vapor/Logging/LoggingSystem+Environment.swift +++ b/Sources/Vapor/Logging/LoggingSystem+Environment.swift @@ -22,28 +22,6 @@ extension LoggingSystem { } extension Logger.Level: LosslessStringConvertible { - public init?(_ description: String) { - switch description.lowercased() { - case "trace": self = .trace - case "debug": self = .debug - case "info": self = .info - case "notice": self = .notice - case "warning": self = .warning - case "error": self = .error - case "critical": self = .critical - default: return nil - } - } - - public var description: String { - switch self { - case .trace: return "trace" - case .debug: return "debug" - case .info: return "info" - case .notice: return "notice" - case .warning: return "warning" - case .error: return "error" - case .critical: return "critical" - } - } + public init?(_ description: String) { self.init(rawValue: description) } + public var description: String { self.rawValue } } From 9efff9aaa0fcfa6ca38333380b9ccc2d9209767b Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Mon, 11 May 2020 02:47:55 -0500 Subject: [PATCH 09/12] Fix a couple of silly mistakes --- Sources/Vapor/Environment/Environment.swift | 3 --- Sources/Vapor/Logging/LoggingSystem+Environment.swift | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Sources/Vapor/Environment/Environment.swift b/Sources/Vapor/Environment/Environment.swift index 4e21878db2..0718e0f78a 100644 --- a/Sources/Vapor/Environment/Environment.swift +++ b/Sources/Vapor/Environment/Environment.swift @@ -60,9 +60,6 @@ public struct Environment: Equatable { // followed by a value argument. Since this is mainly just to get around Xcode's habit of // passing a bunch of these when no other arguments are specified in a test scheme, we ignore // any that don't match the Apple patterns and assume the app knows what it's doing. - // - // Note that we also perform this behavior more forcefully when the `.testing` environment is - // constructed, even if it means while (commandInput.arguments.first?.prefix(6) == "-Apple" || commandInput.arguments.first?.prefix(3) == "-NS"), commandInput.arguments.count > 1 { commandInput.arguments.removeFirst(2) diff --git a/Sources/Vapor/Logging/LoggingSystem+Environment.swift b/Sources/Vapor/Logging/LoggingSystem+Environment.swift index 64e5ab5fb9..51e0ef6c30 100644 --- a/Sources/Vapor/Logging/LoggingSystem+Environment.swift +++ b/Sources/Vapor/Logging/LoggingSystem+Environment.swift @@ -22,6 +22,6 @@ extension LoggingSystem { } extension Logger.Level: LosslessStringConvertible { - public init?(_ description: String) { self.init(rawValue: description) } + public init?(_ description: String) { self.init(rawValue: description.lowercased()) } public var description: String { self.rawValue } } From 79b0ea0f7a617205c4a6dff63e81edb3b808cd8e Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Tue, 26 May 2020 10:38:53 -0500 Subject: [PATCH 10/12] Apply suggestions from code review --- Sources/Vapor/Environment/Environment+Process.swift | 1 - Sources/Vapor/Environment/Environment+Secret.swift | 2 +- Sources/Vapor/Environment/Environment.swift | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/Vapor/Environment/Environment+Process.swift b/Sources/Vapor/Environment/Environment+Process.swift index 0ca7559f85..9e9e4b2e63 100644 --- a/Sources/Vapor/Environment/Environment+Process.swift +++ b/Sources/Vapor/Environment/Environment+Process.swift @@ -1,5 +1,4 @@ extension Environment { - /// The process information of an environment. Wraps `ProcessInto.processInfo`. @dynamicMemberLookup public struct Process { diff --git a/Sources/Vapor/Environment/Environment+Secret.swift b/Sources/Vapor/Environment/Environment+Secret.swift index bb6cb9f539..c6735ad90d 100644 --- a/Sources/Vapor/Environment/Environment+Secret.swift +++ b/Sources/Vapor/Environment/Environment+Secret.swift @@ -52,7 +52,7 @@ extension Environment { } .map { buffer -> String in return buffer - .getString(at: buffer.readerIndex, length: buffer.readableBytes)! + .getString(at: buffer.readerIndex, length: buffer.readableBytes)! .trimmingCharacters(in: .whitespacesAndNewlines) } .recover { _ -> String? in diff --git a/Sources/Vapor/Environment/Environment.swift b/Sources/Vapor/Environment/Environment.swift index 0718e0f78a..37bdb9f2b0 100644 --- a/Sources/Vapor/Environment/Environment.swift +++ b/Sources/Vapor/Environment/Environment.swift @@ -41,7 +41,7 @@ public struct Environment: Equatable { var env: Environment switch try EnvironmentSignature(from: &commandInput).environment ?? - Environment.process.VAPOR_ENV + Environment.process.VAPOR_ENV { case "prod", "production": env = .production case "dev", "development", .none: env = .development From 1c985276b822209f39510c741d4103ea86ad4321 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Tue, 26 May 2020 10:40:29 -0500 Subject: [PATCH 11/12] Missed an indentation fix --- Sources/Vapor/Environment/Environment+Secret.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Vapor/Environment/Environment+Secret.swift b/Sources/Vapor/Environment/Environment+Secret.swift index c6735ad90d..6a35d16682 100644 --- a/Sources/Vapor/Environment/Environment+Secret.swift +++ b/Sources/Vapor/Environment/Environment+Secret.swift @@ -53,7 +53,7 @@ extension Environment { .map { buffer -> String in return buffer .getString(at: buffer.readerIndex, length: buffer.readableBytes)! - .trimmingCharacters(in: .whitespacesAndNewlines) + .trimmingCharacters(in: .whitespacesAndNewlines) } .recover { _ -> String? in nil From b7b332b797875476c53395cf54178d2391daf851 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Tue, 26 May 2020 10:54:33 -0500 Subject: [PATCH 12/12] Not sure what Tanner has against blank lines, really, but what the hey --- Sources/Vapor/Environment/Environment+Process.swift | 2 -- Sources/Vapor/Environment/Environment+Secret.swift | 2 -- Sources/Vapor/Environment/Environment.swift | 1 - 3 files changed, 5 deletions(-) diff --git a/Sources/Vapor/Environment/Environment+Process.swift b/Sources/Vapor/Environment/Environment+Process.swift index 9e9e4b2e63..66aaaadc80 100644 --- a/Sources/Vapor/Environment/Environment+Process.swift +++ b/Sources/Vapor/Environment/Environment+Process.swift @@ -1,7 +1,6 @@ extension Environment { /// The process information of an environment. Wraps `ProcessInto.processInfo`. @dynamicMemberLookup public struct Process { - /// The process information of the environment. private let _info: ProcessInfo @@ -48,5 +47,4 @@ extension Environment { } } } - } diff --git a/Sources/Vapor/Environment/Environment+Secret.swift b/Sources/Vapor/Environment/Environment+Secret.swift index 6a35d16682..eafd3a5d9e 100644 --- a/Sources/Vapor/Environment/Environment+Secret.swift +++ b/Sources/Vapor/Environment/Environment+Secret.swift @@ -1,5 +1,4 @@ extension Environment { - /// Reads a file's content for a secret. The secret key is the name of the environment variable that is expected to /// specify the path of the file containing the secret. /// @@ -59,5 +58,4 @@ extension Environment { nil } } - } diff --git a/Sources/Vapor/Environment/Environment.swift b/Sources/Vapor/Environment/Environment.swift index 37bdb9f2b0..0461b88d3f 100644 --- a/Sources/Vapor/Environment/Environment.swift +++ b/Sources/Vapor/Environment/Environment.swift @@ -14,7 +14,6 @@ import ConsoleKit /// print(Environment.get("DB_PASSWORD")) /// public struct Environment: Equatable { - // MARK: - Detection /// Detects the environment from `CommandLine.arguments`. Invokes `detect(from:)`.