[code-2009] only if ssh is enabled show ssh url box (#2101)

ui/offscreen-diff-contents
Enver Biševac 2024-06-12 18:34:25 +00:00 committed by Harness
parent 19600c3a17
commit f0e12faa67
5 changed files with 48 additions and 24 deletions

View File

@ -25,6 +25,7 @@ import (
type ConfigOutput struct {
UserSignupAllowed bool `json:"user_signup_allowed"`
PublicResourceCreationEnabled bool `json:"public_resource_creation_enabled"`
SSHEnabled bool `json:"ssh_enabled"`
}
// HandleGetConfig returns an http.HandlerFunc that processes an http.Request
@ -40,6 +41,7 @@ func HandleGetConfig(config *types.Config, sysCtrl *system.Controller) http.Hand
}
render.JSON(w, http.StatusOK, ConfigOutput{
SSHEnabled: config.SSH.Enable,
UserSignupAllowed: userSignupAllowed,
PublicResourceCreationEnabled: config.PublicResourceCreationEnabled,
})

View File

@ -91,6 +91,7 @@ type provider struct {
// NOTE: we store it as url.URL so we can derive clone URLS without errors.
gitURL *url.URL
SSHEnabled bool
SSHDefaultUser string
gitSSHURL *url.URL
@ -105,6 +106,7 @@ func NewProvider(
gitURLRaw,
gitSSHURLRaw string,
sshDefaultUser string,
sshEnabled bool,
uiURLRaw string,
) (Provider, error) {
// remove trailing '/' to make usage easier
@ -136,7 +138,7 @@ func NewProvider(
}
gitSSHURL, err := url.Parse(gitSSHURLRaw)
if err != nil {
if sshEnabled && err != nil {
return nil, fmt.Errorf("provided gitSSHURLRaw '%s' is invalid: %w", gitSSHURLRaw, err)
}
@ -152,6 +154,7 @@ func NewProvider(
gitURL: gitURL,
gitSSHURL: gitSSHURL,
SSHDefaultUser: sshDefaultUser,
SSHEnabled: sshEnabled,
uiURL: uiURL,
}, nil
}
@ -179,6 +182,9 @@ func (p *provider) GenerateGITCloneURL(repoPath string) string {
}
func (p *provider) GenerateGITCloneSSHURL(repoPath string) string {
if !p.SSHEnabled {
return ""
}
repoPath = path.Clean(repoPath)
if !strings.HasSuffix(repoPath, GITSuffix) {
repoPath += GITSuffix

View File

@ -31,6 +31,7 @@ func ProvideURLProvider(config *types.Config) (Provider, error) {
config.URL.Git,
config.URL.GitSSH,
config.SSH.DefaultUser,
config.SSH.Enable,
config.URL.UI,
)
}

View File

@ -53,25 +53,30 @@ export function CloneButtonTooltip({ httpsURL, sshURL }: CloneButtonTooltipProps
/>
</Container>
<Text font={{ variation: FontVariation.H4 }}>{getString('cloneHTTPS')}</Text>
<Container padding={{ top: 'small' }}>
<Text font={{ variation: FontVariation.BODY2_SEMI }}>HTTP</Text>
{
// TODO: replace with data from config api
sshURL && <Text font={{ variation: FontVariation.BODY2_SEMI }}>HTTP</Text>
}
<Layout.Horizontal className={css.layout}>
<Text className={css.url}>{httpsURL}</Text>
<CopyButton content={httpsURL} id={css.cloneCopyButton} icon={CodeIcon.Copy} iconProps={{ size: 14 }} />
</Layout.Horizontal>
</Container>
{
// TODO: replace with data from config api
sshURL && (
<Container padding={{ top: 'small' }}>
<Text font={{ variation: FontVariation.BODY2_SEMI }}>SSH</Text>
<Layout.Horizontal className={css.layout}>
<Text className={css.url}>{sshURL}</Text>
<Container padding={{ top: 'small' }}>
<Text font={{ variation: FontVariation.BODY2_SEMI }}>SSH</Text>
<Layout.Horizontal className={css.layout}>
<Text className={css.url}>{sshURL}</Text>
<CopyButton content={sshURL} id={css.cloneCopyButton} icon={CodeIcon.Copy} iconProps={{ size: 14 }} />
</Layout.Horizontal>
</Container>
<CopyButton content={sshURL} id={css.cloneCopyButton} icon={CodeIcon.Copy} iconProps={{ size: 14 }} />
</Layout.Horizontal>
</Container>
)
}
<Render when={!isCurrentSessionPublic}>
<Button
width={300}

View File

@ -96,7 +96,10 @@ export const EmptyRepositoryInfo: React.FC<Pick<GitInfoProps, 'repoMetadata'>> =
</Text>
<Layout.Horizontal>
<Container padding={{ bottom: 'medium' }} width={400} margin={{ right: 'small' }}>
<Text>HTTP</Text>
{
// TODO: replace with data from config api
repoMetadata.git_ssh_url && <Text>HTTP</Text>
}
<Layout.Horizontal className={css.layout}>
<Text className={css.url}>{repoMetadata.git_url}</Text>
<FlexExpander />
@ -107,17 +110,24 @@ export const EmptyRepositoryInfo: React.FC<Pick<GitInfoProps, 'repoMetadata'>> =
iconProps={{ size: 14 }}
/>
</Layout.Horizontal>
<Text>SSH</Text>
<Layout.Horizontal className={css.layout}>
<Text className={css.url}>{repoMetadata.git_ssh_url}</Text>
<FlexExpander />
<CopyButton
content={repoMetadata?.git_ssh_url as string}
id={css.cloneCopyButton}
icon={CodeIcon.Copy}
iconProps={{ size: 14 }}
/>
</Layout.Horizontal>
{
// TODO: replace with data from config api
repoMetadata.git_ssh_url && (
<>
<Text>SSH</Text>
<Layout.Horizontal className={css.layout}>
<Text className={css.url}>{repoMetadata.git_ssh_url}</Text>
<FlexExpander />
<CopyButton
content={repoMetadata?.git_ssh_url as string}
id={css.cloneCopyButton}
icon={CodeIcon.Copy}
iconProps={{ size: 14 }}
/>
</Layout.Horizontal>
</>
)
}
</Container>
</Layout.Horizontal>
<Button