Skip to content

Commit

Permalink
Merge branch 'main' into timrogers/require-aws-region
Browse files Browse the repository at this point in the history
  • Loading branch information
timrogers authored Jul 10, 2023
2 parents 9da28a8 + e455609 commit 40ef791
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 67 deletions.
3 changes: 2 additions & 1 deletion RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- 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 be configured using the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` variables or command line arguments.
- __BREAKING CHANGE:__ Require the AWS region to always be specified with the `--aws-region` argument or `AWS_REGION` environment variable if using AWS S3 for blob storage. Previously, this was optional (with a warning) if you weren't specifying an AWS session token.
- __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 40ef791

Please sign in to comment.