Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"errors"
"net/url"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -196,7 +195,7 @@ func apiToken() string {
return key
}
netrc := getNetrc()
machine := netrc.FindMachine(herokuAPIHost())
machine := netrc.FindMachine(apiHost())
if machine != nil {
return machine.Password
}
Expand Down Expand Up @@ -238,24 +237,3 @@ func (cli *Cli) AddCommand(command *Command) bool {
cli.Commands = append(cli.Commands, command)
return true
}

func herokuAPIHost() string {
env := os.Getenv("HEROKU_API_URL")
if env == "" {
return "api.heroku.com"
}
apiURL, err := url.Parse(env)
ExitIfError(err)
return apiURL.Host
}

func herokuGitHost() string {
if herokuAPIHost() == "api.heroku.com" {
return "git.heroku.com"
}
return "git." + herokuAPIHost()
}

func shouldVerifyHost() bool {
return !strings.HasSuffix(herokuAPIHost(), "herokudev.com")
}
27 changes: 21 additions & 6 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,37 @@ import (
"syscall"
)

func host() string {
if host := os.Getenv("HEROKU_HOST"); host != "" {
return host
}
return "heroku.com"
}

func apiHost() string {
return "api." + host()
}

func gitHost() string {
if herokuGitHost := os.Getenv("HEROKU_GIT_HOST"); herokuGitHost != "" {
return herokuGitHost
if host := os.Getenv("HEROKU_GIT_HOST"); host != "" {
return host
}
if herokuHost := os.Getenv("HEROKU_HOST"); herokuHost != "" {
return herokuHost
return host()
}

func httpGitHost() string {
if host := os.Getenv("HEROKU_HTTP_GIT_HOST"); host != "" {
return host
}
return "heroku.com"
return "git." + host()
}

func gitURLPre() string {
return "git@" + gitHost() + ":"
}

func gitHTTPSURLPre() string {
return "https://git.heroku.com/"
return "https://" + httpGitHost() + "/"
}

func gitRemotes() (map[string]string, error) {
Expand Down
6 changes: 4 additions & 2 deletions login.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ func login() {

func saveOauthToken(email, token string) {
netrc := getNetrc()
netrc.RemoveMachine(apiHost())
netrc.RemoveMachine(httpGitHost())
netrc.Filename = netrcPath()
netrc.NewMachine(herokuAPIHost(), email, token, "")
netrc.NewMachine(herokuGitHost(), email, token, "")
netrc.NewMachine(apiHost(), email, token, "")
netrc.NewMachine(httpGitHost(), email, token, "")
ExitIfError(netrc.Save())
}

Expand Down
14 changes: 11 additions & 3 deletions request.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package main

import "github.com/franela/goreq"
import (
"strings"

"github.com/franela/goreq"
)

func apiRequest(authToken string) *goreq.Request {
req := goreq.Request{
Uri: "https://" + herokuAPIHost(),
Uri: "https://" + apiHost(),
Accept: "application/vnd.heroku+json; version=3",
ShowDebug: debugging,
Insecure: !shouldVerifyHost(),
Insecure: !shouldVerifyHost(apiHost()),
}
if authToken != "" {
req.AddHeader("Authorization", "Bearer "+authToken)
}
return &req
}

func shouldVerifyHost(host string) bool {
return !strings.HasSuffix(host, "herokudev.com")
}