Skip to content

Commit

Permalink
Merge pull request #1057 from github/timrogers/require-bbs-server-rep…
Browse files Browse the repository at this point in the history
…o-and-project

Require the Bitbucket Server URL, project and repo name to always be passed for `bbs2gh migrate-repo`
  • Loading branch information
timrogers authored Jul 10, 2023
2 parents cc14582 + 54cdc71 commit e455609
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 66 deletions.
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- __BREAKING CHANGE:__ Drop support for deprecated `AWS_ACCESS_KEY` and `AWS_SECRET_KEY` environment variables in `gh gei` and `gh bbs2gh`. The AWS S3 credentials can now only be configured using the industry-standard `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` variables or command line arguments.
- __BREAKING CHANGE__: Require the Bitbucket Server URL, project key and repo to always be provided for `bbs2gh migrate-repo`, even if using the upload-and-migrate (`--archive-path`) or migrate-only (`--archive-url`) flows
- Increase timeouts in archive uploads to AWS to prevent timeouts during large uploads
Original file line number Diff line number Diff line change
Expand Up @@ -283,44 +283,6 @@ public void Errors_If_BbsServer_Url_Not_Provided_But_Smb_User_Is_Provided()
.WithMessage("*SSH*SMB*--bbs-server-url*");
}

[Fact]
public void Errors_If_BbsServer_Url_Not_Provided_But_Bbs_Project_Is_Provided()
{
// Act
var args = new MigrateRepoCommandArgs
{
ArchivePath = ARCHIVE_PATH,
GithubOrg = GITHUB_ORG,
GithubRepo = GITHUB_REPO,
BbsProject = BBS_PROJECT
};

// Assert
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--bbs-project*--bbs-server-url*");
}

[Fact]
public void Errors_If_BbsServer_Url_Not_Provided_But_Bbs_Repo_Is_Provided()
{
// Act
var args = new MigrateRepoCommandArgs
{
ArchivePath = ARCHIVE_PATH,
GithubOrg = GITHUB_ORG,
GithubRepo = GITHUB_REPO,
BbsRepo = BBS_REPO
};

// Assert
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--bbs-repo*--bbs-server-url*");
}

[Fact]
public void It_Throws_If_Github_Org_Is_Provided_But_Github_Repo_Is_Not()
{
Expand Down Expand Up @@ -573,7 +535,7 @@ public void Errors_If_Archive_Url_And_Archive_Path_Are_Passed()
}

[Fact]
public void Errors_If_BbsServer_Url_And_Archive_Url_Are_Passed()
public void Allows_BbsServer_Url_And_Archive_Url_To_Be_Passed_Together()
{
// Act
var args = new MigrateRepoCommandArgs
Expand All @@ -587,12 +549,11 @@ public void Errors_If_BbsServer_Url_And_Archive_Url_Are_Passed()
// Assert
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--bbs-server-url*--archive-url*");
.NotThrow();
}

[Fact]
public void Errors_If_BbsServer_Url_And_Archive_Path_Are_Passed()
public void Allows_BbsServer_Url_And_Archive_Path_To_Be_Passed_Together()
{
// Act
var args = new MigrateRepoCommandArgs
Expand All @@ -606,8 +567,7 @@ public void Errors_If_BbsServer_Url_And_Archive_Path_Are_Passed()
// Assert
args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--bbs-server-url*--archive-path*");
.NotThrow();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public void Should_Have_Options()
command.Name.Should().Be("migrate-repo");
command.Options.Count.Should().Be(31);

TestHelpers.VerifyCommandOption(command.Options, "bbs-server-url", false);
TestHelpers.VerifyCommandOption(command.Options, "bbs-project", false);
TestHelpers.VerifyCommandOption(command.Options, "bbs-repo", false);
TestHelpers.VerifyCommandOption(command.Options, "bbs-server-url", true);
TestHelpers.VerifyCommandOption(command.Options, "bbs-project", true);
TestHelpers.VerifyCommandOption(command.Options, "bbs-repo", true);
TestHelpers.VerifyCommandOption(command.Options, "bbs-username", false);
TestHelpers.VerifyCommandOption(command.Options, "bbs-password", false);
TestHelpers.VerifyCommandOption(command.Options, "archive-url", false);
Expand Down
15 changes: 12 additions & 3 deletions src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,24 @@ public MigrateRepoCommand() : base(

public Option<string> BbsServerUrl { get; } = new(
name: "--bbs-server-url",
description: "The full URL of the Bitbucket Server/Data Center to migrate from. E.g. http://bitbucket.contoso.com:7990");
description: "The full URL of the Bitbucket Server/Data Center to migrate from. E.g. http://bitbucket.contoso.com:7990")
{
IsRequired = true
};

public Option<string> BbsProject { get; } = new(
name: "--bbs-project",
description: "The Bitbucket project to migrate.");
description: "The Bitbucket project to migrate.")
{
IsRequired = true
};

public Option<string> BbsRepo { get; } = new(
name: "--bbs-repo",
description: "The Bitbucket repository to migrate.");
description: "The Bitbucket repository to migrate.")
{
IsRequired = true
};

public Option<string> BbsUsername { get; } = new(
name: "--bbs-username",
Expand Down
18 changes: 2 additions & 16 deletions src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommandArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ public override void Validate(OctoLogger log)
throw new OctoshiftCliException("Either --bbs-server-url, --archive-path, or --archive-url must be specified.");
}

if (BbsServerUrl.HasValue() && ArchiveUrl.HasValue())
{
throw new OctoshiftCliException("Only one of --bbs-server-url or --archive-url can be specified.");
}

if (BbsServerUrl.HasValue() && ArchivePath.HasValue())
{
throw new OctoshiftCliException("Only one of --bbs-server-url or --archive-path can be specified.");
}

if (ArchivePath.HasValue() && ArchiveUrl.HasValue())
{
throw new OctoshiftCliException("Only one of --archive-path or --archive-url can be specified.");
Expand Down Expand Up @@ -127,23 +117,19 @@ private void ValidateNoGenerateOptions()
throw new OctoshiftCliException("--no-ssl-verify can only be provided with --bbs-server-url.");
}

if (BbsProject.HasValue() || BbsRepo.HasValue())
{
throw new OctoshiftCliException("--bbs-project and --bbs-repo can only be provided with --bbs-server-url.");
}

if (new[] { SshUser, SshPrivateKey, ArchiveDownloadHost, SmbUser, SmbPassword, SmbDomain }.Any(obj => obj.HasValue()))
{
throw new OctoshiftCliException("SSH or SMB download options can only be provided with --bbs-server-url.");
}
}

public bool ShouldGenerateArchive() => BbsServerUrl.HasValue();
public bool ShouldGenerateArchive() => BbsServerUrl.HasValue() && !ArchivePath.HasValue() && !ArchiveUrl.HasValue();

public bool ShouldDownloadArchive() => SshUser.HasValue() || SmbUser.HasValue();

public bool ShouldUploadArchive() => ArchiveUrl.IsNullOrWhiteSpace() && GithubOrg.HasValue();

// NOTE: ArchiveUrl doesn't necessarily refer to the value passed in by the user to the CLI - it is set during CLI runtime when an archive is uploaded to blob storage
public bool ShouldImportArchive() => ArchiveUrl.HasValue() || GithubOrg.HasValue();

private void ValidateGenerateOptions()
Expand Down

0 comments on commit e455609

Please sign in to comment.