Skip to content

Commit

Permalink
Safely get global ddev directory, fixes #806 (#878)
Browse files Browse the repository at this point in the history
* Use GetGlobalDdevDir to ensure ~/.ddev exists before operating on it, fixes #806.

* Replace gohomedir.Dir() with GetGlobalDdevDir() in providerPantheon.go

* Run goimports and gofmt
  • Loading branch information
andrewfrench committed May 23, 2018
1 parent 2fb3001 commit 5b442e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
9 changes: 4 additions & 5 deletions cmd/ddev/cmd/auth_pantheon.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/drud/ddev/pkg/util"
"github.com/drud/go-pantheon/pkg/pantheon"
gohomedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
)

Expand All @@ -22,12 +21,12 @@ var PantheonAuthCommand = &cobra.Command{
if len(args) != 1 {
util.Failed("Too many arguments detected. Please provide only your Pantheon Machine token., e.g. 'ddev auth-pantheon [token]'. See https://pantheon.io/docs/machine-tokens/ for instructions on creating a token.")
}
userDir, err := gohomedir.Dir()
util.CheckErr(err)
sessionLocation := filepath.Join(userDir, ".ddev", "pantheonconfig.json")

ddevDir := util.GetGlobalDdevDir()
sessionLocation := filepath.Join(ddevDir, "pantheonconfig.json")

session := pantheon.NewAuthSession(args[0])
err = session.Auth()
err := session.Auth()
if err != nil {
util.Failed("Could not authenticate with pantheon: %v", err)
}
Expand Down
18 changes: 8 additions & 10 deletions pkg/ddevapp/providerPantheon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import (
"path/filepath"
"strings"

"fmt"

"github.com/drud/ddev/pkg/fileutil"
"github.com/drud/ddev/pkg/output"
"github.com/drud/ddev/pkg/util"
gohomedir "github.com/mitchellh/go-homedir"

"fmt"

"github.com/drud/go-pantheon/pkg/pantheon"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -133,9 +132,9 @@ func (p *PantheonProvider) prepDownloadDir() {
}

func (p *PantheonProvider) getDownloadDir() string {
userDir, err := gohomedir.Dir()
util.CheckErr(err)
destDir := filepath.Join(userDir, ".ddev", "pantheon", p.app.Name)
ddevDir := util.GetGlobalDdevDir()
destDir := filepath.Join(ddevDir, "pantheon", p.app.Name)

return destDir
}

Expand Down Expand Up @@ -304,15 +303,14 @@ func findPantheonSite(name string) (pantheon.Site, error) {

// getPantheonSession loads the pantheon API config from disk and returns a pantheon session struct.
func getPantheonSession() *pantheon.AuthSession {
userDir, err := gohomedir.Dir()
util.CheckErr(err)
sessionLocation := filepath.Join(userDir, ".ddev", "pantheonconfig.json")
ddevDir := util.GetGlobalDdevDir()
sessionLocation := filepath.Join(ddevDir, "pantheonconfig.json")

// Generate a session object based on the DDEV_PANTHEON_API_TOKEN environment var.
session := &pantheon.AuthSession{}

// Read a previously saved session.
err = session.Read(sessionLocation)
err := session.Read(sessionLocation)

if err != nil {
// If we can't read a previous session fall back to using the API token.
Expand Down

0 comments on commit 5b442e6

Please sign in to comment.