Skip to content

Commit 562c943

Browse files
carderneTrigger.dev RepoOps
authored andcommitted
feat(cli): authenticate promote with environment API keys
Mono-RevId: eeea820997ad473c81c42a56fad43b2cc065624e
1 parent c8d3cf1 commit 562c943

6 files changed

Lines changed: 58 additions & 12 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Authenticate `trigger promote` with environment API keys supplied through `TRIGGER_ACCESS_TOKEN`. Environment API key commands now use the saved profile API URL when no explicit override is provided.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Command } from "commander";
2+
import { describe, expect, it } from "vitest";
3+
import { commonOptions } from "./common.js";
4+
5+
describe("commonOptions", () => {
6+
it("leaves the API URL unset when it is not explicitly provided", () => {
7+
const command = commonOptions(new Command());
8+
9+
command.parse(["node", "trigger"]);
10+
11+
expect(command.opts().apiUrl).toBeUndefined();
12+
});
13+
14+
it("preserves an explicitly provided API URL", () => {
15+
const command = commonOptions(new Command());
16+
17+
command.parse(["node", "trigger", "--api-url", "https://trigger.example.com"]);
18+
19+
expect(command.opts().apiUrl).toBe("https://trigger.example.com");
20+
});
21+
});

‎packages/cli-v3/src/cli/common.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { Command } from "commander";
33
import { z } from "zod";
44
import { fromZodError } from "zod-validation-error";
55
import { BundleError } from "../build/bundle.js";
6-
import { CLOUD_API_URL } from "../consts.js";
76
import { chalkError } from "../utilities/cliOutput.js";
87
import { formatCommandError } from "../utilities/commandError.js";
98
import { readAuthConfigCurrentProfileName } from "../utilities/configFiles.js";
@@ -22,7 +21,7 @@ export type CommonCommandOptions = z.infer<typeof CommonCommandOptions>;
2221
export function commonOptions(command: Command) {
2322
return command
2423
.option("--profile <profile>", "The login profile to use", readAuthConfigCurrentProfileName())
25-
.option("-a, --api-url <value>", "Override the API URL", CLOUD_API_URL)
24+
.option("-a, --api-url <value>", "Override the API URL")
2625
.option(
2726
"-l, --log-level <level>",
2827
"The CLI log level to use (debug, info, log, warn, error, none). This does not effect the log level of your trigger.dev tasks.",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { describe, expect, it } from "vitest";
2+
import { CLOUD_API_URL } from "../consts.js";
3+
import { resolveLoginOptions } from "./login.js";
4+
5+
describe("resolveLoginOptions", () => {
6+
it("uses the cloud API when the caller passes an undefined override", () => {
7+
expect(resolveLoginOptions({ defaultApiUrl: undefined }).defaultApiUrl).toBe(CLOUD_API_URL);
8+
});
9+
10+
it("preserves an explicit API URL", () => {
11+
expect(
12+
resolveLoginOptions({ defaultApiUrl: "https://trigger.example.com" }).defaultApiUrl
13+
).toBe("https://trigger.example.com");
14+
});
15+
});

‎packages/cli-v3/src/commands/login.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import {
4040
import { links } from "@trigger.dev/core/v3";
4141

4242
const LoginCommandOptions = CommonCommandOptions.extend({
43-
apiUrl: z.string(),
4443
browser: z.boolean().default(true),
4544
});
4645

@@ -98,15 +97,19 @@ export type LoginOptions = {
9897
browser?: boolean;
9998
};
10099

100+
export function resolveLoginOptions(options?: LoginOptions) {
101+
return {
102+
embedded: false,
103+
silent: false,
104+
...options,
105+
defaultApiUrl: options?.defaultApiUrl ?? CLOUD_API_URL,
106+
};
107+
}
108+
101109
export async function login(options?: LoginOptions): Promise<LoginResult> {
102110
return await tracer.startActiveSpan("login", async (span) => {
103111
try {
104-
const opts = {
105-
defaultApiUrl: CLOUD_API_URL,
106-
embedded: false,
107-
silent: false,
108-
...options,
109-
};
112+
const opts = resolveLoginOptions(options);
110113

111114
span.setAttributes({
112115
"cli.config.apiUrl": opts.defaultApiUrl,

‎packages/cli-v3/src/commands/promote.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { getProjectClient } from "../utilities/session.js";
1414
import { login } from "./login.js";
1515
import { createGitMeta } from "../utilities/gitMeta.js";
1616
import { getBranch } from "@trigger.dev/core/v3";
17+
import { authenticateForDeploy } from "../deploy/auth.js";
1718

1819
const PromoteCommandOptions = CommonCommandOptions.extend({
1920
projectRef: z.string().optional(),
@@ -70,10 +71,12 @@ async function _promoteCommand(version: string, options: PromoteCommandOptions)
7071

7172
intro(`Promoting version ${version}`);
7273

73-
const authorization = await login({
74-
embedded: true,
75-
defaultApiUrl: options.apiUrl,
74+
const authorization = await authenticateForDeploy({
75+
accessToken: process.env.TRIGGER_ACCESS_TOKEN,
76+
apiUrl: process.env.TRIGGER_API_URL ?? options.apiUrl,
7677
profile: options.profile,
78+
silent: false,
79+
login,
7780
});
7881

7982
if (!authorization.ok) {

0 commit comments

Comments
 (0)