Skip to content

Commit

Permalink
Revert "validate bitbucket api url (#138)" (#140)
Browse files Browse the repository at this point in the history
This reverts commit 5bccfc3.
  • Loading branch information
ktrysmt authored Jun 22, 2021
1 parent 5bccfc3 commit 3382a19
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ const DEFAULT_PAGE_LENGTH = 10
const DEFAULT_MAX_DEPTH = 1
const DEFAULT_BITBUCKET_API_BASE_URL = "https://api.bitbucket.org/2.0"

func apiBaseUrl() (*url.URL, error) {
func apiBaseUrl() string {
ev := os.Getenv("BITBUCKET_API_BASE_URL")
if ev == "" {
ev = DEFAULT_BITBUCKET_API_BASE_URL
if ev != "" {
return ev
}

return url.Parse(ev)
return DEFAULT_BITBUCKET_API_BASE_URL
}

type Client struct {
Expand All @@ -43,7 +43,7 @@ type Client struct {
Workspaces *Workspace
Pagelen uint64
MaxDepth uint64
apiBaseURL *url.URL
apiBaseURL string

HttpClient *http.Client
}
Expand Down Expand Up @@ -135,11 +135,7 @@ func NewBasicAuth(u, p string) *Client {
}

func injectClient(a *auth) *Client {
bitbucketUrl, err := apiBaseUrl()
if err != nil {
log.Fatalf("invalid bitbucket url")
}
c := &Client{Auth: a, Pagelen: DEFAULT_PAGE_LENGTH, MaxDepth: DEFAULT_MAX_DEPTH, apiBaseURL: bitbucketUrl}
c := &Client{Auth: a, Pagelen: DEFAULT_PAGE_LENGTH, MaxDepth: DEFAULT_MAX_DEPTH, apiBaseURL: apiBaseUrl()}
c.Repositories = &Repositories{
c: c,
PullRequests: &PullRequests{c: c},
Expand All @@ -161,15 +157,11 @@ func injectClient(a *auth) *Client {
}

func (c *Client) GetApiBaseURL() string {
return fmt.Sprintf("%s%s", c.apiBaseURL.GetApiHostnameURL(), c.apiBaseURL.Path)
}

func (c *Client) GetApiHostnameURL() string {
return fmt.Sprintf("%s://%s", c.apiBaseURL.Scheme, c.apiBaseURL.Host)
return c.apiBaseURL
}

func (c *Client) SetApiBaseURL(urlStr url.URL) {
c.apiBaseURL = &urlStr
func (c *Client) SetApiBaseURL(urlStr string) {
c.apiBaseURL = urlStr
}

func (c *Client) executeRaw(method string, urlStr string, text string) (io.ReadCloser, error) {
Expand Down Expand Up @@ -387,7 +379,7 @@ func unexpectedHttpStatusCode(statusCode int) bool {
func (c *Client) requestUrl(template string, args ...interface{}) string {

if len(args) == 1 && args[0] == "" {
return c.GetApiBaseURL() + template
return c.apiBaseURL + template
}
return c.GetApiBaseURL() + fmt.Sprintf(template, args...)
return c.apiBaseURL + fmt.Sprintf(template, args...)
}

0 comments on commit 3382a19

Please sign in to comment.