Skip to content

Commit

Permalink
debug: auth workflow (#2168)
Browse files Browse the repository at this point in the history
* fix: auth workflow

* enable: workflow_dispatch

* Update .github/workflows/register-preview-url.yml
  • Loading branch information
thiskevinwang authored Sep 19, 2023
1 parent 84c35d3 commit 48bc666
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/register-preview-url.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# This workflow enables HashiCorp Oauth on Vercel preview deployments.
name: Register Preview URL with CloudIDP

on:
deployment_status:

# workflow_dispatch is here for supporting manual iteration
workflow_dispatch:
inputs:
preview_url:
description: 'A Vercel preview url. Only used during manual runs'
required: true
jobs:
on-deploy:
runs-on: ubuntu-latest
Expand All @@ -26,8 +32,10 @@ jobs:
- name: Add Preview URL to CloudIDP
run: npx hc-tools ./scripts/add-preview-url-to-cloud-idp.ts
env:
# parameters
PREVIEW_URL: ${{ inputs.preview_url || github.event.deployment_status.target_url }}
# secrets
CLOUD_IDP_DEPLOYMENT_PREVIEW_PRIVATE_KEY: ${{ secrets.CLOUD_IDP_DEPLOYMENT_PREVIEW_PRIVATE_KEY }}
PREVIEW_URL: ${{ github.event.deployment_status.target_url }}
FLOW_IDP_DEPLOYMENT_READY_URL: ${{ secrets.FLOW_IDP_DEPLOYMENT_READY_URL }}
VERCEL_API_TOKEN: ${{ secrets.VERCEL_API_TOKEN }}
VERCEL_TEAM_ID: ${{ secrets.VERCEL_TEAM_ID }}
7 changes: 6 additions & 1 deletion scripts/add-preview-url-to-cloud-idp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,26 @@ const fetch = createFetch()
const vercelApiToken = process.env.VERCEL_API_TOKEN
const vercelTeamId = process.env.VERCEL_TEAM_ID

// For Vercel API docs
// see https://vercel.com/docs/rest-api/endpoints#get-a-deployment-by-id-or-url

/** A helper to fetch Vercel Deployment Aliases from Vercel Deploy Preview URLs */
async function fetchDeploymentAlias(previewUrl: string): Promise<string[]> {
console.log('fetchDeploymentAlias', previewUrl)

const previewHostname = new URL(previewUrl).hostname
const url = new URL(
`v13/deployments/${previewHostname}`,
'https://api.vercel.com'
)

url.searchParams.set('teamId', vercelTeamId)
url.searchParams.set('withAutomaticAliases', '1')

const headers = { Authorization: `Bearer ${vercelApiToken}` }

const res = await fetch(url.toString(), { headers })
const data = await res.json()
console.log(data)

// NOTE: returned aliases only contain hostname, and no scheme
// Scheme will need to be prepended before being passed in the
Expand Down

1 comment on commit 48bc666

@vercel
Copy link

@vercel vercel bot commented on 48bc666 Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.