Skip to content

Commit 6573afe

Browse files
committed
v0.0.31: browserless and sessionless fixes
1 parent bce0148 commit 6573afe

File tree

13 files changed

+62
-32
lines changed

13 files changed

+62
-32
lines changed

api/api.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,14 @@ func NewClient(cfg *cli.Config) (*Session, error) {
6565
if apiToken, err = kr.Get(keyring.APIToken); err == keyring.ErrNotFound {
6666
return anc, ErrSignedOut
6767
}
68-
if err != nil {
69-
if gnomeKeyringMissing() {
70-
return anc, ErrGnomeKeyringRequired
71-
}
72-
73-
return nil, fmt.Errorf("reading PAT token from keyring failed: %w", err)
68+
if err != nil && gnomeKeyringMissing() {
69+
return anc, ErrGnomeKeyringRequired
7470
}
7571

76-
if !strings.HasPrefix(apiToken, "ap0_") || len(apiToken) != 64 {
77-
return nil, fmt.Errorf("read invalid PAT token from keyring")
72+
if apiToken != "" {
73+
if !strings.HasPrefix(apiToken, "ap0_") || len(apiToken) != 64 {
74+
return nil, fmt.Errorf("read invalid PAT token from keyring")
75+
}
7876
}
7977
}
8078

auth/signin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/anchordotdev/cli/api"
1515
"github.com/anchordotdev/cli/auth/models"
1616
"github.com/anchordotdev/cli/keyring"
17-
cliModels "github.com/anchordotdev/cli/models"
17+
climodels "github.com/anchordotdev/cli/models"
1818
"github.com/anchordotdev/cli/ui"
1919
)
2020

@@ -76,7 +76,7 @@ func (s *SignIn) RunTUI(ctx context.Context, drv *ui.Driver) error {
7676
}
7777

7878
if err := browser.OpenURL(codes.VerificationUri); err != nil {
79-
drv.Activate(ctx, &cliModels.Browserless{Url: codes.VerificationUri})
79+
drv.Activate(ctx, &climodels.Browserless{Url: codes.VerificationUri})
8080
}
8181

8282
drv.Activate(ctx, new(models.SignInChecker))

lcl/config.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ func (c LclConfig) perform(ctx context.Context, drv *ui.Driver) error {
162162
return err
163163
}
164164

165+
browserless := false
166+
165167
// If no certificates are missing, skip http and go directly to https
166168
if len(auditInfo.Missing) != 0 {
167169
httpURL, err := url.Parse("http://" + domain + ":" + diagPort)
@@ -189,14 +191,17 @@ func (c LclConfig) perform(ctx context.Context, drv *ui.Driver) error {
189191

190192
if !cfg.Trust.MockMode {
191193
if err := browser.OpenURL(httpURL.String()); err != nil {
192-
return err
194+
browserless = true
195+
drv.Activate(ctx, &models.Browserless{})
193196
}
194197
}
195198

196-
select {
197-
case requestedScheme = <-requestc:
198-
case <-ctx.Done():
199-
return ctx.Err()
199+
if !browserless {
200+
select {
201+
case requestedScheme = <-requestc:
202+
case <-ctx.Done():
203+
return ctx.Err()
204+
}
200205
}
201206

202207
if requestedScheme == "https" {
@@ -241,15 +246,18 @@ func (c LclConfig) perform(ctx context.Context, drv *ui.Driver) error {
241246

242247
if !cfg.Trust.MockMode {
243248
if err := browser.OpenURL(httpsURL.String()); err != nil {
244-
return err
249+
browserless = true
250+
drv.Activate(ctx, &models.Browserless{})
245251
}
246252
}
247253

248-
for requestedScheme != "https" {
249-
select {
250-
case requestedScheme = <-requestc:
251-
case <-ctx.Done():
252-
return ctx.Err()
254+
if !browserless {
255+
for requestedScheme != "https" {
256+
select {
257+
case requestedScheme = <-requestc:
258+
case <-ctx.Done():
259+
return ctx.Err()
260+
}
253261
}
254262
}
255263

lcl/models/config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,15 @@ func (m LclConfigSuccess) View() string {
139139

140140
return b.String()
141141
}
142+
143+
type Browserless struct{}
144+
145+
func (m *Browserless) Init() tea.Cmd { return nil }
146+
147+
func (m *Browserless) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil }
148+
149+
func (m *Browserless) View() string {
150+
var b strings.Builder
151+
fmt.Fprintln(&b, ui.Warning("Unable to open browser, skipping browser-based verification."))
152+
return b.String()
153+
}

lcl/setup.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/anchordotdev/cli/cert"
2222
"github.com/anchordotdev/cli/detection"
2323
"github.com/anchordotdev/cli/lcl/models"
24+
climodels "github.com/anchordotdev/cli/models"
2425
"github.com/anchordotdev/cli/ui"
2526
)
2627

@@ -200,7 +201,7 @@ func (c Setup) perform(ctx context.Context, drv *ui.Driver) error {
200201

201202
if !cfg.Trust.MockMode {
202203
if err := browser.OpenURL(setupGuideURL); err != nil {
203-
return err
204+
drv.Activate(ctx, &climodels.Browserless{Url: setupGuideURL})
204205
}
205206
}
206207

models/cli.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ func (m *Browserless) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil }
6767
func (m *Browserless) View() string {
6868
var b strings.Builder
6969

70-
fmt.Fprintln(&b, ui.StepAlert(fmt.Sprintf("Unable to open browser. Please open this URL in a browser to continue: %s", m.Url)))
70+
fmt.Fprintln(&b, ui.Warning("Unable to open browser."))
71+
fmt.Fprintln(&b, ui.StepAlert(fmt.Sprintf("%s this in a browser to continue: %s.",
72+
ui.Action("Open"),
73+
ui.URL(m.Url),
74+
)))
7175

7276
return b.String()
7377
}

testdata/TestError/golden-darwin_arm64.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
# Error! test error ``
77
| We are sorry you encountered this error.
88
! Press Enter to open an issue on Github.
9-
! Unable to open browser. Please open this URL in a browser to continue: https://github.com/anchordotdev/cli/issues/new?body=%2A%2AAre+there+any+additional+details+you+would+like+to+share%3F%2A%2A%0A%0A---%0A%0A%2A%2ACommand%3A%2A%2A+%60%60%0A%2A%2AVersion%3A%2A%2A+%60dev+%28darwin%2Farm64%29+Commit%3A+none+BuildDate%3A+unknown%60%0A%2A%2AArguments%3A%2A%2A+%60%5B%5D%60%0A%2A%2AFlags%3A%2A%2A+%60%5B%5D%60%0A%2A%2AStdout%3A%2A%2A%0A%60%60%60%0A%0A%60%60%60%0A&title=Error%3A+test+error
9+
! Warning: Unable to open browser.
10+
! Open this in a browser to continue: https://github.com/anchordotdev/cli/issues/new?body=%2A%2AAre+there+any+additional+details+you+would+like+to+share%3F%2A%2A%0A%0A---%0A%0A%2A%2ACommand%3A%2A%2A+%60%60%0A%2A%2AVersion%3A%2A%2A+%60dev+%28darwin%2Farm64%29+Commit%3A+none+BuildDate%3A+unknown%60%0A%2A%2AArguments%3A%2A%2A+%60%5B%5D%60%0A%2A%2AFlags%3A%2A%2A+%60%5B%5D%60%0A%2A%2AStdout%3A%2A%2A%0A%60%60%60%0A%0A%60%60%60%0A&title=Error%3A+test+error.

testdata/TestError/golden-linux_amd64.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
# Error! test error ``
77
| We are sorry you encountered this error.
88
! Press Enter to open an issue on Github.
9-
! Unable to open browser. Please open this URL in a browser to continue: https://github.com/anchordotdev/cli/issues/new?body=%2A%2AAre+there+any+additional+details+you+would+like+to+share%3F%2A%2A%0A%0A---%0A%0A%2A%2ACommand%3A%2A%2A+%60%60%0A%2A%2AVersion%3A%2A%2A+%60dev+%28linux%2Famd64%29+Commit%3A+none+BuildDate%3A+unknown%60%0A%2A%2AArguments%3A%2A%2A+%60%5B%5D%60%0A%2A%2AFlags%3A%2A%2A+%60%5B%5D%60%0A%2A%2AStdout%3A%2A%2A%0A%60%60%60%0A%0A%60%60%60%0A&title=Error%3A+test+error
9+
! Warning: Unable to open browser.
10+
! Open this in a browser to continue: https://github.com/anchordotdev/cli/issues/new?body=%2A%2AAre+there+any+additional+details+you+would+like+to+share%3F%2A%2A%0A%0A---%0A%0A%2A%2ACommand%3A%2A%2A+%60%60%0A%2A%2AVersion%3A%2A%2A+%60dev+%28linux%2Famd64%29+Commit%3A+none+BuildDate%3A+unknown%60%0A%2A%2AArguments%3A%2A%2A+%60%5B%5D%60%0A%2A%2AFlags%3A%2A%2A+%60%5B%5D%60%0A%2A%2AStdout%3A%2A%2A%0A%60%60%60%0A%0A%60%60%60%0A&title=Error%3A+test+error.

testdata/TestError/golden-windows_amd64.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
# Error! test error ``
77
| We are sorry you encountered this error.
88
! Press Enter to open an issue on Github.
9-
! Unable to open browser. Please open this URL in a browser to continue: https://github.com/anchordotdev/cli/issues/new?body=%2A%2AAre+there+any+additional+details+you+would+like+to+share%3F%2A%2A%0A%0A---%0A%0A%2A%2ACommand%3A%2A%2A+%60%60%0A%2A%2AVersion%3A%2A%2A+%60dev+%28windows%2Famd64%29+Commit%3A+none+BuildDate%3A+unknown%60%0A%2A%2AArguments%3A%2A%2A+%60%5B%5D%60%0A%2A%2AFlags%3A%2A%2A+%60%5B%5D%60%0A%2A%2AStdout%3A%2A%2A%0A%60%60%60%0A%0A%60%60%60%0A&title=Error%3A+test+error
9+
! Warning: Unable to open browser.
10+
! Open this in a browser to continue: https://github.com/anchordotdev/cli/issues/new?body=%2A%2AAre+there+any+additional+details+you+would+like+to+share%3F%2A%2A%0A%0A---%0A%0A%2A%2ACommand%3A%2A%2A+%60%60%0A%2A%2AVersion%3A%2A%2A+%60dev+%28windows%2Famd64%29+Commit%3A+none+BuildDate%3A+unknown%60%0A%2A%2AArguments%3A%2A%2A+%60%5B%5D%60%0A%2A%2AFlags%3A%2A%2A+%60%5B%5D%60%0A%2A%2AStdout%3A%2A%2A%0A%60%60%60%0A%0A%60%60%60%0A&title=Error%3A+test+error.

testdata/TestPanic/golden-darwin_arm64.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
# Error! test panic ``
77
| We are sorry you encountered this error.
88
! Press Enter to open an issue on Github.
9-
! Unable to open browser. Please open this URL in a browser to continue: https://github.com/anchordotdev/cli/issues/new?body=%2A%2AAre+there+any+additional+details+you+would+like+to+share%3F%2A%2A%0A%0A---%0A%0A%2A%2ACommand%3A%2A%2A+%60%60%0A%2A%2AVersion%3A%2A%2A+%60dev+%28darwin%2Farm64%29+Commit%3A+none+BuildDate%3A+unknown%60%0A%2A%2AArguments%3A%2A%2A+%60%5B%5D%60%0A%2A%2AFlags%3A%2A%2A+%60%5B%5D%60%0A%2A%2AStack%3A%2A%2A%0A%60%60%60%0Apanic%28%7B%3Chex%3E%2C+%3Chex%3E%7D%29%0A%09%3Cgoroot%3E%2Fsrc%2Fruntime%2Fpanic.go%3A%3Cline%3E+%2B%3Chex%3E%0Agithub.com%2Fanchordotdev%2Fcli_test.%28%2APanicCommand%29.run%28...%29%0A%09%3Cpwd%3E%2Fcli_test.go%3A74%0Agithub.com%2Fanchordotdev%2Fcli_test.TestPanic.func1%28%3Chex%3E%29%0A%09%3Cpwd%3E%2Fcli_test.go%3A101+%2B%3Chex%3E%0Atesting.tRunner%28%3Chex%3E%2C+%3Chex%3E%29%0A%09%3Cgoroot%3E%2Fsrc%2Ftesting%2Ftesting.go%3A%3Cline%3E+%2B%3Chex%3E%0Acreated+by+testing.%28%2AT%29.Run+in+gouroutine+%3Cint%3E%0A%09%3Cgoroot%3E%2Fsrc%2Ftesting%2Ftesting.go%3A%3Cline%3E+%2B%3Chex%3E%0A%60%60%60%0A%2A%2AStdout%3A%2A%2A%0A%60%60%60%0A%0A%60%60%60%0A&title=Error%3A+test+panic
9+
! Warning: Unable to open browser.
10+
! Open this in a browser to continue: https://github.com/anchordotdev/cli/issues/new?body=%2A%2AAre+there+any+additional+details+you+would+like+to+share%3F%2A%2A%0A%0A---%0A%0A%2A%2ACommand%3A%2A%2A+%60%60%0A%2A%2AVersion%3A%2A%2A+%60dev+%28darwin%2Farm64%29+Commit%3A+none+BuildDate%3A+unknown%60%0A%2A%2AArguments%3A%2A%2A+%60%5B%5D%60%0A%2A%2AFlags%3A%2A%2A+%60%5B%5D%60%0A%2A%2AStack%3A%2A%2A%0A%60%60%60%0Apanic%28%7B%3Chex%3E%2C+%3Chex%3E%7D%29%0A%09%3Cgoroot%3E%2Fsrc%2Fruntime%2Fpanic.go%3A%3Cline%3E+%2B%3Chex%3E%0Agithub.com%2Fanchordotdev%2Fcli_test.%28%2APanicCommand%29.run%28...%29%0A%09%3Cpwd%3E%2Fcli_test.go%3A74%0Agithub.com%2Fanchordotdev%2Fcli_test.TestPanic.func1%28%3Chex%3E%29%0A%09%3Cpwd%3E%2Fcli_test.go%3A101+%2B%3Chex%3E%0Atesting.tRunner%28%3Chex%3E%2C+%3Chex%3E%29%0A%09%3Cgoroot%3E%2Fsrc%2Ftesting%2Ftesting.go%3A%3Cline%3E+%2B%3Chex%3E%0Acreated+by+testing.%28%2AT%29.Run+in+gouroutine+%3Cint%3E%0A%09%3Cgoroot%3E%2Fsrc%2Ftesting%2Ftesting.go%3A%3Cline%3E+%2B%3Chex%3E%0A%60%60%60%0A%2A%2AStdout%3A%2A%2A%0A%60%60%60%0A%0A%60%60%60%0A&title=Error%3A+test+panic.

0 commit comments

Comments
 (0)