Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PART 2:use-github-storage option validation #1270

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class MigrateRepoCommandArgsTests
private const string AWS_SESSION_TOKEN = "aws-session-token";
private const string AWS_REGION = "aws-region";
private const string AZURE_STORAGE_CONNECTION_STRING = "azure-storage-connection-string";

private const string AWS_BUCKET_NAME = "aws-bucket-name";
private const string BBS_HOST = "our-bbs-server.com";
private const string BBS_SERVER_URL = $"https://{BBS_HOST}";
private const string BBS_USERNAME = "bbs-username";
Expand Down Expand Up @@ -70,6 +70,44 @@ public void It_Throws_When_Aws_Bucket_Name_Not_Provided_But_Aws_Access_Key_Provi
.WithMessage("*AWS S3*--aws-bucket-name*");
}

[Fact]
public void It_Throws_When_Aws_Bucket_Name_Provided_With_UseGithubStorage_Option()
{
var args = new MigrateRepoCommandArgs
{
ArchivePath = ARCHIVE_PATH,
GithubOrg = GITHUB_ORG,
GithubRepo = GITHUB_REPO,
AzureStorageConnectionString = AZURE_STORAGE_CONNECTION_STRING,
begonaguereca marked this conversation as resolved.
Show resolved Hide resolved
AwsBucketName = AWS_BUCKET_NAME,
UseGithubStorage = true
};

args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--use-github-storage flag was provided with an AWS S3 Bucket name*");
}

[Fact]
public void It_Throws_When_Aws_Bucket_Name_Provided_With_AzureStorageConnectionString_Option()
{
var args = new MigrateRepoCommandArgs
{
ArchivePath = ARCHIVE_PATH,
GithubOrg = GITHUB_ORG,
GithubRepo = GITHUB_REPO,
AzureStorageConnectionString = AZURE_STORAGE_CONNECTION_STRING,
AwsBucketName = AWS_BUCKET_NAME,
UseGithubStorage = true
};

args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--use-github-storage flag was provided with a connection string for an Azure storage account*");
}

[Fact]
public void It_Throws_When_Aws_Bucket_Name_Not_Provided_But_Aws_Secret_Key_Provided()
{
Expand Down Expand Up @@ -186,25 +224,6 @@ public void It_Throws_When_Kerberos_Is_Set_And_Bbs_Username_Is_Provided()
.WithMessage("*--bbs-username*--kerberos*");
}

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

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

[Fact]
public void Errors_If_BbsServer_Url_Not_Provided_But_Bbs_Password_Is_Provided()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class MigrateRepoCommandArgsTests
private const string TARGET_REPO = "foo-target-repo";
private const string GITHUB_TARGET_PAT = "github-target-pat";
private const string AWS_BUCKET_NAME = "aws-bucket-name";
private const string GHES_API_URL = "foo-ghes-api.com";

[Fact]
public void Defaults_TargetRepo_To_SourceRepo()
Expand Down Expand Up @@ -67,6 +68,62 @@ public void Aws_Bucket_Name_Without_Ghes_Api_Url_Throws()
.WithMessage("*--aws-bucket-name*");
}

[Fact]
public void UseGithubStorage_Without_Ghes_Api_Url_Throws()
{
var args = new MigrateRepoCommandArgs
{
SourceRepo = SOURCE_REPO,
GithubSourceOrg = SOURCE_ORG,
GithubTargetOrg = TARGET_ORG,
TargetRepo = TARGET_REPO,
UseGithubStorage = true
};

FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--use-github-storage*");
}

[Fact]
public void UseGithubStorage_And_Aws_Bucket_Name_Throws()
{
var args = new MigrateRepoCommandArgs
{
SourceRepo = SOURCE_REPO,
GithubSourceOrg = SOURCE_ORG,
GithubTargetOrg = TARGET_ORG,
TargetRepo = TARGET_REPO,
AwsBucketName = AWS_BUCKET_NAME,
GhesApiUrl = GHES_API_URL,
UseGithubStorage = true
};

FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--use-github-storage flag was provided with an AWS S3 Bucket name*");
}

[Fact]
public void It_Throws_When_Aws_Bucket_Name_Provided_With_AzureStorageConnectionString_Option()
{
var args = new MigrateRepoCommandArgs
{
GithubSourceOrg = SOURCE_ORG,
GithubTargetOrg = TARGET_ORG,
TargetRepo = TARGET_REPO,
AwsBucketName = AWS_BUCKET_NAME,
GhesApiUrl = GHES_API_URL,
UseGithubStorage = true
};

args.Invoking(x => x.Validate(_mockOctoLogger.Object))
.Should()
.ThrowExactly<OctoshiftCliException>()
.WithMessage("*--use-github-storage flag was provided with a connection string for an Azure storage account*");
}
[Fact]
public void No_Ssl_Verify_Without_Ghes_Api_Url_Throws()
{
Expand Down
9 changes: 9 additions & 0 deletions src/bbs2gh/Commands/MigrateRepo/MigrateRepoCommandArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class MigrateRepoCommandArgs : CommandArgs
public string SmbDomain { get; set; }

public bool KeepArchive { get; set; }
public bool UseGithubStorage { get; set; }

public override void Validate(OctoLogger log)
{
Expand Down Expand Up @@ -159,6 +160,14 @@ private void ValidateUploadOptions()
{
throw new OctoshiftCliException("The AWS S3 bucket name must be provided with --aws-bucket-name if other AWS S3 upload options are set.");
}
if (UseGithubStorage && AwsBucketName.HasValue())
{
throw new OctoshiftCliException("The --use-github-storage flag was provided with an AWS S3 Bucket name. Archive cannot be uploaded to both locations.");
}
begonaguereca marked this conversation as resolved.
Show resolved Hide resolved
if (AzureStorageConnectionString.HasValue() && UseGithubStorage)
{
throw new OctoshiftCliException("The --use-github-storage flag was provided with a connection string for an Azure storage account. Archive cannot be uploaded to both locations.");
}
}

private void ValidateImportOptions()
Expand Down
15 changes: 15 additions & 0 deletions src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class MigrateRepoCommandArgs : CommandArgs
[Secret]
public string GithubTargetPat { get; set; }
public bool KeepArchive { get; set; }
public bool UseGithubStorage { get; set; }

public override void Validate(OctoLogger log)
{
Expand Down Expand Up @@ -61,6 +62,20 @@ public override void Validate(OctoLogger log)
{
throw new OctoshiftCliException("--ghes-api-url must be specified when --keep-archive is specified.");
}
if (UseGithubStorage)
{
throw new OctoshiftCliException("--ghes-api-url must be specified when --use-github-storage is specified.");
}
}

if (AwsBucketName.HasValue() && UseGithubStorage)
{
throw new OctoshiftCliException("The --use-github-storage flag was provided with an AWS S3 Bucket name. Archive cannot be uploaded to both locations.");
begonaguereca marked this conversation as resolved.
Show resolved Hide resolved
}

if (AzureStorageConnectionString.HasValue() && UseGithubStorage)
{
throw new OctoshiftCliException("The --use-github-storage flag was provided with a connection string for an Azure storage account. Archive cannot be uploaded to both locations.");
}
}

Expand Down