func providerConfigure(d *schema.ResourceData) (interface{}, error) { remote := d.Get("remote").(string) scheme := d.Get("scheme").(string) daemon_addr := "" switch scheme { case "unix": daemon_addr = fmt.Sprintf("unix:%s", d.Get("address")) case "https": daemon_addr = fmt.Sprintf("https://%s:%s", d.Get("address"), d.Get("port")) default: err := fmt.Errorf("Invalid scheme: %s", scheme) return nil, err } // build LXD config config := lxd.Config{ ConfigDir: os.ExpandEnv("$HOME/.config/lxc"), Remotes: make(map[string]lxd.RemoteConfig), } config.Remotes[remote] = lxd.RemoteConfig{Addr: daemon_addr} log.Printf("[DEBUG] LXD Config: %#v", config) if scheme == "https" { // validate certifictes exist certf := config.ConfigPath("client.crt") keyf := config.ConfigPath("client.key") if !shared.PathExists(certf) || !shared.PathExists(keyf) { err := fmt.Errorf("Certificate or key not found:\n\t%s\n\t%s", certf, keyf) return nil, err } serverCertf := config.ServerCertPath(remote) if !shared.PathExists(serverCertf) { err := fmt.Errorf("Server certificate not found:\n\t%s", serverCertf) return nil, err } } client, err := lxd.NewClient(&config, remote) if err != nil { err := fmt.Errorf("Could not create LXD client: %s", err) return nil, err } log.Printf("[DEBUG] LXD Client: %#v", client) if err := validateClient(client); err != nil { return nil, err } lxdProv := LxdProvider{ Remote: remote, Client: client, } return &lxdProv, nil }
func (c *remoteCmd) removeCertificate(config *lxd.Config, remote string) { certf := config.ServerCertPath(remote) shared.Debugf("Trying to remove %s", certf) os.Remove(certf) }