E2B icon indicating copy to clipboard operation
E2B copied to clipboard

Do not use user config team id for template build command

Open 0div opened this issue 6 months ago • 11 comments

Description

The team ID is derived from the provided access token for this specific command, this PR lets you still explicitly specify the team id via opts but does not take it from the user config to avoid unwanted team does not exist errors when specifying access tokens for different clusters.

Test

$ [E2B/packages/cli] pnpm build

# test while being logged in
$ [E2B/templates/base] e2b auth login # in prod
$ [E2B/templates/base] E2B_DOMAIN=<your_dev_domain> E2B_ACCESS_TOKEN=<your_access_token> ../../packages/cli/dist/index.js template build

# test while being logged in with no env vars
$ [E2B/templates/base] ../../packages/cli/dist/index.js template build

# test while being logged in with no env vars and team id flag
$ [E2B/templates/base] ../../packages/cli/dist/index.js template build --team
<your_prod_team_id>

# test while being looged in with team flag 
$ [E2B/templates/base] E2B_DOMAIN=<your_dev_domain> E2B_ACCESS_TOKEN=<your_access_token> ../../packages/cli/dist/index.js template build --team <your_dev_team_id> 

# test while being logged out 
$ [E2B/templates/base] e2b auth logout
$ [E2B/templates/base] E2B_DOMAIN=<your_dev_domain> E2B_ACCESS_TOKEN=<your_access_token> ../../packages/cli/dist/index.js template build

# test while being logged out and specifying team id
$ [E2B/templates/base] E2B_DOMAIN=<your_dev_domain> E2B_ACCESS_TOKEN=<your_access_token> ../../packages/cli/dist/index.js template build --team <your_dev_team_id> 

0div avatar Jul 07 '25 19:07 0div

⚠️ No Changeset found

Latest commit: 997c65822e67001ae946e9ed240412babe5ccdce

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Jul 07 '25 19:07 changeset-bot[bot]

  1. Does it still work with no env vars
  2. Does it still work when trying to override team id using --team?

mishushakov avatar Jul 07 '25 19:07 mishushakov

  1. Does it still work with no env vars
  2. Does it still work when trying to override team id using --team?

yes, i updated the test description, do you mind testing on your machine for due diligence? thx

0div avatar Jul 07 '25 19:07 0div

how does it know what team to upload the template to if the team id is not provided?

mishushakov avatar Jul 08 '25 14:07 mishushakov

how does it know what team to upload the template to if the team id is not provided?

it derives it from the access token

0div avatar Jul 08 '25 17:07 0div

But if it's a different one in the template.toml? Will it still be using my default team?

mishushakov avatar Jul 08 '25 18:07 mishushakov

But if it's a different one in the template.toml? Will it still be using my default team?

Down the backend call stack of the handler for the request made here in the CLI client code, this is what determines the team ID, in other words it seems like no team ID is used.

/infra/packages/api/internal/handlers/auth.go

func (a *APIStore) GetUserAndTeams(c *gin.Context) (*uuid.UUID, []queries.GetTeamsWithUsersTeamsWithTierRow, error) {
	userID := a.GetUserID(c)
	ctx := c.Request.Context()

	teams, err := a.sqlcDB.GetTeamsWithUsersTeamsWithTier(ctx, userID)
	if err != nil {
		return nil, nil, fmt.Errorf("error when getting default team: %w", err)
	}

	return &userID, teams, err
}

0div avatar Jul 09 '25 00:07 0div

Yeah but the problem here it will always use the default team id or the one supplied as a parameter but will ignore e2b.toml?

mishushakov avatar Jul 09 '25 10:07 mishushakov

Yeah but the problem here it will always use the default team id or the one supplied as a parameter but will ignore e2b.toml?

it also picks up the team id from e2b.toml

0div avatar Jul 10 '25 20:07 0div

Down the backend call stack of the handler for the request made here in the CLI client code, this is what determines the team ID, in other words it seems like no team ID is used.

/infra/packages/api/internal/handlers/auth.go

The GetUserAndTeams returns a list of teams and based on provided team id, some team is selected

jakubno avatar Jul 16 '25 06:07 jakubno