parent
3f335ca628
commit
1c30bdf35b
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -46,6 +47,14 @@ func (c *Config) NewClient() (*Client, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("authentication failed: %v", err)
|
return nil, fmt.Errorf("authentication failed: %v", err)
|
||||||
}
|
}
|
||||||
|
if len(c.EnterpriseURL) > 0 {
|
||||||
|
githubAPIURL, err := getEnterpriseApiUrl(c.EnterpriseURL)
|
||||||
|
if err != nil {
|
||||||
|
c.Log.Error(err, "Enterprise URL incorrect")
|
||||||
|
return nil, fmt.Errorf("enterprise url incorrect: %v", err)
|
||||||
|
}
|
||||||
|
tr.BaseURL = githubAPIURL
|
||||||
|
}
|
||||||
httpClient = &http.Client{Transport: tr}
|
httpClient = &http.Client{Transport: tr}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -218,3 +227,21 @@ func splitOwnerAndRepo(repo string) (string, string, error) {
|
||||||
}
|
}
|
||||||
return chunk[0], chunk[1], nil
|
return chunk[0], chunk[1], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getEnterpriseApiUrl(baseURL string) (string, error) {
|
||||||
|
baseEndpoint, err := url.Parse(baseURL)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if !strings.HasSuffix(baseEndpoint.Path, "/") {
|
||||||
|
baseEndpoint.Path += "/"
|
||||||
|
}
|
||||||
|
if !strings.HasSuffix(baseEndpoint.Path, "/api/v3/") &&
|
||||||
|
!strings.HasPrefix(baseEndpoint.Host, "api.") &&
|
||||||
|
!strings.Contains(baseEndpoint.Host, ".api.") {
|
||||||
|
baseEndpoint.Path += "api/v3/"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trim trailing slash, otherwise there's double slash added to token endpoint
|
||||||
|
return fmt.Sprintf("%s://%s%s", baseEndpoint.Scheme, baseEndpoint.Host, strings.TrimSuffix(baseEndpoint.Path, "/")), nil
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue