Bläddra i källkod

rename packages ( amazon to ecs and azure to aci )

Signed-off-by: aiordache <[email protected]>
aiordache 5 år sedan
förälder
incheckning
87245ef727

+ 19 - 0
.vscode/launch.json

@@ -0,0 +1,19 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "name": "Launch",
+            "type": "go",
+            "request": "launch",
+            "mode": "auto",
+            "program": "${workspaceRoot}/cli/main.go",
+            "env": {},
+            "cwd": "${workspaceRoot}/test/",
+            //"args": ["context", "create", "aws", "ecs", --profile", "sandbox.devtools.developer", "--region", "eu-west-3", "--description", "My ECS account"]
+            "args":["compose", "up"]
+        }
+    ]
+}

+ 3 - 3
azure/aci.go → aci/aci.go

@@ -14,7 +14,7 @@
    limitations under the License.
 */
 
-package azure
+package aci
 
 import (
 	"context"
@@ -33,8 +33,8 @@ import (
 	"github.com/morikuni/aec"
 	"github.com/pkg/errors"
 
-	"github.com/docker/api/azure/convert"
-	"github.com/docker/api/azure/login"
+	"github.com/docker/api/aci/convert"
+	"github.com/docker/api/aci/login"
 	"github.com/docker/api/containers"
 	"github.com/docker/api/context/store"
 	"github.com/docker/api/progress"

+ 1 - 1
azure/aci_test.go → aci/aci_test.go

@@ -1,4 +1,4 @@
-package azure
+package aci
 
 import (
 	"testing"

+ 6 - 4
azure/backend.go → aci/backend.go

@@ -14,7 +14,7 @@
    limitations under the License.
 */
 
-package azure
+package aci
 
 import (
 	"context"
@@ -30,8 +30,8 @@ import (
 	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"
 
-	"github.com/docker/api/azure/convert"
-	"github.com/docker/api/azure/login"
+	"github.com/docker/api/aci/convert"
+	"github.com/docker/api/aci/login"
 	"github.com/docker/api/backend"
 	"github.com/docker/api/compose"
 	"github.com/docker/api/containers"
@@ -41,6 +41,8 @@ import (
 	"github.com/docker/api/errdefs"
 )
 
+const backendType = store.AciContextType
+
 const (
 	singleContainerTag        = "docker-single-container"
 	composeContainerTag       = "docker-compose-application"
@@ -65,7 +67,7 @@ type LoginParams struct {
 }
 
 func init() {
-	backend.Register("aci", "aci", service, getCloudService)
+	backend.Register(backendType, backendType, service, getCloudService)
 }
 
 func service(ctx context.Context) (backend.Service, error) {

+ 1 - 1
azure/backend_test.go → aci/backend_test.go

@@ -14,7 +14,7 @@
    limitations under the License.
 */
 
-package azure
+package aci
 
 import (
 	"context"

+ 1 - 1
azure/context.go → aci/context.go

@@ -14,7 +14,7 @@
    limitations under the License.
 */
 
-package azure
+package aci
 
 import (
 	"context"

+ 1 - 1
azure/context_test.go → aci/context_test.go

@@ -14,7 +14,7 @@
    limitations under the License.
 */
 
-package azure
+package aci
 
 import (
 	"context"

+ 0 - 0
azure/convert/container.go → aci/convert/container.go


+ 0 - 0
azure/convert/container_test.go → aci/convert/container_test.go


+ 0 - 0
azure/convert/convert.go → aci/convert/convert.go


+ 0 - 0
azure/convert/convert_test.go → aci/convert/convert_test.go


+ 0 - 0
azure/convert/ports.go → aci/convert/ports.go


+ 0 - 0
azure/convert/ports_test.go → aci/convert/ports_test.go


+ 0 - 0
azure/convert/registrycredentials.go → aci/convert/registrycredentials.go


+ 0 - 0
azure/convert/registrycredentials_test.go → aci/convert/registrycredentials_test.go


+ 0 - 0
azure/convert/volume.go → aci/convert/volume.go


+ 0 - 0
azure/convert/volume_test.go → aci/convert/volume_test.go


+ 0 - 0
azure/login/local_server.go → aci/login/local_server.go


+ 0 - 0
azure/login/login.go → aci/login/login.go


+ 0 - 0
azure/login/loginHelper.go → aci/login/loginHelper.go


+ 0 - 0
azure/login/login_test.go → aci/login/login_test.go


+ 0 - 0
azure/login/tokenStore.go → aci/login/tokenStore.go


+ 0 - 0
azure/login/tokenStore_test.go → aci/login/tokenStore_test.go


+ 1 - 1
azure/resourcegroup.go → aci/resourcegroup.go

@@ -14,7 +14,7 @@
    limitations under the License.
 */
 
-package azure
+package aci
 
 import (
 	"context"

+ 0 - 1
amazon/doc.go

@@ -1 +0,0 @@
-package amazon

+ 0 - 1
cli/cmd/context/create.go

@@ -76,7 +76,6 @@ $ docker context create my-context --description "some description" --docker "ho
 	}
 
 	cmd.AddCommand(
-		createAciCommand(),
 		createLocalCommand(),
 		createExampleCommand(),
 	)

+ 4 - 4
cli/cmd/context/createaci.go → cli/cmd/context/create_aci.go

@@ -22,7 +22,7 @@ import (
 	"github.com/pkg/errors"
 	"github.com/spf13/cobra"
 
-	"github.com/docker/api/azure"
+	"github.com/docker/api/aci"
 	"github.com/docker/api/client"
 	"github.com/docker/api/context/store"
 	"github.com/docker/api/errdefs"
@@ -38,7 +38,7 @@ $ docker context create aci CONTEXT [flags]
 }
 
 func createAciCommand() *cobra.Command {
-	var opts azure.ContextParams
+	var opts aci.ContextParams
 	cmd := &cobra.Command{
 		Use:   "aci CONTEXT [flags]",
 		Short: "Create a context for Azure Container Instances",
@@ -56,7 +56,7 @@ func createAciCommand() *cobra.Command {
 	return cmd
 }
 
-func runCreateAci(ctx context.Context, contextName string, opts azure.ContextParams) error {
+func runCreateAci(ctx context.Context, contextName string, opts aci.ContextParams) error {
 	if contextExists(ctx, contextName) {
 		return errors.Wrapf(errdefs.ErrAlreadyExists, "context %s", contextName)
 	}
@@ -68,7 +68,7 @@ func runCreateAci(ctx context.Context, contextName string, opts azure.ContextPar
 
 }
 
-func getAciContextData(ctx context.Context, opts azure.ContextParams) (interface{}, string, error) {
+func getAciContextData(ctx context.Context, opts aci.ContextParams) (interface{}, string, error) {
 	cs, err := client.GetCloudService(ctx, store.AciContextType)
 	if err != nil {
 		return nil, "", errors.Wrap(err, "cannot connect to ACI backend")

+ 5 - 5
cli/cmd/context/createecs.go → cli/cmd/context/create_ecs.go

@@ -24,9 +24,9 @@ import (
 	"github.com/pkg/errors"
 	"github.com/spf13/cobra"
 
-	"github.com/docker/api/amazon"
 	"github.com/docker/api/client"
 	"github.com/docker/api/context/store"
+	"github.com/docker/api/ecs"
 	"github.com/docker/api/errdefs"
 )
 
@@ -40,7 +40,7 @@ $ docker context create ecs CONTEXT [flags]
 }
 
 func createEcsCommand() *cobra.Command {
-	var opts amazon.ContextParams
+	var opts ecs.ContextParams
 	cmd := &cobra.Command{
 		Use:   "ecs CONTEXT [flags]",
 		Short: "Create a context for Amazon ECS",
@@ -58,9 +58,9 @@ func createEcsCommand() *cobra.Command {
 	return cmd
 }
 
-func runCreateEcs(ctx context.Context, contextName string, opts amazon.ContextParams) error {
+func runCreateEcs(ctx context.Context, contextName string, opts ecs.ContextParams) error {
 	if contextExists(ctx, contextName) {
-		return errors.Wrapf(errdefs.ErrAlreadyExists, "context %s", contextName)
+		return errors.Wrapf(errdefs.ErrAlreadyExists, "context %q", contextName)
 	}
 	contextData, description, err := getEcsContextData(ctx, opts)
 	if err != nil {
@@ -70,7 +70,7 @@ func runCreateEcs(ctx context.Context, contextName string, opts amazon.ContextPa
 
 }
 
-func getEcsContextData(ctx context.Context, opts amazon.ContextParams) (interface{}, string, error) {
+func getEcsContextData(ctx context.Context, opts ecs.ContextParams) (interface{}, string, error) {
 	cs, err := client.GetCloudService(ctx, store.EcsContextType)
 	if err != nil {
 		return nil, "", errors.Wrap(err, "cannot connect to AWS backend")

+ 2 - 2
cli/cmd/login/azurelogin.go

@@ -3,12 +3,12 @@ package login
 import (
 	"github.com/spf13/cobra"
 
-	"github.com/docker/api/azure"
+	"github.com/docker/api/aci"
 )
 
 // AzureLoginCommand returns the azure login command
 func AzureLoginCommand() *cobra.Command {
-	opts := azure.LoginParams{}
+	opts := aci.LoginParams{}
 	cmd := &cobra.Command{
 		Use:   "azure",
 		Short: "Log in to azure",

+ 2 - 2
cli/main.go

@@ -36,8 +36,8 @@ import (
 	"github.com/spf13/cobra"
 
 	// Backend registrations
-	_ "github.com/docker/api/amazon"
-	_ "github.com/docker/api/azure"
+	_ "github.com/docker/api/aci"
+	_ "github.com/docker/api/ecs"
 	_ "github.com/docker/api/example"
 	_ "github.com/docker/api/local"
 	"github.com/docker/api/metrics"

+ 9 - 0
cli/mobycli/delegate_ecs.go

@@ -0,0 +1,9 @@
+// +build !ecs
+
+package mobycli
+
+import "github.com/docker/api/context/store"
+
+func init() {
+	delegatedContextTypes = append(delegatedContextTypes, store.AwsContextType, store.EcsContextType)
+}

+ 8 - 1
cli/mobycli/exec.go

@@ -29,6 +29,8 @@ import (
 	"github.com/docker/api/context/store"
 )
 
+var delegatedContextTypes = []string{store.DefaultContextType}
+
 // ComDockerCli name of the classic cli binary
 const ComDockerCli = "com.docker.cli"
 
@@ -46,7 +48,12 @@ func ExecIfDefaultCtxType(ctx context.Context) {
 }
 
 func mustDelegateToMoby(ctxType string) bool {
-	return ctxType == store.DefaultContextType
+	for _, ctype := range delegatedContextTypes {
+		if ctxType == ctype {
+			return true
+		}
+	}
+	return false
 }
 
 // Exec delegates to com.docker.cli if on moby context

+ 3 - 0
context/store/contextmetadata.go

@@ -55,6 +55,9 @@ type EcsContext struct {
 	Region  string `json:",omitempty"`
 }
 
+// AwsContext is the context for the ecs plugin
+type AwsContext EcsContext
+
 // LocalContext is the context for the local backend
 type LocalContext struct{}
 

+ 7 - 1
context/store/store.go

@@ -36,7 +36,13 @@ const (
 	DefaultContextName = "default"
 	// DefaultContextType is the type for all moby contexts (not associated with cli backend)
 	DefaultContextType = "moby"
-	// EcsContextType is the type for ecs contexts (currently a CLI plugin, not associated with cli backend)
+
+	// AwsContextType is the type for aws contexts (currently a CLI plugin, not associated with cli backend)
+	// to be removed with the cli plugin
+	AwsContextType = "aws"
+
+	// EcsContextType is the endpoint key in the context endpoints for an ECS
+	// backend
 	EcsContextType = "ecs"
 	// AciContextType is the endpoint key in the context endpoints for an ACI
 	// backend

+ 4 - 4
amazon/backend.go → ecs/backend.go

@@ -13,7 +13,7 @@
    limitations under the License.
 */
 
-package amazon
+package ecs
 
 import (
 	"context"
@@ -25,7 +25,7 @@ import (
 	"github.com/docker/api/context/cloud"
 	"github.com/docker/api/context/store"
 	"github.com/docker/api/errdefs"
-	ecs "github.com/docker/ecs-plugin/pkg/amazon/backend"
+	ecsplugin "github.com/docker/ecs-plugin/pkg/amazon/backend"
 )
 
 const backendType = store.EcsContextType
@@ -57,7 +57,7 @@ func service(ctx context.Context) (backend.Service, error) {
 }
 
 func getEcsAPIService(ecsCtx store.EcsContext) (*ecsAPIService, error) {
-	backend, err := ecs.NewBackend(ecsCtx.Profile, ecsCtx.Region)
+	backend, err := ecsplugin.NewBackend(ecsCtx.Profile, ecsCtx.Region)
 	if err != nil {
 		return nil, err
 	}
@@ -69,7 +69,7 @@ func getEcsAPIService(ecsCtx store.EcsContext) (*ecsAPIService, error) {
 
 type ecsAPIService struct {
 	ctx            store.EcsContext
-	composeBackend *ecs.Backend
+	composeBackend *ecsplugin.Backend
 }
 
 func (a *ecsAPIService) ContainerService() containers.Service {

+ 3 - 2
amazon/context.go → ecs/context.go

@@ -13,7 +13,7 @@
    limitations under the License.
 */
 
-package amazon
+package ecs
 
 import (
 	"context"
@@ -26,9 +26,10 @@ import (
 	"github.com/aws/aws-sdk-go/aws/awserr"
 	"github.com/aws/aws-sdk-go/aws/credentials"
 	"github.com/aws/aws-sdk-go/aws/defaults"
+	"gopkg.in/ini.v1"
+
 	"github.com/docker/api/context/store"
 	"github.com/docker/api/prompt"
-	"gopkg.in/ini.v1"
 )
 
 type contextCreateAWSHelper struct {

+ 14 - 0
ecs/doc.go

@@ -0,0 +1,14 @@
+/*
+   Copyright 2020 Docker, Inc.
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+       http://www.apache.org/licenses/LICENSE-2.0
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
+package ecs

+ 13 - 0
prompt/prompt.go

@@ -1,3 +1,16 @@
+/*
+   Copyright 2020 Docker, Inc.
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+       http://www.apache.org/licenses/LICENSE-2.0
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
 package prompt
 
 import (

+ 2 - 2
tests/aci-e2e/e2e-aci_test.go

@@ -37,8 +37,8 @@ import (
 	log "github.com/sirupsen/logrus"
 	"github.com/stretchr/testify/suite"
 
-	"github.com/docker/api/azure"
-	"github.com/docker/api/azure/login"
+	azure "github.com/docker/api/aci"
+	"github.com/docker/api/aci/login"
 	"github.com/docker/api/context/store"
 	"github.com/docker/api/tests/aci-e2e/storage"
 	. "github.com/docker/api/tests/framework"

+ 1 - 1
tests/aci-e2e/storage/storage.go

@@ -24,7 +24,7 @@ import (
 	"github.com/Azure/go-autorest/autorest"
 	"github.com/Azure/go-autorest/autorest/to"
 
-	"github.com/docker/api/azure/login"
+	"github.com/docker/api/aci/login"
 	"github.com/docker/api/context/store"
 )