Skip to content

Commit 20bbba7

Browse files
author
Arin Ghazarian
authored
Merge pull request #1310 from github/accept-archive-paths-with-github-storage-in-gei
Accept archive paths when using GitHub storage
2 parents 5ef3b27 + 3c678c5 commit 20bbba7

File tree

5 files changed

+253
-12
lines changed

5 files changed

+253
-12
lines changed

RELEASENOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
- Add progress report to `gh [gei|bbs2gh] migrate-repo` command when uploading migration archives to Azure Blob or AWS S3
2+
- `gh gei migrate-repo` now allows using either `--ghes-api-url` or archive paths (`--git-archive-path` and `--metadata-archive-path`).

src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,77 @@ public void It_Falls_Back_To_Github_Target_Pat_If_Github_Source_Pat_Is_Not_Provi
5555
}
5656

5757
[Fact]
58-
public void Aws_Bucket_Name_Without_Ghes_Api_Url_Throws()
58+
public void AwsBucketName_Validates_With_GhesApiUrl()
59+
{
60+
var args = new MigrateRepoCommandArgs
61+
{
62+
GithubSourceOrg = SOURCE_ORG,
63+
SourceRepo = SOURCE_REPO,
64+
GithubTargetOrg = TARGET_ORG,
65+
AwsBucketName = AWS_BUCKET_NAME,
66+
GhesApiUrl = GHES_API_URL
67+
};
68+
69+
args.Validate(_mockOctoLogger.Object);
70+
71+
args.TargetRepo.Should().Be(SOURCE_REPO);
72+
}
73+
74+
[Fact]
75+
public void AwsBucketName_Validates_With_ArchivePaths()
76+
{
77+
var args = new MigrateRepoCommandArgs
78+
{
79+
GithubSourceOrg = SOURCE_ORG,
80+
SourceRepo = SOURCE_REPO,
81+
GithubTargetOrg = TARGET_ORG,
82+
AwsBucketName = AWS_BUCKET_NAME,
83+
GitArchivePath = GIT_ARCHIVE_PATH,
84+
MetadataArchivePath = METADATA_ARCHIVE_PATH
85+
};
86+
87+
args.Validate(_mockOctoLogger.Object);
88+
89+
args.TargetRepo.Should().Be(SOURCE_REPO);
90+
}
91+
92+
[Fact]
93+
public void UseGithubStorage_Validates_With_GhesApiUrl()
94+
{
95+
var args = new MigrateRepoCommandArgs
96+
{
97+
GithubSourceOrg = SOURCE_ORG,
98+
SourceRepo = SOURCE_REPO,
99+
GithubTargetOrg = TARGET_ORG,
100+
GhesApiUrl = GHES_API_URL,
101+
UseGithubStorage = true
102+
};
103+
104+
args.Validate(_mockOctoLogger.Object);
105+
106+
args.TargetRepo.Should().Be(SOURCE_REPO);
107+
}
108+
109+
[Fact]
110+
public void UseGithubStorage_Validates_With_ArchivePaths()
111+
{
112+
var args = new MigrateRepoCommandArgs
113+
{
114+
GithubSourceOrg = SOURCE_ORG,
115+
SourceRepo = SOURCE_REPO,
116+
GithubTargetOrg = TARGET_ORG,
117+
GitArchivePath = GIT_ARCHIVE_PATH,
118+
MetadataArchivePath = METADATA_ARCHIVE_PATH,
119+
UseGithubStorage = true
120+
};
121+
122+
args.Validate(_mockOctoLogger.Object);
123+
124+
args.TargetRepo.Should().Be(SOURCE_REPO);
125+
}
126+
127+
[Fact]
128+
public void Aws_Bucket_Name_Without_GhesApiUrl_Or_ArchivePaths_Throws()
59129
{
60130
var args = new MigrateRepoCommandArgs
61131
{
@@ -73,7 +143,7 @@ public void Aws_Bucket_Name_Without_Ghes_Api_Url_Throws()
73143
}
74144

75145
[Fact]
76-
public void UseGithubStorage_Without_Ghes_Api_Url_Throws()
146+
public void UseGithubStorage_Without_GhesApiUrl_Or_ArchivePaths_Throws()
77147
{
78148
var args = new MigrateRepoCommandArgs
79149
{

src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,175 @@ await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
15101510
.WithMessage("*AWS S3*--aws-bucket-name*");
15111511
}
15121512

1513+
[Fact]
1514+
public async Task GitArchivePath_With_Both_Azure_Storage_Connection_String_And_Aws_Bucket_Name_Throws()
1515+
{
1516+
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);
1517+
1518+
await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
1519+
{
1520+
SourceRepo = SOURCE_REPO,
1521+
GithubSourceOrg = SOURCE_ORG,
1522+
GithubTargetOrg = TARGET_ORG,
1523+
TargetRepo = TARGET_REPO,
1524+
GitArchivePath = GIT_ARCHIVE_FILE_PATH,
1525+
MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH,
1526+
AzureStorageConnectionString = AZURE_CONNECTION_STRING,
1527+
AwsBucketName = AWS_BUCKET_NAME
1528+
}))
1529+
.Should()
1530+
.ThrowAsync<OctoshiftCliException>();
1531+
}
1532+
1533+
[Fact]
1534+
public async Task GitArchivePath_When_Aws_Bucket_Name_Is_Provided_But_No_Aws_Access_Key_Id_Throws()
1535+
{
1536+
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);
1537+
1538+
await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
1539+
{
1540+
SourceRepo = SOURCE_REPO,
1541+
GithubSourceOrg = SOURCE_ORG,
1542+
GithubTargetOrg = TARGET_ORG,
1543+
TargetRepo = TARGET_REPO,
1544+
GitArchivePath = GIT_ARCHIVE_FILE_PATH,
1545+
MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH,
1546+
AwsBucketName = AWS_BUCKET_NAME,
1547+
AwsSecretKey = AWS_SECRET_ACCESS_KEY
1548+
}))
1549+
.Should()
1550+
.ThrowAsync<OctoshiftCliException>()
1551+
.WithMessage("*--aws-access-key*");
1552+
}
1553+
1554+
[Fact]
1555+
public async Task GitArchivePath_When_Aws_Bucket_Name_Is_Provided_But_No_Aws_Secret_Key_Throws()
1556+
{
1557+
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);
1558+
1559+
await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
1560+
{
1561+
SourceRepo = SOURCE_REPO,
1562+
GithubSourceOrg = SOURCE_ORG,
1563+
GithubTargetOrg = TARGET_ORG,
1564+
TargetRepo = TARGET_REPO,
1565+
GitArchivePath = GIT_ARCHIVE_FILE_PATH,
1566+
MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH,
1567+
AwsBucketName = AWS_BUCKET_NAME,
1568+
AwsAccessKey = AWS_ACCESS_KEY_ID
1569+
}))
1570+
.Should()
1571+
.ThrowAsync<OctoshiftCliException>()
1572+
.WithMessage("*--aws-secret-key*");
1573+
}
1574+
1575+
[Fact]
1576+
public async Task GitArchivePath_When_Aws_Bucket_Name_Is_Provided_But_No_Aws_Region_Throws()
1577+
{
1578+
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);
1579+
1580+
await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
1581+
{
1582+
SourceRepo = SOURCE_REPO,
1583+
GithubSourceOrg = SOURCE_ORG,
1584+
GithubTargetOrg = TARGET_ORG,
1585+
TargetRepo = TARGET_REPO,
1586+
GitArchivePath = GIT_ARCHIVE_FILE_PATH,
1587+
MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH,
1588+
AwsBucketName = AWS_BUCKET_NAME,
1589+
AwsAccessKey = AWS_ACCESS_KEY_ID,
1590+
AwsSecretKey = AWS_SECRET_ACCESS_KEY,
1591+
AwsSessionToken = AWS_SESSION_TOKEN
1592+
}))
1593+
.Should()
1594+
.ThrowAsync<OctoshiftCliException>()
1595+
.WithMessage("Either --aws-region or AWS_REGION environment variable must be set.");
1596+
}
1597+
1598+
[Fact]
1599+
public async Task GitArchivePath_When_Aws_Bucket_Name_Not_Provided_But_Aws_Access_Key_Provided()
1600+
{
1601+
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);
1602+
1603+
await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
1604+
{
1605+
SourceRepo = SOURCE_REPO,
1606+
GithubSourceOrg = SOURCE_ORG,
1607+
GithubTargetOrg = TARGET_ORG,
1608+
TargetRepo = TARGET_REPO,
1609+
GitArchivePath = GIT_ARCHIVE_FILE_PATH,
1610+
MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH,
1611+
AzureStorageConnectionString = AZURE_CONNECTION_STRING,
1612+
AwsAccessKey = AWS_ACCESS_KEY_ID
1613+
}))
1614+
.Should()
1615+
.ThrowAsync<OctoshiftCliException>()
1616+
.WithMessage("*AWS S3*--aws-bucket-name*");
1617+
}
1618+
1619+
[Fact]
1620+
public async Task GitArchivePath_When_Aws_Bucket_Name_Not_Provided_But_Aws_Secret_Key_Provided()
1621+
{
1622+
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);
1623+
1624+
await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
1625+
{
1626+
SourceRepo = SOURCE_REPO,
1627+
GithubSourceOrg = SOURCE_ORG,
1628+
GithubTargetOrg = TARGET_ORG,
1629+
TargetRepo = TARGET_REPO,
1630+
GitArchivePath = GIT_ARCHIVE_FILE_PATH,
1631+
MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH,
1632+
AzureStorageConnectionString = AZURE_CONNECTION_STRING,
1633+
AwsSecretKey = AWS_SECRET_ACCESS_KEY
1634+
}))
1635+
.Should()
1636+
.ThrowAsync<OctoshiftCliException>()
1637+
.WithMessage("*AWS S3*--aws-bucket-name*");
1638+
}
1639+
1640+
[Fact]
1641+
public async Task GitArchivePath_When_Aws_Bucket_Name_Not_Provided_But_Aws_Session_Token_Provided()
1642+
{
1643+
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);
1644+
1645+
await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
1646+
{
1647+
SourceRepo = SOURCE_REPO,
1648+
GithubSourceOrg = SOURCE_ORG,
1649+
GithubTargetOrg = TARGET_ORG,
1650+
TargetRepo = TARGET_REPO,
1651+
GitArchivePath = GIT_ARCHIVE_FILE_PATH,
1652+
MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH,
1653+
AzureStorageConnectionString = AZURE_CONNECTION_STRING,
1654+
AwsSessionToken = AWS_SECRET_ACCESS_KEY
1655+
}))
1656+
.Should()
1657+
.ThrowAsync<OctoshiftCliException>()
1658+
.WithMessage("*AWS S3*--aws-bucket-name*");
1659+
}
1660+
1661+
[Fact]
1662+
public async Task GitArchivePath_When_Aws_Bucket_Name_Not_Provided_But_Aws_Region_Provided()
1663+
{
1664+
_mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true);
1665+
1666+
await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs
1667+
{
1668+
SourceRepo = SOURCE_REPO,
1669+
GithubSourceOrg = SOURCE_ORG,
1670+
GithubTargetOrg = TARGET_ORG,
1671+
TargetRepo = TARGET_REPO,
1672+
GitArchivePath = GIT_ARCHIVE_FILE_PATH,
1673+
MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH,
1674+
AzureStorageConnectionString = AZURE_CONNECTION_STRING,
1675+
AwsRegion = AWS_REGION
1676+
}))
1677+
.Should()
1678+
.ThrowAsync<OctoshiftCliException>()
1679+
.WithMessage("*AWS S3*--aws-bucket-name*");
1680+
}
1681+
15131682
[Fact]
15141683
public async Task Keep_Archive_Does_Not_Call_DeleteIfExists()
15151684
{

src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,14 @@ public override void Validate(OctoLogger log)
6565

6666
if (GhesApiUrl.IsNullOrWhiteSpace())
6767
{
68-
if (AwsBucketName.HasValue())
68+
if (AwsBucketName.HasValue() && GitArchivePath.IsNullOrWhiteSpace())
6969
{
70-
throw new OctoshiftCliException("--ghes-api-url must be specified when --aws-bucket-name is specified.");
70+
throw new OctoshiftCliException("When using --aws-bucket-name, you must provide --ghes-api-url, or --git-archive-path and --metadata-archive-path");
71+
}
72+
73+
if (UseGithubStorage && GitArchivePath.IsNullOrWhiteSpace())
74+
{
75+
throw new OctoshiftCliException("When using --use-github-storage, you must provide --ghes-api-url, or --git-archive-path and --metadata-archive-path");
7176
}
7277

7378
if (NoSslVerify)
@@ -79,10 +84,6 @@ public override void Validate(OctoLogger log)
7984
{
8085
throw new OctoshiftCliException("--ghes-api-url must be specified when --keep-archive is specified.");
8186
}
82-
if (UseGithubStorage)
83-
{
84-
throw new OctoshiftCliException("--ghes-api-url must be specified when --use-github-storage is specified.");
85-
}
8687
}
8788

8889
if (AwsBucketName.HasValue() && UseGithubStorage)

src/gei/Commands/MigrateRepo/MigrateRepoCommandHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ public async Task Handle(MigrateRepoCommandArgs args)
6565

6666
_log.LogInformation("Migrating Repo...");
6767

68-
var blobCredentialsRequired = await _ghesVersionChecker.AreBlobCredentialsRequired(args.GhesApiUrl);
68+
var blobCredentialsRequired = args.GitArchivePath.HasValue() || await _ghesVersionChecker.AreBlobCredentialsRequired(args.GhesApiUrl);
6969

70-
if (args.GhesApiUrl.HasValue())
70+
if (args.GhesApiUrl.HasValue() || args.GitArchivePath.HasValue())
7171
{
72-
ValidateGHESOptions(args, blobCredentialsRequired);
72+
ValidateUploadOptions(args, blobCredentialsRequired);
7373
}
7474

7575
if (args.GhesApiUrl.HasValue())
@@ -402,7 +402,7 @@ private async Task<string> WaitForArchiveGeneration(GithubApi githubApi, string
402402

403403
private string GetGithubRepoUrl(string org, string repo, string baseUrl) => $"{baseUrl ?? DEFAULT_GITHUB_BASE_URL}/{org.EscapeDataString()}/{repo.EscapeDataString()}";
404404

405-
private void ValidateGHESOptions(MigrateRepoCommandArgs args, bool cloudCredentialsRequired)
405+
private void ValidateUploadOptions(MigrateRepoCommandArgs args, bool cloudCredentialsRequired)
406406
{
407407
var shouldUseAzureStorage = GetAzureStorageConnectionString(args).HasValue();
408408
var shouldUseAwsS3 = args.AwsBucketName.HasValue();

0 commit comments

Comments
 (0)