Double check CloneURL is acceptable (#20869)
Some Migration Downloaders provide re-writing of CloneURLs that may point to unallowed urls. Recheck after the CloneURL is rewritten. Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
6784a707d1
commit
6d3181406d
3 changed files with 24 additions and 5 deletions
|
@ -560,6 +560,10 @@ func (g *RepositoryDumper) Finish() error {
|
||||||
|
|
||||||
// DumpRepository dump repository according MigrateOptions to a local directory
|
// DumpRepository dump repository according MigrateOptions to a local directory
|
||||||
func DumpRepository(ctx context.Context, baseDir, ownerName string, opts base.MigrateOptions) error {
|
func DumpRepository(ctx context.Context, baseDir, ownerName string, opts base.MigrateOptions) error {
|
||||||
|
doer, err := user_model.GetAdminUser()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
downloader, err := newDownloader(ctx, ownerName, opts)
|
downloader, err := newDownloader(ctx, ownerName, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -569,7 +573,7 @@ func DumpRepository(ctx context.Context, baseDir, ownerName string, opts base.Mi
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := migrateRepository(downloader, uploader, opts, nil); err != nil {
|
if err := migrateRepository(doer, downloader, uploader, opts, nil); err != nil {
|
||||||
if err1 := uploader.Rollback(); err1 != nil {
|
if err1 := uploader.Rollback(); err1 != nil {
|
||||||
log.Error("rollback failed: %v", err1)
|
log.Error("rollback failed: %v", err1)
|
||||||
}
|
}
|
||||||
|
@ -641,7 +645,7 @@ func RestoreRepository(ctx context.Context, baseDir, ownerName, repoName string,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = migrateRepository(downloader, uploader, migrateOpts, nil); err != nil {
|
if err = migrateRepository(doer, downloader, uploader, migrateOpts, nil); err != nil {
|
||||||
if err1 := uploader.Rollback(); err1 != nil {
|
if err1 := uploader.Rollback(); err1 != nil {
|
||||||
log.Error("rollback failed: %v", err1)
|
log.Error("rollback failed: %v", err1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||||
uploader = NewGiteaLocalUploader(graceful.GetManager().HammerContext(), user, user.Name, repoName)
|
uploader = NewGiteaLocalUploader(graceful.GetManager().HammerContext(), user, user.Name, repoName)
|
||||||
)
|
)
|
||||||
|
|
||||||
err := migrateRepository(downloader, uploader, base.MigrateOptions{
|
err := migrateRepository(user, downloader, uploader, base.MigrateOptions{
|
||||||
CloneAddr: "https://github.com/go-xorm/builder",
|
CloneAddr: "https://github.com/go-xorm/builder",
|
||||||
RepoName: repoName,
|
RepoName: repoName,
|
||||||
AuthUsername: "",
|
AuthUsername: "",
|
||||||
|
|
|
@ -128,7 +128,7 @@ func MigrateRepository(ctx context.Context, doer *user_model.User, ownerName str
|
||||||
uploader := NewGiteaLocalUploader(ctx, doer, ownerName, opts.RepoName)
|
uploader := NewGiteaLocalUploader(ctx, doer, ownerName, opts.RepoName)
|
||||||
uploader.gitServiceType = opts.GitServiceType
|
uploader.gitServiceType = opts.GitServiceType
|
||||||
|
|
||||||
if err := migrateRepository(downloader, uploader, opts, messenger); err != nil {
|
if err := migrateRepository(doer, downloader, uploader, opts, messenger); err != nil {
|
||||||
if err1 := uploader.Rollback(); err1 != nil {
|
if err1 := uploader.Rollback(); err1 != nil {
|
||||||
log.Error("rollback failed: %v", err1)
|
log.Error("rollback failed: %v", err1)
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ func newDownloader(ctx context.Context, ownerName string, opts base.MigrateOptio
|
||||||
// migrateRepository will download information and then upload it to Uploader, this is a simple
|
// migrateRepository will download information and then upload it to Uploader, this is a simple
|
||||||
// process for small repository. For a big repository, save all the data to disk
|
// process for small repository. For a big repository, save all the data to disk
|
||||||
// before upload is better
|
// before upload is better
|
||||||
func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts base.MigrateOptions, messenger base.Messenger) error {
|
func migrateRepository(doer *user_model.User, downloader base.Downloader, uploader base.Uploader, opts base.MigrateOptions, messenger base.Messenger) error {
|
||||||
if messenger == nil {
|
if messenger == nil {
|
||||||
messenger = base.NilMessenger
|
messenger = base.NilMessenger
|
||||||
}
|
}
|
||||||
|
@ -198,6 +198,21 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the downloader is not a RepositoryRestorer then we need to recheck the CloneURL
|
||||||
|
if _, ok := downloader.(*RepositoryRestorer); !ok {
|
||||||
|
// Now the clone URL can be rewritten by the downloader so we must recheck
|
||||||
|
if err := IsMigrateURLAllowed(repo.CloneURL, doer); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// And so can the original URL too so again we must recheck
|
||||||
|
if repo.OriginalURL != "" {
|
||||||
|
if err := IsMigrateURLAllowed(repo.OriginalURL, doer); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.Trace("migrating git data from %s", repo.CloneURL)
|
log.Trace("migrating git data from %s", repo.CloneURL)
|
||||||
messenger("repo.migrate.migrating_git")
|
messenger("repo.migrate.migrating_git")
|
||||||
if err = uploader.CreateRepo(repo, opts); err != nil {
|
if err = uploader.CreateRepo(repo, opts); err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue