Skip to content

Commit 8e3f009

Browse files
fix: prioritize CREATEOS_API_KEY over OAuth so the flag actually
overrides stored credentials
1 parent 7e5d78c commit 8e3f009

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

cmd/root/root.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ func NewApp() *cli.App {
6969
EnvVars: []string{"CREATEOS_SANDBOX_GATEWAY"},
7070
Value: "gateway.sb.createos.sh:2222",
7171
},
72+
&cli.StringFlag{
73+
Name: "api-key",
74+
Usage: "API key for authentication (overrides stored token)",
75+
EnvVars: []string{"CREATEOS_API_KEY"},
76+
},
7277
&cli.StringFlag{
7378
Name: "output",
7479
Aliases: []string{"o"},
@@ -100,7 +105,16 @@ func NewApp() *cli.App {
100105
return nil
101106
}
102107

103-
// Try OAuth session first
108+
// CREATEOS_API_KEY env var (or --api-key flag) — injected by Stripe Projects
109+
if apiKey := c.String("api-key"); apiKey != "" {
110+
client := api.NewClient(apiKey, c.String("api-url"), c.Bool("debug"))
111+
c.App.Metadata[api.ClientKey] = &client
112+
sandboxClient := api.NewSandboxClient(apiKey, c.String("sandbox-api-url"), c.Bool("debug"))
113+
c.App.Metadata[api.SandboxClientKey] = &sandboxClient
114+
return nil
115+
}
116+
117+
// Try OAuth session
104118
if config.HasOAuthSession() {
105119
session, err := config.LoadOAuthSession()
106120
if err != nil {
@@ -133,7 +147,7 @@ func NewApp() *cli.App {
133147
}
134148
}
135149

136-
// Fall back to API key
150+
// Fall back to stored token (~/.createos/.token)
137151
token, err := config.LoadToken()
138152
if err != nil {
139153
return err

internal/config/token.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func tokenFileExists() bool {
9191
return err == nil
9292
}
9393

94-
// IsLoggedIn returns true if the user is signed in via API key or OAuth
94+
// IsLoggedIn returns true if the user is signed in via API key, env var, or OAuth
9595
func IsLoggedIn() bool {
96-
return tokenFileExists() || HasOAuthSession()
96+
return os.Getenv("CREATEOS_API_KEY") != "" || tokenFileExists() || HasOAuthSession()
9797
}

0 commit comments

Comments
 (0)