mirror of https://github.com/portainer/portainer
				
				
				
			feat(gitops): support to store git credentials [EE-2683] (#7066)
							parent
							
								
									9ef5636718
								
							
						
					
					
						commit
						fa162cafc1
					
				| 
						 | 
					@ -19,6 +19,10 @@ import (
 | 
				
			||||||
	"github.com/go-git/go-git/v5/storage/memory"
 | 
						"github.com/go-git/go-git/v5/storage/memory"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var (
 | 
				
			||||||
 | 
						ErrAuthenticationFailure = errors.New("Authentication failed, please ensure that the git credentials are correct.")
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type fetchOptions struct {
 | 
					type fetchOptions struct {
 | 
				
			||||||
	repositoryUrl string
 | 
						repositoryUrl string
 | 
				
			||||||
	username      string
 | 
						username      string
 | 
				
			||||||
| 
						 | 
					@ -57,6 +61,9 @@ func (c gitClient) download(ctx context.Context, dst string, opt cloneOptions) e
 | 
				
			||||||
	_, err := git.PlainCloneContext(ctx, dst, false, &gitOptions)
 | 
						_, err := git.PlainCloneContext(ctx, dst, false, &gitOptions)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 | 
							if err.Error() == "authentication required" {
 | 
				
			||||||
 | 
								return ErrAuthenticationFailure
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		return errors.Wrap(err, "failed to clone git repository")
 | 
							return errors.Wrap(err, "failed to clone git repository")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -79,6 +86,9 @@ func (c gitClient) latestCommitID(ctx context.Context, opt fetchOptions) (string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	refs, err := remote.List(listOptions)
 | 
						refs, err := remote.List(listOptions)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 | 
							if err.Error() == "authentication required" {
 | 
				
			||||||
 | 
								return "", ErrAuthenticationFailure
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		return "", errors.Wrap(err, "failed to list repository refs")
 | 
							return "", errors.Wrap(err, "failed to list repository refs")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,4 +17,8 @@ type RepoConfig struct {
 | 
				
			||||||
type GitAuthentication struct {
 | 
					type GitAuthentication struct {
 | 
				
			||||||
	Username string
 | 
						Username string
 | 
				
			||||||
	Password string
 | 
						Password string
 | 
				
			||||||
 | 
						// Git credentials identifier when the value is not 0
 | 
				
			||||||
 | 
						// When the value is 0, Username and Password are set without using saved credential
 | 
				
			||||||
 | 
						// This is introduced since 2.15.0
 | 
				
			||||||
 | 
						GitCredentialID int `example:"0"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue