Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
frasdav committed May 30, 2024
1 parent 893e182 commit 2cb18a6
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tasks/SheriffApply/SheriffApplyV0/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,28 @@
const fs = require('fs');
const path = require('path');

const { getHandlerFromToken, WebApi } = require('azure-devops-node-api');

Check failure on line 6 in tasks/SheriffApply/SheriffApplyV0/src/index.js

View workflow job for this annotation

GitHub Actions / build / build

'azure-devops-node-api' should be listed in the project's dependencies. Run 'npm i -S azure-devops-node-api' to add it

Check failure on line 6 in tasks/SheriffApply/SheriffApplyV0/src/index.js

View workflow job for this annotation

GitHub Actions / build / build

'azure-devops-node-api' should be listed in the project's dependencies. Run 'npm i -S azure-devops-node-api' to add it
const tl = require('azure-pipelines-task-lib/task');
const { getSystemAccessToken } = require('azure-pipelines-tasks-artifacts-common/webapi');

Check failure on line 8 in tasks/SheriffApply/SheriffApplyV0/src/index.js

View workflow job for this annotation

GitHub Actions / build / build

Unable to resolve path to module 'azure-pipelines-tasks-artifacts-common/webapi'

Check failure on line 8 in tasks/SheriffApply/SheriffApplyV0/src/index.js

View workflow job for this annotation

GitHub Actions / build / build

Unable to resolve path to module 'azure-pipelines-tasks-artifacts-common/webapi'

async function getIdToken(connectedService) {
const jobId = tl.getVariable('System.JobId');
const planId = tl.getVariable('System.PlanId');
const projectId = tl.getVariable('System.TeamProjectId');
const hub = tl.getVariable('System.HostType');
const uri = tl.getVariable('System.CollectionUri');
const token = getSystemAccessToken();

const authHandler = getHandlerFromToken(token);
const connection = new WebApi(uri, authHandler);
const api = await connection.getTaskApi();
const response = await api.createOidcToken({}, projectId, hub, planId, jobId, connectedService);
if (response == null) {
return null;
}

return response.oidcToken;
}

async function run() {
try {
Expand Down Expand Up @@ -33,7 +54,7 @@ async function run() {
const tenantId = tl.getEndpointAuthorizationParameter(connectedService, 'tenantid', false);
env.AZURE_TENANT_ID = tenantId;

const federatedToken = await this.getIdToken(connectedService);
const federatedToken = await getIdToken(connectedService);
tl.setSecret(federatedToken);

const federatedTokenFilePath = path.join(agentTempDirectory, 'azure-identity-token');
Expand Down

0 comments on commit 2cb18a6

Please sign in to comment.