MCPcopy Create free account
hub / github.com/buildpacks/pack / tryInitSSHDockerClient

Function tryInitSSHDockerClient

cmd/docker_init.go:22–58  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20)
21
22func tryInitSSHDockerClient() (*dockerClient.Client, error) {
23 dockerHost := os.Getenv("DOCKER_HOST")
24 _url, err := url.Parse(dockerHost)
25 isSSH := err == nil && _url.Scheme == "ssh"
26
27 if !isSSH {
28 return nil, nil
29 }
30
31 credentialsConfig := sshdialer.Config{
32 Identity: os.Getenv("DOCKER_HOST_SSH_IDENTITY"),
33 PassPhrase: os.Getenv("DOCKER_HOST_SSH_IDENTITY_PASSPHRASE"),
34 PasswordCallback: newReadSecretCbk("please enter password:"),
35 PassPhraseCallback: newReadSecretCbk("please enter passphrase to private key:"),
36 HostKeyCallback: newHostKeyCbk(),
37 }
38 dialContext, err := sshdialer.NewDialContext(_url, credentialsConfig)
39 if err != nil {
40 return nil, err
41 }
42
43 httpClient := &http.Client{
44 // No tls
45 // No proxy
46 Transport: &http.Transport{
47 DialContext: dialContext,
48 },
49 }
50
51 dockerClientOpts := []dockerClient.Opt{
52 dockerClient.WithHTTPClient(httpClient),
53 dockerClient.WithHost("http://dummy"),
54 dockerClient.WithDialContext(dialContext),
55 }
56
57 return dockerClient.New(dockerClientOpts...)
58}
59
60// readSecret prompts for a secret and returns value input by user from stdin
61// Unlike terminal.ReadPassword(), $(echo $SECRET | podman...) is supported.

Callers 1

initClientFunction · 0.85

Calls 3

NewDialContextFunction · 0.92
newReadSecretCbkFunction · 0.85
newHostKeyCbkFunction · 0.85

Tested by

no test coverage detected