feat: [AH-713]: add method to get base UI url (#3103)

* feat: [AH-713]: add method to get base UI url
pull/3597/head
Tudor Macari 2024-12-03 13:37:48 +00:00 committed by Harness
parent 26408533e1
commit ed2597bdcc
2 changed files with 18 additions and 0 deletions

View File

@ -78,6 +78,8 @@ type Provider interface {
GetAPIProto(ctx context.Context) string
RegistryURL(ctx context.Context, params ...string) string
GetUIBaseURL(ctx context.Context) string
}
// Provider provides the URLs of the Harness system.
@ -250,6 +252,10 @@ func (p *provider) RegistryURL(_ context.Context, params ...string) string {
return strings.TrimRight(u.String(), "/")
}
func (p *provider) GetUIBaseURL(_ context.Context) string {
return p.uiURL.String()
}
func BuildGITCloneSSHURL(user string, sshURL *url.URL, repoPath string) string {
repoPath = path.Clean(repoPath)
if !strings.HasSuffix(repoPath, GITSuffix) {

View File

@ -45,6 +45,18 @@ func GetHost(urlStr string) string {
return u.Host
}
func GetHostName(urlStr string) string {
if !strings.Contains(urlStr, "://") {
urlStr = "https://" + urlStr
}
u, err := url.Parse(urlStr)
if err != nil {
log.Warn().Msgf("Failed to parse URL: %s", urlStr)
return ""
}
return u.Hostname()
}
func TrimURLScheme(urlStr string) string {
u, err := url.Parse(urlStr)
if err != nil {