Skip to content

Commit b922dae

Browse files
author
Lindsay Holmwood
authored
Merge pull request #103 from AskAlice/sectionctl-login-error-handling
sectionctl login keychain error handling
2 parents a90a0dc + 74dcafa commit b922dae

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ bin/
1919
build/
2020
dist/
2121
sectionctl
22-
22+
.vscode/
23+
__debug_bin
2324
# Debug outputs
2425
sectionctl-debug-*.log

.vscode.example/launch.json

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "deploy",
6+
"type": "go",
7+
"request": "launch",
8+
"mode": "debug",
9+
"cwd": "${workspaceFolder}/commands/testdata/deploy/api-routes-app",
10+
"program": "${workspaceFolder}/sectionctl.go",
11+
"args": ["deploy", "-a", "replaceMeWithYourAccountID", "-i", "replaceMeWithYourApplicationID"]
12+
},
13+
{
14+
"name": "accounts/list",
15+
"type": "go",
16+
"request": "launch",
17+
"mode": "debug",
18+
"cwd": "${workspaceFolder}",
19+
"program": "${workspaceFolder}/sectionctl.go",
20+
"args": ["accounts", "list"]
21+
},
22+
{
23+
"name": "apps/list",
24+
"type": "go",
25+
"request": "launch",
26+
"mode": "debug",
27+
"cwd": "${workspaceFolder}",
28+
"program": "${workspaceFolder}/sectionctl.go",
29+
"args": ["apps", "list", "-a", "replaceMeWithYourAccountID"]
30+
},
31+
{
32+
"name": "apps/info",
33+
"type": "go",
34+
"request": "launch",
35+
"mode": "debug",
36+
"cwd": "${workspaceFolder}",
37+
"program": "${workspaceFolder}/sectionctl.go",
38+
"args": ["apps", "info", "-a", "replaceMeWithYourAccountID", "-i", "replaceMeWithYourApplicationID"]
39+
},
40+
{
41+
"name": "apps/stacks",
42+
"type": "go",
43+
"request": "launch",
44+
"mode": "debug",
45+
"cwd": "${workspaceFolder}",
46+
"program": "${workspaceFolder}/sectionctl.go",
47+
"args": ["apps", "stacks"]
48+
},
49+
{
50+
"name": "domains/list",
51+
"type": "go",
52+
"request": "launch",
53+
"mode": "debug",
54+
"cwd": "${workspaceFolder}",
55+
"program": "${workspaceFolder}/sectionctl.go",
56+
"args": ["domains", "list"]
57+
},
58+
{
59+
"name": "logs",
60+
"type": "go",
61+
"request": "launch",
62+
"mode": "debug",
63+
"cwd": "${workspaceFolder}",
64+
"program": "${workspaceFolder}/sectionctl.go",
65+
"args": ["logs", "-a", "replaceMeWithYourAccountID", "-i", "replaceMeWithYourApplicationID"]
66+
},
67+
{
68+
"name": "ps",
69+
"type": "go",
70+
"request": "launch",
71+
"mode": "debug",
72+
"cwd": "${workspaceFolder}",
73+
"program": "${workspaceFolder}/sectionctl.go",
74+
"args": ["ps", "-a", "replaceMeWithYourAccountID"]
75+
},
76+
{
77+
"name": "login",
78+
"type": "go",
79+
"request": "launch",
80+
"mode": "debug",
81+
"cwd": "${workspaceFolder}",
82+
"program": "${workspaceFolder}/sectionctl.go",
83+
"args": ["login", "--section-token", "replaceMeWithYourSectionToken"]
84+
}
85+
]
86+
}

commands/login.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"os"
8+
"runtime"
89

910
"github.com/section/sectionctl/api"
1011
"github.com/section/sectionctl/credentials"
@@ -21,6 +22,14 @@ func (c *LoginCmd) Run() (err error) {
2122
if api.Token != "" {
2223
err = credentials.Write(api.PrefixURI.Host, api.Token)
2324
if err != nil {
25+
if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
26+
fmt.Printf("Unable to write credential.\n\nPlease run this command, and add it to your ~/.bashrc\n\nexport SECTION_TOKEN=%s\n",api.Token)
27+
return nil
28+
} else if runtime.GOOS == "windows" {
29+
screenshot := "https://raw.githubusercontent.com/section/sectionctl/main/docs/section_token_control_panel.png"
30+
fmt.Printf("Unable to write credential.\n\nPlease execute the following, add it to your Powershell profile, or add it to your environment variables in control panel: \nWith Powershell:\n$env:SECTION_TOKEN=\"%s\"\n\nWith CMD:\nset SECTION_TOKEN=%s\n\nWith control panel:\n%s",api.Token,api.Token,screenshot)
31+
return nil
32+
}
2433
return fmt.Errorf("unable to write credential: %w", err)
2534
}
2635
} else {
@@ -30,7 +39,6 @@ func (c *LoginCmd) Run() (err error) {
3039
}
3140
api.Token = t
3241
}
33-
3442
fmt.Print("\nValidating credentials...")
3543
_, err = api.CurrentUser()
3644
if err != nil {
34.7 KB
Loading

0 commit comments

Comments
 (0)