MCPcopy Index your code
hub / github.com/docker/cli / createNewContext

Function createNewContext

cli/command/context/create.go:86–117  ·  view source on GitHub ↗
(contextStore store.ReaderWriter, name string, opts createOptions)

Source from the content-addressed store, hash-verified

84}
85
86func 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
119func checkContextNameForCreation(s store.Reader, name string) error {
120 if err := store.ValidateContextName(name); err != nil {

Callers 1

runCreateFunction · 0.85

Calls 4

validateEndpointsFunction · 0.85
CreateOrUpdateMethod · 0.65
ResetTLSMaterialMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…