diff --git a/cmd/preferences/setpref.go b/cmd/preferences/setpref.go index d2e4e1826..9c6a63fdd 100644 --- a/cmd/preferences/setpref.go +++ b/cmd/preferences/setpref.go @@ -34,6 +34,10 @@ var SetCmd = &cobra.Command{ return err } + if err = apiclient.SetGithubURL(gitHubURL); err != nil { + return err + } + if nocheck { if err = apiclient.SetNoCheck(nocheck); err != nil { return err @@ -45,8 +49,8 @@ var SetCmd = &cobra.Command{ } var ( - org, proxyURL string - usestage, nocheck bool + org, proxyURL, gitHubURL string + usestage, nocheck bool ) func init() { @@ -61,4 +65,7 @@ func init() { SetCmd.Flags().BoolVarP(&nocheck, "nocheck", "", false, "Don't check for newer versions of cmd") + + SetCmd.Flags().StringVarP(&gitHubURL, "github", "g", + "", "On premises Github URL") } diff --git a/internal/apiclient/clifile.go b/internal/apiclient/clifile.go index c1680d4ee..669e02588 100644 --- a/internal/apiclient/clifile.go +++ b/internal/apiclient/clifile.go @@ -36,7 +36,8 @@ type apigeeCLI struct { LastCheck string `json:"lastCheck,omitempty"` Org string `json:"defaultOrg,omitempty"` Staging bool `json:"staging,omitempty"` - ProxyUrl string `json:"proxyUrl,omitempty"` + ProxyURL string `json:"proxyUrl,omitempty"` + GithubURL string `json:"githubURL,omitempty"` Nocheck bool `json:"nocheck,omitempty" default:"false"` } @@ -69,8 +70,12 @@ func ReadPreferencesFile() (err error) { UseStaging() } - if cliPref.ProxyUrl != "" { - SetProxyURL(cliPref.ProxyUrl) + if cliPref.ProxyURL != "" { + SetProxyURL(cliPref.ProxyURL) + } + + if cliPref.GithubURL != "" { + SetGithubURL(cliPref.GithubURL) } if cliPref.Org != "" { @@ -195,7 +200,7 @@ func SetProxy(url string) (err error) { return nil } - cliPref.ProxyUrl = url + cliPref.ProxyURL = url data, err := json.Marshal(&cliPref) if err != nil { clilog.Debug.Printf("Error marshalling: %v\n", err) @@ -205,6 +210,25 @@ func SetProxy(url string) (err error) { return WritePerferencesFile(data) } +func SetGithubURL(url string) (err error) { + if url == "" { + return nil + } + + cliPref.GithubURL = url + data, err := json.Marshal(&cliPref) + if err != nil { + clilog.Debug.Printf("Error marshalling: %v\n", err) + return err + } + clilog.Debug.Println("Writing ", string(data)) + return WritePerferencesFile(data) +} + +func GetGithubURL() string { + return cliPref.GithubURL +} + func GetPreferences() (err error) { output, err := json.Marshal(&cliPref) if err != nil { diff --git a/internal/bundlegen/proxybundle/proxybundle.go b/internal/bundlegen/proxybundle/proxybundle.go index 81e60b83c..49e2a831c 100644 --- a/internal/bundlegen/proxybundle/proxybundle.go +++ b/internal/bundlegen/proxybundle/proxybundle.go @@ -21,12 +21,14 @@ import ( "fmt" "io" "net/http" + "net/url" "os" "path" "path/filepath" "regexp" "strings" + "internal/apiclient" "internal/clilog" "internal/bundlegen" @@ -638,6 +640,15 @@ func GitHubImportBundle(owner string, repo string, repopath string) (err error) client = github.NewClient(nil) } + // set the url for on premises versions + if apiclient.GetGithubURL() != "" { + u, err := url.Parse(apiclient.GetGithubURL()) + if err != nil { + return err + } + client.BaseURL = u + } + // 1. download the proxy if err := downloadProxyFromRepo(client, ctx, owner, repo, repopath); err != nil { return err