From 5a33af28ace261807232c50909cf6ea1d7646edd Mon Sep 17 00:00:00 2001 From: Garrett Delfosse Date: Tue, 30 Apr 2024 16:37:28 +0000 Subject: [PATCH] fmt --- github-upload-public-key/README.md | 4 +-- github-upload-public-key/main.tf | 8 +++--- github-upload-public-key/run.sh | 43 ++++++++++++++++-------------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/github-upload-public-key/README.md b/github-upload-public-key/README.md index e581fb6..98c27c1 100644 --- a/github-upload-public-key/README.md +++ b/github-upload-public-key/README.md @@ -11,7 +11,7 @@ tags: [helper, git] 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. -# Example +# Example ```tf module "github-upload-public-key" { @@ -33,4 +33,4 @@ CODER_EXTERNAL_AUTH_0_CLIENT_SECRET=xxxxxxx CODER_EXTERNAL_AUTH_0_SCOPES="repo,workflow,admin:public_key" ``` -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. \ No newline at end of file +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. diff --git a/github-upload-public-key/main.tf b/github-upload-public-key/main.tf index 7728f45..313d716 100644 --- a/github-upload-public-key/main.tf +++ b/github-upload-public-key/main.tf @@ -18,9 +18,9 @@ resource "coder_script" "github_upload_public_key" { agent_id = var.agent_id script = templatefile("${path.module}/run.sh", { CODER_OWNER_SESSION_TOKEN : data.coder_workspace.me.owner_session_token, - CODER_ACCESS_URL : data.coder_workspace.me.access_url, + CODER_ACCESS_URL : data.coder_workspace.me.access_url, }) - display_name = "Github Upload Public Key" - icon = "/icon/github.svg" - run_on_start = true + display_name = "Github Upload Public Key" + icon = "/icon/github.svg" + run_on_start = true } \ No newline at end of file diff --git a/github-upload-public-key/run.sh b/github-upload-public-key/run.sh index 1e39ec2..fa8e115 100755 --- a/github-upload-public-key/run.sh +++ b/github-upload-public-key/run.sh @@ -28,11 +28,12 @@ fi echo "GitHub token found!" echo "Fetching Coder public SSH key..." -PUBLIC_KEY_RESPONSE=$(curl -L -s \ - -w "%{http_code}" \ - -H 'accept: application/json' \ - -H "cookie: coder_session_token=$CODER_OWNER_SESSION_TOKEN" \ - "$CODER_ACCESS_URL/api/v2/users/me/gitsshkey" +PUBLIC_KEY_RESPONSE=$( + curl -L -s \ + -w "%{http_code}" \ + -H 'accept: application/json' \ + -H "cookie: coder_session_token=$CODER_OWNER_SESSION_TOKEN" \ + "$CODER_ACCESS_URL/api/v2/users/me/gitsshkey" ) PUBLIC_KEY_RESPONSE_STATUS=$(tail -n1 <<< "$PUBLIC_KEY_RESPONSE") PUBLIC_KEY_BODY=$(sed \$d <<< "$PUBLIC_KEY_RESPONSE") @@ -52,12 +53,13 @@ if [ -z "$PUBLIC_KEY" ]; then fi echo "Fetching GitHub public SSH keys..." -GITHUB_KEYS_RESPONSE=$(curl -L -s \ - -w "%{http_code}" \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer $GITHUB_TOKEN" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/user/keys +GITHUB_KEYS_RESPONSE=$( + curl -L -s \ + -w "%{http_code}" \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/user/keys ) GITHUB_KEYS_RESPONSE_STATUS=$(tail -n1 <<< "$GITHUB_KEYS_RESPONSE") GITHUB_KEYS_RESPONSE_BODY=$(sed \$d <<< "$GITHUB_KEYS_RESPONSE") @@ -78,14 +80,15 @@ fi echo "Coder public SSH key not found in GitHub keys!" echo "Uploading Coder public SSH key to GitHub..." CODER_PUBLIC_KEY_NAME="$CODER_ACCESS_URL Workspaces" -UPLOAD_RESPONSE=$(curl -L -s \ - -X POST \ - -w "%{http_code}" \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer $GITHUB_TOKEN" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/user/keys \ - -d "{\"title\":\"$CODER_PUBLIC_KEY_NAME\",\"key\":\"$PUBLIC_KEY\"}" +UPLOAD_RESPONSE=$( + curl -L -s \ + -X POST \ + -w "%{http_code}" \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/user/keys \ + -d "{\"title\":\"$CODER_PUBLIC_KEY_NAME\",\"key\":\"$PUBLIC_KEY\"}" ) UPLOAD_RESPONSE_STATUS=$(tail -n1 <<< "$UPLOAD_RESPONSE") UPLOAD_RESPONSE_BODY=$(sed \$d <<< "$UPLOAD_RESPONSE") @@ -96,4 +99,4 @@ if [ "$UPLOAD_RESPONSE_STATUS" -ne 201 ]; then exit 1 fi -echo "Coder public SSH key uploaded to GitHub!" \ No newline at end of file +echo "Coder public SSH key uploaded to GitHub!"