github.com/aspring/terraform@v0.8.2-0.20161216122603-6a8619a5db2e/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  		return dc.NewTLSClientFromBytes(c.Host, []byte(c.Cert), []byte(c.Key), []byte(c.Ca))
    28  	}
    29  
    30  	if c.CertPath != "" {
    31  		// If there is cert information, load it and use it.
    32  		ca := filepath.Join(c.CertPath, "ca.pem")
    33  		cert := filepath.Join(c.CertPath, "cert.pem")
    34  		key := filepath.Join(c.CertPath, "key.pem")
    35  		return dc.NewTLSClient(c.Host, cert, key, ca)
    36  	}
    37  
    38  	// If there is no cert information, then just return the direct client
    39  	return dc.NewClient(c.Host)
    40  }
    41  
    42  // Data ia structure for holding data that we fetch from Docker.
    43  type Data struct {
    44  	DockerImages map[string]*dc.APIImages
    45  }