mirror of
https://github.com/harness/drone.git
synced 2025-05-05 15:32:56 +00:00
feat: [CDE-742]: add common scm auth functionality (#3729)
* feat: [CDE-742]: add common scm auth functionality * feat: [CDE-742]: add common scm auth functionality * feat: [CDE-742]: add common scm auth functionality * feat: [CDE-742]: add common scm auth functionality * feat: [CDE-742]: add common scm auth functionality
This commit is contained in:
parent
c3a70ca12e
commit
8d0c8b2f1e
@ -200,9 +200,8 @@ func (s *GitnessSCM) ResolveCredentials(
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error while parsing the clone url: %s", gitURL)
|
||||
}
|
||||
userInfo := url.UserPassword("harness", jwtToken)
|
||||
modifiedURL.User = userInfo
|
||||
resolvedCredentails.CloneURL = types.NewMaskSecret(modifiedURL.String())
|
||||
resolvedCredentails.CloneURL = types.NewMaskSecret(
|
||||
BuildAuthenticatedCloneURL(modifiedURL, jwtToken, enum.CodeRepoTypeGitness).String())
|
||||
credentials := &UserPasswordCredentials{
|
||||
Email: user.Email,
|
||||
Name: types.NewMaskSecret(user.DisplayName),
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
@ -27,6 +28,7 @@ import (
|
||||
"github.com/harness/gitness/types"
|
||||
"github.com/harness/gitness/types/enum"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/tidwall/jsonc"
|
||||
)
|
||||
|
||||
@ -133,7 +135,7 @@ func (s *SCM) GetBranchURL(
|
||||
repoURL string,
|
||||
branch string,
|
||||
) (string, error) {
|
||||
scmProvider, err := s.scmProviderFactory.GetSCMProvider(repoType)
|
||||
scmProvider, err := s.getSCMAuthAndFileProvider(repoType)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to resolve scm provider while generating branch url: %w", err)
|
||||
}
|
||||
@ -198,3 +200,23 @@ func (s *SCM) getDevcontainerConfig(
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func BuildAuthenticatedCloneURL(repoURL *url.URL, accessToken string, codeRepoType enum.GitspaceCodeRepoType) *url.URL {
|
||||
switch codeRepoType {
|
||||
case enum.CodeRepoTypeGithubEnterprise, enum.CodeRepoTypeGithub:
|
||||
repoURL.User = url.UserPassword(accessToken, "x-oauth-basic")
|
||||
case enum.CodeRepoTypeGitlab, enum.CodeRepoTypeGitlabOnPrem:
|
||||
repoURL.User = url.UserPassword("oauth2", accessToken)
|
||||
case enum.CodeRepoTypeBitbucket, enum.CodeRepoTypeBitbucketServer:
|
||||
repoURL.User = url.UserPassword("x-token-auth", accessToken)
|
||||
case enum.CodeRepoTypeGitness:
|
||||
repoURL.User = url.UserPassword("harness", accessToken)
|
||||
case enum.CodeRepoTypeHarnessCode:
|
||||
repoURL.User = url.UserPassword("Basic", accessToken)
|
||||
case enum.CodeRepoTypeUnknown:
|
||||
log.Warn().Msgf("unknown repo type, cannot set credentials")
|
||||
default:
|
||||
log.Warn().Msgf("Unsupported repo type: %s", codeRepoType)
|
||||
}
|
||||
return repoURL
|
||||
}
|
||||
|
@ -27,5 +27,8 @@ type AuthAndFileContentProvider interface {
|
||||
filePath string,
|
||||
credentials *ResolvedCredentials,
|
||||
) ([]byte, error)
|
||||
|
||||
ResolveCredentials(ctx context.Context, gitspaceConfig types.GitspaceConfig) (*ResolvedCredentials, error)
|
||||
|
||||
GetBranchURL(spacePath string, repoURL string, branch string) (string, error)
|
||||
}
|
||||
|
@ -30,6 +30,4 @@ type ListingProvider interface {
|
||||
filter *BranchFilter,
|
||||
credentials *ResolvedCredentials,
|
||||
) ([]Branch, error)
|
||||
|
||||
GetBranchURL(spacePath string, repoURL string, branch string) (string, error)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user