runUpdate updates a Docker context.
(dockerCLI command.Cli, name string, opts updateOptions)
| 52 | |
| 53 | // runUpdate updates a Docker context. |
| 54 | func runUpdate(dockerCLI command.Cli, name string, opts updateOptions) error { |
| 55 | if err := store.ValidateContextName(name); err != nil { |
| 56 | return err |
| 57 | } |
| 58 | s := dockerCLI.ContextStore() |
| 59 | c, err := s.GetMetadata(name) |
| 60 | if err != nil { |
| 61 | return err |
| 62 | } |
| 63 | dockerContext, err := command.GetDockerContext(c) |
| 64 | if err != nil { |
| 65 | return err |
| 66 | } |
| 67 | if opts.description != "" { |
| 68 | dockerContext.Description = opts.description |
| 69 | } |
| 70 | |
| 71 | c.Metadata = dockerContext |
| 72 | |
| 73 | tlsDataToReset := make(map[string]*store.EndpointTLSData) |
| 74 | |
| 75 | if opts.endpoint != nil { |
| 76 | dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(s, opts.endpoint) |
| 77 | if err != nil { |
| 78 | return fmt.Errorf("unable to create docker endpoint config: %w", err) |
| 79 | } |
| 80 | c.Endpoints[docker.DockerEndpoint] = dockerEP |
| 81 | tlsDataToReset[docker.DockerEndpoint] = dockerTLS |
| 82 | } |
| 83 | if err := validateEndpoints(c); err != nil { |
| 84 | return err |
| 85 | } |
| 86 | if err := s.CreateOrUpdate(c); err != nil { |
| 87 | return err |
| 88 | } |
| 89 | for ep, tlsData := range tlsDataToReset { |
| 90 | if err := s.ResetEndpointTLSMaterial(name, ep, tlsData); err != nil { |
| 91 | return err |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | _, _ = fmt.Fprintln(dockerCLI.Out(), name) |
| 96 | _, _ = fmt.Fprintf(dockerCLI.Err(), "Successfully updated context %q\n", name) |
| 97 | return nil |
| 98 | } |
| 99 | |
| 100 | func validateEndpoints(c store.Metadata) error { |
| 101 | _, err := command.GetDockerContext(c) |
searching dependent graphs…