@shipfox/api-workflows 7.0.2 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +15 -15
- package/CHANGELOG.md +32 -0
- package/dist/core/agent-defaults.d.ts +2 -1
- package/dist/core/agent-defaults.d.ts.map +1 -1
- package/dist/core/agent-defaults.js.map +1 -1
- package/dist/core/agent-tools.d.ts +3 -2
- package/dist/core/agent-tools.d.ts.map +1 -1
- package/dist/core/agent-tools.js.map +1 -1
- package/dist/core/checkout.d.ts +2 -2
- package/dist/core/checkout.d.ts.map +1 -1
- package/dist/core/checkout.js.map +1 -1
- package/dist/core/entities/step.d.ts +2 -1
- package/dist/core/entities/step.d.ts.map +1 -1
- package/dist/core/entities/step.js.map +1 -1
- package/dist/core/run-workflow.d.ts +2 -2
- package/dist/core/run-workflow.d.ts.map +1 -1
- package/dist/core/run-workflow.js.map +1 -1
- package/dist/core/step-config/agent.d.ts +1 -1
- package/dist/core/step-config/agent.d.ts.map +1 -1
- package/dist/core/step-config/agent.js.map +1 -1
- package/dist/db/job-listeners.d.ts +2 -2
- package/dist/db/job-listeners.d.ts.map +1 -1
- package/dist/db/job-listeners.js.map +1 -1
- package/dist/db/workflow-runs/run-create.d.ts +2 -2
- package/dist/db/workflow-runs/run-create.d.ts.map +1 -1
- package/dist/db/workflow-runs/run-create.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/presentation/inter-module.d.ts +2 -2
- package/dist/presentation/inter-module.d.ts.map +1 -1
- package/dist/presentation/inter-module.js +2 -1
- package/dist/presentation/inter-module.js.map +1 -1
- package/dist/presentation/routes/cancel-run.d.ts +1 -1
- package/dist/presentation/routes/cancel-run.d.ts.map +1 -1
- package/dist/presentation/routes/cancel-run.js.map +1 -1
- package/dist/presentation/routes/checkout-token.d.ts +2 -2
- package/dist/presentation/routes/checkout-token.d.ts.map +1 -1
- package/dist/presentation/routes/checkout-token.js +1 -1
- package/dist/presentation/routes/checkout-token.js.map +1 -1
- package/dist/presentation/routes/get-run-aggregates.d.ts +1 -1
- package/dist/presentation/routes/get-run-aggregates.d.ts.map +1 -1
- package/dist/presentation/routes/get-run-aggregates.js.map +1 -1
- package/dist/presentation/routes/get-run.d.ts +1 -1
- package/dist/presentation/routes/get-run.d.ts.map +1 -1
- package/dist/presentation/routes/get-run.js.map +1 -1
- package/dist/presentation/routes/index.d.ts +2 -2
- package/dist/presentation/routes/index.d.ts.map +1 -1
- package/dist/presentation/routes/index.js.map +1 -1
- package/dist/presentation/routes/list-run-attempts.d.ts +1 -1
- package/dist/presentation/routes/list-run-attempts.d.ts.map +1 -1
- package/dist/presentation/routes/list-run-attempts.js.map +1 -1
- package/dist/presentation/routes/list-runs.d.ts +1 -1
- package/dist/presentation/routes/list-runs.d.ts.map +1 -1
- package/dist/presentation/routes/list-runs.js.map +1 -1
- package/dist/presentation/routes/project-access.d.ts +1 -1
- package/dist/presentation/routes/project-access.d.ts.map +1 -1
- package/dist/presentation/routes/project-access.js.map +1 -1
- package/dist/presentation/routes/require-accessible-run.d.ts +1 -1
- package/dist/presentation/routes/require-accessible-run.d.ts.map +1 -1
- package/dist/presentation/routes/require-accessible-run.js.map +1 -1
- package/dist/presentation/routes/rerun-run.d.ts +1 -1
- package/dist/presentation/routes/rerun-run.d.ts.map +1 -1
- package/dist/presentation/routes/rerun-run.js.map +1 -1
- package/dist/temporal/activities/index.d.ts +2 -2
- package/dist/temporal/activities/index.d.ts.map +1 -1
- package/dist/temporal/activities/index.js.map +1 -1
- package/dist/temporal/activities/orchestration-activities.d.ts +2 -2
- package/dist/temporal/activities/orchestration-activities.d.ts.map +1 -1
- package/dist/temporal/activities/orchestration-activities.js.map +1 -1
- package/dist/temporal/workflows/index.bundle.js +17212 -3354
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +15 -15
- package/src/core/agent-defaults.ts +2 -1
- package/src/core/agent-tool-capability-warning.test.ts +1 -1
- package/src/core/agent-tools.ts +2 -2
- package/src/core/checkout.test.ts +2 -2
- package/src/core/checkout.ts +2 -2
- package/src/core/entities/step.ts +1 -2
- package/src/core/run-workflow.test.ts +2 -0
- package/src/core/run-workflow.ts +2 -2
- package/src/core/step-config/agent.ts +1 -1
- package/src/core/step-config/materialize-workflow-model.test.ts +11 -2
- package/src/db/job-listeners.ts +2 -2
- package/src/db/workflow-runs/run-create.test.ts +11 -2
- package/src/db/workflow-runs/run-create.ts +2 -2
- package/src/index.ts +2 -2
- package/src/presentation/inter-module.ts +4 -7
- package/src/presentation/routes/agent-runtime-config.test.ts +2 -35
- package/src/presentation/routes/cancel-run.test.ts +1 -1
- package/src/presentation/routes/cancel-run.ts +1 -1
- package/src/presentation/routes/checkout-token.test.ts +4 -37
- package/src/presentation/routes/checkout-token.ts +2 -2
- package/src/presentation/routes/get-run-aggregates.test.ts +1 -1
- package/src/presentation/routes/get-run-aggregates.ts +1 -1
- package/src/presentation/routes/get-run.test.ts +1 -1
- package/src/presentation/routes/get-run.ts +1 -1
- package/src/presentation/routes/get-step-secrets.test.ts +2 -2
- package/src/presentation/routes/index.test.ts +3 -3
- package/src/presentation/routes/index.ts +2 -2
- package/src/presentation/routes/list-run-attempts.test.ts +1 -1
- package/src/presentation/routes/list-run-attempts.ts +1 -1
- package/src/presentation/routes/list-runs.test.ts +1 -1
- package/src/presentation/routes/list-runs.ts +1 -1
- package/src/presentation/routes/next-step.test.ts +9 -57
- package/src/presentation/routes/project-access.ts +1 -1
- package/src/presentation/routes/report-step.test.ts +2 -3
- package/src/presentation/routes/require-accessible-run.ts +1 -1
- package/src/presentation/routes/rerun-run.test.ts +1 -1
- package/src/presentation/routes/rerun-run.ts +1 -1
- package/src/temporal/activities/index.ts +2 -2
- package/src/temporal/activities/orchestration-activities.ts +2 -2
- package/test/fixtures/agent-inter-module.ts +31 -1
- package/test/fixtures/auth-inter-module.ts +2 -13
- package/test/fixtures/lease-token.ts +43 -29
- package/test/fixtures/projects-inter-module.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type {AnnotationsInterModuleClient} from '@shipfox/annotations-dto/inter-module';
|
|
2
|
-
import {createLeaseTokenAuthMethod, verifyJobLeaseToken} from '@shipfox/api-auth';
|
|
3
2
|
import {closeApp, createApp, type FastifyInstance} from '@shipfox/node-fastify';
|
|
4
3
|
import {eq, sql} from 'drizzle-orm';
|
|
5
4
|
import {JobNotFoundError} from '#core/errors.js';
|
|
@@ -16,7 +15,11 @@ import {insertRunningJobLease, mintActiveLeaseToken} from '#test/fixtures/active
|
|
|
16
15
|
import {agentTestClient} from '#test/fixtures/agent-inter-module.js';
|
|
17
16
|
import {workflowsTestAuthClient} from '#test/fixtures/auth-inter-module.js';
|
|
18
17
|
import {arrangeJobWithSteps} from '#test/fixtures/job-with-steps.js';
|
|
19
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
fakeLeaseTokenAuthMethod,
|
|
20
|
+
getLeaseTokenClaims,
|
|
21
|
+
mintLeaseToken,
|
|
22
|
+
} from '#test/fixtures/lease-token.js';
|
|
20
23
|
import {projectsTestClient} from '#test/fixtures/projects-inter-module.js';
|
|
21
24
|
import {runnersTestClient} from '#test/fixtures/runners-inter-module.js';
|
|
22
25
|
import {createTestSecretsClient} from '#test/fixtures/secrets-inter-module.js';
|
|
@@ -58,7 +61,7 @@ describe('POST /runs/jobs/current/steps/next', () => {
|
|
|
58
61
|
|
|
59
62
|
beforeAll(async () => {
|
|
60
63
|
app = await createApp({
|
|
61
|
-
auth: [
|
|
64
|
+
auth: [fakeLeaseTokenAuthMethod],
|
|
62
65
|
routes: [
|
|
63
66
|
createLeaseTokenRouteGroup({
|
|
64
67
|
agent: agentTestClient,
|
|
@@ -108,57 +111,6 @@ describe('POST /runs/jobs/current/steps/next', () => {
|
|
|
108
111
|
expect(res.statusCode).toBe(401);
|
|
109
112
|
expect(res.json().code).toBe('unauthorized');
|
|
110
113
|
});
|
|
111
|
-
|
|
112
|
-
test('rejects an expired token', async () => {
|
|
113
|
-
const token = await mintLeaseToken({
|
|
114
|
-
jobId: crypto.randomUUID(),
|
|
115
|
-
jobExecutionId: crypto.randomUUID(),
|
|
116
|
-
expiresIn: '-1s',
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
const res = await app.inject({
|
|
120
|
-
method: 'POST',
|
|
121
|
-
url: URL,
|
|
122
|
-
headers: {authorization: `Bearer ${token}`},
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
expect(res.statusCode).toBe(401);
|
|
126
|
-
expect(res.json().code).toBe('unauthorized');
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
test('rejects a token signed with the wrong secret', async () => {
|
|
130
|
-
const token = await mintLeaseToken({
|
|
131
|
-
jobId: crypto.randomUUID(),
|
|
132
|
-
jobExecutionId: crypto.randomUUID(),
|
|
133
|
-
secret: 'wrong-secret',
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
const res = await app.inject({
|
|
137
|
-
method: 'POST',
|
|
138
|
-
url: URL,
|
|
139
|
-
headers: {authorization: `Bearer ${token}`},
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
expect(res.statusCode).toBe(401);
|
|
143
|
-
expect(res.json().code).toBe('unauthorized');
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
test('rejects a token with the wrong audience (e.g. a user JWT)', async () => {
|
|
147
|
-
const token = await mintLeaseToken({
|
|
148
|
-
jobId: crypto.randomUUID(),
|
|
149
|
-
jobExecutionId: crypto.randomUUID(),
|
|
150
|
-
audience: 'user-session',
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
const res = await app.inject({
|
|
154
|
-
method: 'POST',
|
|
155
|
-
url: URL,
|
|
156
|
-
headers: {authorization: `Bearer ${token}`},
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
expect(res.statusCode).toBe(401);
|
|
160
|
-
expect(res.json().code).toBe('unauthorized');
|
|
161
|
-
});
|
|
162
114
|
});
|
|
163
115
|
|
|
164
116
|
test('returns the lowest-position pending step and marks it running', async () => {
|
|
@@ -177,7 +129,7 @@ describe('POST /runs/jobs/current/steps/next', () => {
|
|
|
177
129
|
expect(body.step.id).toBe(steps[0]?.id);
|
|
178
130
|
expect(body.step.status).toBe('running');
|
|
179
131
|
expect(body.lease_token).toEqual(expect.any(String));
|
|
180
|
-
const scopedLease =
|
|
132
|
+
const scopedLease = getLeaseTokenClaims(body.lease_token);
|
|
181
133
|
expect(scopedLease).toMatchObject({
|
|
182
134
|
jobId,
|
|
183
135
|
jobExecutionId: steps[0]?.jobExecutionId,
|
|
@@ -228,7 +180,7 @@ describe('POST /runs/jobs/current/steps/next', () => {
|
|
|
228
180
|
})
|
|
229
181
|
.where(eq(stepsTable.id, steps[0]?.id as string));
|
|
230
182
|
const token = await mintActiveLeaseToken({jobId});
|
|
231
|
-
const lease =
|
|
183
|
+
const lease = getLeaseTokenClaims(token);
|
|
232
184
|
if (!lease) throw new Error('Expected minted lease token to verify');
|
|
233
185
|
await setRunnerToolCapabilities(lease.runnerSessionId, {harnesses: {pi: {tools: ['read']}}});
|
|
234
186
|
|
|
@@ -378,7 +330,7 @@ describe('POST /runs/jobs/current/steps/next', () => {
|
|
|
378
330
|
expect(res.statusCode).toBe(200);
|
|
379
331
|
const body = res.json();
|
|
380
332
|
expect(body.attempt).toBe(2);
|
|
381
|
-
const scopedLease =
|
|
333
|
+
const scopedLease = getLeaseTokenClaims(body.lease_token);
|
|
382
334
|
expect(scopedLease?.currentStepId).toBe(steps[0]?.id);
|
|
383
335
|
expect(scopedLease?.currentStepAttempt).toBe(body.attempt);
|
|
384
336
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {requireWorkspaceAccess} from '@shipfox/api-auth-context';
|
|
2
|
-
import type {ProjectsModuleClient} from '@shipfox/api-projects-dto';
|
|
2
|
+
import type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';
|
|
3
3
|
import {ClientError} from '@shipfox/node-fastify';
|
|
4
4
|
import type {FastifyRequest} from 'fastify';
|
|
5
5
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {createLeaseTokenAuthMethod} from '@shipfox/api-auth';
|
|
2
1
|
import {closeApp, createApp, type FastifyInstance} from '@shipfox/node-fastify';
|
|
3
2
|
import {nextStepForJob} from '#core/job-execution.js';
|
|
4
3
|
import {
|
|
@@ -13,7 +12,7 @@ import {agentTestClient} from '#test/fixtures/agent-inter-module.js';
|
|
|
13
12
|
import {annotationsTestClient} from '#test/fixtures/annotations-inter-module.js';
|
|
14
13
|
import {workflowsTestAuthClient} from '#test/fixtures/auth-inter-module.js';
|
|
15
14
|
import {arrangeJobWithSteps} from '#test/fixtures/job-with-steps.js';
|
|
16
|
-
import {mintLeaseToken} from '#test/fixtures/lease-token.js';
|
|
15
|
+
import {fakeLeaseTokenAuthMethod, mintLeaseToken} from '#test/fixtures/lease-token.js';
|
|
17
16
|
import {projectsTestClient} from '#test/fixtures/projects-inter-module.js';
|
|
18
17
|
import {runnersTestClient} from '#test/fixtures/runners-inter-module.js';
|
|
19
18
|
import {createTestSecretsClient} from '#test/fixtures/secrets-inter-module.js';
|
|
@@ -32,7 +31,7 @@ describe('POST /runs/jobs/current/steps/:stepId/report', () => {
|
|
|
32
31
|
|
|
33
32
|
beforeAll(async () => {
|
|
34
33
|
app = await createApp({
|
|
35
|
-
auth: [
|
|
34
|
+
auth: [fakeLeaseTokenAuthMethod],
|
|
36
35
|
routes: [
|
|
37
36
|
createLeaseTokenRouteGroup({
|
|
38
37
|
agent: agentTestClient,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {ProjectsModuleClient} from '@shipfox/api-projects-dto';
|
|
1
|
+
import type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';
|
|
2
2
|
import {ClientError} from '@shipfox/node-fastify';
|
|
3
3
|
import type {FastifyRequest} from 'fastify';
|
|
4
4
|
import type {WorkflowRun} from '#core/entities/workflow-run.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {buildUserContext, setUserContext} from '@shipfox/api-auth-context';
|
|
2
|
-
import type {ProjectsModuleClient} from '@shipfox/api-projects-dto';
|
|
2
|
+
import type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';
|
|
3
3
|
import {ClientError} from '@shipfox/node-fastify';
|
|
4
4
|
import type {FastifyInstance} from 'fastify';
|
|
5
5
|
import Fastify from 'fastify';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {requireUserContext} from '@shipfox/api-auth-context';
|
|
2
|
-
import type {ProjectsModuleClient} from '@shipfox/api-projects-dto';
|
|
2
|
+
import type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';
|
|
3
3
|
import {rerunWorkflowRunBodySchema, workflowRunResponseSchema} from '@shipfox/api-workflows-dto';
|
|
4
4
|
import {ClientError, defineRoute} from '@shipfox/node-fastify';
|
|
5
5
|
import {z} from 'zod';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {AgentInterModuleClient} from '@shipfox/api-agent-dto/inter-module';
|
|
2
|
-
import type {IntegrationsModuleClient} from '@shipfox/api-integration-core-dto';
|
|
3
|
-
import type {ProjectsModuleClient} from '@shipfox/api-projects-dto';
|
|
2
|
+
import type {IntegrationsModuleClient} from '@shipfox/api-integration-core-dto/inter-module';
|
|
3
|
+
import type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';
|
|
4
4
|
import type {RunnersInterModuleClient} from '@shipfox/api-runners-dto/inter-module';
|
|
5
5
|
import type {SecretsInterModuleClient} from '@shipfox/api-secrets-dto/inter-module';
|
|
6
6
|
import {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {AgentInterModuleClient} from '@shipfox/api-agent-dto/inter-module';
|
|
2
|
-
import type {IntegrationsModuleClient} from '@shipfox/api-integration-core-dto';
|
|
3
|
-
import type {ProjectsModuleClient} from '@shipfox/api-projects-dto';
|
|
2
|
+
import type {IntegrationsModuleClient} from '@shipfox/api-integration-core-dto/inter-module';
|
|
3
|
+
import type {ProjectsModuleClient} from '@shipfox/api-projects-dto/inter-module';
|
|
4
4
|
import {
|
|
5
5
|
type RunnersInterModuleClient,
|
|
6
6
|
runnersInterModuleContract,
|
|
@@ -1,7 +1,37 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_HARNESS_TOOL_DEPLOYMENT_CONFIG,
|
|
3
|
+
getModelProviderEntry,
|
|
4
|
+
listEnabledHarnessTools,
|
|
5
|
+
listHarnessDescriptors,
|
|
6
|
+
MODEL_PROVIDER_IDS,
|
|
7
|
+
} from '@shipfox/api-agent-dto';
|
|
8
|
+
import type {
|
|
9
|
+
AgentInterModuleClient,
|
|
10
|
+
AgentValidationCatalog,
|
|
11
|
+
} from '@shipfox/api-agent-dto/inter-module';
|
|
2
12
|
import type {AgentDefaultsResolver} from '#core/agent-defaults.js';
|
|
3
13
|
|
|
14
|
+
export const agentValidationCatalog: AgentValidationCatalog = {
|
|
15
|
+
version: 1,
|
|
16
|
+
providers: MODEL_PROVIDER_IDS.map((id) => ({
|
|
17
|
+
id,
|
|
18
|
+
support_status: getModelProviderEntry(id)?.support_status ?? 'unsupported',
|
|
19
|
+
})),
|
|
20
|
+
harnesses: listHarnessDescriptors().map((harness) => ({
|
|
21
|
+
id: harness.id,
|
|
22
|
+
supported_provider_ids: [...harness.supportedProviderIds],
|
|
23
|
+
thinking_levels: [...harness.thinkingLevels],
|
|
24
|
+
effective_tools: listEnabledHarnessTools(
|
|
25
|
+
harness.id,
|
|
26
|
+
DEFAULT_HARNESS_TOOL_DEPLOYMENT_CONFIG,
|
|
27
|
+
).map((tool) => tool.name),
|
|
28
|
+
})),
|
|
29
|
+
};
|
|
30
|
+
|
|
4
31
|
export const agentTestClient: AgentInterModuleClient = {
|
|
32
|
+
getValidationCatalog() {
|
|
33
|
+
return Promise.resolve(agentValidationCatalog);
|
|
34
|
+
},
|
|
5
35
|
resolveAgentConfig({config}) {
|
|
6
36
|
return Promise.resolve(resolveTestAgentDefaults(config));
|
|
7
37
|
},
|
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
import {JOB_LEASE_TOKEN_AUDIENCE} from '@shipfox/api-auth-dto';
|
|
2
1
|
import type {AuthInterModuleClient} from '@shipfox/api-auth-dto/inter-module';
|
|
3
|
-
import {
|
|
4
|
-
import {signHs256} from '@shipfox/node-jwt';
|
|
5
|
-
|
|
6
|
-
const leaseSecret = jobLeaseTokenKey();
|
|
2
|
+
import {mintLeaseToken} from './lease-token.js';
|
|
7
3
|
|
|
8
4
|
export const workflowsTestAuthClient: AuthInterModuleClient = {
|
|
9
5
|
mintRunnerSessionToken() {
|
|
10
6
|
throw new Error('Runner session token minting is not configured');
|
|
11
7
|
},
|
|
12
8
|
async mintJobLeaseToken(claims) {
|
|
13
|
-
return {
|
|
14
|
-
token: await signHs256({
|
|
15
|
-
payload: claims,
|
|
16
|
-
secret: leaseSecret,
|
|
17
|
-
expiresIn: '90m',
|
|
18
|
-
audience: JOB_LEASE_TOKEN_AUDIENCE,
|
|
19
|
-
}),
|
|
20
|
-
};
|
|
9
|
+
return {token: await mintLeaseToken(claims)};
|
|
21
10
|
},
|
|
22
11
|
};
|
|
@@ -1,45 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import {AUTH_LEASED_JOB, setLeasedJobContext} from '@shipfox/api-auth-context';
|
|
2
|
+
import {JOB_LEASE_TOKEN_AUDIENCE, type JobLeaseTokenClaims} from '@shipfox/api-auth-dto';
|
|
3
|
+
import {type AuthMethod, ClientError, extractBearerToken} from '@shipfox/node-fastify';
|
|
4
4
|
import {getFirstJobExecutionByJobId} from '#db/workflow-runs.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
const SECRET = jobLeaseTokenKey();
|
|
6
|
+
const leaseClaims = new Map<string, JobLeaseTokenClaims>();
|
|
8
7
|
|
|
9
8
|
export interface MintLeaseTokenParams {
|
|
10
9
|
jobId: string;
|
|
11
10
|
jobExecutionId?: string;
|
|
12
|
-
// Override informational claims to pair a job with chosen surrounding context.
|
|
13
11
|
workflowRunId?: string;
|
|
14
12
|
workflowRunAttemptId?: string;
|
|
15
13
|
projectId?: string;
|
|
16
14
|
workspaceId?: string;
|
|
17
15
|
runnerSessionId?: string;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
audience?: string;
|
|
16
|
+
currentStepId?: string | undefined;
|
|
17
|
+
currentStepAttempt?: number | undefined;
|
|
21
18
|
}
|
|
22
19
|
|
|
23
20
|
export async function mintLeaseToken(params: MintLeaseTokenParams): Promise<string> {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
21
|
+
const jobExecution =
|
|
22
|
+
params.jobExecutionId === undefined
|
|
23
|
+
? await getFirstJobExecutionByJobId(params.jobId)
|
|
24
|
+
: undefined;
|
|
25
|
+
const jobExecutionId = params.jobExecutionId ?? jobExecution?.id;
|
|
26
|
+
if (!jobExecutionId) throw new Error('Expected job execution to exist');
|
|
27
|
+
const token = `test-auth-${crypto.randomUUID()}`;
|
|
28
|
+
leaseClaims.set(token, {
|
|
29
|
+
jobId: params.jobId,
|
|
30
|
+
jobExecutionId,
|
|
31
|
+
workflowRunId: params.workflowRunId ?? crypto.randomUUID(),
|
|
32
|
+
workflowRunAttemptId: params.workflowRunAttemptId ?? crypto.randomUUID(),
|
|
33
|
+
projectId: params.projectId ?? crypto.randomUUID(),
|
|
34
|
+
workspaceId: params.workspaceId ?? crypto.randomUUID(),
|
|
35
|
+
runnerSessionId: params.runnerSessionId ?? crypto.randomUUID(),
|
|
36
|
+
...(params.currentStepId && params.currentStepAttempt !== undefined
|
|
37
|
+
? {currentStepId: params.currentStepId, currentStepAttempt: params.currentStepAttempt}
|
|
38
|
+
: {}),
|
|
39
|
+
aud: JOB_LEASE_TOKEN_AUDIENCE,
|
|
40
|
+
iat: 0,
|
|
41
|
+
exp: Number.MAX_SAFE_INTEGER,
|
|
44
42
|
});
|
|
43
|
+
return token;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function getLeaseTokenClaims(token: string): JobLeaseTokenClaims | undefined {
|
|
47
|
+
return leaseClaims.get(token);
|
|
45
48
|
}
|
|
49
|
+
|
|
50
|
+
export const fakeLeaseTokenAuthMethod: AuthMethod = {
|
|
51
|
+
name: AUTH_LEASED_JOB,
|
|
52
|
+
authenticate: (request) => {
|
|
53
|
+
const token = extractBearerToken(request.headers.authorization);
|
|
54
|
+
const claims = token ? leaseClaims.get(token) : undefined;
|
|
55
|
+
if (!claims) throw new ClientError('Authentication required', 'unauthorized', {status: 401});
|
|
56
|
+
setLeasedJobContext(request, claims);
|
|
57
|
+
return Promise.resolve();
|
|
58
|
+
},
|
|
59
|
+
};
|