FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(BRE2-915): API Key as auth method by patelspratik · Pull Request #369 · brevdev/brev-cli · GitHub

feat(BRE2-915): API Key as auth method - #369

Merged
patelspratik merged 2 commits into
mainfrom
supportapikeyauth
May 7, 2026
Merged

feat(BRE2-915): API Key as auth method#369
patelspratik merged 2 commits into
mainfrom
supportapikeyauth

Conversation

patelspratik commented Apr 27, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

brev-cli allows for API Keys to be used to login. Currently closed alpha as this behavior is vetted.

patelspratik force-pushed the supportapikeyauth branch 4 times, most recently from 630ddd7 to 6237763 Compare April 28, 2026 21:34
patelspratik changed the title initial codex api key as auth feat(BRE2-915): API Key as auth method Apr 28, 2026
patelspratik marked this pull request as ready for review April 28, 2026 22:07
patelspratik requested a review from a team as a code owner April 28, 2026 22:07
patelspratik force-pushed the supportapikeyauth branch 2 times, most recently from b9b11c1 to c097c8d Compare April 30, 2026 23:08
patelspratik marked this pull request as draft May 2, 2026 00:52
patelspratik marked this pull request as ready for review May 2, 2026 00:56
patelspratik marked this pull request as draft May 2, 2026 00:56
patelspratik force-pushed the supportapikeyauth branch 2 times, most recently from 2a100c9 to 67058c5 Compare May 6, 2026 00:03
patelspratik marked this pull request as ready for review May 6, 2026 00:30

Copy link
Copy Markdown
Contributor

Comment on pkg/cmd/ls/ls.go:88

If feels like we could benefit from having a centralized "CLIAuth" construct:

type CLIAuth struct {
	apiKey bool
	user   *entity.User
}
func (a CLIAuth) IsAPIKey() bool { return a.apiKey }
func (a CLIAuth) User() *entity.User { return a.user }

type currentUserStore interface {
	APIKeyAuthStore
	GetCurrentUser() (*entity.User, error)
}

func ResolveCLIAuth(store currentUserStore) (CLIAuth, error) {
	if IsAPIKeyAuthStore(store) {
		return CLIAuth{apiKey: true}, nil
	}
	user, err := store.GetCurrentUser()
	if err != nil {
		return CLIAuth{}, breverrors.WrapAndTrace(err)
	}
	return CLIAuth{user: user}, nil
}

if we had that our "Run" and "RunE" commands could routinely just start with that at the very top:

...
    RunE: func(cmd *cobra.Command, args []string) error {
	    cliAuth, err := ResolveCLIAuth(loginLsStore)
		if err != nil {
		    return breverrors.WrapAndTrace(err)
        }
...

and commands like this one could start taking the auth object and threading it down:

func RunLs(t *terminal.Terminal, cliAuth CLIAuth, lsStore LsStore, args []string, orgflag string, showAll bool, jsonOutput bool) error {
	ls := NewLs(lsStore, t, jsonOutput)

	org, err := getOrgForRunLs(cliAuth, lsStore, orgflag) // use the cliAuth object here
	if err != nil {
		return breverrors.WrapAndTrace(err)
	}
...

func handleLsArg(ls *Ls, cliAuth CLIAuth, arg string, org *entity.Organization, showAll bool) error {
	switch classifyLsArg(arg) {
	case lsArgOrgs:
		if cliAuth.IsAPIKey() {
			return breverrors.NewValidationError("api key auth cannot list organizations")
		}
		return wrapLsRun(ls.RunOrgs())
	case lsArgWorkspaces:
		return wrapLsRun(ls.RunWorkspaces(cliAuth, org, showAll))


...
func (ls Ls) RunWorkspaces(cliAuth CLIAuth, org *entity.Organization, showAll bool) error {
...
	// Determine which workspaces to show
	var workspacesToShow []entity.Workspace
	switch {
	case showAll:
		workspacesToShow = allWorkspaces
	case cliAuth.IsAPIKey(): // changed from "case user == nil:"
		workspacesToShow = allWorkspaces
	default:
        // changed from "workspacesToShow = store.FilterForUserWorkspaces(allWorkspaces, cliAuth.ID)"
		workspacesToShow = store.FilterForUserWorkspaces(allWorkspaces, cliAuth.User().ID)
	}

mainly in an effort to cut down on bools and "sometimes the user is nil" driving this logic.

patelspratik merged commit 83ace83 into main May 7, 2026
9 checks passed
patelspratik deleted the supportapikeyauth branch May 7, 2026 20:14
iExalt pushed a commit to iExalt/brev-cli that referenced this pull request May 11, 2026
* feat(BRE2-915): api key as auth method

* review feedback
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL