toitware / public

Issue tracking for the Toit IoT platform, the Toit language, and the Toit APIs.
8 stars 0 forks source link

Support authentication for vscode .devcontainer #19

Open floitsch opened 2 years ago

floitsch commented 2 years ago

When using vscode .devcontainers, the authentication is not stored, and it's necessary to copy/paste a login url from vscode to a browser for every deploy. Would be nice to save some kind of token as a file to handle login.

hasherdk commented 2 years ago

I have attached a starting point for a .devcontainer. However, the toit CLI fails rather hard after logging in using the browser.

vscode ➜ /workspaces/projects/toitTest (master ✗) $ toit doctor
Toit health:
[!] No Toit SDK installed
[OK] Visual Studio Code
Could not open your browser, please login here:
https://auth.toit.io/oauth/authorize?client_id=some_id&code_challenge=some_challenge&code_challenge_method=S256&redirect_uri=http%3A%2F%2Flocalhost%3A43409&response_type=code&state=some_state
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5037fb]

goroutine 1 [running]:
os.(*Process).signal(0x0, 0x198d7e0, 0x247cd90, 0x0, 0x0)
        /usr/lib/go-1.15/src/os/exec_unix.go:65 +0x3b
os.(*Process).Signal(...)
        /usr/lib/go-1.15/src/os/exec.go:131
os.(*Process).kill(...)
        /usr/lib/go-1.15/src/os/exec_posix.go:66
os.(*Process).Kill(...)
        /usr/lib/go-1.15/src/os/exec.go:116
github.com/toitware/console.git/cmds/shared/context/oauth.SSOLogin(0x199d820, 0xc000054900, 0x19a78c0, 0xc00040fdb0, 0xc00043ab20, 0x101, 0x0, 0x0, 0x0)
        /home/jenkins/agent/workspace/Toit_console_master/cmds/shared/context/oauth/oauth.go:87 +0xa13
github.com/toitware/console.git/cmds/shared/context.(*Context).SSOLogin(0xc00000e8e0, 0x199d820, 0xc000054900, 0xc00043ab20, 0xc0009b4101, 0x0, 0x513ae7, 0xc000072800)
        /home/jenkins/agent/workspace/Toit_console_master/cmds/shared/context/context.go:340 +0xb4
github.com/toitware/console.git/cmds/shared/context.(*Context).GetUserOrLogin(0xc00000e8e0, 0x199d820, 0xc000054900, 0xc00043ab20, 0x0, 0x0, 0xc00000000041bd58)
        /home/jenkins/agent/workspace/Toit_console_master/cmds/shared/context/context.go:248 +0xe9
github.com/toitware/console.git/cmds/shared/context/archive.(*Archive).client(0xc000831040, 0x199d820, 0xc000054900, 0xf, 0xc0005dc620, 0x2b)
        /home/jenkins/agent/workspace/Toit_console_master/cmds/shared/context/archive/archive.go:326 +0x95
github.com/toitware/console.git/cmds/shared/context/archive.(*Archive).httpGet(0xc000831040, 0x199d820, 0xc000054900, 0xc000112690, 0x2b, 0xc0000b1520, 0xc00099e628, 0x50fe8b)
        /home/jenkins/agent/workspace/Toit_console_master/cmds/shared/context/archive/archive.go:353 +0x259
github.com/toitware/console.git/cmds/shared/context/archive.(*Archive).downloadGetTags(0xc000831040, 0x199d820, 0xc000054900, 0xc000112690, 0x2b, 0x0, 0x0, 0x0, 0x0, 0x0)
        /home/jenkins/agent/workspace/Toit_console_master/cmds/shared/context/archive/archive.go:300 +0xa5
github.com/toitware/console.git/cmds/shared/context/archive.(*Archive).ListCLI(0xc000831040, 0x199d820, 0xc000054900, 0x1751495, 0x10, 0x1741ca5, 0x1, 0x9, 0x1752aed, 0x1)
        /home/jenkins/agent/workspace/Toit_console_master/cmds/shared/context/archive/archive.go:247 +0x10f
github.com/toitware/console.git/cmds/toit/commands.checkCLI(0x199d820, 0xc000054900, 0xc00099e888, 0xc00099e8a8, 0x0, 0x0)
        /home/jenkins/agent/workspace/Toit_console_master/cmds/toit/commands/doctor.go:282 +0x76
github.com/toitware/console.git/cmds/toit/commands.doctor(0x199d820, 0xc000054900, 0xc000152000, 0xc000831040, 0x194afe4, 0x6, 0x0, 0xed8ac6a63, 0x0, 0xc00043ab20, ...)
        /home/jenkins/agent/workspace/Toit_console_master/cmds/toit/commands/doctor.go:116 +0x1b8
