mirror of https://github.com/docker/compose.git
aci.login: Return pointer to login service
Signed-off-by: Christopher Crone <christopher.crone@docker.com>
This commit is contained in:
parent
f41934ed90
commit
6412b9f638
|
@ -367,7 +367,7 @@ func (cs *aciComposeService) Down(ctx context.Context, opts cli.ProjectOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
type aciCloudService struct {
|
type aciCloudService struct {
|
||||||
loginService login.AzureLoginService
|
loginService *login.AzureLoginService
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *aciCloudService) Login(ctx context.Context, params interface{}) error {
|
func (cs *aciCloudService) Login(ctx context.Context, params interface{}) error {
|
||||||
|
|
|
@ -75,16 +75,16 @@ type AzureLoginService struct {
|
||||||
const tokenStoreFilename = "dockerAccessToken.json"
|
const tokenStoreFilename = "dockerAccessToken.json"
|
||||||
|
|
||||||
// NewAzureLoginService creates a NewAzureLoginService
|
// NewAzureLoginService creates a NewAzureLoginService
|
||||||
func NewAzureLoginService() (AzureLoginService, error) {
|
func NewAzureLoginService() (*AzureLoginService, error) {
|
||||||
return newAzureLoginServiceFromPath(GetTokenStorePath(), azureAPIHelper{})
|
return newAzureLoginServiceFromPath(GetTokenStorePath(), azureAPIHelper{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAzureLoginServiceFromPath(tokenStorePath string, helper apiHelper) (AzureLoginService, error) {
|
func newAzureLoginServiceFromPath(tokenStorePath string, helper apiHelper) (*AzureLoginService, error) {
|
||||||
store, err := newTokenStore(tokenStorePath)
|
store, err := newTokenStore(tokenStorePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return AzureLoginService{}, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return AzureLoginService{
|
return &AzureLoginService{
|
||||||
tokenStore: store,
|
tokenStore: store,
|
||||||
apiHelper: helper,
|
apiHelper: helper,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -92,7 +92,7 @@ func newAzureLoginServiceFromPath(tokenStorePath string, helper apiHelper) (Azur
|
||||||
|
|
||||||
// TestLoginFromServicePrincipal login with clientId / clientSecret from a previously created service principal.
|
// TestLoginFromServicePrincipal login with clientId / clientSecret from a previously created service principal.
|
||||||
// The resulting token does not include a refresh token, used for tests only
|
// The resulting token does not include a refresh token, used for tests only
|
||||||
func (login AzureLoginService) TestLoginFromServicePrincipal(clientID string, clientSecret string, tenantID string) error {
|
func (login *AzureLoginService) TestLoginFromServicePrincipal(clientID string, clientSecret string, tenantID string) error {
|
||||||
// Tried with auth2.NewUsernamePasswordConfig() but could not make this work with username / password, setting this for CI with clientID / clientSecret
|
// Tried with auth2.NewUsernamePasswordConfig() but could not make this work with username / password, setting this for CI with clientID / clientSecret
|
||||||
creds := auth2.NewClientCredentialsConfig(clientID, clientSecret, tenantID)
|
creds := auth2.NewClientCredentialsConfig(clientID, clientSecret, tenantID)
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ func (login AzureLoginService) TestLoginFromServicePrincipal(clientID string, cl
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logout remove azure token data
|
// Logout remove azure token data
|
||||||
func (login AzureLoginService) Logout(ctx context.Context) error {
|
func (login *AzureLoginService) Logout(ctx context.Context) error {
|
||||||
err := login.tokenStore.removeData()
|
err := login.tokenStore.removeData()
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return errors.New("No Azure login data to be removed")
|
return errors.New("No Azure login data to be removed")
|
||||||
|
@ -126,7 +126,7 @@ func (login AzureLoginService) Logout(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Login performs an Azure login through a web browser
|
// Login performs an Azure login through a web browser
|
||||||
func (login AzureLoginService) Login(ctx context.Context, requestedTenantID string) error {
|
func (login *AzureLoginService) Login(ctx context.Context, requestedTenantID string) error {
|
||||||
queryCh := make(chan localResponse, 1)
|
queryCh := make(chan localResponse, 1)
|
||||||
s, err := NewLocalServer(queryCh)
|
s, err := NewLocalServer(queryCh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -267,7 +267,7 @@ func newAuthorizerFromLoginStorePath(storeTokenPath string) (autorest.Authorizer
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetValidToken returns an access token. Refresh token if needed
|
// GetValidToken returns an access token. Refresh token if needed
|
||||||
func (login AzureLoginService) GetValidToken() (oauth2.Token, error) {
|
func (login *AzureLoginService) GetValidToken() (oauth2.Token, error) {
|
||||||
loginInfo, err := login.tokenStore.readToken()
|
loginInfo, err := login.tokenStore.readToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return oauth2.Token{}, err
|
return oauth2.Token{}, err
|
||||||
|
@ -288,7 +288,7 @@ func (login AzureLoginService) GetValidToken() (oauth2.Token, error) {
|
||||||
return token, nil
|
return token, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (login AzureLoginService) refreshToken(currentRefreshToken string, tenantID string) (oauth2.Token, error) {
|
func (login *AzureLoginService) refreshToken(currentRefreshToken string, tenantID string) (oauth2.Token, error) {
|
||||||
data := url.Values{
|
data := url.Values{
|
||||||
"grant_type": []string{"refresh_token"},
|
"grant_type": []string{"refresh_token"},
|
||||||
"client_id": []string{clientID},
|
"client_id": []string{clientID},
|
||||||
|
|
|
@ -33,10 +33,10 @@ import (
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testLoginService(t *testing.T, m *MockAzureHelper) (AzureLoginService, error) {
|
func testLoginService(t *testing.T, m *MockAzureHelper) (*AzureLoginService, error) {
|
||||||
dir, err := ioutil.TempDir("", "test_store")
|
dir, err := ioutil.TempDir("", "test_store")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return AzureLoginService{}, err
|
return nil, err
|
||||||
}
|
}
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
_ = os.RemoveAll(dir)
|
_ = os.RemoveAll(dir)
|
||||||
|
|
Loading…
Reference in New Issue