[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 { type ConfigOutput struct {
UserSignupAllowed bool `json:"user_signup_allowed"` UserSignupAllowed bool `json:"user_signup_allowed"`
PublicResourceCreationEnabled bool `json:"public_resource_creation_enabled"` PublicResourceCreationEnabled bool `json:"public_resource_creation_enabled"`
SSHEnabled bool `json:"ssh_enabled"`
} }
// HandleGetConfig returns an http.HandlerFunc that processes an http.Request // 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{ render.JSON(w, http.StatusOK, ConfigOutput{
SSHEnabled: config.SSH.Enable,
UserSignupAllowed: userSignupAllowed, UserSignupAllowed: userSignupAllowed,
PublicResourceCreationEnabled: config.PublicResourceCreationEnabled, 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. // NOTE: we store it as url.URL so we can derive clone URLS without errors.
gitURL *url.URL gitURL *url.URL
SSHEnabled bool
SSHDefaultUser string SSHDefaultUser string
gitSSHURL *url.URL gitSSHURL *url.URL
@ -105,6 +106,7 @@ func NewProvider(
gitURLRaw, gitURLRaw,
gitSSHURLRaw string, gitSSHURLRaw string,
sshDefaultUser string, sshDefaultUser string,
sshEnabled bool,
uiURLRaw string, uiURLRaw string,
) (Provider, error) { ) (Provider, error) {
// remove trailing '/' to make usage easier // remove trailing '/' to make usage easier
@ -136,7 +138,7 @@ func NewProvider(
} }
gitSSHURL, err := url.Parse(gitSSHURLRaw) gitSSHURL, err := url.Parse(gitSSHURLRaw)
if err != nil { if sshEnabled && err != nil {
return nil, fmt.Errorf("provided gitSSHURLRaw '%s' is invalid: %w", gitSSHURLRaw, err) return nil, fmt.Errorf("provided gitSSHURLRaw '%s' is invalid: %w", gitSSHURLRaw, err)
} }
@ -152,6 +154,7 @@ func NewProvider(
gitURL: gitURL, gitURL: gitURL,
gitSSHURL: gitSSHURL, gitSSHURL: gitSSHURL,
SSHDefaultUser: sshDefaultUser, SSHDefaultUser: sshDefaultUser,
SSHEnabled: sshEnabled,
uiURL: uiURL, uiURL: uiURL,
}, nil }, nil
} }
@ -179,6 +182,9 @@ func (p *provider) GenerateGITCloneURL(repoPath string) string {
} }
func (p *provider) GenerateGITCloneSSHURL(repoPath string) string { func (p *provider) GenerateGITCloneSSHURL(repoPath string) string {
if !p.SSHEnabled {
return ""
}
repoPath = path.Clean(repoPath) repoPath = path.Clean(repoPath)
if !strings.HasSuffix(repoPath, GITSuffix) { if !strings.HasSuffix(repoPath, GITSuffix) {
repoPath += GITSuffix repoPath += GITSuffix

View File

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

View File

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

View File

@ -96,7 +96,10 @@ export const EmptyRepositoryInfo: React.FC<Pick<GitInfoProps, 'repoMetadata'>> =
</Text> </Text>
<Layout.Horizontal> <Layout.Horizontal>
<Container padding={{ bottom: 'medium' }} width={400} margin={{ right: 'small' }}> <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}> <Layout.Horizontal className={css.layout}>
<Text className={css.url}>{repoMetadata.git_url}</Text> <Text className={css.url}>{repoMetadata.git_url}</Text>
<FlexExpander /> <FlexExpander />
@ -107,6 +110,10 @@ export const EmptyRepositoryInfo: React.FC<Pick<GitInfoProps, 'repoMetadata'>> =
iconProps={{ size: 14 }} iconProps={{ size: 14 }}
/> />
</Layout.Horizontal> </Layout.Horizontal>
{
// TODO: replace with data from config api
repoMetadata.git_ssh_url && (
<>
<Text>SSH</Text> <Text>SSH</Text>
<Layout.Horizontal className={css.layout}> <Layout.Horizontal className={css.layout}>
<Text className={css.url}>{repoMetadata.git_ssh_url}</Text> <Text className={css.url}>{repoMetadata.git_ssh_url}</Text>
@ -118,6 +125,9 @@ export const EmptyRepositoryInfo: React.FC<Pick<GitInfoProps, 'repoMetadata'>> =
iconProps={{ size: 14 }} iconProps={{ size: 14 }}
/> />
</Layout.Horizontal> </Layout.Horizontal>
</>
)
}
</Container> </Container>
</Layout.Horizontal> </Layout.Horizontal>
<Button <Button