Skip to content

Commit 327815b

Browse files
authored
Add option to load github token from conf file (#7)
* Add option to load github token from conf file * bumb version
1 parent 6ca93ca commit 327815b

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ Each entry uses the format:
2424
- **api:** Fetches from a private GitHub repo using the GitHub API (requires `GITHUB_TOKEN` environment variable).
2525
- **ghuser:** Fetches public keys from a GitHub user's profile (provide the GitHub username after the colon).
2626

27+
You can also set your GitHub token in the config file using `CONF_GITHUB_TOKEN`.
28+
If `GITHUB_TOKEN` is not set in the environment, the script will use `CONF_GITHUB_TOKEN` from `users.conf`.
29+
2730
**Example `users.conf`:**
2831
```bash
32+
CONF_GITHUB_TOKEN="your_github_token_here"
33+
2934
declare -A USER_KEYS=(
3035
["ubuntu"]="raw:https://example.com/ssh-keys/ubuntu.authorized_keys"
3136
["devuser"]="api:https://api.github.com/repos/yourorg/ssh-keys/contents/keys/devuser.authorized_keys?ref=main"
@@ -36,7 +41,7 @@ declare -A USER_KEYS=(
3641
## Usage
3742

3843
1. Edit the `users.conf` file to define users and their key URLs or GitHub usernames.
39-
2. If using the `api` method, export your GitHub token:
44+
2. If using the `api` method, either export your GitHub token or set `CONF_GITHUB_TOKEN` in `users.conf`:
4045
```bash
4146
export GITHUB_TOKEN=your_token_here
4247
```

sync-ssh-keys.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -euo pipefail
33

44
# shellcheck disable=SC2034 # planned to be used in a future release
5-
SCRIPT_VERSION="0.0.6"
5+
SCRIPT_VERSION="0.0.7"
66

77
# === Load user configuration ===
88
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -15,6 +15,11 @@ if ! source "$SCRIPT_DIR/users.conf"; then
1515
exit 1
1616
fi
1717

18+
# Load GITHUB_TOKEN from config if set and not already in environment
19+
if [[ -n "${CONF_GITHUB_TOKEN:-}" && -z "${GITHUB_TOKEN:-}" ]]; then
20+
export GITHUB_TOKEN="$CONF_GITHUB_TOKEN"
21+
fi
22+
1823
log_message() {
1924
local TIMESTAMP
2025
TIMESTAMP="$(date '+%Y-%m-%d %H:%M:%S')"

users.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
CONF_GITHUB_TOKEN="your_github_token_here"
3+
14
declare -A USER_KEYS=(
25
["ubuntu"]="raw:https://example.com/ssh-keys/ubuntu.authorized_keys"
36
["devuser"]="api:https://api.github.com/repos/yourorg/ssh-keys/contents/keys/devuser.authorized_keys?ref=main"

0 commit comments

Comments
 (0)