(contextStore store.ReaderWriter, name string, opts createOptions)
| 84 | } |
| 85 | |
| 86 | func createNewContext(contextStore store.ReaderWriter, name string, opts createOptions) error { |
| 87 | if opts.endpoint == nil { |
| 88 | return errors.New("docker endpoint configuration is required") |
| 89 | } |
| 90 | dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(contextStore, opts.endpoint) |
| 91 | if err != nil { |
| 92 | return fmt.Errorf("unable to create docker endpoint config: %w", err) |
| 93 | } |
| 94 | contextMetadata := store.Metadata{ |
| 95 | Endpoints: map[string]any{ |
| 96 | docker.DockerEndpoint: dockerEP, |
| 97 | }, |
| 98 | Metadata: command.DockerContext{ |
| 99 | Description: opts.description, |
| 100 | AdditionalFields: opts.metaData, |
| 101 | }, |
| 102 | Name: name, |
| 103 | } |
| 104 | contextTLSData := store.ContextTLSData{} |
| 105 | if dockerTLS != nil { |
| 106 | contextTLSData.Endpoints = map[string]store.EndpointTLSData{ |
| 107 | docker.DockerEndpoint: *dockerTLS, |
| 108 | } |
| 109 | } |
| 110 | if err := validateEndpoints(contextMetadata); err != nil { |
| 111 | return err |
| 112 | } |
| 113 | if err := contextStore.CreateOrUpdate(contextMetadata); err != nil { |
| 114 | return err |
| 115 | } |
| 116 | return contextStore.ResetTLSMaterial(name, &contextTLSData) |
| 117 | } |
| 118 | |
| 119 | func checkContextNameForCreation(s store.Reader, name string) error { |
| 120 | if err := store.ValidateContextName(name); err != nil { |
no test coverage detected
searching dependent graphs…