2015-02-17 17:28:33 +01:00
|
|
|
package docker
|
|
|
|
|
2015-03-27 23:18:52 +01:00
|
|
|
import (
|
2016-11-22 13:18:09 +01:00
|
|
|
"fmt"
|
2015-03-27 23:18:52 +01:00
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
dc "github.com/fsouza/go-dockerclient"
|
|
|
|
)
|
2015-02-17 17:28:33 +01:00
|
|
|
|
2015-03-29 03:37:20 +02:00
|
|
|
// Config is the structure that stores the configuration to talk to a
|
|
|
|
// Docker API compatible host.
|
2015-02-17 17:28:33 +01:00
|
|
|
type Config struct {
|
2015-03-27 23:18:52 +01:00
|
|
|
Host string
|
2016-11-22 13:18:09 +01:00
|
|
|
Ca string
|
|
|
|
Cert string
|
|
|
|
Key string
|
2015-03-27 23:18:52 +01:00
|
|
|
CertPath string
|
2015-02-17 17:28:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewClient() returns a new Docker client.
|
|
|
|
func (c *Config) NewClient() (*dc.Client, error) {
|
2016-11-22 13:18:09 +01:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2016-12-17 13:41:08 +01:00
|
|
|
if c.CertPath != "" {
|
|
|
|
return nil, fmt.Errorf("cert_path must not be specified")
|
|
|
|
}
|
|
|
|
|
2016-11-22 13:18:09 +01:00
|
|
|
return dc.NewTLSClientFromBytes(c.Host, []byte(c.Cert), []byte(c.Key), []byte(c.Ca))
|
2015-03-27 23:18:52 +01:00
|
|
|
}
|
|
|
|
|
2016-11-22 13:18:09 +01:00
|
|
|
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)
|
2015-02-17 17:28:33 +01:00
|
|
|
}
|
|
|
|
|
2015-03-29 03:37:20 +02:00
|
|
|
// Data ia structure for holding data that we fetch from Docker.
|
|
|
|
type Data struct {
|
|
|
|
DockerImages map[string]*dc.APIImages
|
2015-02-17 17:28:33 +01:00
|
|
|
}
|