chore(docker): openemr-cmd up prompt for gh token#624
chore(docker): openemr-cmd up prompt for gh token#624stephenwaite wants to merge 6 commits intoopenemr:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds an interactive flow in openemr-cmd to help developers set a GitHub Personal Access Token for Composer (to avoid GitHub API rate limiting) and simplifies the flex container startup script to only consume the raw GITHUB_COMPOSER_TOKEN.
Changes:
- Add
setup-composer-env(sce) command to create/update a.envfile containingGITHUB_COMPOSER_TOKEN, and auto-run it fromopenemr-cmd upwhen missing/invalid. - Add a GitHub rate-limit check during
openemr-cmd upto decide whether to re-run token setup. - Remove encoded-token fallback logic in
docker/openemr/flex/openemr.sh, leaving onlyGITHUB_COMPOSER_TOKEN.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| utilities/openemr-cmd/openemr-cmd | Adds token setup command and hooks it into up, including a GitHub API check. |
| docker/openemr/flex/openemr.sh | Simplifies composer token handling to only try GITHUB_COMPOSER_TOKEN. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| echo "" | ||
| echo "A GitHub Personal Access Token lets Composer avoid GitHub API rate limits" | ||
| echo "when pulling dependencies. It should never be committed to the repository." | ||
| echo "This writes GITHUB_COMPOSER_TOKEN plus its derived encoded variants to: ${ENV_FILE}" |
There was a problem hiding this comment.
The setup text says it will write “derived encoded variants” of the token, but this function only writes GITHUB_COMPOSER_TOKEN. Either remove that wording or actually write the encoded variants (if they’re still needed elsewhere).
| echo "This writes GITHUB_COMPOSER_TOKEN plus its derived encoded variants to: ${ENV_FILE}" | |
| echo "This writes GITHUB_COMPOSER_TOKEN to: ${ENV_FILE}" |
| echo "" | ||
|
|
||
| local TOKEN | ||
| read -r -e -p "Paste your GitHub Personal Access Token: " TOKEN </dev/tty |
There was a problem hiding this comment.
The prompt reads the PAT with normal read, which echoes the token to the terminal and stores it in scrollback/history for many shells. Use silent input (eg, read -s) and consider disabling readline (-e) for secret entry.
| read -r -e -p "Paste your GitHub Personal Access Token: " TOKEN </dev/tty | |
| read -r -s -p "Paste your GitHub Personal Access Token: " TOKEN </dev/tty | |
| echo "" |
|
|
||
| echo "" | ||
| echo "✓ Written to ${ENV_FILE}: GITHUB_COMPOSER_TOKEN = ${TOKEN:0:12}..." | ||
| echo " (.env is covered by the root .gitignore)" |
There was a problem hiding this comment.
This message claims the root .gitignore covers .env, but the repo’s .gitignore currently does not ignore .env. Since this command creates/updates ../../.env with a PAT, this is a real risk of accidentally committing credentials. Either update the repo ignore rules / use a file that’s already ignored, or change the guidance and default path.
| echo " (.env is covered by the root .gitignore)" | |
| echo " WARNING: ${ENV_FILE} is not ignored by git by default. Add it to .gitignore to avoid committing credentials." |
There was a problem hiding this comment.
added .env to the .gitignore here in this repo even though it applies when running in openemr
| else | ||
| UP_TOKEN=$(grep "^GITHUB_COMPOSER_TOKEN=" "../../.env" | cut -d= -f2) | ||
| UP_REMAINING=$(curl -sf -H "Authorization: token ${UP_TOKEN}" \ | ||
| https://api.github.com/rate_limit | grep -o '"remaining":[0-9]*' | head -1 | cut -d: -f2) |
There was a problem hiding this comment.
With set -euo pipefail, this command substitution will cause openemr-cmd up to exit immediately if curl fails (offline), GitHub is unreachable, or grep finds no match. Wrap the curl/parse pipeline in || true (or temporarily disable errexit) and handle an empty/failed response explicitly so up still proceeds or falls back to setup_composer_env. Also note the PAT is passed on the curl command line (visible via process listings); consider avoiding this validity check or using a safer mechanism.
| https://api.github.com/rate_limit | grep -o '"remaining":[0-9]*' | head -1 | cut -d: -f2) | |
| https://api.github.com/rate_limit | grep -o '"remaining":[0-9]*' | head -1 | cut -d: -f2 || true) |
|
|
||
| if [[ ! -f "docker-compose.yml" ]]; then | ||
| echo "Error: docker-compose.yml not found in current directory." >&2 | ||
| echo "Please run this command from the docker/development-easy directory." >&2 |
There was a problem hiding this comment.
can't this also be other directories? (insane one, predis one)
|
neat stuff! |
|
prob makes sense to get the worktree stuff in the code first since this mechanism may result in some minor modificaitons to work with that feature in place. |
Fixes #
Short description of what this resolves:
walks a dev thru getting their own personal access token
in tandem with openemr/openemr#11386
claude helped with bash stuff
Changes proposed in this pull request: