mirror of
https://github.com/docker/compose.git
synced 2025-07-23 13:45:00 +02:00
Merge pull request #387 from docker/fix_subscriptionID_param
Fixing subscription-id parameter not passed to backend...
This commit is contained in:
commit
f7d1b8d4bf
@ -50,6 +50,19 @@ const (
|
|||||||
// ErrNoSuchContainer is returned when the mentioned container does not exist
|
// ErrNoSuchContainer is returned when the mentioned container does not exist
|
||||||
var ErrNoSuchContainer = errors.New("no such container")
|
var ErrNoSuchContainer = errors.New("no such container")
|
||||||
|
|
||||||
|
// ContextParams options for creating ACI context
|
||||||
|
type ContextParams struct {
|
||||||
|
Description string
|
||||||
|
Location string
|
||||||
|
SubscriptionID string
|
||||||
|
ResourceGroup string
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoginParams azure login options
|
||||||
|
type LoginParams struct {
|
||||||
|
TenantID string
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
backend.Register("aci", "aci", service, getCloudService)
|
backend.Register("aci", "aci", service, getCloudService)
|
||||||
}
|
}
|
||||||
@ -351,15 +364,17 @@ type aciCloudService struct {
|
|||||||
loginService login.AzureLoginService
|
loginService login.AzureLoginService
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *aciCloudService) Login(ctx context.Context, params map[string]string) error {
|
func (cs *aciCloudService) Login(ctx context.Context, params interface{}) error {
|
||||||
return cs.loginService.Login(ctx, params[login.TenantIDLoginParam])
|
createOpts := params.(LoginParams)
|
||||||
|
return cs.loginService.Login(ctx, createOpts.TenantID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *aciCloudService) Logout(ctx context.Context) error {
|
func (cs *aciCloudService) Logout(ctx context.Context) error {
|
||||||
return cs.loginService.Logout(ctx)
|
return cs.loginService.Logout(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *aciCloudService) CreateContextData(ctx context.Context, params map[string]string) (interface{}, string, error) {
|
func (cs *aciCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) {
|
||||||
contextHelper := newContextCreateHelper()
|
contextHelper := newContextCreateHelper()
|
||||||
return contextHelper.createContextData(ctx, params)
|
createOpts := params.(ContextParams)
|
||||||
|
return contextHelper.createContextData(ctx, createOpts)
|
||||||
}
|
}
|
||||||
|
@ -43,10 +43,10 @@ func newContextCreateHelper() contextCreateACIHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (helper contextCreateACIHelper) createContextData(ctx context.Context, opts map[string]string) (interface{}, string, error) {
|
func (helper contextCreateACIHelper) createContextData(ctx context.Context, opts ContextParams) (interface{}, string, error) {
|
||||||
var subscriptionID string
|
var subscriptionID string
|
||||||
if opts["aciSubscriptionID"] != "" {
|
if opts.SubscriptionID != "" {
|
||||||
subscriptionID = opts["aciSubscriptionID"]
|
subscriptionID = opts.SubscriptionID
|
||||||
} else {
|
} else {
|
||||||
subs, err := helper.resourceGroupHelper.GetSubscriptionIDs(ctx)
|
subs, err := helper.resourceGroupHelper.GetSubscriptionIDs(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -61,10 +61,10 @@ func (helper contextCreateACIHelper) createContextData(ctx context.Context, opts
|
|||||||
var group resources.Group
|
var group resources.Group
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if opts["aciResourceGroup"] != "" {
|
if opts.ResourceGroup != "" {
|
||||||
group, err = helper.resourceGroupHelper.GetGroup(ctx, subscriptionID, opts["aciResourceGroup"])
|
group, err = helper.resourceGroupHelper.GetGroup(ctx, subscriptionID, opts.ResourceGroup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", errors.Wrapf(err, "Could not find resource group %q", opts["aciResourceGroup"])
|
return nil, "", errors.Wrapf(err, "Could not find resource group %q", opts.ResourceGroup)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
groups, err := helper.resourceGroupHelper.ListGroups(ctx, subscriptionID)
|
groups, err := helper.resourceGroupHelper.ListGroups(ctx, subscriptionID)
|
||||||
@ -80,8 +80,8 @@ func (helper contextCreateACIHelper) createContextData(ctx context.Context, opts
|
|||||||
location := *group.Location
|
location := *group.Location
|
||||||
|
|
||||||
description := fmt.Sprintf("%s@%s", *group.Name, location)
|
description := fmt.Sprintf("%s@%s", *group.Name, location)
|
||||||
if opts["description"] != "" {
|
if opts.Description != "" {
|
||||||
description = fmt.Sprintf("%s (%s)", opts["description"], description)
|
description = fmt.Sprintf("%s (%s)", opts.Description, description)
|
||||||
}
|
}
|
||||||
|
|
||||||
return store.AciContext{
|
return store.AciContext{
|
||||||
@ -108,7 +108,7 @@ func (helper contextCreateACIHelper) createGroup(ctx context.Context, subscripti
|
|||||||
return g, nil
|
return g, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (helper contextCreateACIHelper) chooseGroup(ctx context.Context, subscriptionID string, opts map[string]string, groups []resources.Group) (resources.Group, error) {
|
func (helper contextCreateACIHelper) chooseGroup(ctx context.Context, subscriptionID string, opts ContextParams, groups []resources.Group) (resources.Group, error) {
|
||||||
groupNames := []string{"create a new resource group"}
|
groupNames := []string{"create a new resource group"}
|
||||||
for _, g := range groups {
|
for _, g := range groups {
|
||||||
groupNames = append(groupNames, fmt.Sprintf("%s (%s)", *g.Name, *g.Location))
|
groupNames = append(groupNames, fmt.Sprintf("%s (%s)", *g.Name, *g.Location))
|
||||||
@ -124,7 +124,7 @@ func (helper contextCreateACIHelper) chooseGroup(ctx context.Context, subscripti
|
|||||||
}
|
}
|
||||||
|
|
||||||
if group == 0 {
|
if group == 0 {
|
||||||
return helper.createGroup(ctx, subscriptionID, opts["aciLocation"])
|
return helper.createGroup(ctx, subscriptionID, opts.Location)
|
||||||
}
|
}
|
||||||
|
|
||||||
return groups[group-1], nil
|
return groups[group-1], nil
|
||||||
|
@ -175,11 +175,11 @@ func aciContext(subscriptionID string, resourceGroupName string, location string
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func options(subscriptionID string, resourceGroupName string) map[string]string {
|
func options(subscriptionID string, resourceGroupName string) ContextParams {
|
||||||
return map[string]string{
|
return ContextParams{
|
||||||
"aciSubscriptionID": subscriptionID,
|
SubscriptionID: subscriptionID,
|
||||||
"aciResourceGroup": resourceGroupName,
|
ResourceGroup: resourceGroupName,
|
||||||
"aciLocation": "eastus",
|
Location: "eastus",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,9 +45,6 @@ const (
|
|||||||
// v1 scope like "https://management.azure.com/.default" for ARM access
|
// v1 scope like "https://management.azure.com/.default" for ARM access
|
||||||
scopes = "offline_access https://management.azure.com/.default"
|
scopes = "offline_access https://management.azure.com/.default"
|
||||||
clientID = "04b07795-8ddb-461a-bbee-02f9e1bf7b46" // Azure CLI client id
|
clientID = "04b07795-8ddb-461a-bbee-02f9e1bf7b46" // Azure CLI client id
|
||||||
|
|
||||||
// TenantIDLoginParam
|
|
||||||
TenantIDLoginParam = "tenantId"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -22,20 +22,14 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/docker/api/azure"
|
||||||
"github.com/docker/api/client"
|
"github.com/docker/api/client"
|
||||||
"github.com/docker/api/context/store"
|
"github.com/docker/api/context/store"
|
||||||
"github.com/docker/api/errdefs"
|
"github.com/docker/api/errdefs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type aciCreateOpts struct {
|
|
||||||
description string
|
|
||||||
location string
|
|
||||||
subscriptionID string
|
|
||||||
resourceGroup string
|
|
||||||
}
|
|
||||||
|
|
||||||
func createAciCommand() *cobra.Command {
|
func createAciCommand() *cobra.Command {
|
||||||
var opts aciCreateOpts
|
var opts azure.ContextParams
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "aci CONTEXT [flags]",
|
Use: "aci CONTEXT [flags]",
|
||||||
Short: "Create a context for Azure Container Instances",
|
Short: "Create a context for Azure Container Instances",
|
||||||
@ -45,15 +39,15 @@ func createAciCommand() *cobra.Command {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
addDescriptionFlag(cmd, &opts.description)
|
addDescriptionFlag(cmd, &opts.Description)
|
||||||
cmd.Flags().StringVar(&opts.location, "location", "eastus", "Location")
|
cmd.Flags().StringVar(&opts.Location, "location", "eastus", "Location")
|
||||||
cmd.Flags().StringVar(&opts.subscriptionID, "subscription-id", "", "Location")
|
cmd.Flags().StringVar(&opts.SubscriptionID, "subscription-id", "", "Location")
|
||||||
cmd.Flags().StringVar(&opts.resourceGroup, "resource-group", "", "Resource group")
|
cmd.Flags().StringVar(&opts.ResourceGroup, "resource-group", "", "Resource group")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func runCreateAci(ctx context.Context, contextName string, opts aciCreateOpts) error {
|
func runCreateAci(ctx context.Context, contextName string, opts azure.ContextParams) error {
|
||||||
if contextExists(ctx, contextName) {
|
if contextExists(ctx, contextName) {
|
||||||
return errors.Wrapf(errdefs.ErrAlreadyExists, "context %s", contextName)
|
return errors.Wrapf(errdefs.ErrAlreadyExists, "context %s", contextName)
|
||||||
}
|
}
|
||||||
@ -65,19 +59,10 @@ func runCreateAci(ctx context.Context, contextName string, opts aciCreateOpts) e
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAciContextData(ctx context.Context, opts aciCreateOpts) (interface{}, string, error) {
|
func getAciContextData(ctx context.Context, opts azure.ContextParams) (interface{}, string, error) {
|
||||||
cs, err := client.GetCloudService(ctx, store.AciContextType)
|
cs, err := client.GetCloudService(ctx, store.AciContextType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", errors.Wrap(err, "cannot connect to ACI backend")
|
return nil, "", errors.Wrap(err, "cannot connect to ACI backend")
|
||||||
}
|
}
|
||||||
return cs.CreateContextData(ctx, convertAciOpts(opts))
|
return cs.CreateContextData(ctx, opts)
|
||||||
}
|
|
||||||
|
|
||||||
func convertAciOpts(opts aciCreateOpts) map[string]string {
|
|
||||||
return map[string]string{
|
|
||||||
"aciSubscriptionId": opts.subscriptionID,
|
|
||||||
"aciResourceGroup": opts.resourceGroup,
|
|
||||||
"aciLocation": opts.location,
|
|
||||||
"description": opts.description,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,26 +3,22 @@ package login
|
|||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/docker/api/azure/login"
|
"github.com/docker/api/azure"
|
||||||
)
|
)
|
||||||
|
|
||||||
type azureLoginOpts struct {
|
|
||||||
tenantID string
|
|
||||||
}
|
|
||||||
|
|
||||||
// AzureLoginCommand returns the azure login command
|
// AzureLoginCommand returns the azure login command
|
||||||
func AzureLoginCommand() *cobra.Command {
|
func AzureLoginCommand() *cobra.Command {
|
||||||
opts := azureLoginOpts{}
|
opts := azure.LoginParams{}
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "azure",
|
Use: "azure",
|
||||||
Short: "Log in to azure",
|
Short: "Log in to azure",
|
||||||
Args: cobra.MaximumNArgs(0),
|
Args: cobra.MaximumNArgs(0),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return cloudLogin(cmd, "aci", map[string]string{login.TenantIDLoginParam: opts.tenantID})
|
return cloudLogin(cmd, "aci", opts)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
flags.StringVar(&opts.tenantID, "tenant-id", "", "Specify tenant ID to use from your azure account")
|
flags.StringVar(&opts.TenantID, "tenant-id", "", "Specify tenant ID to use from your azure account")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ func runLogin(cmd *cobra.Command, args []string) error {
|
|||||||
return mobycli.ExecCmd(cmd)
|
return mobycli.ExecCmd(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloudLogin(cmd *cobra.Command, backendType string, params map[string]string) error {
|
func cloudLogin(cmd *cobra.Command, backendType string, params interface{}) error {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
cs, err := client.GetCloudService(ctx, backendType)
|
cs, err := client.GetCloudService(ctx, backendType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -25,11 +25,11 @@ import (
|
|||||||
// Service cloud specific services
|
// Service cloud specific services
|
||||||
type Service interface {
|
type Service interface {
|
||||||
// Login login to cloud provider
|
// Login login to cloud provider
|
||||||
Login(ctx context.Context, params map[string]string) error
|
Login(ctx context.Context, params interface{}) error
|
||||||
// Logout logout from cloud provider
|
// Logout logout from cloud provider
|
||||||
Logout(ctx context.Context) error
|
Logout(ctx context.Context) error
|
||||||
// CreateContextData create data for cloud context
|
// CreateContextData create data for cloud context
|
||||||
CreateContextData(ctx context.Context, params map[string]string) (contextData interface{}, description string, err error)
|
CreateContextData(ctx context.Context, params interface{}) (contextData interface{}, description string, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotImplementedCloudService to use for backend that don't provide cloud services
|
// NotImplementedCloudService to use for backend that don't provide cloud services
|
||||||
@ -45,10 +45,10 @@ func (cs notImplementedCloudService) Logout(ctx context.Context) error {
|
|||||||
return errdefs.ErrNotImplemented
|
return errdefs.ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs notImplementedCloudService) Login(ctx context.Context, params map[string]string) error {
|
func (cs notImplementedCloudService) Login(ctx context.Context, params interface{}) error {
|
||||||
return errdefs.ErrNotImplemented
|
return errdefs.ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs notImplementedCloudService) CreateContextData(ctx context.Context, params map[string]string) (interface{}, string, error) {
|
func (cs notImplementedCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) {
|
||||||
return nil, "", errdefs.ErrNotImplemented
|
return nil, "", errdefs.ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user