Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment cleanups #2353

Merged
merged 12 commits into from May 26, 2020
Merged

Environment cleanups #2353

merged 12 commits into from May 26, 2020

Conversation

gwynne
Copy link
Member

@gwynne gwynne commented May 10, 2020

  • Clean up Environment's implementation.

  • Add the ability to specify the application environment using the environment variable VAPOR_ENV (partial implementation of Support $PORT and $HOSTNAME #2333). If both VAPOR_ENV and --env are provided, the latter always takes precedence.

  • Environment now recognizes and strips the spurious arguments Xcode passes to test runners when a scheme doesn't specify any arguments of its own. It will do this especially specifically for the testing environment, which is often explicitly specified to Application's initializers instead of .detect() in unit tests. This behavior is only enabled when building in Xcode or with xcodebuild. This negates the need to explicitly override the input arguments in the non-production presets, meaning command line arguments no longer occasionally seem to vanish into thin air in certain cases.

  • Redo the documentation comments for both versions of Environment.secret() and significantly simplify the implementation. Important: This is an interim cleanup step pending a complete revamp of the secret() API.

Note: Pains have been taken not to change the observable behavior of any public APIs and to remain otherwise behaviorally consistent. The addition of VAPOR_ENV counts as new public API and thus drives this being a semver-minor change, but in all other respects it should have no visible effect.

… the value is effectively a compile-time constant. Also improve the use of MARK comments so Xcode renders the intended divisions nicely.
…ions). 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.
@gwynne gwynne added enhancement New feature or request semver-patch Internal changes only labels May 10, 2020
@gwynne gwynne requested a review from tanner0101 May 10, 2020 19:37
@gwynne gwynne self-assigned this May 10, 2020
@gwynne gwynne added this to Awaiting Review in Vapor 4 via automation May 10, 2020
@gwynne
Copy link
Member Author

gwynne commented May 10, 2020

I have a complete rework of the secret() API in progress which will provide a more robust and safe interface for loading and working with secrets. Planned features:

  • Implements both synchronous API with a completion callback for sensible use in configure(_:) and asynchronous API in case use after app launch is needed.
  • Allows a timeout to be provided in case reading data from a network-mounted path takes too long
  • Zeroes out memory buffers as much as possible as soon as done with them (these are supposed to be secrets, after all!)
  • Returns full error information
  • Implemented as a provider on Application rather than an extension on Environment to simplify invocation and efficient usage.

(The existing API on Environment would ideally be deprecated by the new API, but not removed since that would be API breakage and thus semver-major.)

…ons for the testing environment. I forgot to mention in a previous commit that support was added for `VAPOR_ENV` too...
@gwynne gwynne added semver-minor Contains new API and removed semver-patch Internal changes only labels May 10, 2020
@gwynne
Copy link
Member Author

gwynne commented May 10, 2020

(Note: CI failures are being addressed.)

MrLotU
MrLotU previously approved these changes May 10, 2020
Copy link
Sponsor Member

@MrLotU MrLotU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 lil nit

…ary. 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.
…Convertible 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.)
@gwynne gwynne requested a review from MrLotU May 10, 2020 22:22
@gwynne gwynne dismissed MrLotU’s stale review May 10, 2020 22:22

Want a new review for new changes, dismissing old

Copy link
Sponsor Member

@MrLotU MrLotU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall. 2 small comments

Sources/Vapor/Environment/Environment.swift Outdated Show resolved Hide resolved
Sources/Vapor/Logging/LoggingSystem+Environment.swift Outdated Show resolved Hide resolved
@MrLotU
Copy link
Sponsor Member

MrLotU commented May 23, 2020

Ping @tanner0101

Copy link
Member

@tanner0101 tanner0101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks! Only style nits.

Sources/Vapor/Environment/Environment+Process.swift Outdated Show resolved Hide resolved
Sources/Vapor/Environment/Environment+Secret.swift Outdated Show resolved Hide resolved
Sources/Vapor/Environment/Environment.swift Outdated Show resolved Hide resolved
Sources/Vapor/Environment/Environment+Process.swift Outdated Show resolved Hide resolved
Sources/Vapor/Environment/Environment+Process.swift Outdated Show resolved Hide resolved
Sources/Vapor/Environment/Environment+Secret.swift Outdated Show resolved Hide resolved
Sources/Vapor/Environment/Environment+Secret.swift Outdated Show resolved Hide resolved
Sources/Vapor/Environment/Environment.swift Outdated Show resolved Hide resolved
@gwynne gwynne merged commit a049aff into master May 26, 2020
Vapor 4 automation moved this from Awaiting Review to Done May 26, 2020
@gwynne gwynne deleted the environment-cleanups branch May 26, 2020 17:27
@tanner0101
Copy link
Member

These changes are now available in 4.6.0

nachoBonafonte pushed a commit to scope-demo/vapor that referenced this pull request May 27, 2020
* New works-for-everything CI (vapor#2365)

* New works-for-everything CI

This version of the test workflow can be pasted without changes into any repo whose tests don't have additional dependencies and don't need to separately test that they're still Vapor-compatible (such as console-kit). Improvements over existing CI:

- Runs on pushes to master as well as PRs
- Full coverage of all available Swift runner images for Linux
- Uses latest Xcode without hardcoding on macOS
- Nice names for each test step
- Nice name for the workflow itself

* Apply suggestions from code review

* `Environment` cleanups (vapor#2353)

* Remove numerous unnecessary code stanzas.

* Don't check `isRelease` in `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.

* Add warning to `Environment.isRelease` explaining the seemingly unusual behavior of its value.

* 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.

* 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...

* 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.

* 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.)

Co-authored-by: Gwynne Raskind <gwynne@darkrainfall.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request semver-minor Contains new API
Projects
Vapor 4
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants