parent
							
								
									3f335ca628
								
							
						
					
					
						commit
						1c30bdf35b
					
				|  | @ -4,6 +4,7 @@ import ( | |||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"net/http" | ||||
| 	"net/url" | ||||
| 	"strings" | ||||
| 	"sync" | ||||
| 	"time" | ||||
|  | @ -46,6 +47,14 @@ func (c *Config) NewClient() (*Client, error) { | |||
| 		if err != nil { | ||||
| 			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} | ||||
| 	} | ||||
| 
 | ||||
|  | @ -218,3 +227,21 @@ func splitOwnerAndRepo(repo string) (string, string, error) { | |||
| 	} | ||||
| 	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