mirror of
https://github.com/docker/compose.git
synced 2025-07-25 14:44:29 +02:00
Merge pull request #259 from docker/aci_group_pagination
Aci context create & group pagination
This commit is contained in:
commit
5e630eb63d
@ -65,6 +65,16 @@ func (mgt aciResourceGroupHelperImpl) ListGroups(ctx context.Context, subscripti
|
|||||||
}
|
}
|
||||||
|
|
||||||
groups := groupResponse.Values()
|
groups := groupResponse.Values()
|
||||||
|
|
||||||
|
for groupResponse.NotDone() {
|
||||||
|
err = groupResponse.NextWithContext(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
newValues := groupResponse.Values()
|
||||||
|
groups = append(groups, newValues...)
|
||||||
|
}
|
||||||
|
|
||||||
return groups, nil
|
return groups, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,6 +130,11 @@ func createDockerContext(ctx context.Context, name string, contextType string, d
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func contextExists(ctx context.Context, name string) bool {
|
||||||
|
s := store.ContextStore(ctx)
|
||||||
|
return s.ContextExists(name)
|
||||||
|
}
|
||||||
|
|
||||||
func addDescriptionFlag(cmd *cobra.Command, descriptionOpt *string) {
|
func addDescriptionFlag(cmd *cobra.Command, descriptionOpt *string) {
|
||||||
cmd.Flags().StringVar(descriptionOpt, "description", "", "Description of the context")
|
cmd.Flags().StringVar(descriptionOpt, "description", "", "Description of the context")
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
|
|
||||||
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
type aciCreateOpts struct {
|
type aciCreateOpts struct {
|
||||||
@ -40,11 +41,7 @@ func createAciCommand() *cobra.Command {
|
|||||||
Short: "Create a context for Azure Container Instances",
|
Short: "Create a context for Azure Container Instances",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
contextData, description, err := getAciContextData(cmd.Context(), opts)
|
return runCreateAci(cmd.Context(), args[0], opts)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return createDockerContext(cmd.Context(), args[0], store.AciContextType, description, contextData)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +53,18 @@ func createAciCommand() *cobra.Command {
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runCreateAci(ctx context.Context, contextName string, opts aciCreateOpts) error {
|
||||||
|
if contextExists(ctx, contextName) {
|
||||||
|
return errors.Wrapf(errdefs.ErrAlreadyExists, "context %s", contextName)
|
||||||
|
}
|
||||||
|
contextData, description, err := getAciContextData(ctx, opts)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return createDockerContext(ctx, contextName, store.AciContextType, description, contextData)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func getAciContextData(ctx context.Context, opts aciCreateOpts) (interface{}, string, error) {
|
func getAciContextData(ctx context.Context, opts aciCreateOpts) (interface{}, string, error) {
|
||||||
cs, err := client.GetCloudService(ctx, store.AciContextType)
|
cs, err := client.GetCloudService(ctx, store.AciContextType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -83,6 +83,8 @@ type Store interface {
|
|||||||
List() ([]*DockerContext, error)
|
List() ([]*DockerContext, error)
|
||||||
// Remove removes a context by name from the context store
|
// Remove removes a context by name from the context store
|
||||||
Remove(name string) error
|
Remove(name string) error
|
||||||
|
// ContextExists checks if a context already exists
|
||||||
|
ContextExists(name string) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Endpoint holds the Docker or the Kubernetes endpoint, they both have the
|
// Endpoint holds the Docker or the Kubernetes endpoint, they both have the
|
||||||
@ -218,15 +220,24 @@ func toTypedEndpoints(endpoints map[string]interface{}) (map[string]interface{},
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *store) Create(name string, contextType string, description string, data interface{}) error {
|
func (s *store) ContextExists(name string) bool {
|
||||||
if name == DefaultContextName {
|
if name == DefaultContextName {
|
||||||
return errors.Wrap(errdefs.ErrAlreadyExists, objectName(name))
|
return true
|
||||||
}
|
}
|
||||||
dir := contextDirOf(name)
|
dir := contextDirOf(name)
|
||||||
metaDir := filepath.Join(s.root, contextsDir, metadataDir, dir)
|
metaDir := filepath.Join(s.root, contextsDir, metadataDir, dir)
|
||||||
if _, err := os.Stat(metaDir); !os.IsNotExist(err) {
|
if _, err := os.Stat(metaDir); !os.IsNotExist(err) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *store) Create(name string, contextType string, description string, data interface{}) error {
|
||||||
|
if s.ContextExists(name) {
|
||||||
return errors.Wrap(errdefs.ErrAlreadyExists, objectName(name))
|
return errors.Wrap(errdefs.ErrAlreadyExists, objectName(name))
|
||||||
}
|
}
|
||||||
|
dir := contextDirOf(name)
|
||||||
|
metaDir := filepath.Join(s.root, contextsDir, metadataDir, dir)
|
||||||
|
|
||||||
err := os.Mkdir(metaDir, 0755)
|
err := os.Mkdir(metaDir, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -103,6 +103,12 @@ func (s *E2eSuite) TestCanForceRemoveCurrentContext() {
|
|||||||
Expect(out).To(ContainSubstring("default *"))
|
Expect(out).To(ContainSubstring("default *"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *E2eSuite) TestContextCreateAciChecksContextNameBeforeInteractivePart() {
|
||||||
|
s.NewDockerCommand("context", "create", "mycontext", "--from", "default").ExecOrDie()
|
||||||
|
_, err := s.NewDockerCommand("context", "create", "aci", "mycontext").Exec()
|
||||||
|
Expect(err.Error()).To(ContainSubstring("context mycontext: already exists"))
|
||||||
|
}
|
||||||
|
|
||||||
func (s *E2eSuite) TestClassicLoginWithparameters() {
|
func (s *E2eSuite) TestClassicLoginWithparameters() {
|
||||||
output, err := s.NewDockerCommand("login", "-u", "nouser", "-p", "wrongpasword").Exec()
|
output, err := s.NewDockerCommand("login", "-u", "nouser", "-p", "wrongpasword").Exec()
|
||||||
Expect(output).To(ContainSubstring("Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password"))
|
Expect(output).To(ContainSubstring("Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user