Skip to content

Commit a9fafbb

Browse files
committed
don’t run the linker plugin in mirror mode
1 parent 72cb7c7 commit a9fafbb

File tree

4 files changed

+46
-26
lines changed

4 files changed

+46
-26
lines changed

Sources/SwiftinitServer/Configurations/Swiftinit.ServerOptions.Mode.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@ extension Swiftinit.ServerOptions
33
enum Mode
44
{
55
case development(Cache<Swiftinit.Asset>, Development)
6-
case production
6+
case production(mirror:Bool)
77
}
88
}
99
extension Swiftinit.ServerOptions.Mode
1010
{
11+
var mirror:Bool
12+
{
13+
switch self
14+
{
15+
case .development: false
16+
case .production(let mirror): mirror
17+
}
18+
}
1119
var secure:Bool
1220
{
1321
switch self

Sources/SwiftinitServer/Configurations/Swiftinit.ServerOptions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension Swiftinit
1515
init(authority:any ServerAuthority,
1616
github:GitHub.Integration? = nil,
1717
bucket:AWS.S3.Bucket? = nil,
18-
mode:Mode = .production)
18+
mode:Mode = .production(mirror: false))
1919
{
2020
self.authority = authority
2121
self.github = github

Sources/SwiftinitServer/Main.swift

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ struct Main
1616
var development:Swiftinit.ServerOptions.Development
1717

1818
var redirect:Bool
19-
/// Whether to enable GitHub integration if access keys are available.
20-
/// Defaults to false.
21-
var github:Bool
19+
var mirror:Bool
2220
var mongo:Mongo.Host
2321

2422
private
@@ -28,7 +26,7 @@ struct Main
2826
self.certificates = "Local/Server/Certificates"
2927
self.development = .init()
3028
self.redirect = false
31-
self.github = false
29+
self.mirror = false
3230
self.mongo = "unidoc-mongod"
3331
}
3432
}
@@ -84,6 +82,9 @@ extension Main
8482
case "--enable-whitelists":
8583
self.development.whitelists = true
8684

85+
case "-q", "--mirror":
86+
self.mirror = true
87+
8788
case "-r", "--redirect":
8889
self.redirect = true
8990

@@ -104,7 +105,9 @@ extension Main
104105
}
105106

106107
case "--enable-github":
107-
self.github = true
108+
Log[.warning] = """
109+
This option is deprecated, GitHub integration is now always enabled.
110+
"""
108111

109112
case "-p", "--port":
110113
guard let port:String = arguments.next()
@@ -155,31 +158,36 @@ extension Main
155158
// configuration.applicationProtocols = ["h2", "http/1.1"]
156159
configuration.applicationProtocols = ["h2"]
157160

158-
var options:Swiftinit.ServerOptions = .init(
159-
authority: self.authority.init(tls: try .init(configuration: configuration)))
161+
let authority:any ServerAuthority = self.authority.init(
162+
tls: try .init(configuration: configuration))
160163

161164
let assets:FilePath = "Assets"
165+
let github:GitHub.Integration?
162166
do
163167
{
164-
options.github = try .load(secrets: assets / "secrets", active: self.github)
168+
github = try .load(secrets: assets / "secrets")
165169
}
166170
catch let error
167171
{
168172
// Temporary workaround for bypassing backtrace collection.
169173
Log[.debug] = "GitHub integration disabled (\(error))"
174+
github = nil
170175
}
171176

172177
if self.authority is Localhost.Type
173178
{
174-
options.mode = .development(.init(source: assets), self.development)
175-
options.bucket = self.development.bucket
179+
return .init(authority: authority,
180+
github: github,
181+
bucket: self.development.bucket,
182+
mode: .development(.init(source: assets), self.development))
176183
}
177184
else
178185
{
179-
options.bucket = .init(region: .us_east_1, name: "symbolgraphs")
186+
return .init(authority: authority,
187+
github: github,
188+
bucket: .init(region: .us_east_1, name: "symbolgraphs"),
189+
mode: .production(mirror: self.mirror))
180190
}
181-
182-
return options
183191
}
184192

185193
private consuming
@@ -222,18 +230,25 @@ extension Main
222230
{
223231
@Sendable (pool:Mongo.SessionPool) in
224232

225-
var plugins:[any Swiftinit.ServerPlugin] =
226-
[
227-
Swiftinit.LinkerPlugin.init(bucket: options.bucket),
228-
]
233+
var plugins:[any Swiftinit.ServerPlugin] = []
229234

230235
if options.whitelists
231236
{
232237
plugins.append(Swiftinit.PolicyPlugin.init())
233238
}
234-
if let github:GitHub.Integration = options.github,
235-
github.active
239+
240+
nonmirror:
241+
if !options.mode.mirror
236242
{
243+
plugins.append(Swiftinit.LinkerPlugin.init(bucket: options.bucket))
244+
245+
guard
246+
let github:GitHub.Integration = options.github
247+
else
248+
{
249+
break nonmirror
250+
}
251+
237252
plugins.append(GitHub.CrawlerPlugin<GitHub.RepoTelescope>.init(
238253
api: github.api,
239254
id: "telescope"))

Sources/SwiftinitServer/Plugins/GitHub.Integration.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ extension GitHub
55
{
66
struct Integration:Sendable
77
{
8-
let active:Bool
98
let oauth:GitHub.OAuth
109
let app:GitHub.App
1110
let pat:String
1211

13-
init(active:Bool, oauth:GitHub.OAuth, app:GitHub.App, pat:String)
12+
init(oauth:GitHub.OAuth, app:GitHub.App, pat:String)
1413
{
15-
self.active = active
1614
self.oauth = oauth
1715
self.app = app
1816
self.pat = pat
@@ -22,10 +20,9 @@ extension GitHub
2220
extension GitHub.Integration
2321
{
2422
static
25-
func load(secrets:FilePath, active:Bool) throws -> Self
23+
func load(secrets:FilePath) throws -> Self
2624
{
2725
.init(
28-
active: active,
2926
oauth: .init(
3027
client: "2378cacaed3ace362867",
3128
secret: try (secrets / "github-oauth-secret").readLine()),

0 commit comments

Comments
 (0)