Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit e8ce194

Browse files
committed
use code cli for token and update readme
1 parent 1273378 commit e8ce194

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

github-upload-public-key/README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ display_name: Github Upload Public Key
33
description: Automates uploading Coder public key to Github so users don't have to.
44
icon: ../.icons/github.svg
55
maintainer_github: f0ssel
6-
verified: false
7-
tags: [helper]
6+
verified: true
7+
tags: [helper, git]
88
---
99

1010
# github-upload-public-key
1111

12-
<!-- Describes what this module does -->
12+
Templates that utilize Github External Auth can automatically ensure that the Coder public key is uploaded to Github so that users can clone repositories without needing to upload the public key themselves.
1313

1414
```tf
1515
module "github-upload-public-key" {
@@ -19,5 +19,16 @@ module "github-upload-public-key" {
1919
}
2020
```
2121

22-
<!-- Add a screencast or screenshot here put them in .images directory -->
23-
<!-- TODO: Add examples -->
22+
# Requirements
23+
24+
Github External Auth must be enabled in the workspace for this module to work. The Github app that is configured for external auth must have both read and write permissions to "Git SSH keys" in order to upload the public key. Additionally, a Coder admin must also have the `admin:public_key` scope added to the external auth configuration of the Coder deployment. For example:
25+
26+
```
27+
CODER_EXTERNAL_AUTH_0_ID="USER_DEFINED_ID"
28+
CODER_EXTERNAL_AUTH_0_TYPE=github
29+
CODER_EXTERNAL_AUTH_0_CLIENT_ID=xxxxxx
30+
CODER_EXTERNAL_AUTH_0_CLIENT_SECRET=xxxxxxx
31+
CODER_EXTERNAL_AUTH_0_SCOPES="repo,workflow,admin:public_key"
32+
```
33+
34+
Note that the default scopes if not provided are `repo,workflow`.

github-upload-public-key/run.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ if [ -z "$CODER_OWNER_SESSION_TOKEN" ]; then
1515
exit 1
1616
fi
1717

18+
echo "Fetching GitHub token..."
19+
GITHUB_TOKEN=$(coder external-auth access-token github)
20+
if [ $? -ne 0 ]; then
21+
echo "Failed to fetch GitHub token!"
22+
exit 1
23+
fi
1824
if [ -z "$GITHUB_TOKEN" ]; then
19-
echo "No GITHUB_TOKEN in the workspace environment!"
20-
echo "The user must be authenticated with Github before this script can be run."
25+
echo "No GitHub token found!"
2126
exit 1
2227
fi
28+
echo "GitHub token found!"
2329

2430
echo "Fetching Coder public SSH key..."
2531
PUBLIC_KEY_RESPONSE=$(curl -L -s \

0 commit comments

Comments
 (0)