Add directory-local config and wildcard TERMINUS_USER matching#2827
Open
georgestephanis wants to merge 2 commits into
Open
Add directory-local config and wildcard TERMINUS_USER matching#2827georgestephanis wants to merge 2 commits into
georgestephanis wants to merge 2 commits into
Conversation
Introduce DirectoryConfig which walks up from a starting directory (typically getcwd()) to locate a .terminus YAML file, parses it, and merges its values into the Terminus configuration (setting the config source name). Wire DirectoryConfig into Terminus so the runtime will extend its Defaults/Yaml/user-home config chain with any per-project .terminus settings before loading DotEnv/Env configs.
Allow TERMINUS_USER to be a wildcard or shorthand pattern (e.g. "*@domain.com" or "@domain.com") when selecting a saved token. The token-selection logic now checks the configured user first, matches patterns via fnmatch (with '@domain.com' normalized to '*@domain.com'), and falls back to the single saved token if no user is configured. Added helper methods isEmailPattern() and matchTokenByPattern() and improved error messages for zero or multiple matches.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds two small quality-of-life features for users who work with multiple Pantheon accounts (e.g. agency developers juggling client accounts).
1. Directory-local
.terminusconfig filesA new
DirectoryConfigclass walks up from the current working directory to the filesystem root, looking for a.terminusYAML file. If one is found, it is loaded into the config chain between~/.terminus/config.ymland the existing.env/ environment-variable layers.This lets you drop a
.terminusfile in any project root:Any
terminuscommand run from that directory or any of its subdirectories will automatically pick up those settings — no flags or environment variables required.Config precedence (lowest → highest):
constants.yml→~/.terminus/config.yml→.terminus(walk-up) →.env→ environment variables2. Wildcard/partial matching for
TERMINUS_USERAuthorizer::ensureLogin()now supports fnmatch-style patterns inTERMINUS_USER, so a shared.terminusfile can target the right account without hardcoding a specific email:Supported forms:
george@example.com@example.com*@example.com)*@example.comgeorge@*If the pattern matches zero tokens, a clear error directs the user to
auth:login. If it matches more than one, an error asks them to be more specific — useful when a team member has tokens for multiple accounts at the same domain.The
TERMINUS_USERcheck is now evaluated before the single-token auto-select, so an explicit pattern always takes priority.Changed files
src/Config/DirectoryConfig.php(new) — walks up directory tree to find and load.terminussrc/Terminus.php— insertsDirectoryConfiginto thefactory()config chainsrc/Hooks/Authorizer.php— addsisEmailPattern()andmatchTokenByPattern()helpersTesting
All existing unit tests pass. Because both features interact with the filesystem and the saved-token store rather than the Pantheon API, they are best exercised manually or via future functional tests: