Use cli context for login

This commit is contained in:
Guillaume Tardif 2020-05-13 16:58:00 +02:00
parent bd5e3af2d4
commit d49773e348
2 changed files with 5 additions and 10 deletions

View File

@ -274,5 +274,5 @@ type aciCloudService struct {
} }
func (cs *aciCloudService) Login(ctx context.Context, params map[string]string) error { func (cs *aciCloudService) Login(ctx context.Context, params map[string]string) error {
return cs.loginService.Login() return cs.loginService.Login(ctx)
} }

View File

@ -1,6 +1,7 @@
package login package login
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
@ -9,14 +10,11 @@ import (
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"net/url" "net/url"
"os"
"os/exec" "os/exec"
"os/signal"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"syscall"
"time" "time"
"github.com/docker/api/errdefs" "github.com/docker/api/errdefs"
@ -91,16 +89,13 @@ func newAzureLoginServiceFromPath(tokenStorePath string, helper apiHelper) Azure
} }
type apiHelper interface { type apiHelper interface {
queryToken(data url.Values, tenantID string) (token azureToken, err error) queryToken(data url.Values, tenantID string) (azureToken, error)
} }
type azureAPIHelper struct{} type azureAPIHelper struct{}
//Login perform azure login through browser //Login perform azure login through browser
func (login AzureLoginService) Login() error { func (login AzureLoginService) Login(ctx context.Context) error {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
queryCh := make(chan url.Values, 1) queryCh := make(chan url.Values, 1)
mux := http.NewServeMux() mux := http.NewServeMux()
mux.HandleFunc("/", queryHandler(queryCh)) mux.HandleFunc("/", queryHandler(queryCh))
@ -118,7 +113,7 @@ func (login AzureLoginService) Login() error {
openbrowser(authURL) openbrowser(authURL)
select { select {
case <-sigs: case <-ctx.Done():
return nil return nil
case qsValues := <-queryCh: case qsValues := <-queryCh:
errorMsg, hasError := qsValues["error"] errorMsg, hasError := qsValues["error"]