mirror of
https://github.com/docker/compose.git
synced 2025-07-26 07:04:32 +02:00
Plug new authorizer and remove az dependency
This commit is contained in:
parent
69f10fe80c
commit
bd5e3af2d4
20
azure/aci.go
20
azure/aci.go
@ -6,14 +6,14 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/api/azure/login"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/resources/mgmt/resources"
|
"github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/resources/mgmt/resources"
|
||||||
"github.com/Azure/azure-sdk-for-go/profiles/preview/preview/subscription/mgmt/subscription"
|
"github.com/Azure/azure-sdk-for-go/profiles/preview/preview/subscription/mgmt/subscription"
|
||||||
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance"
|
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance"
|
||||||
"github.com/Azure/azure-sdk-for-go/services/keyvault/auth"
|
|
||||||
"github.com/Azure/go-autorest/autorest"
|
"github.com/Azure/go-autorest/autorest"
|
||||||
"github.com/Azure/go-autorest/autorest/to"
|
"github.com/Azure/go-autorest/autorest/to"
|
||||||
tm "github.com/buger/goterm"
|
tm "github.com/buger/goterm"
|
||||||
@ -24,14 +24,6 @@ import (
|
|||||||
"github.com/docker/api/context/store"
|
"github.com/docker/api/context/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
// required to get auth.NewAuthorizerFromCLI() to work, otherwise getting "The access token has been obtained for wrong audience or resource 'https://vault.azure.net'."
|
|
||||||
err := os.Setenv("AZURE_KEYVAULT_RESOURCE", "https://management.azure.com")
|
|
||||||
if err != nil {
|
|
||||||
panic("unable to set environment variable AZURE_KEYVAULT_RESOURCE")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func createACIContainers(ctx context.Context, aciContext store.AciContext, groupDefinition containerinstance.ContainerGroup) error {
|
func createACIContainers(ctx context.Context, aciContext store.AciContext, groupDefinition containerinstance.ContainerGroup) error {
|
||||||
containerGroupsClient, err := getContainerGroupsClient(aciContext.SubscriptionID)
|
containerGroupsClient, err := getContainerGroupsClient(aciContext.SubscriptionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -243,7 +235,7 @@ func getACIContainerLogs(ctx context.Context, aciContext store.AciContext, conta
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getContainerGroupsClient(subscriptionID string) (containerinstance.ContainerGroupsClient, error) {
|
func getContainerGroupsClient(subscriptionID string) (containerinstance.ContainerGroupsClient, error) {
|
||||||
auth, err := auth.NewAuthorizerFromCLI()
|
auth, err := login.NewAzureLoginService().NewAuthorizerFromLogin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return containerinstance.ContainerGroupsClient{}, err
|
return containerinstance.ContainerGroupsClient{}, err
|
||||||
}
|
}
|
||||||
@ -256,7 +248,7 @@ func getContainerGroupsClient(subscriptionID string) (containerinstance.Containe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getContainerClient(subscriptionID string) (containerinstance.ContainerClient, error) {
|
func getContainerClient(subscriptionID string) (containerinstance.ContainerClient, error) {
|
||||||
auth, err := auth.NewAuthorizerFromCLI()
|
auth, err := login.NewAzureLoginService().NewAuthorizerFromLogin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return containerinstance.ContainerClient{}, err
|
return containerinstance.ContainerClient{}, err
|
||||||
}
|
}
|
||||||
@ -267,7 +259,7 @@ func getContainerClient(subscriptionID string) (containerinstance.ContainerClien
|
|||||||
|
|
||||||
func getSubscriptionsClient() subscription.SubscriptionsClient {
|
func getSubscriptionsClient() subscription.SubscriptionsClient {
|
||||||
subc := subscription.NewSubscriptionsClient()
|
subc := subscription.NewSubscriptionsClient()
|
||||||
authorizer, _ := auth.NewAuthorizerFromCLI()
|
authorizer, _ := login.NewAzureLoginService().NewAuthorizerFromLogin()
|
||||||
subc.Authorizer = authorizer
|
subc.Authorizer = authorizer
|
||||||
return subc
|
return subc
|
||||||
}
|
}
|
||||||
@ -275,7 +267,7 @@ func getSubscriptionsClient() subscription.SubscriptionsClient {
|
|||||||
// GetGroupsClient ...
|
// GetGroupsClient ...
|
||||||
func GetGroupsClient(subscriptionID string) resources.GroupsClient {
|
func GetGroupsClient(subscriptionID string) resources.GroupsClient {
|
||||||
groupsClient := resources.NewGroupsClient(subscriptionID)
|
groupsClient := resources.NewGroupsClient(subscriptionID)
|
||||||
authorizer, _ := auth.NewAuthorizerFromCLI()
|
authorizer, _ := login.NewAzureLoginService().NewAuthorizerFromLogin()
|
||||||
groupsClient.Authorizer = authorizer
|
groupsClient.Authorizer = authorizer
|
||||||
return groupsClient
|
return groupsClient
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/docker/api/context/cloud"
|
"github.com/docker/api/context/cloud"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance"
|
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance"
|
||||||
"github.com/Azure/go-autorest/autorest/azure/auth"
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -53,7 +52,7 @@ func New(ctx context.Context) (backend.Service, error) {
|
|||||||
}
|
}
|
||||||
aciContext, _ := metadata.Metadata.Data.(store.AciContext)
|
aciContext, _ := metadata.Metadata.Data.(store.AciContext)
|
||||||
|
|
||||||
auth, _ := auth.NewAuthorizerFromCLI()
|
auth, _ := login.NewAzureLoginService().NewAuthorizerFromLogin()
|
||||||
containerGroupsClient := containerinstance.NewContainerGroupsClient(aciContext.SubscriptionID)
|
containerGroupsClient := containerinstance.NewContainerGroupsClient(aciContext.SubscriptionID)
|
||||||
containerGroupsClient.Authorizer = auth
|
containerGroupsClient.Authorizer = auth
|
||||||
|
|
||||||
@ -67,7 +66,6 @@ func getAciAPIService(cgc containerinstance.ContainerGroupsClient, aciCtx store.
|
|||||||
ctx: aciCtx,
|
ctx: aciCtx,
|
||||||
},
|
},
|
||||||
aciComposeService: aciComposeService{
|
aciComposeService: aciComposeService{
|
||||||
containerGroupsClient: cgc,
|
|
||||||
ctx: aciCtx,
|
ctx: aciCtx,
|
||||||
},
|
},
|
||||||
aciCloudService: aciCloudService{
|
aciCloudService: aciCloudService{
|
||||||
@ -236,7 +234,6 @@ func (cs *aciContainerService) Delete(ctx context.Context, containerID string, _
|
|||||||
}
|
}
|
||||||
|
|
||||||
type aciComposeService struct {
|
type aciComposeService struct {
|
||||||
containerGroupsClient containerinstance.ContainerGroupsClient
|
|
||||||
ctx store.AciContext
|
ctx store.AciContext
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ func (login AzureLoginService) NewAuthorizerFromLogin() (autorest.Authorizer, er
|
|||||||
token := adal.Token{
|
token := adal.Token{
|
||||||
AccessToken: oauthToken.AccessToken,
|
AccessToken: oauthToken.AccessToken,
|
||||||
Type: oauthToken.TokenType,
|
Type: oauthToken.TokenType,
|
||||||
ExpiresIn: json.Number(strconv.Itoa(int(oauthToken.Expiry.Sub(time.Now()).Seconds()))),
|
ExpiresIn: json.Number(strconv.Itoa(int(time.Until(oauthToken.Expiry).Seconds()))),
|
||||||
ExpiresOn: json.Number(strconv.Itoa(int(oauthToken.Expiry.Sub(date.UnixEpoch()).Seconds()))),
|
ExpiresOn: json.Number(strconv.Itoa(int(oauthToken.Expiry.Sub(date.UnixEpoch()).Seconds()))),
|
||||||
RefreshToken: "",
|
RefreshToken: "",
|
||||||
Resource: "",
|
Resource: "",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user