Skip to content

Commit

Permalink
Allow the action to customize the domain. (#28)
Browse files Browse the repository at this point in the history
This allows folks to host their own instance of Octo STS.

Signed-off-by: Matt Moore <[email protected]>
  • Loading branch information
mattmoor authored May 18, 2024
1 parent 3622e4d commit 43a7677
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `octo-sts-action`
# `octo-sts/action`

This action federates the GitHub Actions identity token for a Github App token
according to the Trust Policy in the target organization or repository.
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ description: |
organization or repository.
inputs:
domain:
description: |
The domain of the Octo STS instance to use to federate.
default: octo-sts.dev

scope:
description: |
The org/repo of the repository to which to request access.
Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if (!actionsToken || !actionsUrl) {

const scope = process.env.INPUT_SCOPE;
const identity = process.env.INPUT_IDENTITY;
const domain = process.env.INPUT_DOMAIN;

if (!scope || !identity) {
console.log(`::error::Missing required inputs 'scope' and 'identity'`);
Expand Down Expand Up @@ -37,9 +38,9 @@ async function fetchWithRetry(url, options = {}, retries = 3, initialDelay = 100
(async function main() {
// You can use await inside this function block
try {
const res = await fetchWithRetry(`${actionsUrl}&audience=octo-sts.dev`, { headers: { 'Authorization': `Bearer ${actionsToken}` } }, 5);
const res = await fetchWithRetry(`${actionsUrl}&audience=${domain}`, { headers: { 'Authorization': `Bearer ${actionsToken}` } }, 5);
const json = await res.json();
const res2 = await fetchWithRetry(`https://octo-sts.dev/sts/exchange?scope=${scope}&identity=${identity}`, { headers: { 'Authorization': `Bearer ${json.value}` } });
const res2 = await fetchWithRetry(`https://${domain}/sts/exchange?scope=${scope}&identity=${identity}`, { headers: { 'Authorization': `Bearer ${json.value}` } });
const json2 = await res2.json();

if (!json2.token) { console.log(`::error::${json2.message}`); process.exit(1); }
Expand Down

0 comments on commit 43a7677

Please sign in to comment.