@ -40,7 +40,7 @@ func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error
cmd := git . NewCommand ( ctx , "remote" , "add" , remoteName , "--mirror=fetch" , addr )
cmd := git . NewCommand ( ctx , "remote" , "add" , remoteName , "--mirror=fetch" , addr )
if strings . Contains ( addr , "://" ) && strings . Contains ( addr , "@" ) {
if strings . Contains ( addr , "://" ) && strings . Contains ( addr , "@" ) {
cmd . SetDescription ( fmt . Sprintf ( "remote add %s --mirror=fetch %s [repo_path: %s]" , remoteName , util . NewStringURLSanitizer ( addr , true ) . Replace ( addr ) , repoPath ) )
cmd . SetDescription ( fmt . Sprintf ( "remote add %s --mirror=fetch %s [repo_path: %s]" , remoteName , util . SanitizeCredentialURLs ( addr ) , repoPath ) )
} else {
} else {
cmd . SetDescription ( fmt . Sprintf ( "remote add %s --mirror=fetch %s [repo_path: %s]" , remoteName , addr , repoPath ) )
cmd . SetDescription ( fmt . Sprintf ( "remote add %s --mirror=fetch %s [repo_path: %s]" , remoteName , addr , repoPath ) )
}
}
@ -60,7 +60,7 @@ func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error
cmd = git . NewCommand ( ctx , "remote" , "add" , remoteName , "--mirror=fetch" , wikiRemotePath )
cmd = git . NewCommand ( ctx , "remote" , "add" , remoteName , "--mirror=fetch" , wikiRemotePath )
if strings . Contains ( wikiRemotePath , "://" ) && strings . Contains ( wikiRemotePath , "@" ) {
if strings . Contains ( wikiRemotePath , "://" ) && strings . Contains ( wikiRemotePath , "@" ) {
cmd . SetDescription ( fmt . Sprintf ( "remote add %s --mirror=fetch %s [repo_path: %s]" , remoteName , util . NewStringURLSanitizer ( wikiRemotePath , true ) . Replace ( wikiRemotePath ) , wikiPath ) )
cmd . SetDescription ( fmt . Sprintf ( "remote add %s --mirror=fetch %s [repo_path: %s]" , remoteName , util . SanitizeCredentialURLs ( wikiRemotePath ) , wikiPath ) )
} else {
} else {
cmd . SetDescription ( fmt . Sprintf ( "remote add %s --mirror=fetch %s [repo_path: %s]" , remoteName , wikiRemotePath , wikiPath ) )
cmd . SetDescription ( fmt . Sprintf ( "remote add %s --mirror=fetch %s [repo_path: %s]" , remoteName , wikiRemotePath , wikiPath ) )
}
}
@ -160,7 +160,6 @@ func pruneBrokenReferences(ctx context.Context,
repoPath string ,
repoPath string ,
timeout time . Duration ,
timeout time . Duration ,
stdoutBuilder , stderrBuilder * strings . Builder ,
stdoutBuilder , stderrBuilder * strings . Builder ,
sanitizer * strings . Replacer ,
isWiki bool ,
isWiki bool ,
) error {
) error {
wiki := ""
wiki := ""
@ -184,8 +183,8 @@ func pruneBrokenReferences(ctx context.Context,
// sanitize the output, since it may contain the remote address, which may
// sanitize the output, since it may contain the remote address, which may
// contain a password
// contain a password
stderrMessage := sanitizer . Replace ( stderr )
stderrMessage := util . SanitizeCredentialURLs ( stderr )
stdoutMessage := sanitizer . Replace ( stdout )
stdoutMessage := util . SanitizeCredentialURLs ( stdout )
log . Error ( "Failed to prune mirror repository %s%-v references:\nStdout: %s\nStderr: %s\nErr: %v" , wiki , m . Repo , stdoutMessage , stderrMessage , pruneErr )
log . Error ( "Failed to prune mirror repository %s%-v references:\nStdout: %s\nStderr: %s\nErr: %v" , wiki , m . Repo , stdoutMessage , stderrMessage , pruneErr )
desc := fmt . Sprintf ( "Failed to prune mirror repository %s'%s' references: %s" , wiki , repoPath , stderrMessage )
desc := fmt . Sprintf ( "Failed to prune mirror repository %s'%s' references: %s" , wiki , repoPath , stderrMessage )
@ -229,11 +228,9 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
stdout := stdoutBuilder . String ( )
stdout := stdoutBuilder . String ( )
stderr := stderrBuilder . String ( )
stderr := stderrBuilder . String ( )
// sanitize the output, since it may contain the remote address, which may
// sanitize the output, since it may contain the remote address, which may contain a password
// contain a password
stderrMessage := util . SanitizeCredentialURLs ( stderr )
sanitizer := util . NewURLSanitizer ( remoteAddr , true )
stdoutMessage := util . SanitizeCredentialURLs ( stdout )
stderrMessage := sanitizer . Replace ( stderr )
stdoutMessage := sanitizer . Replace ( stdout )
// Now check if the error is a resolve reference due to broken reference
// Now check if the error is a resolve reference due to broken reference
if strings . Contains ( stderr , "unable to resolve reference" ) && strings . Contains ( stderr , "reference broken" ) {
if strings . Contains ( stderr , "unable to resolve reference" ) && strings . Contains ( stderr , "reference broken" ) {
@ -241,7 +238,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
err = nil
err = nil
// Attempt prune
// Attempt prune
pruneErr := pruneBrokenReferences ( ctx , m , repoPath , timeout , & stdoutBuilder , & stderrBuilder , sanitizer , false )
pruneErr := pruneBrokenReferences ( ctx , m , repoPath , timeout , & stdoutBuilder , & stderrBuilder , false )
if pruneErr == nil {
if pruneErr == nil {
// Successful prune - reattempt mirror
// Successful prune - reattempt mirror
stderrBuilder . Reset ( )
stderrBuilder . Reset ( )
@ -259,8 +256,8 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
// sanitize the output, since it may contain the remote address, which may
// sanitize the output, since it may contain the remote address, which may
// contain a password
// contain a password
stderrMessage = sanitizer . Replace ( stderr )
stderrMessage = util . SanitizeCredentialURLs ( stderr )
stdoutMessage = sanitizer . Replace ( stdout )
stdoutMessage = util . SanitizeCredentialURLs ( stdout )
}
}
}
}
}
}
@ -322,19 +319,9 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
stdout := stdoutBuilder . String ( )
stdout := stdoutBuilder . String ( )
stderr := stderrBuilder . String ( )
stderr := stderrBuilder . String ( )
// sanitize the output, since it may contain the remote address, which may
// sanitize the output, since it may contain the remote address, which may contain a password
// contain a password
stderrMessage := util . SanitizeCredentialURLs ( stderr )
stdoutMessage := util . SanitizeCredentialURLs ( stdout )
remoteAddr , remoteErr := git . GetRemoteAddress ( ctx , wikiPath , m . GetRemoteName ( ) )
if remoteErr != nil {
log . Error ( "SyncMirrors [repo: %-v Wiki]: unable to get GetRemoteAddress Error %v" , m . Repo , remoteErr )
}
// sanitize the output, since it may contain the remote address, which may
// contain a password
sanitizer := util . NewURLSanitizer ( remoteAddr , true )
stderrMessage := sanitizer . Replace ( stderr )
stdoutMessage := sanitizer . Replace ( stdout )
// Now check if the error is a resolve reference due to broken reference
// Now check if the error is a resolve reference due to broken reference
if strings . Contains ( stderrMessage , "unable to resolve reference" ) && strings . Contains ( stderrMessage , "reference broken" ) {
if strings . Contains ( stderrMessage , "unable to resolve reference" ) && strings . Contains ( stderrMessage , "reference broken" ) {
@ -342,7 +329,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
err = nil
err = nil
// Attempt prune
// Attempt prune
pruneErr := pruneBrokenReferences ( ctx , m , repoPath , timeout , & stdoutBuilder , & stderrBuilder , sanitizer , true )
pruneErr := pruneBrokenReferences ( ctx , m , repoPath , timeout , & stdoutBuilder , & stderrBuilder , true )
if pruneErr == nil {
if pruneErr == nil {
// Successful prune - reattempt mirror
// Successful prune - reattempt mirror
stderrBuilder . Reset ( )
stderrBuilder . Reset ( )
@ -358,8 +345,8 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
} ) ; err != nil {
} ) ; err != nil {
stdout := stdoutBuilder . String ( )
stdout := stdoutBuilder . String ( )
stderr := stderrBuilder . String ( )
stderr := stderrBuilder . String ( )
stderrMessage = sanitizer . Replace ( stderr )
stderrMessage = util . SanitizeCredentialURLs ( stderr )
stdoutMessage = sanitizer . Replace ( stdout )
stdoutMessage = util . SanitizeCredentialURLs ( stdout )
}
}
}
}
}
}