mirror of
https://github.com/docker/compose.git
synced 2025-07-21 20:54:32 +02:00
Revert "Return an error if unable to open the browser"
This reverts commit e22b0ba6768ef817aa53888be8b51f3eb5287b4b.
This commit is contained in:
parent
43d8f2fa18
commit
1d8e0ef9e6
@ -20,9 +20,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -134,9 +137,7 @@ func (login AzureLoginService) Login(ctx context.Context, requestedTenantID stri
|
|||||||
if redirectURL == "" {
|
if redirectURL == "" {
|
||||||
return errors.Wrap(errdefs.ErrLoginFailed, "empty redirect URL")
|
return errors.Wrap(errdefs.ErrLoginFailed, "empty redirect URL")
|
||||||
}
|
}
|
||||||
if err = login.apiHelper.openAzureLoginPage(redirectURL); err != nil {
|
login.apiHelper.openAzureLoginPage(redirectURL)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
@ -301,3 +302,21 @@ func (login AzureLoginService) refreshToken(currentRefreshToken string, tenantID
|
|||||||
|
|
||||||
return toOAuthToken(token), nil
|
return toOAuthToken(token), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func openbrowser(url string) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "linux":
|
||||||
|
err = exec.Command("xdg-open", url).Start()
|
||||||
|
case "windows":
|
||||||
|
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
|
||||||
|
case "darwin":
|
||||||
|
err = exec.Command("open", url).Start()
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("unsupported platform")
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -25,22 +25,21 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/browser"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
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)
|
||||||
queryAuthorizationAPI(authorizationURL string, authorizationHeader string) ([]byte, int, error)
|
queryAuthorizationAPI(authorizationURL string, authorizationHeader string) ([]byte, int, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type azureAPIHelper struct{}
|
type azureAPIHelper struct{}
|
||||||
|
|
||||||
func (helper azureAPIHelper) openAzureLoginPage(redirectURL string) error {
|
func (helper azureAPIHelper) openAzureLoginPage(redirectURL string) {
|
||||||
state := randomString("", 10)
|
state := randomString("", 10)
|
||||||
authURL := fmt.Sprintf(authorizeFormat, clientID, redirectURL, state, scopes)
|
authURL := fmt.Sprintf(authorizeFormat, clientID, redirectURL, state, scopes)
|
||||||
return browser.OpenURL(authURL)
|
openbrowser(authURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (helper azureAPIHelper) queryAuthorizationAPI(authorizationURL string, authorizationHeader string) ([]byte, int, error) {
|
func (helper azureAPIHelper) queryAuthorizationAPI(authorizationURL string, authorizationHeader string) ([]byte, int, error) {
|
||||||
|
@ -370,7 +370,6 @@ func (s *MockAzureHelper) queryAuthorizationAPI(authorizationURL string, authori
|
|||||||
return args.Get(0).([]byte), args.Int(1), args.Error(2)
|
return args.Get(0).([]byte), args.Int(1), args.Error(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MockAzureHelper) openAzureLoginPage(redirectURL string) error {
|
func (s *MockAzureHelper) openAzureLoginPage(redirectURL string) {
|
||||||
s.Called(redirectURL)
|
s.Called(redirectURL)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
1
go.mod
1
go.mod
@ -39,7 +39,6 @@ require (
|
|||||||
github.com/opencontainers/go-digest v1.0.0
|
github.com/opencontainers/go-digest v1.0.0
|
||||||
github.com/opencontainers/image-spec v1.0.1 // indirect
|
github.com/opencontainers/image-spec v1.0.1 // indirect
|
||||||
github.com/opencontainers/runc v0.1.1 // indirect
|
github.com/opencontainers/runc v0.1.1 // indirect
|
||||||
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
|
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/robpike/filter v0.0.0-20150108201509-2984852a2183
|
github.com/robpike/filter v0.0.0-20150108201509-2984852a2183
|
||||||
github.com/sirupsen/logrus v1.6.0
|
github.com/sirupsen/logrus v1.6.0
|
||||||
|
2
go.sum
2
go.sum
@ -249,8 +249,6 @@ github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59P
|
|||||||
github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700 h1:eNUVfm/RFLIi1G7flU5/ZRTHvd4kcVuzfRnL6OFlzCI=
|
github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700 h1:eNUVfm/RFLIi1G7flU5/ZRTHvd4kcVuzfRnL6OFlzCI=
|
||||||
github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
|
github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
|
||||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||||
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98=
|
|
||||||
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
|
|
||||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user