reflect.Value.call(0x1550920, 0x17b8000, 0x13, 0x1742a2a, 0x4, 0xc000199000, 0x5, 0x5, 0x19b4980, 0x16e75c0, ...)
        /usr/lib/go-1.15/src/reflect/value.go:476 +0x8c7
reflect.Value.Call(0x1550920, 0x17b8000, 0x13, 0xc000199000, 0x5, 0x5, 0x5, 0xc0000a1300, 0xc000199000)
        /usr/lib/go-1.15/src/reflect/value.go:337 +0xb9
go.uber.org/dig.defaultInvoker(0x1550920, 0x17b8000, 0x13, 0xc000199000, 0x5, 0x5, 0xc0001aafa0, 0xc000199000, 0x5)
        /go/pkg/mod/go.uber.org/dig@v1.10.0/dig.go:284 +0x65
go.uber.org/dig.(*Container).Invoke(0xc0001aafa0, 0x1550920, 0x17b8000, 0x0, 0x0, 0x0, 0x0, 0x0)
        /go/pkg/mod/go.uber.org/dig@v1.10.0/dig.go:439 +0x39b
github.com/toitware/console.git/cmds/shared/cliq.(*Cliq).execRun(0xc000198e00, 0x1550920, 0x17b8000, 0x0, 0x0)
        /home/jenkins/agent/workspace/Toit_console_master/cmds/shared/cliq/cliq.go:211 +0x172
github.com/toitware/console.git/cmds/shared/cliq.(*Cliq).provideRun.func1.1(0xc000152000, 0x25388e8, 0x0, 0x0)
        /home/jenkins/agent/workspace/Toit_console_master/cmds/shared/cliq/cliq.go:186 +0xa5
github.com/spf13/cobra.(*Command).execute(0xc000152000, 0x25388e8, 0x0, 0x0, 0xc000152000, 0x25388e8)
        /go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:830 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0xc0004d1b80, 0xc00018d018, 0xc000507088, 0x8)
        /go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:914 +0x30b
github.com/spf13/cobra.(*Command).Execute(...)
        /go/pkg/mod/github.com/spf13/cobra@v0.0.5/command.go:864
github.com/toitware/console.git/cmds/shared/cliq.(*Cliq).execute(...)
        /home/jenkins/agent/workspace/Toit_console_master/cmds/shared/cliq/cliq.go:144
reflect.Value.call(0x14a9060, 0xc00007d180, 0x13, 0x1742a2a, 0x4, 0xc00000fa20, 0x1, 0x1, 0x19b4980, 0x14d62a0, ...)
        /usr/lib/go-1.15/src/reflect/value.go:476 +0x8c7
reflect.Value.Call(0x14a9060, 0xc00007d180, 0x13, 0xc00000fa20, 0x1, 0x1, 0x1, 0xc000507000, 0xc00000fa20)
        /usr/lib/go-1.15/src/reflect/value.go:337 +0xb9
go.uber.org/dig.defaultInvoker(0x14a9060, 0xc00007d180, 0x13, 0xc00000fa20, 0x1, 0x1, 0xc0001ab3b0, 0xc00000fa20, 0x1)
        /go/pkg/mod/go.uber.org/dig@v1.10.0/dig.go:284 +0x65
go.uber.org/dig.(*Container).Invoke(0xc0001ab3b0, 0x14a9060, 0xc00007d180, 0x0, 0x0, 0x0, 0x0, 0x0)
        /go/pkg/mod/go.uber.org/dig@v1.10.0/dig.go:439 +0x39b
go.uber.org/fx.(*App).executeInvokes(0xc000218a80, 0x14bee40, 0xc0005dbd50)
        /go/pkg/mod/go.uber.org/fx@v1.13.1/app.go:692 +0x48d
go.uber.org/fx.New(0xc0008cca00, 0x29, 0x50, 0x28)
        /go/pkg/mod/go.uber.org/fx@v1.13.1/app.go:471 +0x6eb
github.com/toitware/console.git/cmds/shared/cliq.(*Cliq).Run(0xc000198e00)
        /home/jenkins/agent/workspace/Toit_console_master/cmds/shared/cliq/cliq.go:135 +0x8cc
main.main()
        /home/jenkins/agent/workspace/Toit_console_master/cmds/toit/main.go:80 +0xbf6
vscode ➜ /workspaces/projects/toitTest (master ✗) $ 

I'm not sure what the problem is. It looks like it could actually be the login that is the problem. So my first thought that it wasn't saving login info may be caused by the login not ever really happening.

Anyway, a working .devcontainer environment would still be nice to have.

devcontainer.zip