forked from github/gh-gei
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMigrateRepoCommandArgs.cs
More file actions
140 lines (126 loc) · 6 KB
/
Copy pathMigrateRepoCommandArgs.cs
File metadata and controls
140 lines (126 loc) · 6 KB
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
using System;
using OctoshiftCLI.Commands;
using OctoshiftCLI.Extensions;
using OctoshiftCLI.Services;
namespace OctoshiftCLI.GithubEnterpriseImporter.Commands.MigrateRepo
{
public class MigrateRepoCommandArgs : CommandArgs
{
public string GithubSourceOrg { get; set; }
public string SourceRepo { get; set; }
public string GithubTargetOrg { get; set; }
public string TargetRepo { get; set; }
public string TargetApiUrl { get; set; }
public string TargetUploadsUrl { get; set; }
public string GhesApiUrl { 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 bool NoSslVerify { get; set; }
public string GitArchiveUrl { get; set; }
public string MetadataArchiveUrl { get; set; }
public string GitArchivePath { get; set; }
public string MetadataArchivePath { get; set; }
public bool SkipReleases { get; set; }
public bool LockSourceRepo { get; set; }
public bool QueueOnly { get; set; }
public string TargetRepoVisibility { get; set; }
[Secret]
public string GithubSourcePat { get; set; }
[Secret]
public string GithubTargetPat { get; set; }
public bool KeepArchive { get; set; }
public bool UseGithubStorage { get; set; }
public override void Validate(OctoLogger log)
{
DefaultSourcePat(log);
DefaultTargetRepo(log);
if (GitArchiveUrl.HasValue() && GitArchivePath.HasValue())
{
throw new OctoshiftCliException("The options --git-archive-url and --git-archive-path may not be used together");
}
if (MetadataArchiveUrl.HasValue() && MetadataArchivePath.HasValue())
{
throw new OctoshiftCliException("The options --metadata-archive-url and --metadata-archive-path may not be used together");
}
if (string.IsNullOrWhiteSpace(GitArchiveUrl) != string.IsNullOrWhiteSpace(MetadataArchiveUrl))
{
throw new OctoshiftCliException("When using archive urls, you must provide both --git-archive-url --metadata-archive-url");
}
if (string.IsNullOrWhiteSpace(GitArchivePath) != string.IsNullOrWhiteSpace(MetadataArchivePath))
{
throw new OctoshiftCliException("When using archive files, you must provide both --git-archive-path --metadata-archive-path");
}
if (GhesApiUrl.IsNullOrWhiteSpace())
{
if (AwsBucketName.HasValue() && GitArchivePath.IsNullOrWhiteSpace())
{
throw new OctoshiftCliException("When using --aws-bucket-name, you must provide --ghes-api-url, or --git-archive-path and --metadata-archive-path");
}
if (UseGithubStorage && GitArchivePath.IsNullOrWhiteSpace())
{
throw new OctoshiftCliException("When using --use-github-storage, you must provide --ghes-api-url, or --git-archive-path and --metadata-archive-path");
}
if (NoSslVerify)
{
throw new OctoshiftCliException("--ghes-api-url must be specified when --no-ssl-verify is specified.");
}
if (KeepArchive)
{
throw new OctoshiftCliException("--ghes-api-url must be specified when --keep-archive 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.");
}
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.");
}
ValidateNamesAreNotUrls();
}
private void DefaultTargetRepo(OctoLogger log)
{
if (TargetRepo.IsNullOrWhiteSpace())
{
log?.LogInformation($"Target repo name not provided, defaulting to same as source repo ({SourceRepo})");
TargetRepo = SourceRepo;
}
}
private void DefaultSourcePat(OctoLogger log)
{
if (GithubTargetPat.HasValue() && GithubSourcePat.IsNullOrWhiteSpace())
{
GithubSourcePat = GithubTargetPat;
log?.LogInformation("Since github-target-pat is provided, github-source-pat will also use its value.");
}
}
private void ValidateNamesAreNotUrls()
{
if (GithubSourceOrg.HasValue() && Uri.IsWellFormedUriString(GithubSourceOrg, UriKind.Absolute))
{
throw new OctoshiftCliException("GithubSourceOrg should be an org name, not a URL.");
}
if (GithubTargetOrg.HasValue() && Uri.IsWellFormedUriString(GithubTargetOrg, UriKind.Absolute))
{
throw new OctoshiftCliException("GithubTargetOrg should be an org name, not a URL.");
}
if (SourceRepo.HasValue() && Uri.IsWellFormedUriString(SourceRepo, UriKind.Absolute))
{
throw new OctoshiftCliException("SourceRepo should be a repo name, not a URL.");
}
if (TargetRepo.HasValue() && Uri.IsWellFormedUriString(TargetRepo, UriKind.Absolute))
{
throw new OctoshiftCliException("TargetRepo should be a repo name, not a URL.");
}
}
}
}