Skip to content

Commit

Permalink
feat: add support for on-prem GH #293
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Sep 19, 2023
1 parent 051dc9f commit 8b74a3e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
11 changes: 9 additions & 2 deletions cmd/preferences/setpref.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,8 +49,8 @@ var SetCmd = &cobra.Command{
}

var (
org, proxyURL string
usestage, nocheck bool
org, proxyURL, gitHubURL string
usestage, nocheck bool
)

func init() {
Expand All @@ -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")
}
32 changes: 28 additions & 4 deletions internal/apiclient/clifile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions internal/bundlegen/proxybundle/proxybundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"regexp"
"strings"

"internal/apiclient"
"internal/clilog"

"internal/bundlegen"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8b74a3e

Please sign in to comment.