1
0
Fork 0

add util for pulling IDs from claims

artifact-next
Bethany 2023-08-02 13:52:27 -07:00
parent 898dd8c2a1
commit 6a61612f93
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
import { getRuntimeToken } from './config';
export interface BackendIds {
workflowRunBackendId: string;
workflowJobRunBackendId: string;
}
export function getBackendIds(): BackendIds {
const token = getRuntimeToken();
const parsedToken = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString())
if (!parsedToken["scp"]) {
throw new Error('Unable to get scp from token')
}
const scp = parsedToken["scp"]
const scpParts = scp.split(' ')
if (scpParts.length == 0) {
throw new Error('No scp parts found')
}
for (const part of scpParts) {
const partParts = part.split(':')
if(partParts.length == 0) {
continue
}
if (partParts[0] == "Actions.Results") {
if (partParts.length == 3) {
return {workflowRunBackendId: partParts[1], workflowJobRunBackendId: partParts[2]}
}
throw new Error('Unable to parse Actions.Results scp part')
}
}
throw new Error('Unable to find ids')
}