mirror of https://github.com/docker/compose.git
Move the struct for creating and aci context to azure package
This commit is contained in:
parent
43b54ef75a
commit
84dbd1467d
|
@ -23,10 +23,6 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
clilogin "github.com/docker/api/cli/cmd/login"
|
||||
|
||||
acicontext "github.com/docker/api/cli/cmd/context"
|
||||
|
||||
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance"
|
||||
"github.com/Azure/go-autorest/autorest/to"
|
||||
"github.com/compose-spec/compose-go/cli"
|
||||
|
@ -54,6 +50,19 @@ const (
|
|||
// ErrNoSuchContainer is returned when the mentioned container does not exist
|
||||
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() {
|
||||
backend.Register("aci", "aci", service, getCloudService)
|
||||
}
|
||||
|
@ -356,7 +365,7 @@ type aciCloudService struct {
|
|||
}
|
||||
|
||||
func (cs *aciCloudService) Login(ctx context.Context, params interface{}) error {
|
||||
createOpts := params.(clilogin.AzureLoginOpts)
|
||||
createOpts := params.(LoginParams)
|
||||
return cs.loginService.Login(ctx, createOpts.TenantID)
|
||||
}
|
||||
|
||||
|
@ -366,6 +375,6 @@ func (cs *aciCloudService) Logout(ctx context.Context) error {
|
|||
|
||||
func (cs *aciCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) {
|
||||
contextHelper := newContextCreateHelper()
|
||||
createOpts := params.(acicontext.AciCreateOpts)
|
||||
createOpts := params.(ContextParams)
|
||||
return contextHelper.createContextData(ctx, createOpts)
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
acicontext "github.com/docker/api/cli/cmd/context"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/Azure/azure-sdk-for-go/profiles/preview/preview/subscription/mgmt/subscription"
|
||||
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources"
|
||||
|
@ -45,7 +43,7 @@ func newContextCreateHelper() contextCreateACIHelper {
|
|||
}
|
||||
}
|
||||
|
||||
func (helper contextCreateACIHelper) createContextData(ctx context.Context, opts acicontext.AciCreateOpts) (interface{}, string, error) {
|
||||
func (helper contextCreateACIHelper) createContextData(ctx context.Context, opts ContextParams) (interface{}, string, error) {
|
||||
var subscriptionID string
|
||||
if opts.SubscriptionID != "" {
|
||||
subscriptionID = opts.SubscriptionID
|
||||
|
@ -110,7 +108,7 @@ func (helper contextCreateACIHelper) createGroup(ctx context.Context, subscripti
|
|||
return g, nil
|
||||
}
|
||||
|
||||
func (helper contextCreateACIHelper) chooseGroup(ctx context.Context, subscriptionID string, opts acicontext.AciCreateOpts, 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"}
|
||||
for _, g := range groups {
|
||||
groupNames = append(groupNames, fmt.Sprintf("%s (%s)", *g.Name, *g.Location))
|
||||
|
|
|
@ -20,8 +20,6 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
acicontext "github.com/docker/api/cli/cmd/context"
|
||||
|
||||
"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/go-autorest/autorest/to"
|
||||
|
@ -177,8 +175,8 @@ func aciContext(subscriptionID string, resourceGroupName string, location string
|
|||
}
|
||||
}
|
||||
|
||||
func options(subscriptionID string, resourceGroupName string) acicontext.AciCreateOpts {
|
||||
return acicontext.AciCreateOpts{
|
||||
func options(subscriptionID string, resourceGroupName string) ContextParams {
|
||||
return ContextParams{
|
||||
SubscriptionID: subscriptionID,
|
||||
ResourceGroup: resourceGroupName,
|
||||
Location: "eastus",
|
||||
|
|
|
@ -22,21 +22,14 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/api/azure"
|
||||
"github.com/docker/api/client"
|
||||
"github.com/docker/api/context/store"
|
||||
"github.com/docker/api/errdefs"
|
||||
)
|
||||
|
||||
// AciCreateOpts options for creating ACI context
|
||||
type AciCreateOpts struct {
|
||||
Description string
|
||||
Location string
|
||||
SubscriptionID string
|
||||
ResourceGroup string
|
||||
}
|
||||
|
||||
func createAciCommand() *cobra.Command {
|
||||
var opts AciCreateOpts
|
||||
var opts azure.ContextParams
|
||||
cmd := &cobra.Command{
|
||||
Use: "aci CONTEXT [flags]",
|
||||
Short: "Create a context for Azure Container Instances",
|
||||
|
@ -54,7 +47,7 @@ func createAciCommand() *cobra.Command {
|
|||
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) {
|
||||
return errors.Wrapf(errdefs.ErrAlreadyExists, "context %s", contextName)
|
||||
}
|
||||
|
@ -66,7 +59,7 @@ 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)
|
||||
if err != nil {
|
||||
return nil, "", errors.Wrap(err, "cannot connect to ACI backend")
|
||||
|
|
|
@ -2,16 +2,13 @@ package login
|
|||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// AzureLoginOpts azure login options
|
||||
type AzureLoginOpts struct {
|
||||
TenantID string
|
||||
}
|
||||
"github.com/docker/api/azure"
|
||||
)
|
||||
|
||||
// AzureLoginCommand returns the azure login command
|
||||
func AzureLoginCommand() *cobra.Command {
|
||||
opts := AzureLoginOpts{}
|
||||
opts := azure.LoginParams{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "azure",
|
||||
Short: "Log in to azure",
|
||||
|
|
Loading…
Reference in New Issue