MCPcopy
hub / github.com/slimtoolkit/slim / New

Function New

pkg/docker/dockerclient/client.go:134–265  ·  view source on GitHub ↗

New creates a new Docker client instance

(config *config.DockerClient)

Source from the content-addressed store, hash-verified

132
133// New creates a new Docker client instance
134func New(config *config.DockerClient) (*docker.Client, error) {
135 var client *docker.Client
136 var err error
137
138 newTLSClient := func(host string, certPath string, verify bool, apiVersion string) (*docker.Client, error) {
139 var ca []byte
140
141 cert, err := os.ReadFile(filepath.Join(certPath, "cert.pem"))
142 if err != nil {
143 return nil, err
144 }
145
146 key, err := os.ReadFile(filepath.Join(certPath, "key.pem"))
147 if err != nil {
148 return nil, err
149 }
150
151 if verify {
152 var err error
153 ca, err = os.ReadFile(filepath.Join(certPath, "ca.pem"))
154 if err != nil {
155 return nil, err
156 }
157 }
158
159 return docker.NewVersionedTLSClientFromBytes(host, cert, key, ca, apiVersion)
160 }
161
162 switch {
163 case config.Host != "" &&
164 config.UseTLS &&
165 config.VerifyTLS &&
166 config.TLSCertPath != "":
167 client, err = newTLSClient(config.Host, config.TLSCertPath, true, config.APIVersion)
168 if err != nil {
169 return nil, err
170 }
171
172 log.Debug("dockerclient.New: new Docker client (TLS,verify) [1]")
173
174 case config.Host != "" &&
175 config.UseTLS &&
176 !config.VerifyTLS &&
177 config.TLSCertPath != "":
178 client, err = newTLSClient(config.Host, config.TLSCertPath, false, config.APIVersion)
179 if err != nil {
180 return nil, err
181 }
182
183 log.Debug("dockerclient.New: new Docker client (TLS,no verify) [2]")
184
185 case config.Host != "" &&
186 !config.UseTLS:
187 client, err = docker.NewVersionedClient(config.Host, config.APIVersion)
188 if err != nil {
189 return nil, err
190 }
191

Callers 15

NewInteractiveAppFunction · 0.92
OnPushCommandFunction · 0.92
OnPullCommandFunction · 0.92
OnCopyCommandFunction · 0.92
OnCommandFunction · 0.92
OnCommandFunction · 0.92
OnCommandFunction · 0.92
OnCommandFunction · 0.92
OnCommandFunction · 0.92
OnCommandFunction · 0.92
OnCommandFunction · 0.92

Calls 2

WarnOnFunction · 0.92
GetUnixSocketAddrFunction · 0.85

Tested by

no test coverage detected