-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathMigrateRepoCommandArgs.cs
176 lines (145 loc) · 6.24 KB
/
MigrateRepoCommandArgs.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using System.Linq;
using OctoshiftCLI.Commands;
using OctoshiftCLI.Extensions;
using OctoshiftCLI.Services;
namespace OctoshiftCLI.BbsToGithub.Commands.MigrateRepo;
public class MigrateRepoCommandArgs : CommandArgs
{
public string ArchiveUrl { get; set; }
public string ArchivePath { get; set; }
[Secret]
public string AzureStorageConnectionString { get; set; }
public string AwsBucketName { get; set; }
[Secret]
public string AwsAccessKey { get; set; }
[Secret]
public string AwsSecretKey { get; set; }
[Secret]
public string AwsSessionToken { get; set; }
public string AwsRegion { get; set; }
public string GithubOrg { get; set; }
public string GithubRepo { get; set; }
[Secret]
public string GithubPat { get; set; }
public bool QueueOnly { get; set; }
public string TargetRepoVisibility { get; set; }
public string TargetApiUrl { get; set; }
public bool Kerberos { get; set; }
public string BbsServerUrl { get; set; }
public string BbsProject { get; set; }
public string BbsRepo { get; set; }
public string BbsUsername { get; set; }
[Secret]
public string BbsPassword { get; set; }
public string BbsSharedHome { get; set; }
public bool NoSslVerify { get; set; }
public string ArchiveDownloadHost { get; set; }
public string SshUser { get; set; }
public string SshPrivateKey { get; set; }
public int SshPort { get; set; } = 22;
public string SmbUser { get; set; }
[Secret]
public string SmbPassword { get; set; }
public string SmbDomain { get; set; }
public bool KeepArchive { get; set; }
public override void Validate(OctoLogger log)
{
if (!BbsServerUrl.HasValue() && !ArchiveUrl.HasValue() && !ArchivePath.HasValue())
{
throw new OctoshiftCliException("Either --bbs-server-url, --archive-path, or --archive-url must be specified.");
}
if (ArchivePath.HasValue() && ArchiveUrl.HasValue())
{
throw new OctoshiftCliException("Only one of --archive-path or --archive-url can be specified.");
}
if (ShouldGenerateArchive())
{
ValidateGenerateOptions();
ValidateDownloadOptions();
}
else
{
ValidateNoGenerateOptions();
}
if (ShouldUploadArchive())
{
ValidateUploadOptions();
}
if (ShouldImportArchive())
{
ValidateImportOptions();
}
if (SshPort == 7999)
{
log?.LogWarning("--ssh-port is set to 7999, which is the default port that Bitbucket Server and Bitbucket Data Center use for Git operations over SSH. This is probably the wrong value, because --ssh-port should be configured with the SSH port used to manage the server where Bitbucket Server/Bitbucket Data Center is running, not the port used for Git operations over SSH.");
}
}
private void ValidateNoGenerateOptions()
{
if (BbsUsername.HasValue() || BbsPassword.HasValue())
{
throw new OctoshiftCliException("--bbs-username and --bbs-password can only be provided with --bbs-server-url.");
}
if (NoSslVerify)
{
throw new OctoshiftCliException("--no-ssl-verify 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() && !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()
{
if (Kerberos && (BbsUsername.HasValue() || BbsPassword.HasValue()))
{
throw new OctoshiftCliException("--bbs-username and --bbs-password cannot be provided with --kerberos.");
}
if (BbsProject.IsNullOrWhiteSpace() || BbsRepo.IsNullOrWhiteSpace())
{
throw new OctoshiftCliException("Both --bbs-project and --bbs-repo must be provided.");
}
}
private void ValidateDownloadOptions()
{
var sshArgs = new[] { SshUser, SshPrivateKey };
var smbArgs = new[] { SmbUser, SmbPassword };
var shouldUseSsh = sshArgs.Any(arg => arg.HasValue());
var shouldUseSmb = smbArgs.Any(arg => arg.HasValue());
if (shouldUseSsh && shouldUseSmb)
{
throw new OctoshiftCliException("You can't provide both SSH and SMB credentials together.");
}
if (SshUser.HasValue() ^ SshPrivateKey.HasValue())
{
throw new OctoshiftCliException("Both --ssh-user and --ssh-private-key must be specified for SSH download.");
}
if (ArchiveDownloadHost.HasValue() && !shouldUseSsh && !shouldUseSmb)
{
throw new OctoshiftCliException("--archive-download-host can only be provided if SSH or SMB download options are provided.");
}
}
private void ValidateUploadOptions()
{
if (AwsBucketName.IsNullOrWhiteSpace() && new[] { AwsAccessKey, AwsSecretKey, AwsSessionToken, AwsRegion }.Any(x => x.HasValue()))
{
throw new OctoshiftCliException("The AWS S3 bucket name must be provided with --aws-bucket-name if other AWS S3 upload options are set.");
}
}
private void ValidateImportOptions()
{
if (GithubOrg.IsNullOrWhiteSpace())
{
throw new OctoshiftCliException("--github-org must be provided in order to import the Bitbucket archive.");
}
if (GithubRepo.IsNullOrWhiteSpace())
{
throw new OctoshiftCliException("--github-repo must be provided in order to import the Bitbucket archive.");
}
}
}