Exemplo n.º 1
0
func NodeCreateCmd(c *cli.Context, client drone.Client) error {
	node := drone.Node{
		Addr: c.String("docker-host"),
		Arch: "linux_amd64",
	}

	cert, _ := ioutil.ReadFile(filepath.Join(
		c.String("docker-cert-path"),
		"cert.pem",
	))

	key, _ := ioutil.ReadFile(filepath.Join(
		c.String("docker-cert-path"),
		"key.pem",
	))

	ca, _ := ioutil.ReadFile(filepath.Join(
		c.String("docker-cert-path"),
		"ca.pem",
	))

	if len(cert) == 0 || len(key) == 0 {
		return fmt.Errorf("Error reading cert.pem or key.pem from %s",
			c.String("docker-cert-path"))
	}

	node.Cert = string(cert)
	node.Key = string(key)

	// only use the certificate authority if tls verify
	// is enabled for this docker host.
	if c.Bool("docker-tls-verify") {
		node.CA = string(ca)
	}

	_, err := client.NodePost(&node)
	if err != nil {
		return err
	}

	fmt.Printf("Successfully added %s\n", node.Addr)
	return nil
}