From 2805a72cf56df8cc38de72179974505fb319f3d0 Mon Sep 17 00:00:00 2001 From: bbsadmin Date: Mon, 4 Nov 2024 12:25:09 -0800 Subject: [PATCH] Code review --- .../GhesToGithub.cs | 45 +++++++++++++------ .../GenerateScriptCommandArgs.cs | 17 ++++++- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs index f96bdd20..9f6efe39 100644 --- a/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs +++ b/src/OctoshiftCLI.IntegrationTests/GhesToGithub.cs @@ -25,9 +25,11 @@ public sealed class GhesToGithub : IDisposable private readonly GithubClient _sourceGithubClient; private readonly GithubApi _sourceGithubApi; private readonly BlobServiceClient _blobServiceClient; - private readonly Dictionary _tokens; private readonly DateTime _startTime; private readonly ArchiveUploader _archiveUploader; + private readonly string _sourceGithubToken; + private readonly string _targetGithubToken; + private readonly string _azureStorageConnectionString; public GhesToGithub(ITestOutputHelper output) { @@ -36,15 +38,9 @@ public GhesToGithub(ITestOutputHelper output) var logger = new OctoLogger(_ => { }, x => _output.WriteLine(x), _ => { }, _ => { }); - var sourceGithubToken = Environment.GetEnvironmentVariable("GHES_PAT"); - var targetGithubToken = Environment.GetEnvironmentVariable("GHEC_PAT"); - var azureStorageConnectionString = Environment.GetEnvironmentVariable($"AZURE_STORAGE_CONNECTION_STRING_GHES_{TestHelper.GetOsName().ToUpper()}"); - _tokens = new Dictionary - { - ["GH_SOURCE_PAT"] = sourceGithubToken, - ["GH_PAT"] = targetGithubToken, - ["AZURE_STORAGE_CONNECTION_STRING"] = azureStorageConnectionString - }; + _sourceGithubToken = Environment.GetEnvironmentVariable("GHES_PAT"); + _targetGithubToken = Environment.GetEnvironmentVariable("GHEC_PAT"); + _azureStorageConnectionString = Environment.GetEnvironmentVariable($"AZURE_STORAGE_CONNECTION_STRING_GHES_{TestHelper.GetOsName().ToUpper()}"); _versionClient = new HttpClient(); _archiveUploader = new ArchiveUploader(_targetGithubClient, logger); @@ -57,7 +53,7 @@ public GhesToGithub(ITestOutputHelper output) _targetGithubClient = new GithubClient(logger, _targetGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), targetGithubToken); _targetGithubApi = new GithubApi(_targetGithubClient, "https://api.github.com", new RetryPolicy(logger), _archiveUploader); - _blobServiceClient = new BlobServiceClient(azureStorageConnectionString); + _blobServiceClient = new BlobServiceClient(_azureStorageConnectionString); _sourceHelper = new TestHelper(_output, _sourceGithubApi, _sourceGithubClient) { GithubApiBaseUrl = GHES_API_URL }; _targetHelper = new TestHelper(_output, _targetGithubApi, _targetGithubClient, _blobServiceClient); @@ -73,11 +69,34 @@ public async Task Basic(bool useGithubStorage) const string repo1 = "repo-1"; const string repo2 = "repo-2"; + var tokens = new Dictionary { }; + + if (useGithubStorage) + { + tokens = new Dictionary + { + ["GH_SOURCE_PAT"] = _sourceGithubToken, + ["GH_PAT"] = _targetGithubToken, + }; + } + else + { + tokens = new Dictionary + { + ["GH_SOURCE_PAT"] = _sourceGithubToken, + ["GH_PAT"] = _targetGithubToken, + ["AZURE_STORAGE_CONNECTION_STRING"] = _azureStorageConnectionString + }; + } + var retryPolicy = new RetryPolicy(null); await retryPolicy.Retry(async () => { - await _targetHelper.ResetBlobContainers(); + if (!useGithubStorage) + { + await _targetHelper.ResetBlobContainers(); + } await _sourceHelper.ResetGithubTestEnvironment(githubSourceOrg); await _targetHelper.ResetGithubTestEnvironment(githubTargetOrg); @@ -93,7 +112,7 @@ await retryPolicy.Retry(async () => command += " --use-github-storage true"; } - await _targetHelper.RunGeiCliMigration(command, _tokens); + await _targetHelper.RunGeiCliMigration(command, tokens); _targetHelper.AssertNoErrorInLogs(_startTime); diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs index 09c1ce75..9123381c 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs @@ -27,9 +27,17 @@ public class GenerateScriptCommandArgs : CommandArgs public override void Validate(OctoLogger log) { - if (AwsBucketName.HasValue() && GhesApiUrl.IsNullOrWhiteSpace()) + if (AwsBucketName.HasValue()) { - throw new OctoshiftCliException("--ghes-api-url must be specified when --aws-bucket-name is specified."); + if (GhesApiUrl.IsNullOrWhiteSpace()) + { + throw new OctoshiftCliException("--ghes-api-url must be specified when --aws-bucket-name is specified."); + } + + if (UseGithubStorage) + { + throw new OctoshiftCliException("The --use-github-storage flag was provided with an AWS S3 Bucket name. Archive cannot be uploaded to both locations."); + } } if (NoSslVerify && GhesApiUrl.IsNullOrWhiteSpace()) @@ -46,6 +54,11 @@ public override void Validate(OctoLogger log) { throw new OctoshiftCliException("--ghes-api-url is invalid. Please check URL before trying again."); } + + if (UseGithubStorage) + { + throw new OctoshiftCliException("--ghes-api-url must be specified when --use-github-storage is specified."); + } } } }