forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
49 lines (40 loc) · 1.24 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package docker
import (
"fmt"
"path/filepath"
dc "github.com/fsouza/go-dockerclient"
)
// Config is the structure that stores the configuration to talk to a
// Docker API compatible host.
type Config struct {
Host string
Ca string
Cert string
Key string
CertPath string
}
// NewClient() returns a new Docker client.
func (c *Config) NewClient() (*dc.Client, error) {
if c.Ca != "" || c.Cert != "" || c.Key != "" {
if c.Ca == "" || c.Cert == "" || c.Key == "" {
return nil, fmt.Errorf("ca_material, cert_material, and key_material must be specified")
}
if c.CertPath != "" {
return nil, fmt.Errorf("cert_path must not be specified")
}
return dc.NewTLSClientFromBytes(c.Host, []byte(c.Cert), []byte(c.Key), []byte(c.Ca))
}
if c.CertPath != "" {
// If there is cert information, load it and use it.
ca := filepath.Join(c.CertPath, "ca.pem")
cert := filepath.Join(c.CertPath, "cert.pem")
key := filepath.Join(c.CertPath, "key.pem")
return dc.NewTLSClient(c.Host, cert, key, ca)
}
// If there is no cert information, then just return the direct client
return dc.NewClient(c.Host)
}
// Data ia structure for holding data that we fetch from Docker.
type Data struct {
DockerImages map[string]*dc.APIImages
}