From f2091fd5388494c99d9895b60ae6a355c9b472df Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Wed, 6 Nov 2024 20:26:51 -0600 Subject: [PATCH 01/16] Bug --- .../GenerateScript/GenerateScriptCommandHandler.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs index 914b9717..5cc2ac3d 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs @@ -93,14 +93,15 @@ private async Task GenerateSequentialGithubScript(IEnumerable<(string Na content.AppendLine(EXEC_FUNCTION_BLOCK); content.AppendLine(VALIDATE_GH_PAT); - if (await _ghesVersionChecker.AreBlobCredentialsRequired(ghesApiUrl)) + + if (await _ghesVersionChecker.AreBlobCredentialsRequired(ghesApiUrl, useGithubStorage)) { if (awsBucketName.HasValue() || awsRegion.HasValue()) { content.AppendLine(VALIDATE_AWS_ACCESS_KEY_ID); content.AppendLine(VALIDATE_AWS_SECRET_ACCESS_KEY); } - else + else if (!useGithubStorage) { content.AppendLine(VALIDATE_AZURE_STORAGE_CONNECTION_STRING); } @@ -131,14 +132,14 @@ private async Task GenerateParallelGithubScript(IEnumerable<(string Name content.AppendLine(EXEC_AND_GET_MIGRATION_ID_FUNCTION_BLOCK); content.AppendLine(VALIDATE_GH_PAT); - if (await _ghesVersionChecker.AreBlobCredentialsRequired(ghesApiUrl)) + if (await _ghesVersionChecker.AreBlobCredentialsRequired(ghesApiUrl, useGithubStorage)) { if (awsBucketName.HasValue() || awsRegion.HasValue()) { content.AppendLine(VALIDATE_AWS_ACCESS_KEY_ID); content.AppendLine(VALIDATE_AWS_SECRET_ACCESS_KEY); } - else + else if (!useGithubStorage) { content.AppendLine(VALIDATE_AZURE_STORAGE_CONNECTION_STRING); } From 7f1c29d636e81ce203dca452c96bdd09a5125ad8 Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Thu, 7 Nov 2024 09:43:26 -0600 Subject: [PATCH 02/16] Remove git-owne-storage from veify ghes version checker --- .../GenerateScriptCommandHandlerTests.cs | 22 +++++----- .../MigrateRepoCommandHandlerTests.cs | 40 +++++++++---------- .../GenerateScriptCommandHandler.cs | 4 +- .../MigrateRepo/MigrateRepoCommandHandler.cs | 2 +- src/gei/Services/GhesVersionChecker.cs | 6 +-- 5 files changed, 35 insertions(+), 39 deletions(-) diff --git a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs index f594c012..b026dcce 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandHandlerTests.cs @@ -222,7 +222,7 @@ public async Task Sequential_Github_Ghes_Repo() _mockGithubApi .Setup(m => m.GetRepos(SOURCE_ORG)) .ReturnsAsync(new[] { (REPO, "private") }); - _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true); + _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true); var expected = $"Exec {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --ghes-api-url \"{ghesApiUrl}\" --target-repo-visibility private }}"; @@ -333,7 +333,7 @@ public async Task Parallel_Github_Ghes_Single_Repo() .ReturnsAsync(new[] { (REPO, "private") }); _mockVersionProvider.Setup(m => m.GetCurrentVersion()).Returns("1.1.1"); - _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true); + _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true); var expected = new StringBuilder(); expected.AppendLine("#!/usr/bin/env pwsh"); @@ -502,7 +502,7 @@ public async Task Parallel_Github_Ghes_Single_Repo_With_Download_Migration_Logs( .ReturnsAsync(new[] { (REPO, "private") }); _mockVersionProvider.Setup(m => m.GetCurrentVersion()).Returns("1.1.1"); - _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true); + _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true); var expected = new StringBuilder(); expected.AppendLine("#!/usr/bin/env pwsh"); @@ -588,7 +588,7 @@ public async Task Parallel_Github_Ghes_Single_Repo_No_Ssl() .ReturnsAsync(new[] { (REPO, "private") }); _mockVersionProvider.Setup(m => m.GetCurrentVersion()).Returns("1.1.1"); - _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true); + _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true); var expected = new StringBuilder(); expected.AppendLine("#!/usr/bin/env pwsh"); @@ -673,7 +673,7 @@ public async Task Parallel_Github_Ghes_Single_Repo_Keep_Archive() .ReturnsAsync(new[] { (REPO, "private") }); _mockVersionProvider.Setup(m => m.GetCurrentVersion()).Returns("1.1.1"); - _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(false); + _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(false); var expected = new StringBuilder(); expected.AppendLine("#!/usr/bin/env pwsh"); @@ -909,7 +909,7 @@ public async Task Sequential_Ghes_Single_Repo_Aws_S3() _mockGithubApi .Setup(m => m.GetRepos(SOURCE_ORG)) .ReturnsAsync(new[] { (REPO, "private") }); - _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true); + _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true); var expected = $"Exec {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --ghes-api-url \"{ghesApiUrl}\" --aws-bucket-name \"{AWS_BUCKET_NAME}\" --aws-region \"{AWS_REGION}\" --target-repo-visibility private }}"; @@ -941,7 +941,7 @@ public async Task Sequential_Ghes_Single_Repo_Keep_Archive() _mockGithubApi .Setup(m => m.GetRepos(SOURCE_ORG)) .ReturnsAsync(new[] { (REPO, "private") }); - _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true); + _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true); var expected = $"Exec {{ gh gei migrate-repo --github-source-org \"{SOURCE_ORG}\" --source-repo \"{REPO}\" --github-target-org \"{TARGET_ORG}\" --target-repo \"{REPO}\" --ghes-api-url \"{ghesApiUrl}\" --aws-bucket-name \"{AWS_BUCKET_NAME}\" --aws-region \"{AWS_REGION}\" --keep-archive --target-repo-visibility private }}"; @@ -974,7 +974,7 @@ public async Task Validates_Env_Vars() _mockGithubApi .Setup(m => m.GetRepos(SOURCE_ORG)) .ReturnsAsync(new[] { (REPO, "private") }); - _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true); + _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true); var expected = @" if (-not $env:GH_PAT) { @@ -1019,7 +1019,7 @@ public async Task Validates_Env_Vars_AWS() _mockGithubApi .Setup(m => m.GetRepos(SOURCE_ORG)) .ReturnsAsync(new[] { (REPO, "private") }); - _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true); + _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true); var expected = @" if (-not $env:GH_PAT) { @@ -1072,7 +1072,7 @@ public async Task Validates_Env_Vars_AZURE_STORAGE_CONNECTION_STRING_Not_Validat _mockGithubApi .Setup(m => m.GetRepos(SOURCE_ORG)) .ReturnsAsync(new[] { (REPO, "private") }); - _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(true); + _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(true); var expected = @" if (-not $env:AZURE_STORAGE_CONNECTION_STRING) { @@ -1173,7 +1173,7 @@ public async Task Validates_Env_Vars_Blob_Storage_Not_Validated_When_GHES_3_8() _mockGithubApi .Setup(m => m.GetRepos(SOURCE_ORG)) .ReturnsAsync(new[] { (REPO, "private") }); - _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl, false)).ReturnsAsync(false); + _mockGhesVersionCheckerService.Setup(m => m.AreBlobCredentialsRequired(ghesApiUrl)).ReturnsAsync(false); var expected = @" if (-not $env:GH_PAT) { diff --git a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs index 8738b41c..f6d557bb 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs @@ -67,7 +67,7 @@ public async Task Dont_Generate_Archives_If_Target_Repo_Exists() { // Arrange _mockTargetGithubApi.Setup(x => x.DoesRepoExist(TARGET_ORG, TARGET_REPO)).ReturnsAsync(true); - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); // Act var args = new MigrateRepoCommandArgs @@ -306,7 +306,7 @@ public async Task Happy_Path_GithubSource_Ghes() _mockEnvironmentVariableProvider.Setup(m => m.SourceGithubPersonalAccessToken(It.IsAny())).Returns(sourceGithubPat); _mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny())).Returns(targetGithubPat); - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); var args = new MigrateRepoCommandArgs { @@ -365,7 +365,7 @@ public async Task Happy_Path_UseGithubStorage() .Setup(m => m.OpenRead(metadataArchiveDownloadFilePath)) .Returns(metaContentStream); - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, true)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); _mockTargetGithubApi.Setup(x => x.DoesOrgExist(TARGET_ORG).Result).Returns(true); @@ -482,7 +482,7 @@ public async Task Happy_Path_GithubSource_Ghes_Repo_Renamed() _mockEnvironmentVariableProvider.Setup(m => m.SourceGithubPersonalAccessToken(It.IsAny())).Returns(sourceGithubPat); _mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny())).Returns(targetGithubPat); - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); var args = new MigrateRepoCommandArgs { @@ -635,7 +635,7 @@ public async Task Ghes_AzureConnectionString_Uses_Env_When_Option_Empty() _mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny())).Returns(targetGithubPat); _mockEnvironmentVariableProvider.Setup(m => m.AzureStorageConnectionString(It.IsAny())).Returns(azureConnectionStringEnv); - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); var args = new MigrateRepoCommandArgs { @@ -699,7 +699,7 @@ public async Task Ghes_With_NoSslVerify_Uses_NoSsl_Client() _mockEnvironmentVariableProvider.Setup(m => m.SourceGithubPersonalAccessToken(It.IsAny())).Returns(sourceGithubPat); _mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny())).Returns(targetGithubPat); - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); var args = new MigrateRepoCommandArgs { @@ -762,7 +762,7 @@ public async Task Ghes_With_3_8_0_Version_Returns_Archive_Urls_Directly() _mockEnvironmentVariableProvider.Setup(m => m.SourceGithubPersonalAccessToken(It.IsAny())).Returns(sourceGithubPat); _mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny())).Returns(targetGithubPat); - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(false); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(false); var args = new MigrateRepoCommandArgs { @@ -789,7 +789,7 @@ public async Task Ghes_Failed_Archive_Generation_Throws_Error() _mockSourceGithubApi.Setup(x => x.StartMetadataArchiveGeneration(SOURCE_ORG, SOURCE_REPO, false, false).Result).Returns(metadataArchiveId); _mockSourceGithubApi.Setup(x => x.GetArchiveMigrationStatus(SOURCE_ORG, gitArchiveId).Result).Returns(ArchiveMigrationStatus.Failed); - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); await FluentActions .Invoking(async () => await _handler.Handle(new MigrateRepoCommandArgs @@ -881,7 +881,7 @@ public async Task Ghes_Retries_Archive_Generation_On_Any_Error() _mockEnvironmentVariableProvider.Setup(m => m.SourceGithubPersonalAccessToken(It.IsAny())).Returns(sourceGithubPat); _mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny())).Returns(targetGithubPat); - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); var args = new MigrateRepoCommandArgs { @@ -1065,7 +1065,7 @@ public async Task Does_Not_Pass_Lock_Repos_To_StartMigration_For_GHES() _mockTargetGithubApi.Setup(x => x.DoesOrgExist(TARGET_ORG).Result).Returns(true); _mockAzureApi.Setup(x => x.UploadToBlob(It.IsAny(), It.IsAny()).Result).Returns(new Uri("https://example.com/resource")); - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); // Act var args = new MigrateRepoCommandArgs @@ -1329,7 +1329,7 @@ public async Task It_Uses_Aws_If_Arguments_Are_Included() _mockAwsApi.Setup(m => m.UploadToBucket(awsBucketName, It.IsAny(), It.IsAny())).ReturnsAsync(archiveUrl); - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); var handler = new MigrateRepoCommandHandler( _mockOctoLogger.Object, @@ -1368,7 +1368,7 @@ public async Task It_Uses_Aws_If_Arguments_Are_Included() [Fact] public async Task Ghes_With_Both_Azure_Storage_Connection_String_And_Aws_Bucket_Name_Throws() { - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs { @@ -1387,7 +1387,7 @@ await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs [Fact] public async Task Ghes_When_Aws_Bucket_Name_Is_Provided_But_No_Aws_Access_Key_Id_Throws() { - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs { @@ -1407,7 +1407,7 @@ await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs [Fact] public async Task Ghes_When_Aws_Bucket_Name_Is_Provided_But_No_Aws_Secret_Key_Throws() { - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs { @@ -1427,7 +1427,7 @@ await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs [Fact] public async Task Ghes_When_Aws_Bucket_Name_Is_Provided_But_No_Aws_Region_Throws() { - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs { @@ -1449,7 +1449,7 @@ await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs [Fact] public async Task Ghes_When_Aws_Bucket_Name_Not_Provided_But_Aws_Access_Key_Provided() { - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs { @@ -1469,7 +1469,7 @@ await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs [Fact] public async Task Ghes_When_Aws_Bucket_Name_Not_Provided_But_Aws_Secret_Key_Provided() { - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs { @@ -1489,7 +1489,7 @@ await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs [Fact] public async Task Ghes_When_Aws_Bucket_Name_Not_Provided_But_Aws_Session_Token_Provided() { - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs { @@ -1509,7 +1509,7 @@ await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs [Fact] public async Task Ghes_When_Aws_Bucket_Name_Not_Provided_But_Aws_Region_Provided() { - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs { @@ -1581,7 +1581,7 @@ public async Task Keep_Archive_Does_Not_Call_DeleteIfExists() _mockEnvironmentVariableProvider.Setup(m => m.SourceGithubPersonalAccessToken(It.IsAny())).Returns(sourceGithubPat); _mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny())).Returns(targetGithubPat); - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL, false)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); var args = new MigrateRepoCommandArgs { diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs index 5cc2ac3d..fc2f5ec1 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs @@ -94,7 +94,7 @@ private async Task GenerateSequentialGithubScript(IEnumerable<(string Na content.AppendLine(VALIDATE_GH_PAT); - if (await _ghesVersionChecker.AreBlobCredentialsRequired(ghesApiUrl, useGithubStorage)) + if (await _ghesVersionChecker.AreBlobCredentialsRequired(ghesApiUrl)) { if (awsBucketName.HasValue() || awsRegion.HasValue()) { @@ -132,7 +132,7 @@ private async Task GenerateParallelGithubScript(IEnumerable<(string Name content.AppendLine(EXEC_AND_GET_MIGRATION_ID_FUNCTION_BLOCK); content.AppendLine(VALIDATE_GH_PAT); - if (await _ghesVersionChecker.AreBlobCredentialsRequired(ghesApiUrl, useGithubStorage)) + if (await _ghesVersionChecker.AreBlobCredentialsRequired(ghesApiUrl)) { if (awsBucketName.HasValue() || awsRegion.HasValue()) { diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs index afb5fd41..0392b545 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs @@ -64,7 +64,7 @@ public async Task Handle(MigrateRepoCommandArgs args) _log.LogInformation("Migrating Repo..."); - var blobCredentialsRequired = await _ghesVersionChecker.AreBlobCredentialsRequired(args.GhesApiUrl, args.UseGithubStorage); + var blobCredentialsRequired = await _ghesVersionChecker.AreBlobCredentialsRequired(args.GhesApiUrl); if (args.GhesApiUrl.HasValue()) { diff --git a/src/gei/Services/GhesVersionChecker.cs b/src/gei/Services/GhesVersionChecker.cs index 5f1a0b3d..61550913 100644 --- a/src/gei/Services/GhesVersionChecker.cs +++ b/src/gei/Services/GhesVersionChecker.cs @@ -16,14 +16,10 @@ public GhesVersionChecker(OctoLogger log, GithubApi githubApi) _githubApi = githubApi; } - public virtual async Task AreBlobCredentialsRequired(string ghesApiUrl, bool useGithubStorage = false) + public virtual async Task AreBlobCredentialsRequired(string ghesApiUrl) { var blobCredentialsRequired = false; - if (useGithubStorage) - { - return true; - } if (ghesApiUrl.HasValue()) { From 996dd417fe7af61aca23bc15b572f7edf6dd1bae Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Tue, 12 Nov 2024 12:56:41 -0600 Subject: [PATCH 03/16] Add additional logic back in --- src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs index 0392b545..1827992e 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs @@ -64,7 +64,7 @@ public async Task Handle(MigrateRepoCommandArgs args) _log.LogInformation("Migrating Repo..."); - var blobCredentialsRequired = await _ghesVersionChecker.AreBlobCredentialsRequired(args.GhesApiUrl); + var blobCredentialsRequired = !args.UseGithubStorage || (await _ghesVersionChecker.AreBlobCredentialsRequired(args.GhesApiUrl)); if (args.GhesApiUrl.HasValue()) { From e42723d9e0493db344dfbf09eb6d23676625536a Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Tue, 12 Nov 2024 13:23:10 -0600 Subject: [PATCH 04/16] CLean up --- .../Commands/GenerateScript/GenerateScriptCommandHandler.cs | 4 ++-- src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs index fc2f5ec1..250bbe3a 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs @@ -94,7 +94,7 @@ private async Task GenerateSequentialGithubScript(IEnumerable<(string Na content.AppendLine(VALIDATE_GH_PAT); - if (await _ghesVersionChecker.AreBlobCredentialsRequired(ghesApiUrl)) + if (!useGithubStorage && await _ghesVersionChecker.AreBlobCredentialsRequired(ghesApiUrl)) { if (awsBucketName.HasValue() || awsRegion.HasValue()) { @@ -132,7 +132,7 @@ private async Task GenerateParallelGithubScript(IEnumerable<(string Name content.AppendLine(EXEC_AND_GET_MIGRATION_ID_FUNCTION_BLOCK); content.AppendLine(VALIDATE_GH_PAT); - if (await _ghesVersionChecker.AreBlobCredentialsRequired(ghesApiUrl)) + if (!useGithubStorage && await _ghesVersionChecker.AreBlobCredentialsRequired(ghesApiUrl)) { if (awsBucketName.HasValue() || awsRegion.HasValue()) { diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs index 1827992e..10eed4bd 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs @@ -396,7 +396,7 @@ private void ValidateGHESOptions(MigrateRepoCommandArgs args, bool cloudCredenti if (args.UseGithubStorage) { - _log.LogWarning("Ignoring --use-github-storage flag because you are running GitHub Enterprise Server (GHES) 3.8.0 or later. The blob storage credentials configured in your GHES Management Console will be used instead."); + _log.LogWarning("Provding the --use-github-storage flag will supersede any credentials you have configured in your GitHub Enterprise Server (GHES) Management Console."); } if (args.KeepArchive) From 57f53cd87da2fe299caf08c2090b2c63495a1dcf Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Tue, 12 Nov 2024 15:53:18 -0600 Subject: [PATCH 05/16] Update src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs Co-authored-by: Arin Ghazarian --- src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs index 250bbe3a..c7c150bf 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs @@ -101,7 +101,6 @@ private async Task GenerateSequentialGithubScript(IEnumerable<(string Na content.AppendLine(VALIDATE_AWS_ACCESS_KEY_ID); content.AppendLine(VALIDATE_AWS_SECRET_ACCESS_KEY); } - else if (!useGithubStorage) { content.AppendLine(VALIDATE_AZURE_STORAGE_CONNECTION_STRING); } From 73d3717b1d8b0734425ce36359c829ec2cdeee0a Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Tue, 12 Nov 2024 15:53:26 -0600 Subject: [PATCH 06/16] Update src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs Co-authored-by: Arin Ghazarian --- src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs index c7c150bf..63a57469 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs @@ -138,7 +138,6 @@ private async Task GenerateParallelGithubScript(IEnumerable<(string Name content.AppendLine(VALIDATE_AWS_ACCESS_KEY_ID); content.AppendLine(VALIDATE_AWS_SECRET_ACCESS_KEY); } - else if (!useGithubStorage) { content.AppendLine(VALIDATE_AZURE_STORAGE_CONNECTION_STRING); } From c40eb8fc10a297f26cc969b3a3202ade733f1a91 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Tue, 12 Nov 2024 15:56:39 -0600 Subject: [PATCH 07/16] Update src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs Co-authored-by: Arin Ghazarian --- src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs index 10eed4bd..3e26145a 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs @@ -64,7 +64,7 @@ public async Task Handle(MigrateRepoCommandArgs args) _log.LogInformation("Migrating Repo..."); - var blobCredentialsRequired = !args.UseGithubStorage || (await _ghesVersionChecker.AreBlobCredentialsRequired(args.GhesApiUrl)); + var blobCredentialsRequired = await _ghesVersionChecker.AreBlobCredentialsRequired(args.GhesApiUrl); if (args.GhesApiUrl.HasValue()) { From df9e0dc20cd9dc05f5009b9625bac327a005f774 Mon Sep 17 00:00:00 2001 From: Arin Ghazarian Date: Tue, 12 Nov 2024 14:07:33 -0800 Subject: [PATCH 08/16] Fix build error --- src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs index 63a57469..d0d405ab 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandHandler.cs @@ -101,6 +101,7 @@ private async Task GenerateSequentialGithubScript(IEnumerable<(string Na content.AppendLine(VALIDATE_AWS_ACCESS_KEY_ID); content.AppendLine(VALIDATE_AWS_SECRET_ACCESS_KEY); } + else { content.AppendLine(VALIDATE_AZURE_STORAGE_CONNECTION_STRING); } @@ -138,6 +139,7 @@ private async Task GenerateParallelGithubScript(IEnumerable<(string Name content.AppendLine(VALIDATE_AWS_ACCESS_KEY_ID); content.AppendLine(VALIDATE_AWS_SECRET_ACCESS_KEY); } + else { content.AppendLine(VALIDATE_AZURE_STORAGE_CONNECTION_STRING); } From 8b96c4a282ac6c68c6a2a4a1f8e57286b757ec24 Mon Sep 17 00:00:00 2001 From: Arin Ghazarian Date: Tue, 12 Nov 2024 14:18:37 -0800 Subject: [PATCH 09/16] Add the missing namespace --- .../Octoshift/Services/ArchiveUploadersTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OctoshiftCLI.Tests/Octoshift/Services/ArchiveUploadersTests.cs b/src/OctoshiftCLI.Tests/Octoshift/Services/ArchiveUploadersTests.cs index 0ed1eba7..ebcd5904 100644 --- a/src/OctoshiftCLI.Tests/Octoshift/Services/ArchiveUploadersTests.cs +++ b/src/OctoshiftCLI.Tests/Octoshift/Services/ArchiveUploadersTests.cs @@ -7,9 +7,10 @@ using Moq; using OctoshiftCLI.Extensions; using OctoshiftCLI.Services; -using OctoshiftCLI.Tests; using Xunit; +namespace OctoshiftCLI.Tests.Octoshift.Services; + public class ArchiveUploaderTests { private readonly Mock _githubClientMock; From 0f8aa984d756b96b188ffdb95fc9e74618f2434d Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Tue, 12 Nov 2024 15:02:57 -0600 Subject: [PATCH 10/16] Update github owned storage conditional check --- src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs index 3e26145a..7d4210ae 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs @@ -221,7 +221,7 @@ private string ExtractGhesBaseUrl(string ghesApiUrl) var (gitArchiveUrl, metadataArchiveUrl, gitArchiveId, metadataArchiveId) = await _retryPolicy.Retry( async () => await GenerateArchive(githubSourceOrg, sourceRepo, skipReleases, lockSourceRepo)); - if (!blobCredentialsRequired) + if (!useGithubStorage && !blobCredentialsRequired) { return (gitArchiveUrl, metadataArchiveUrl); } From 66b9ca771b0f7293062939c83c8477ba92ee32b2 Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Tue, 12 Nov 2024 15:09:56 -0600 Subject: [PATCH 11/16] Add conditional --- src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs index 7d4210ae..7d2f3e76 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs @@ -116,7 +116,7 @@ public async Task Handle(MigrateRepoCommandArgs args) args.UseGithubStorage ); - if (blobCredentialsRequired) + if (args.UseGithubStorage && blobCredentialsRequired) { _log.LogInformation("Archives uploaded to blob storage, now starting migration..."); } From 4bce2ef2ba5ff512daa488edd5be45967153bbdb Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Wed, 13 Nov 2024 11:10:06 -0600 Subject: [PATCH 12/16] Update src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs Co-authored-by: Arin Ghazarian --- src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs index 7d2f3e76..faf447b0 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs @@ -116,7 +116,7 @@ public async Task Handle(MigrateRepoCommandArgs args) args.UseGithubStorage ); - if (args.UseGithubStorage && blobCredentialsRequired) + if (args.UseGithubStorage || blobCredentialsRequired) { _log.LogInformation("Archives uploaded to blob storage, now starting migration..."); } From 5683e20c84642f25af5cf61c2100293f2afdc8c3 Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Wed, 13 Nov 2024 10:04:09 -0600 Subject: [PATCH 13/16] Add unit test --- .../MigrateRepoCommandHandlerTests.cs | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs index f6d557bb..313bd97c 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs @@ -1632,5 +1632,107 @@ public async Task Sets_Target_Repo_Visibility() targetRepoVisibility, It.IsAny())); } + [Fact] + public async Task GenerateAndUploadArchive_UsesGithubStorage_When_UseGithubStorageIsTrue_And_BlobCredentialsRequiredIsFalse() + { + var githubOrgId = Guid.NewGuid().ToString(); + var githubOrgDatabaseId = Guid.NewGuid().ToString(); + var migrationSourceId = Guid.NewGuid().ToString(); + var sourceGithubPat = Guid.NewGuid().ToString(); + var targetGithubPat = Guid.NewGuid().ToString(); + var githubRepoUrl = $"https://myghes/{SOURCE_ORG}/{SOURCE_REPO}"; + var migrationId = "valid-migration-id"; // Ensure a valid migration ID is returned + var gitArchiveId = 1; + var metadataArchiveId = 2; + var gitArchiveUrl = $"https://example.com/{gitArchiveId}"; + var metadataArchiveUrl = $"https://example.com/{metadataArchiveId}"; + var uploadedGitArchiveUrl = "gei://archive/1"; + var uploadedMetadataArchiveUrl = "gei://archive/2"; + var gitArchiveFilePath = "./gitdata_archive"; + var metadataArchiveFilePath = "./metadata_archive"; + var gitArchiveDownloadFilePath = "git_archive_downaloded.tmp"; + var metadataArchiveDownloadFilePath = "metadata_archive_downloaded.tmp"; + + File.WriteAllText(gitArchiveFilePath, "I am git archive"); + File.WriteAllText(metadataArchiveFilePath, "I am metadata archive"); + + using var gitContentStream = File.OpenRead(gitArchiveFilePath); + using var metaContentStream = File.OpenRead(metadataArchiveFilePath); + + _mockFileSystemProvider + .SetupSequence(m => m.GetTempFileName()) + .Returns(gitArchiveDownloadFilePath) + .Returns(metadataArchiveDownloadFilePath); + + _mockFileSystemProvider + .Setup(m => m.OpenRead(gitArchiveDownloadFilePath)) + .Returns(gitContentStream); + + _mockFileSystemProvider + .Setup(m => m.OpenRead(metadataArchiveDownloadFilePath)) + .Returns(metaContentStream); + + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(false); + + _mockTargetGithubApi.Setup(x => x.DoesOrgExist(TARGET_ORG).Result).Returns(true); + + _mockTargetGithubApi.Setup(x => x.GetOrganizationId(TARGET_ORG).Result).Returns(githubOrgId); + _mockTargetGithubApi.Setup(x => x.GetOrganizationDatabaseId(TARGET_ORG).Result).Returns(githubOrgDatabaseId); + _mockTargetGithubApi.Setup(x => x.CreateGhecMigrationSource(githubOrgId).Result).Returns(migrationSourceId); + + _mockTargetGithubApi.Setup(x => x.StartMigration( + migrationSourceId, + githubRepoUrl, + githubOrgId, + TARGET_REPO, + sourceGithubPat, + targetGithubPat, + uploadedGitArchiveUrl, + uploadedMetadataArchiveUrl, + false, + null, + false).Result) + .Returns(migrationId); + + _mockTargetGithubApi.Setup(x => x.GetMigration(migrationId).Result) + .Returns((State: RepositoryMigrationStatus.Succeeded, TARGET_REPO, 0, null, null)); + + _mockSourceGithubApi.Setup(x => x.StartGitArchiveGeneration(SOURCE_ORG, SOURCE_REPO).Result).Returns(gitArchiveId); + _mockSourceGithubApi.Setup(x => x.StartMetadataArchiveGeneration(SOURCE_ORG, SOURCE_REPO, false, false).Result).Returns(metadataArchiveId); + _mockSourceGithubApi.Setup(x => x.GetArchiveMigrationStatus(SOURCE_ORG, gitArchiveId).Result).Returns(ArchiveMigrationStatus.Exported); + _mockSourceGithubApi.Setup(x => x.GetArchiveMigrationStatus(SOURCE_ORG, metadataArchiveId).Result).Returns(ArchiveMigrationStatus.Exported); + _mockSourceGithubApi.Setup(x => x.GetArchiveMigrationUrl(SOURCE_ORG, gitArchiveId).Result).Returns(gitArchiveUrl); + _mockSourceGithubApi.Setup(x => x.GetArchiveMigrationUrl(SOURCE_ORG, metadataArchiveId).Result).Returns(metadataArchiveUrl); + + _mockTargetGithubApi + .Setup(x => x.UploadArchiveToGithubStorage(githubOrgDatabaseId, It.Is(a => a.EndsWith("git_archive.tar.gz")), gitContentStream).Result) + .Returns(uploadedGitArchiveUrl); + + _mockTargetGithubApi + .Setup(x => x.UploadArchiveToGithubStorage(githubOrgDatabaseId, It.Is(a => a.EndsWith("metadata_archive.tar.gz")), metaContentStream).Result) + .Returns(uploadedMetadataArchiveUrl); + + Console.WriteLine($"MigrationSourceId: {migrationSourceId}, MigrationId: {migrationId}"); + + var args = new MigrateRepoCommandArgs + { + GithubSourceOrg = SOURCE_ORG, + SourceRepo = SOURCE_REPO, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GithubSourcePat = sourceGithubPat, + GithubTargetPat = targetGithubPat, + TargetApiUrl = TARGET_API_URL, + GhesApiUrl = GHES_API_URL, + UseGithubStorage = true, + }; + + await _handler.Handle(args); + + _mockTargetGithubApi.Verify(x => x.GetMigration(migrationId)); + _mockFileSystemProvider.Verify(x => x.DeleteIfExists(gitArchiveDownloadFilePath), Times.Once); + _mockFileSystemProvider.Verify(x => x.DeleteIfExists(metadataArchiveDownloadFilePath), Times.Once); + } + } } From f4bda36aa4ee971498c3577218dde3c867b00860 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Wed, 13 Nov 2024 15:43:03 -0600 Subject: [PATCH 14/16] Update src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs Co-authored-by: Arin Ghazarian --- .../gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs index 313bd97c..f892c237 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs @@ -1712,7 +1712,6 @@ public async Task GenerateAndUploadArchive_UsesGithubStorage_When_UseGithubStora .Setup(x => x.UploadArchiveToGithubStorage(githubOrgDatabaseId, It.Is(a => a.EndsWith("metadata_archive.tar.gz")), metaContentStream).Result) .Returns(uploadedMetadataArchiveUrl); - Console.WriteLine($"MigrationSourceId: {migrationSourceId}, MigrationId: {migrationId}"); var args = new MigrateRepoCommandArgs { From b4485316607b7b0fe409e69bc3d10fe7b959dd17 Mon Sep 17 00:00:00 2001 From: Begona Guereca Date: Wed, 13 Nov 2024 16:08:33 -0600 Subject: [PATCH 15/16] Update src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs Co-authored-by: Dylan Smith --- src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs index faf447b0..0eb1acc2 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs @@ -396,7 +396,7 @@ private void ValidateGHESOptions(MigrateRepoCommandArgs args, bool cloudCredenti if (args.UseGithubStorage) { - _log.LogWarning("Provding the --use-github-storage flag will supersede any credentials you have configured in your GitHub Enterprise Server (GHES) Management Console."); + _log.LogWarning("Providing the --use-github-storage flag will supersede any credentials you have configured in your GitHub Enterprise Server (GHES) Management Console."); } if (args.KeepArchive) From edf8870744709620bc2aa2eb9d1fbf491959c25d Mon Sep 17 00:00:00 2001 From: Arin Ghazarian Date: Wed, 13 Nov 2024 17:52:02 -0800 Subject: [PATCH 16/16] Simplify test by using a Theory instead of a Fact --- .../MigrateRepoCommandHandlerTests.cs | 109 +----------------- 1 file changed, 5 insertions(+), 104 deletions(-) diff --git a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs index f892c237..5f208f75 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs @@ -325,8 +325,10 @@ public async Task Happy_Path_GithubSource_Ghes() _mockFileSystemProvider.Verify(x => x.DeleteIfExists(metadataArchiveFilePath), Times.Once); } - [Fact] - public async Task Happy_Path_UseGithubStorage() + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task Happy_Path_UseGithubStorage(bool useGhesBlobCredentials) { var githubOrgId = Guid.NewGuid().ToString(); var githubOrgDatabaseId = Guid.NewGuid().ToString(); @@ -365,7 +367,7 @@ public async Task Happy_Path_UseGithubStorage() .Setup(m => m.OpenRead(metadataArchiveDownloadFilePath)) .Returns(metaContentStream); - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); + _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(useGhesBlobCredentials); _mockTargetGithubApi.Setup(x => x.DoesOrgExist(TARGET_ORG).Result).Returns(true); @@ -1632,106 +1634,5 @@ public async Task Sets_Target_Repo_Visibility() targetRepoVisibility, It.IsAny())); } - [Fact] - public async Task GenerateAndUploadArchive_UsesGithubStorage_When_UseGithubStorageIsTrue_And_BlobCredentialsRequiredIsFalse() - { - var githubOrgId = Guid.NewGuid().ToString(); - var githubOrgDatabaseId = Guid.NewGuid().ToString(); - var migrationSourceId = Guid.NewGuid().ToString(); - var sourceGithubPat = Guid.NewGuid().ToString(); - var targetGithubPat = Guid.NewGuid().ToString(); - var githubRepoUrl = $"https://myghes/{SOURCE_ORG}/{SOURCE_REPO}"; - var migrationId = "valid-migration-id"; // Ensure a valid migration ID is returned - var gitArchiveId = 1; - var metadataArchiveId = 2; - var gitArchiveUrl = $"https://example.com/{gitArchiveId}"; - var metadataArchiveUrl = $"https://example.com/{metadataArchiveId}"; - var uploadedGitArchiveUrl = "gei://archive/1"; - var uploadedMetadataArchiveUrl = "gei://archive/2"; - var gitArchiveFilePath = "./gitdata_archive"; - var metadataArchiveFilePath = "./metadata_archive"; - var gitArchiveDownloadFilePath = "git_archive_downaloded.tmp"; - var metadataArchiveDownloadFilePath = "metadata_archive_downloaded.tmp"; - - File.WriteAllText(gitArchiveFilePath, "I am git archive"); - File.WriteAllText(metadataArchiveFilePath, "I am metadata archive"); - - using var gitContentStream = File.OpenRead(gitArchiveFilePath); - using var metaContentStream = File.OpenRead(metadataArchiveFilePath); - - _mockFileSystemProvider - .SetupSequence(m => m.GetTempFileName()) - .Returns(gitArchiveDownloadFilePath) - .Returns(metadataArchiveDownloadFilePath); - - _mockFileSystemProvider - .Setup(m => m.OpenRead(gitArchiveDownloadFilePath)) - .Returns(gitContentStream); - - _mockFileSystemProvider - .Setup(m => m.OpenRead(metadataArchiveDownloadFilePath)) - .Returns(metaContentStream); - - _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(false); - - _mockTargetGithubApi.Setup(x => x.DoesOrgExist(TARGET_ORG).Result).Returns(true); - - _mockTargetGithubApi.Setup(x => x.GetOrganizationId(TARGET_ORG).Result).Returns(githubOrgId); - _mockTargetGithubApi.Setup(x => x.GetOrganizationDatabaseId(TARGET_ORG).Result).Returns(githubOrgDatabaseId); - _mockTargetGithubApi.Setup(x => x.CreateGhecMigrationSource(githubOrgId).Result).Returns(migrationSourceId); - - _mockTargetGithubApi.Setup(x => x.StartMigration( - migrationSourceId, - githubRepoUrl, - githubOrgId, - TARGET_REPO, - sourceGithubPat, - targetGithubPat, - uploadedGitArchiveUrl, - uploadedMetadataArchiveUrl, - false, - null, - false).Result) - .Returns(migrationId); - - _mockTargetGithubApi.Setup(x => x.GetMigration(migrationId).Result) - .Returns((State: RepositoryMigrationStatus.Succeeded, TARGET_REPO, 0, null, null)); - - _mockSourceGithubApi.Setup(x => x.StartGitArchiveGeneration(SOURCE_ORG, SOURCE_REPO).Result).Returns(gitArchiveId); - _mockSourceGithubApi.Setup(x => x.StartMetadataArchiveGeneration(SOURCE_ORG, SOURCE_REPO, false, false).Result).Returns(metadataArchiveId); - _mockSourceGithubApi.Setup(x => x.GetArchiveMigrationStatus(SOURCE_ORG, gitArchiveId).Result).Returns(ArchiveMigrationStatus.Exported); - _mockSourceGithubApi.Setup(x => x.GetArchiveMigrationStatus(SOURCE_ORG, metadataArchiveId).Result).Returns(ArchiveMigrationStatus.Exported); - _mockSourceGithubApi.Setup(x => x.GetArchiveMigrationUrl(SOURCE_ORG, gitArchiveId).Result).Returns(gitArchiveUrl); - _mockSourceGithubApi.Setup(x => x.GetArchiveMigrationUrl(SOURCE_ORG, metadataArchiveId).Result).Returns(metadataArchiveUrl); - - _mockTargetGithubApi - .Setup(x => x.UploadArchiveToGithubStorage(githubOrgDatabaseId, It.Is(a => a.EndsWith("git_archive.tar.gz")), gitContentStream).Result) - .Returns(uploadedGitArchiveUrl); - - _mockTargetGithubApi - .Setup(x => x.UploadArchiveToGithubStorage(githubOrgDatabaseId, It.Is(a => a.EndsWith("metadata_archive.tar.gz")), metaContentStream).Result) - .Returns(uploadedMetadataArchiveUrl); - - - var args = new MigrateRepoCommandArgs - { - GithubSourceOrg = SOURCE_ORG, - SourceRepo = SOURCE_REPO, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GithubSourcePat = sourceGithubPat, - GithubTargetPat = targetGithubPat, - TargetApiUrl = TARGET_API_URL, - GhesApiUrl = GHES_API_URL, - UseGithubStorage = true, - }; - - await _handler.Handle(args); - - _mockTargetGithubApi.Verify(x => x.GetMigration(migrationId)); - _mockFileSystemProvider.Verify(x => x.DeleteIfExists(gitArchiveDownloadFilePath), Times.Once); - _mockFileSystemProvider.Verify(x => x.DeleteIfExists(metadataArchiveDownloadFilePath), Times.Once); - } - } }