-
Notifications
You must be signed in to change notification settings - Fork 925
feat(cli): accept E2B_API_KEY in template list & create #1361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mishushakov
wants to merge
9
commits into
main
Choose a base branch
from
mishushakov/cli-access-token-methods
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+99
−37
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7cff3d8
feat(cli): accept E2B_API_KEY in template list
mishushakov f064be9
fix(cli): drop spurious access-token check in template create
mishushakov 7d6df20
test(cli): cover template create auth and validation paths
mishushakov 65542e8
test(cli): narrow template create test to logged-in positive path
mishushakov 5711d35
test(cli): convert template create test to real backend integration
mishushakov 444526a
simplify
mishushakov 281c133
test(cli): simplify template create test setup
mishushakov 2d91330
test(cli): require E2B_API_KEY for template create test (don't skip)
mishushakov ab24582
refactor(cli): require E2B_API_KEY for template list & create
mishushakov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@e2b/cli': patch | ||
| --- | ||
|
|
||
| `e2b template list` and `e2b template create` now authenticate with `E2B_API_KEY` instead of requiring `E2B_ACCESS_TOKEN`. `E2B_ACCESS_TOKEN` is deprecated, so commands whose endpoints accept either credential now use the API key. This also unblocks API-key-only environments (e.g. CI/CD) that previously could not create or list templates. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { spawnSync } from 'node:child_process' | ||
| import * as fs from 'node:fs/promises' | ||
| import * as path from 'node:path' | ||
| import { afterAll, beforeAll, describe, expect, test } from 'vitest' | ||
|
|
||
| const apiKey = process.env.E2B_API_KEY | ||
| const domain = process.env.E2B_DOMAIN || 'e2b.app' | ||
|
|
||
| const cliPath = path.join(process.cwd(), 'dist', 'index.js') | ||
| const templateName = `cli-create-api-key-test-${Date.now()}` | ||
|
|
||
| describe('template create cli backend integration', () => { | ||
| let testDir: string | ||
|
|
||
| beforeAll(async () => { | ||
| if (!apiKey) { | ||
| throw new Error( | ||
| 'E2B_API_KEY must be set to run template create backend tests' | ||
| ) | ||
| } | ||
|
mishushakov marked this conversation as resolved.
|
||
| testDir = await fs.mkdtemp('e2b-create-test-') | ||
| await fs.writeFile( | ||
| path.join(testDir, 'e2b.Dockerfile'), | ||
| 'FROM ubuntu:latest\n' | ||
| ) | ||
| }) | ||
|
|
||
| afterAll(async () => { | ||
| if (!testDir) return | ||
| runCli(['template', 'delete', '--yes', templateName]) | ||
| await fs.rm(testDir, { recursive: true, force: true }) | ||
| }) | ||
|
|
||
| test( | ||
| 'template create succeeds with E2B_API_KEY alone (no E2B_ACCESS_TOKEN)', | ||
| { timeout: 300_000 }, | ||
| () => { | ||
| const result = runCli([ | ||
| 'template', | ||
| 'create', | ||
| templateName, | ||
| '--path', | ||
| testDir, | ||
| ]) | ||
| const output = String(result.stdout || '') + String(result.stderr || '') | ||
|
|
||
| expect(result.status, output).toBe(0) | ||
| // Success marker printed by create.ts on a finished build; the failure | ||
| // path prints "❌ Template build failed." instead. | ||
| expect(output).toContain('✅ Building sandbox template') | ||
| expect(output).not.toContain('❌ Template build failed') | ||
| // Auth never fell through to the access-token error box. | ||
| expect(output).not.toMatch(/You must be logged in/) | ||
| } | ||
| ) | ||
| }) | ||
|
|
||
| function runCli(args: string[]): ReturnType<typeof spawnSync> { | ||
| // Intentionally exclude E2B_ACCESS_TOKEN from the child env so this test | ||
| // verifies the API-key-only auth path end-to-end. | ||
| return spawnSync('node', [cliPath, ...args], { | ||
| env: { | ||
| PATH: process.env.PATH, | ||
| HOME: process.env.HOME, | ||
| E2B_DOMAIN: domain, | ||
| E2B_API_KEY: apiKey, | ||
| }, | ||
| encoding: 'utf8', | ||
| timeout: 300_000, | ||
| }) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.