refactor(locations): replace env_token with direct-value token field#404
Merged
Conversation
Rename env_token → token across all location types (git, maven, pypi,
npm) and change semantics: the field now holds the token value directly
rather than an environment variable name. Users supply tokens via
\${VAR} interpolation introduced in #397 (e.g. token: \${GITLAB_TOKEN}).
Removes os.getenv() indirection from all location classes. Updates
JSON schema, generated Pydantic models, CLI flag (--env_token →
--token), model generator, all test fixtures, and unit / integration
tests accordingly.
Signed-off-by: Jimisola Laursen <jimisola@jimisola.com>
Signed-off-by: Jimisola Laursen <jimisola@jimisola.com>
- SecretStr: use pydantic.SecretStr for token field in all 4 location
classes — prevents raw secret from appearing in repr/model_dump/
ValidationError messages; callers extract value via .get_secret_value()
- Credentials: pass callbacks=None to clone_repository when no token,
eliminating UserPass(password=None) passed to pygit2
- Schema: add writeOnly:true to all 4 token property definitions and
regenerate models
- Docs examples: quote token interpolation as token: "${VAR}" to prevent
YAML injection when env value contains structural characters
- Remote fixture: change literal token to token: "${GITLAB_TOKEN:-}"
- CLI help: fix $VAR → ${VAR} in all --token help strings
- CLI ternaries: simplify x if x else None → x or None (×4)
- Integration tests: fix choose_token() skipif; rename _GITHUB_TOKEN_ENV
→ _GITHUB_TOKEN_VAR_NAME
- Test fixtures: use clearly dummy token values (dummy-gitlab-token etc.)
- Exception message: use type(e).__name__ instead of {e} in pypi
- Copyright: add missing # Copyright © LFV header to pypi_location.py
- New tests: token forwarding for git/maven/pypi; empty-string no-auth;
repr does not expose secret value; --token CLI flag for git/maven/pypi
Signed-off-by: Jimisola Laursen <jimisola@jimisola.com>
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
env_token→tokenin all four location types (git, maven, pypi, npm)tokennow holds the value directly rather than an environment variable name — theos.getenv()indirection in each location class is removed${VAR}interpolation (added in feat(locations): interpolate environment variables in YAML input (#158) #397):env_token: "GITLAB_TOKEN"→token: "${GITLAB_TOKEN}"Breaking change
YAML files using
env_token:must be updated to usetoken: "${VAR}". The CLI flag--env_token/-tis also renamed to--token.Files changed
requirements.schema.json+ regeneratedrequirements_schema.py(codegen viahatch run dev:codegen)import os, replacedos.getenv(self.env_token)withself.tokencommand.py:--env_tokenflag →--tokenrequirements_model_generator.py: keyword arg renameTest plan
hatch run dev:pytest tests/unit— 794 passedhatch run dev:codegen-check— schema/model consistenthatch run python src/reqstool/command.py status local -p tests/resources/...— output unchangedreqstool status git --helpconfirms--tokenflag with updated help text