twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
13.4k stars 493 forks source link

gitHubKeys aborts `chezmoi status` if rate limited #2253

Closed indirect closed 2 years ago

indirect commented 2 years ago

What exactly are you trying to do?

Trying to run chezmoi status after getting rate-limited by GitHub (for unrelated reasons).

What have you tried so far?

I have run chezmoi status --verbose.

Where else have you checked for solutions?

Output of any commands you've tried with --verbose flag

$ chezmoi --verbose status
chezmoi: template: private_dot_ssh/private_authorized_keys.tmpl:1:9: executing "private_dot_ssh/private_authorized_keys.tmpl" at <gitHubKeys .github.username>: error calling gitHubKeys: GET https://api.github.com/users/indirect/keys?per_page=100: 403 API rate limit exceeded for 157.131.168.122. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.) [rate reset in 34m44s]

The contents of private_dot_ssh/private_authorized_keys.tmpl:

❯ cat private_dot_ssh/private_authorized_keys.tmpl
{{ range gitHubKeys .github.username -}}
{{   .Key }}
{{ end -}}

Output of chezmoi doctor

```console ❯ chezmoi doctor RESULT CHECK MESSAGE warning version dev failed latest-version GitHub rate limit exceeded ok os-arch darwin/arm64 ok uname Darwin gnk.local 22.0.0 Darwin Kernel Version 22.0.0: Wed Jul 20 01:53:56 PDT 2022; root:xnu-8792.0.188.141.3~2/RELEASE_ARM64_T6000 arm64 ok go-version go1.18.3 (gc) ok executable ~/.bin/chezmoi ok upgrade-method replace-executable ok config-file ~/.config/chezmoi/chezmoi.toml ok source-dir ~/.local/share/chezmoi is a directory ok suspicious-entries no suspicious entries ok working-tree ~/.local/share/chezmoi is a directory ok dest-dir ~ is a directory ok shell-command found /bin/zsh ok shell-args /bin/zsh ok cd-command found /bin/zsh ok cd-args /bin/zsh ok edit-command found /opt/homebrew/bin/mvim ok edit-args mvim -f --nomru -c 'au VimLeave * !open -a $TERM_APPLICATION' info diff-command not set ok umask 022 ok git-command found /opt/homebrew/bin/git, version 2.36.1 ok merge-command found /opt/homebrew/bin/vimdiff ok age-command found /opt/homebrew/bin/age, version 1.0.0 ok gpg-command found /opt/homebrew/bin/gpg, version 2.3.6 info pinentry-command not set ok 1password-command found /usr/local/bin/op, version 2.6.0 info bitwarden-command bw not found in $PATH info gopass-command gopass not found in $PATH info keepassxc-command keepassxc-cli not found in $PATH info keeper-command keeper not found in $PATH info keepassxc-db not set info lastpass-command lpass not found in $PATH info pass-command pass not found in $PATH info vault-command vault not found in $PATH info secret-command not set ```

Additional context

I can understand chezmoi apply failing if I am rate limited, since it can't fetch my keys from GitHub. My next idea was to run apply targeting just the specific files that I want to update—but to know which files need updating, I have to run status. And apparently just status also requires a successful API call to GitHub to get my keys, I am guessing to diff with the file on disk and report status? In that case, maybe it should be possible to skip that file, or warn that the API request failed, or something?

I can work around it by temporarily adding any templates that talk to GitHub to my .chezmoiignore, but it would be nice if it didn't abort the entire process.

Thanks!

twpayne commented 2 years ago

I'd recommend creating a GitHub personal access token for use by chezmoi, as described here.

It is technically possible for chezmoi to cache the last output of the various gitHub* template functions and re-use the last output when a rate limit is encountered, but using a personal access token is a more correct and much simpler solution :)

indirect commented 2 years ago

Sounds good, thanks for the suggestion!