mirror of
https://github.com/harness/drone.git
synced 2025-05-05 23:42:57 +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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error while parsing the clone url: %s", gitURL)
|
return nil, fmt.Errorf("error while parsing the clone url: %s", gitURL)
|
||||||
}
|
}
|
||||||
userInfo := url.UserPassword("harness", jwtToken)
|
resolvedCredentails.CloneURL = types.NewMaskSecret(
|
||||||
modifiedURL.User = userInfo
|
BuildAuthenticatedCloneURL(modifiedURL, jwtToken, enum.CodeRepoTypeGitness).String())
|
||||||
resolvedCredentails.CloneURL = types.NewMaskSecret(modifiedURL.String())
|
|
||||||
credentials := &UserPasswordCredentials{
|
credentials := &UserPasswordCredentials{
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
Name: types.NewMaskSecret(user.DisplayName),
|
Name: types.NewMaskSecret(user.DisplayName),
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -27,6 +28,7 @@ import (
|
|||||||
"github.com/harness/gitness/types"
|
"github.com/harness/gitness/types"
|
||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/tidwall/jsonc"
|
"github.com/tidwall/jsonc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -133,7 +135,7 @@ func (s *SCM) GetBranchURL(
|
|||||||
repoURL string,
|
repoURL string,
|
||||||
branch string,
|
branch string,
|
||||||
) (string, error) {
|
) (string, error) {
|
||||||
scmProvider, err := s.scmProviderFactory.GetSCMProvider(repoType)
|
scmProvider, err := s.getSCMAuthAndFileProvider(repoType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to resolve scm provider while generating branch url: %w", err)
|
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
|
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,
|
filePath string,
|
||||||
credentials *ResolvedCredentials,
|
credentials *ResolvedCredentials,
|
||||||
) ([]byte, error)
|
) ([]byte, error)
|
||||||
|
|
||||||
ResolveCredentials(ctx context.Context, gitspaceConfig types.GitspaceConfig) (*ResolvedCredentials, 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,
|
filter *BranchFilter,
|
||||||
credentials *ResolvedCredentials,
|
credentials *ResolvedCredentials,
|
||||||
) ([]Branch, error)
|
) ([]Branch, error)
|
||||||
|
|
||||||
GetBranchURL(spacePath string, repoURL string, branch string) (string, error)
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user