mirror of https://github.com/docker/compose.git
Merge pull request #438 from docker/fix-wsl2-azure-login
Fix azure login inside WSL2
This commit is contained in:
commit
76cb9f3ad7
|
@ -30,6 +30,10 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
letterRunes = []rune("abcdefghijklmnopqrstuvwxyz123456789")
|
||||||
|
)
|
||||||
|
|
||||||
type apiHelper interface {
|
type apiHelper interface {
|
||||||
queryToken(data url.Values, tenantID string) (azureToken, error)
|
queryToken(data url.Values, tenantID string) (azureToken, error)
|
||||||
openAzureLoginPage(redirectURL string) error
|
openAzureLoginPage(redirectURL string) error
|
||||||
|
@ -80,22 +84,30 @@ func (helper azureAPIHelper) queryToken(data url.Values, tenantID string) (azure
|
||||||
return token, nil
|
return token, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func openbrowser(url string) error {
|
func openbrowser(address string) error {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "linux":
|
case "linux":
|
||||||
return exec.Command("xdg-open", url).Start()
|
if isWsl() {
|
||||||
|
return exec.Command("wslview", address).Start()
|
||||||
|
}
|
||||||
|
return exec.Command("xdg-open", address).Start()
|
||||||
case "windows":
|
case "windows":
|
||||||
return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
|
return exec.Command("rundll32", "url.dll,FileProtocolHandler", address).Start()
|
||||||
case "darwin":
|
case "darwin":
|
||||||
return exec.Command("open", url).Start()
|
return exec.Command("open", address).Start()
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unsupported platform")
|
return fmt.Errorf("unsupported platform")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
func isWsl() bool {
|
||||||
letterRunes = []rune("abcdefghijklmnopqrstuvwxyz123456789")
|
b, err := ioutil.ReadFile("/proc/version")
|
||||||
)
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Contains(string(b), "microsoft")
|
||||||
|
}
|
||||||
|
|
||||||
func randomString(prefix string, length int) string {
|
func randomString(prefix string, length int) string {
|
||||||
b := make([]rune, length)
|
b := make([]rune, length)
|
||||||
|
|
Loading…
Reference in New Issue