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

Commit 5a33af2

Browse files
committed
fmt
1 parent 428f386 commit 5a33af2

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

github-upload-public-key/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tags: [helper, git]
1111

1212
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

14-
# Example
14+
# Example
1515

1616
```tf
1717
module "github-upload-public-key" {
@@ -33,4 +33,4 @@ CODER_EXTERNAL_AUTH_0_CLIENT_SECRET=xxxxxxx
3333
CODER_EXTERNAL_AUTH_0_SCOPES="repo,workflow,admin:public_key"
3434
```
3535

36-
Note that the default scopes if not provided are `repo,workflow`. If the module is failing to complete after updating the external auth configuration, instruct users of the module to "Unlink" and "Link" their Github account in the External Auth user settings page to get the new scopes.
36+
Note that the default scopes if not provided are `repo,workflow`. If the module is failing to complete after updating the external auth configuration, instruct users of the module to "Unlink" and "Link" their Github account in the External Auth user settings page to get the new scopes.

github-upload-public-key/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ resource "coder_script" "github_upload_public_key" {
1818
agent_id = var.agent_id
1919
script = templatefile("${path.module}/run.sh", {
2020
CODER_OWNER_SESSION_TOKEN : data.coder_workspace.me.owner_session_token,
21-
CODER_ACCESS_URL : data.coder_workspace.me.access_url,
21+
CODER_ACCESS_URL : data.coder_workspace.me.access_url,
2222
})
23-
display_name = "Github Upload Public Key"
24-
icon = "/icon/github.svg"
25-
run_on_start = true
23+
display_name = "Github Upload Public Key"
24+
icon = "/icon/github.svg"
25+
run_on_start = true
2626
}

github-upload-public-key/run.sh

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ fi
2828
echo "GitHub token found!"
2929

3030
echo "Fetching Coder public SSH key..."
31-
PUBLIC_KEY_RESPONSE=$(curl -L -s \
32-
-w "%{http_code}" \
33-
-H 'accept: application/json' \
34-
-H "cookie: coder_session_token=$CODER_OWNER_SESSION_TOKEN" \
35-
"$CODER_ACCESS_URL/api/v2/users/me/gitsshkey"
31+
PUBLIC_KEY_RESPONSE=$(
32+
curl -L -s \
33+
-w "%{http_code}" \
34+
-H 'accept: application/json' \
35+
-H "cookie: coder_session_token=$CODER_OWNER_SESSION_TOKEN" \
36+
"$CODER_ACCESS_URL/api/v2/users/me/gitsshkey"
3637
)
3738
PUBLIC_KEY_RESPONSE_STATUS=$(tail -n1 <<< "$PUBLIC_KEY_RESPONSE")
3839
PUBLIC_KEY_BODY=$(sed \$d <<< "$PUBLIC_KEY_RESPONSE")
@@ -52,12 +53,13 @@ if [ -z "$PUBLIC_KEY" ]; then
5253
fi
5354

5455
echo "Fetching GitHub public SSH keys..."
55-
GITHUB_KEYS_RESPONSE=$(curl -L -s \
56-
-w "%{http_code}" \
57-
-H "Accept: application/vnd.github+json" \
58-
-H "Authorization: Bearer $GITHUB_TOKEN" \
59-
-H "X-GitHub-Api-Version: 2022-11-28" \
60-
https://api.github.com/user/keys
56+
GITHUB_KEYS_RESPONSE=$(
57+
curl -L -s \
58+
-w "%{http_code}" \
59+
-H "Accept: application/vnd.github+json" \
60+
-H "Authorization: Bearer $GITHUB_TOKEN" \
61+
-H "X-GitHub-Api-Version: 2022-11-28" \
62+
https://api.github.com/user/keys
6163
)
6264
GITHUB_KEYS_RESPONSE_STATUS=$(tail -n1 <<< "$GITHUB_KEYS_RESPONSE")
6365
GITHUB_KEYS_RESPONSE_BODY=$(sed \$d <<< "$GITHUB_KEYS_RESPONSE")
@@ -78,14 +80,15 @@ fi
7880
echo "Coder public SSH key not found in GitHub keys!"
7981
echo "Uploading Coder public SSH key to GitHub..."
8082
CODER_PUBLIC_KEY_NAME="$CODER_ACCESS_URL Workspaces"
81-
UPLOAD_RESPONSE=$(curl -L -s \
82-
-X POST \
83-
-w "%{http_code}" \
84-
-H "Accept: application/vnd.github+json" \
85-
-H "Authorization: Bearer $GITHUB_TOKEN" \
86-
-H "X-GitHub-Api-Version: 2022-11-28" \
87-
https://api.github.com/user/keys \
88-
-d "{\"title\":\"$CODER_PUBLIC_KEY_NAME\",\"key\":\"$PUBLIC_KEY\"}"
83+
UPLOAD_RESPONSE=$(
84+
curl -L -s \
85+
-X POST \
86+
-w "%{http_code}" \
87+
-H "Accept: application/vnd.github+json" \
88+
-H "Authorization: Bearer $GITHUB_TOKEN" \
89+
-H "X-GitHub-Api-Version: 2022-11-28" \
90+
https://api.github.com/user/keys \
91+
-d "{\"title\":\"$CODER_PUBLIC_KEY_NAME\",\"key\":\"$PUBLIC_KEY\"}"
8992
)
9093
UPLOAD_RESPONSE_STATUS=$(tail -n1 <<< "$UPLOAD_RESPONSE")
9194
UPLOAD_RESPONSE_BODY=$(sed \$d <<< "$UPLOAD_RESPONSE")
@@ -96,4 +99,4 @@ if [ "$UPLOAD_RESPONSE_STATUS" -ne 201 ]; then
9699
exit 1
97100
fi
98101

99-
echo "Coder public SSH key uploaded to GitHub!"
102+
echo "Coder public SSH key uploaded to GitHub!"

0 commit comments

Comments
 (0)