github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/docker/config.go (about)

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