Skip to content

Remove dependency on Swift-NIO SSL #254

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

Merged
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
9 changes: 0 additions & 9 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ This product contains Swift NIO.

---

This product contains Swift NIO SSL.

* LICENSE (Apache License 2.0):
* https://www.apache.org/licenses/LICENSE-2.0
* HOMEPAGE:
* https://github.com/apple/swift-nio-ssl

---

This product contains Swift Crypto.

* LICENSE (Apache License 2.0):
Expand Down
9 changes: 0 additions & 9 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ let package = Package(
name: "SwiftDocCUtilities",
dependencies: [
"SwiftDocC",
.product(name: "NIOSSL", package: "swift-nio-ssl"),
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "ArgumentParser", package: "swift-argument-parser")
]),
Expand Down Expand Up @@ -115,7 +114,6 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
// Building standalone, so fetch all dependencies remotely.
package.dependencies += [
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMinor(from: "2.31.2")),
.package(url: "https://github.com/apple/swift-nio-ssl.git", .upToNextMinor(from: "2.15.0")),
.package(name: "swift-markdown", url: "https://github.com/apple/swift-markdown.git", .branch("main")),
.package(name: "CLMDB", url: "https://github.com/apple/swift-lmdb.git", .branch("main")),
.package(url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(from: "1.0.1")),
Expand All @@ -133,7 +131,6 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
// Building in the Swift.org CI system, so rely on local versions of dependencies.
package.dependencies += [
.package(path: "../swift-nio"),
.package(path: "../swift-nio-ssl"),
.package(path: "../swift-markdown"),
.package(name: "CLMDB", path: "../swift-lmdb"),
.package(path: "../swift-argument-parser"),
Expand Down
54 changes: 22 additions & 32 deletions Sources/SwiftDocCUtilities/Action/Actions/PreviewAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,12 @@ public final class PreviewAction: Action, RecreatingContext {

var logHandle = LogHandle.standardOutput

let tlsCertificateKey: URL?
let tlsCertificateChain: URL?
let serverUsername: String?
let serverPassword: String?
let port: Int

var convertAction: ConvertAction

public var setupContext: ((inout DocumentationContext) -> Void)?
private var previewPaths: [String] = []
private var runSecure: Bool {
return tlsCertificateKey != nil && tlsCertificateChain != nil
}

// Use for testing to override binding to a system port
var bindServerToSocketPath: String?
Expand All @@ -80,15 +73,7 @@ public final class PreviewAction: Action, RecreatingContext {

/// Creates a new preview action from the given parameters.
///
/// The `tlsCertificateKey`, `tlsCertificateChain`, `serverUsername`, and `serverPassword`
/// parameters are optional, but if you provide one, all four are expected. They are used by the preview server
/// to serve content on the local network over SSL.
///
/// - Parameters:
/// - tlsCertificateKey: The path to the TLS certificate key used by the preview server for SSL configuration.
/// - tlsCertificateChain: The path to the TLS certificate chain used by the preview server for SSL configuration.
/// - serverUsername: The username used by the preview server for HTTP authentication.
/// - serverPassword: The password used by the preview server for HTTP authentication.
/// - port: The port number used by the preview server.
/// - convertAction: The action used to convert the documentation bundle before preview.
/// On macOS, this action will be reused to convert documentation each time the source is modified.
Expand All @@ -98,8 +83,7 @@ public final class PreviewAction: Action, RecreatingContext {
/// is performed.
/// - Throws: If an error is encountered while initializing the documentation context.
public init(
tlsCertificateKey: URL?, tlsCertificateChain: URL?, serverUsername: String?,
serverPassword: String?, port: Int,
port: Int,
createConvertAction: @escaping () throws -> ConvertAction,
workspace: DocumentationWorkspace = DocumentationWorkspace(),
context: DocumentationContext? = nil,
Expand All @@ -110,10 +94,6 @@ public final class PreviewAction: Action, RecreatingContext {
}

// Initialize the action context.
self.tlsCertificateKey = tlsCertificateKey
self.tlsCertificateChain = tlsCertificateChain
self.serverUsername = serverUsername
self.serverPassword = serverPassword
self.port = port
self.createConvertAction = createConvertAction
self.convertAction = try createConvertAction()
Expand All @@ -123,6 +103,24 @@ public final class PreviewAction: Action, RecreatingContext {
self.context = try context ?? DocumentationContext(dataProvider: workspace, diagnosticEngine: engine)
self.printHTMLTemplatePath = printTemplatePath
}

@available(*, deprecated, message: "TLS support has been removed.")
public convenience init(
tlsCertificateKey: URL?, tlsCertificateChain: URL?, serverUsername: String?,
serverPassword: String?, port: Int,
createConvertAction: @escaping () throws -> ConvertAction,
workspace: DocumentationWorkspace = DocumentationWorkspace(),
context: DocumentationContext? = nil,
printTemplatePath: Bool = true) throws
{
try self.init(
port: port,
createConvertAction: createConvertAction,
workspace: workspace,
context: context,
printTemplatePath: printTemplatePath
)
}

/// Converts a documentation bundle and starts a preview server to render the result of that conversion.
///
Expand Down Expand Up @@ -164,20 +162,12 @@ public final class PreviewAction: Action, RecreatingContext {
// Preview the output and monitor the source bundle for changes.
do {
print(String(repeating: "=", count: 40), to: &logHandle)
if runSecure, let serverUsername = serverUsername, let serverPassword = serverPassword {
print("Starting TLS-Enabled Web Server", to: &logHandle)
printPreviewAddresses(base: URL(string: "https://\(ProcessInfo.processInfo.hostName):\(port)")!)
print("\tUsername: \(serverUsername)", to: &logHandle)
print("\tPassword: \(serverPassword)", to: &logHandle)

} else {
print("Starting Local Preview Server", to: &logHandle)
printPreviewAddresses(base: URL(string: "http://localhost:\(port)")!)
}
print("Starting Local Preview Server", to: &logHandle)
printPreviewAddresses(base: URL(string: "http://localhost:\(port)")!)
print(String(repeating: "=", count: 40), to: &logHandle)

let to: PreviewServer.Bind = bindServerToSocketPath.map { .socket(path: $0) } ?? .localhost(port: port)
servers[serverIdentifier] = try PreviewServer(contentURL: convertAction.targetDirectory, bindTo: to, username: serverUsername, password: serverPassword, tlsCertificateChainURL: tlsCertificateChain, tlsCertificateKeyURL: tlsCertificateKey, logHandle: &logHandle)
servers[serverIdentifier] = try PreviewServer(contentURL: convertAction.targetDirectory, bindTo: to, logHandle: &logHandle)

// When the user stops docc - stop the preview server first before exiting.
trapSignals()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ extension PreviewAction {
{
// Initialize the `PreviewAction` from the options provided by the `Preview` command
try self.init(
tlsCertificateKey: previewOptions.externalConnectionOptions.tlsCertificateKeyURL,
tlsCertificateChain: previewOptions.externalConnectionOptions.tlsCertificateChainURL,
serverUsername: previewOptions.externalConnectionOptions.username,
serverPassword: previewOptions.externalConnectionOptions.password,
port: previewOptions.port,
createConvertAction: {
try ConvertAction(
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ public struct PreviewOptions: ParsableArguments {
valueName: "port-number"))
public var port: Int = 8080

/// The options used when configuring the preview server for external connections.
///
/// This group of options is only considered valid if either none of
/// the ``PreviewExternalConnectionOptions/username``, ``PreviewExternalConnectionOptions/password``,
/// ``PreviewExternalConnectionOptions/tlsCertificateChainURL``, ``PreviewExternalConnectionOptions/tlsCertificateKeyURL``
/// values were provided **or** if they all were.
///
/// If the ``PreviewExternalConnectionOptions/externalConnectionsAreEnabled`` Boolean value
/// is true, then **all** four values were provided and validated.
@OptionGroup()
public var externalConnectionOptions: PreviewExternalConnectionOptions

public mutating func validate() throws {
// Check that a valid port has been provided
guard port > 1023 else {
Expand Down
Loading