diff --git a/Sources/Deployer/DeploymentDestination.swift b/Sources/Deployer/DeploymentDestination.swift index eee0cfa8..34bcb6a6 100644 --- a/Sources/Deployer/DeploymentDestination.swift +++ b/Sources/Deployer/DeploymentDestination.swift @@ -1,4 +1,5 @@ import Foundation +import PathLib import QueueModels public struct DeploymentDestination: Codable, CustomStringConvertible, Hashable { @@ -7,7 +8,7 @@ public struct DeploymentDestination: Codable, CustomStringConvertible, Hashable public let port: Int32 public let username: String public let authentication: DeploymentDestinationAuthenticationType - public let remoteDeploymentPath: String + public let remoteDeploymentPath: AbsolutePath enum CodingKeys: String, CodingKey { case host @@ -23,14 +24,15 @@ public struct DeploymentDestination: Codable, CustomStringConvertible, Hashable let port = try container.decode(Int32.self, forKey: .port) let username = try container.decode(String.self, forKey: .username) let authentication = try container.decode(DeploymentDestinationAuthenticationType.self, forKey: .authentication) - let remoteDeploymentPath = try container.decode(String.self, forKey: .remoteDeploymentPath) + let remoteDeploymentPath = try container.decode(AbsolutePath.self, forKey: .remoteDeploymentPath) self.init( host: host, port: port, username: username, authentication: authentication, - remoteDeploymentPath: remoteDeploymentPath) + remoteDeploymentPath: remoteDeploymentPath + ) } public init( @@ -38,8 +40,8 @@ public struct DeploymentDestination: Codable, CustomStringConvertible, Hashable port: Int32, username: String, authentication: DeploymentDestinationAuthenticationType, - remoteDeploymentPath: String) - { + remoteDeploymentPath: AbsolutePath + ) { self.workerId = WorkerId(value: host) self.host = host self.port = port diff --git a/Sources/Deployer/DeploymentDestinationAuthenticationType.swift b/Sources/Deployer/DeploymentDestinationAuthenticationType.swift index 30b8ee98..0639ae83 100644 --- a/Sources/Deployer/DeploymentDestinationAuthenticationType.swift +++ b/Sources/Deployer/DeploymentDestinationAuthenticationType.swift @@ -1,8 +1,9 @@ import Foundation +import PathLib public enum DeploymentDestinationAuthenticationType: Codable, CustomStringConvertible, Equatable, Hashable { case password(String) - case key(path: String) + case key(path: AbsolutePath) public var description: String { switch self { @@ -14,25 +15,16 @@ public enum DeploymentDestinationAuthenticationType: Codable, CustomStringConver } private enum CodingKeys: String, CodingKey { - case type case password - case path - } - - private enum AuthType: String, Codable { - case plain - case key + case keyPath } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) - let type = try container.decode(AuthType.self, forKey: .type) - - switch type { - case .plain: + do { self = .password(try container.decode(String.self, forKey: .password)) - case .key: - self = .key(path: try container.decode(String.self, forKey: .path)) + } catch { + self = .key(path: try container.decode(AbsolutePath.self, forKey: .keyPath)) } } @@ -40,11 +32,9 @@ public enum DeploymentDestinationAuthenticationType: Codable, CustomStringConver var container = encoder.container(keyedBy: CodingKeys.self) switch self { case .password(let password): - try container.encode(AuthType.plain, forKey: .type) try container.encode(password, forKey: .password) case .key(let path): - try container.encode(AuthType.key, forKey: .type) - try container.encode(path, forKey: .path) + try container.encode(path, forKey: .keyPath) } } } diff --git a/Sources/SSHDeployer/DefaultSSHClient.swift b/Sources/SSHDeployer/DefaultSSHClient.swift index 6cce99de..f5c9a7c3 100644 --- a/Sources/SSHDeployer/DefaultSSHClient.swift +++ b/Sources/SSHDeployer/DefaultSSHClient.swift @@ -23,7 +23,7 @@ public final class DefaultSSHClient: SSHClient { case .password(let password): try ssh.authenticate(username: username, password: password) case .key(let path): - try ssh.authenticate(username: username, privateKey: path) + try ssh.authenticate(username: username, privateKey: path.pathString) } } diff --git a/Sources/SSHDeployer/SSHDeployer.swift b/Sources/SSHDeployer/SSHDeployer.swift index 95391f43..ac226900 100644 --- a/Sources/SSHDeployer/SSHDeployer.swift +++ b/Sources/SSHDeployer/SSHDeployer.swift @@ -54,8 +54,9 @@ public final class SSHDeployer: Deployer { destination: DeploymentDestination, deploymentId: String ) -> AbsolutePath { - return AbsolutePath(destination.remoteDeploymentPath) - .appending(components: [deploymentId, deployable.name]) + return destination.remoteDeploymentPath.appending( + components: [deploymentId, deployable.name] + ) } public static func remotePath( diff --git a/Tests/DeployerTestHelpers/DeploymentDestinationFixtures.swift b/Tests/DeployerTestHelpers/DeploymentDestinationFixtures.swift index 6f52a035..dde880ff 100644 --- a/Tests/DeployerTestHelpers/DeploymentDestinationFixtures.swift +++ b/Tests/DeployerTestHelpers/DeploymentDestinationFixtures.swift @@ -1,5 +1,6 @@ import Deployer import Foundation +import PathLib public final class DeploymentDestinationFixtures { @@ -7,7 +8,7 @@ public final class DeploymentDestinationFixtures { public var port: Int32 = 42 public var username: String = "user" public var authentication: DeploymentDestinationAuthenticationType = .password("pass") - public var remoteDeploymentPath: String = "/Users/username/path" + public var remoteDeploymentPath = AbsolutePath("/Users/username/path") public init() {} @@ -31,7 +32,7 @@ public final class DeploymentDestinationFixtures { return self } - public func with(remoteDeploymentPath: String) -> DeploymentDestinationFixtures { + public func with(remoteDeploymentPath: AbsolutePath) -> DeploymentDestinationFixtures { self.remoteDeploymentPath = remoteDeploymentPath return self } diff --git a/Tests/LocalQueueServerRunnerTests/QueueServerConfigurationTests.swift b/Tests/LocalQueueServerRunnerTests/QueueServerConfigurationTests.swift index 7db80e01..6c8259e8 100644 --- a/Tests/LocalQueueServerRunnerTests/QueueServerConfigurationTests.swift +++ b/Tests/LocalQueueServerRunnerTests/QueueServerConfigurationTests.swift @@ -39,7 +39,6 @@ final class QueueServerConfigurationTests: XCTestCase { "port": 22, "username": "q_user", "authentication": { - "type": "plain", "password": "pass" }, "remoteDeploymentPath": "/remote/queue/depl/path" @@ -54,7 +53,6 @@ final class QueueServerConfigurationTests: XCTestCase { "port": 1, "username": "username", "authentication": { - "type": "plain", "password": "pass" }, "remoteDeploymentPath": "/remote/deployment/path" @@ -107,8 +105,7 @@ final class QueueServerConfigurationTests: XCTestCase { "port": 1, "username": "username", "authentication": { - "type": "key", - "path": "key" + "keyPath": "/path/to/key" }, "remoteDeploymentPath": "/remote/deployment/path" } @@ -117,7 +114,7 @@ final class QueueServerConfigurationTests: XCTestCase { let config = try JSONDecoder().decode(DeploymentDestination.self, from: data) XCTAssertEqual( config, - DeploymentDestination(host: "host", port: 1, username: "username", authentication: .key(path: "key"), remoteDeploymentPath: "/remote/deployment/path") + DeploymentDestination(host: "host", port: 1, username: "username", authentication: .key(path: "/path/to/key"), remoteDeploymentPath: "/remote/deployment/path") ) } }