From 87245ef727ec9dd949d6c3ad91f0e9357b8a5547 Mon Sep 17 00:00:00 2001 From: aiordache Date: Wed, 29 Jul 2020 15:12:45 +0200 Subject: [PATCH] rename packages ( amazon to ecs and azure to aci ) Signed-off-by: aiordache --- .vscode/launch.json | 19 +++++++++++++++++++ {azure => aci}/aci.go | 6 +++--- {azure => aci}/aci_test.go | 2 +- {azure => aci}/backend.go | 10 ++++++---- {azure => aci}/backend_test.go | 2 +- {azure => aci}/context.go | 2 +- {azure => aci}/context_test.go | 2 +- {azure => aci}/convert/container.go | 0 {azure => aci}/convert/container_test.go | 0 {azure => aci}/convert/convert.go | 0 {azure => aci}/convert/convert_test.go | 0 {azure => aci}/convert/ports.go | 0 {azure => aci}/convert/ports_test.go | 0 {azure => aci}/convert/registrycredentials.go | 0 .../convert/registrycredentials_test.go | 0 {azure => aci}/convert/volume.go | 0 {azure => aci}/convert/volume_test.go | 0 {azure => aci}/login/local_server.go | 0 {azure => aci}/login/login.go | 0 {azure => aci}/login/loginHelper.go | 0 {azure => aci}/login/login_test.go | 0 {azure => aci}/login/tokenStore.go | 0 {azure => aci}/login/tokenStore_test.go | 0 {azure => aci}/resourcegroup.go | 2 +- amazon/doc.go | 1 - cli/cmd/context/create.go | 1 - .../context/{createaci.go => create_aci.go} | 8 ++++---- .../context/{createecs.go => create_ecs.go} | 10 +++++----- cli/cmd/login/azurelogin.go | 4 ++-- cli/main.go | 4 ++-- cli/mobycli/delegate_ecs.go | 9 +++++++++ cli/mobycli/exec.go | 9 ++++++++- context/store/contextmetadata.go | 3 +++ context/store/store.go | 8 +++++++- {amazon => ecs}/backend.go | 8 ++++---- {amazon => ecs}/context.go | 5 +++-- ecs/doc.go | 14 ++++++++++++++ prompt/prompt.go | 13 +++++++++++++ tests/aci-e2e/e2e-aci_test.go | 4 ++-- tests/aci-e2e/storage/storage.go | 2 +- 40 files changed, 110 insertions(+), 38 deletions(-) create mode 100644 .vscode/launch.json rename {azure => aci}/aci.go (99%) rename {azure => aci}/aci_test.go (94%) rename {azure => aci}/backend.go (98%) rename {azure => aci}/backend_test.go (99%) rename {azure => aci}/context.go (99%) rename {azure => aci}/context_test.go (99%) rename {azure => aci}/convert/container.go (100%) rename {azure => aci}/convert/container_test.go (100%) rename {azure => aci}/convert/convert.go (100%) rename {azure => aci}/convert/convert_test.go (100%) rename {azure => aci}/convert/ports.go (100%) rename {azure => aci}/convert/ports_test.go (100%) rename {azure => aci}/convert/registrycredentials.go (100%) rename {azure => aci}/convert/registrycredentials_test.go (100%) rename {azure => aci}/convert/volume.go (100%) rename {azure => aci}/convert/volume_test.go (100%) rename {azure => aci}/login/local_server.go (100%) rename {azure => aci}/login/login.go (100%) rename {azure => aci}/login/loginHelper.go (100%) rename {azure => aci}/login/login_test.go (100%) rename {azure => aci}/login/tokenStore.go (100%) rename {azure => aci}/login/tokenStore_test.go (100%) rename {azure => aci}/resourcegroup.go (99%) delete mode 100644 amazon/doc.go rename cli/cmd/context/{createaci.go => create_aci.go} (91%) rename cli/cmd/context/{createecs.go => create_ecs.go} (89%) create mode 100644 cli/mobycli/delegate_ecs.go rename {amazon => ecs}/backend.go (93%) rename {amazon => ecs}/context.go (99%) create mode 100644 ecs/doc.go diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..ac2097b07 --- /dev/null +++ b/.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"] + } + ] +} \ No newline at end of file diff --git a/azure/aci.go b/aci/aci.go similarity index 99% rename from azure/aci.go rename to aci/aci.go index d488b0edb..eca480a6a 100644 --- a/azure/aci.go +++ b/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" diff --git a/azure/aci_test.go b/aci/aci_test.go similarity index 94% rename from azure/aci_test.go rename to aci/aci_test.go index 4af8cf5a2..c9976e468 100644 --- a/azure/aci_test.go +++ b/aci/aci_test.go @@ -1,4 +1,4 @@ -package azure +package aci import ( "testing" diff --git a/azure/backend.go b/aci/backend.go similarity index 98% rename from azure/backend.go rename to aci/backend.go index a1e541b32..abd8956bf 100644 --- a/azure/backend.go +++ b/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) { diff --git a/azure/backend_test.go b/aci/backend_test.go similarity index 99% rename from azure/backend_test.go rename to aci/backend_test.go index 022eac56c..5b95ce7df 100644 --- a/azure/backend_test.go +++ b/aci/backend_test.go @@ -14,7 +14,7 @@ limitations under the License. */ -package azure +package aci import ( "context" diff --git a/azure/context.go b/aci/context.go similarity index 99% rename from azure/context.go rename to aci/context.go index b723bf842..f3923a096 100644 --- a/azure/context.go +++ b/aci/context.go @@ -14,7 +14,7 @@ limitations under the License. */ -package azure +package aci import ( "context" diff --git a/azure/context_test.go b/aci/context_test.go similarity index 99% rename from azure/context_test.go rename to aci/context_test.go index 486bb9445..7da6f876b 100644 --- a/azure/context_test.go +++ b/aci/context_test.go @@ -14,7 +14,7 @@ limitations under the License. */ -package azure +package aci import ( "context" diff --git a/azure/convert/container.go b/aci/convert/container.go similarity index 100% rename from azure/convert/container.go rename to aci/convert/container.go diff --git a/azure/convert/container_test.go b/aci/convert/container_test.go similarity index 100% rename from azure/convert/container_test.go rename to aci/convert/container_test.go diff --git a/azure/convert/convert.go b/aci/convert/convert.go similarity index 100% rename from azure/convert/convert.go rename to aci/convert/convert.go diff --git a/azure/convert/convert_test.go b/aci/convert/convert_test.go similarity index 100% rename from azure/convert/convert_test.go rename to aci/convert/convert_test.go diff --git a/azure/convert/ports.go b/aci/convert/ports.go similarity index 100% rename from azure/convert/ports.go rename to aci/convert/ports.go diff --git a/azure/convert/ports_test.go b/aci/convert/ports_test.go similarity index 100% rename from azure/convert/ports_test.go rename to aci/convert/ports_test.go diff --git a/azure/convert/registrycredentials.go b/aci/convert/registrycredentials.go similarity index 100% rename from azure/convert/registrycredentials.go rename to aci/convert/registrycredentials.go diff --git a/azure/convert/registrycredentials_test.go b/aci/convert/registrycredentials_test.go similarity index 100% rename from azure/convert/registrycredentials_test.go rename to aci/convert/registrycredentials_test.go diff --git a/azure/convert/volume.go b/aci/convert/volume.go similarity index 100% rename from azure/convert/volume.go rename to aci/convert/volume.go diff --git a/azure/convert/volume_test.go b/aci/convert/volume_test.go similarity index 100% rename from azure/convert/volume_test.go rename to aci/convert/volume_test.go diff --git a/azure/login/local_server.go b/aci/login/local_server.go similarity index 100% rename from azure/login/local_server.go rename to aci/login/local_server.go diff --git a/azure/login/login.go b/aci/login/login.go similarity index 100% rename from azure/login/login.go rename to aci/login/login.go diff --git a/azure/login/loginHelper.go b/aci/login/loginHelper.go similarity index 100% rename from azure/login/loginHelper.go rename to aci/login/loginHelper.go diff --git a/azure/login/login_test.go b/aci/login/login_test.go similarity index 100% rename from azure/login/login_test.go rename to aci/login/login_test.go diff --git a/azure/login/tokenStore.go b/aci/login/tokenStore.go similarity index 100% rename from azure/login/tokenStore.go rename to aci/login/tokenStore.go diff --git a/azure/login/tokenStore_test.go b/aci/login/tokenStore_test.go similarity index 100% rename from azure/login/tokenStore_test.go rename to aci/login/tokenStore_test.go diff --git a/azure/resourcegroup.go b/aci/resourcegroup.go similarity index 99% rename from azure/resourcegroup.go rename to aci/resourcegroup.go index dc1b64ebd..91a82ba89 100644 --- a/azure/resourcegroup.go +++ b/aci/resourcegroup.go @@ -14,7 +14,7 @@ limitations under the License. */ -package azure +package aci import ( "context" diff --git a/amazon/doc.go b/amazon/doc.go deleted file mode 100644 index 1f74174fe..000000000 --- a/amazon/doc.go +++ /dev/null @@ -1 +0,0 @@ -package amazon diff --git a/cli/cmd/context/create.go b/cli/cmd/context/create.go index 42520bc04..802a8a732 100644 --- a/cli/cmd/context/create.go +++ b/cli/cmd/context/create.go @@ -76,7 +76,6 @@ $ docker context create my-context --description "some description" --docker "ho } cmd.AddCommand( - createAciCommand(), createLocalCommand(), createExampleCommand(), ) diff --git a/cli/cmd/context/createaci.go b/cli/cmd/context/create_aci.go similarity index 91% rename from cli/cmd/context/createaci.go rename to cli/cmd/context/create_aci.go index 9a889e836..a2cba9610 100644 --- a/cli/cmd/context/createaci.go +++ b/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") diff --git a/cli/cmd/context/createecs.go b/cli/cmd/context/create_ecs.go similarity index 89% rename from cli/cmd/context/createecs.go rename to cli/cmd/context/create_ecs.go index f0a154fff..b26aeea21 100644 --- a/cli/cmd/context/createecs.go +++ b/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") diff --git a/cli/cmd/login/azurelogin.go b/cli/cmd/login/azurelogin.go index 363b6cbf4..4d80413c2 100644 --- a/cli/cmd/login/azurelogin.go +++ b/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", diff --git a/cli/main.go b/cli/main.go index 85efdf745..0645a7c8c 100644 --- a/cli/main.go +++ b/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" diff --git a/cli/mobycli/delegate_ecs.go b/cli/mobycli/delegate_ecs.go new file mode 100644 index 000000000..dccc7e095 --- /dev/null +++ b/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) +} diff --git a/cli/mobycli/exec.go b/cli/mobycli/exec.go index 0e2be5b89..bbb6c4ea1 100644 --- a/cli/mobycli/exec.go +++ b/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 diff --git a/context/store/contextmetadata.go b/context/store/contextmetadata.go index 54c9baf3e..b6138e583 100644 --- a/context/store/contextmetadata.go +++ b/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{} diff --git a/context/store/store.go b/context/store/store.go index 7ffad198c..15ce3ef0c 100644 --- a/context/store/store.go +++ b/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 diff --git a/amazon/backend.go b/ecs/backend.go similarity index 93% rename from amazon/backend.go rename to ecs/backend.go index b7234144f..6fe5d187e 100644 --- a/amazon/backend.go +++ b/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 { diff --git a/amazon/context.go b/ecs/context.go similarity index 99% rename from amazon/context.go rename to ecs/context.go index 0432eed96..de7a34153 100644 --- a/amazon/context.go +++ b/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 { diff --git a/ecs/doc.go b/ecs/doc.go new file mode 100644 index 000000000..2ea49a880 --- /dev/null +++ b/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 diff --git a/prompt/prompt.go b/prompt/prompt.go index dc2bb6899..34623b933 100644 --- a/prompt/prompt.go +++ b/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 ( diff --git a/tests/aci-e2e/e2e-aci_test.go b/tests/aci-e2e/e2e-aci_test.go index d1d2faffa..67e71badd 100644 --- a/tests/aci-e2e/e2e-aci_test.go +++ b/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" diff --git a/tests/aci-e2e/storage/storage.go b/tests/aci-e2e/storage/storage.go index ed1fd0ceb..bf5b803c9 100644 --- a/tests/aci-e2e/storage/storage.go +++ b/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" )