@@ -15,9 +15,9 @@ struct CloudflaredE2ECLI {
1515 case serviceToken = " 2 "
1616 }
1717
18- private struct ManualOAuthFlow : SSHOAuthFlow {
18+ private struct ManualOAuthFlow : OAuthFlow {
1919 func fetchToken( teamDomain: String , appDomain: String , callbackScheme: String , hostname: String ) async throws -> String {
20- let originURL = try SSHURLTools . normalizeOriginURL ( from: hostname)
20+ let originURL = try URLTools . normalizeOriginURL ( from: hostname)
2121
2222 print ( " " )
2323 print ( " Open this protected app URL in your browser and complete Cloudflare Access login: " )
@@ -30,7 +30,7 @@ struct CloudflaredE2ECLI {
3030 . trimmingCharacters ( in: . whitespacesAndNewlines)
3131
3232 guard !token. isEmpty else {
33- throw SSHFailure . auth ( " oauth token input was empty " )
33+ throw Failure . auth ( " oauth token input was empty " )
3434 }
3535
3636 return token
@@ -40,7 +40,7 @@ struct CloudflaredE2ECLI {
4040 static func main( ) async {
4141 do {
4242 try await run ( )
43- } catch let failure as SSHFailure {
43+ } catch let failure as Failure {
4444 fputs ( " Error: \( failure) \n " , stderr)
4545 Foundation . exit ( 1 )
4646 } catch {
@@ -56,14 +56,14 @@ struct CloudflaredE2ECLI {
5656 let hostname = try promptRequired ( " Cloudflare-protected hostname (e.g. ssh.example.com): " )
5757 let authChoice = try promptAuthChoice ( )
5858
59- let authProvider : any SSHAuthProviding
60- let method : SSHAuthMethod
59+ let authProvider : any AuthProviding
60+ let method : AuthMethod
6161
6262 switch authChoice {
6363 case . oauth:
64- let oauthProvider = SSHOAuthProvider (
64+ let oauthProvider = OAuthProvider (
6565 flow: ManualOAuthFlow ( ) ,
66- tokenStore: SSHInMemoryTokenStore ( )
66+ tokenStore: InMemoryTokenStore ( )
6767 )
6868 authProvider = oauthProvider
6969 method = try await resolveOAuthMethod ( hostname: hostname)
@@ -72,14 +72,14 @@ struct CloudflaredE2ECLI {
7272 let clientID = try promptRequired ( " Service token client ID: " )
7373 let clientSecret = try promptSecretRequired ( " Service token client secret: " )
7474
75- authProvider = SSHServiceTokenProvider ( )
75+ authProvider = ServiceTokenProvider ( )
7676 method = . serviceToken( teamDomain: " local " , clientID: clientID, clientSecret: clientSecret)
7777 }
7878
79- let session = SSHSessionActor (
79+ let session = SessionActor (
8080 authProvider: authProvider,
81- tunnelProvider: SSHCloudflareTunnelProvider ( ) ,
82- retryPolicy: SSHRetryPolicy ( maxReconnectAttempts: 2 , baseDelayNanoseconds: 500_000_000 ) ,
81+ tunnelProvider: CloudflareTunnelProvider ( ) ,
82+ retryPolicy: RetryPolicy ( maxReconnectAttempts: 2 , baseDelayNanoseconds: 500_000_000 ) ,
8383 oauthFallback: nil ,
8484 sleep: { delay in
8585 try ? await Task . sleep ( nanoseconds: delay)
@@ -120,19 +120,19 @@ struct CloudflaredE2ECLI {
120120 stateTask. cancel ( )
121121 }
122122
123- private struct URLSessionHTTPClient : SSHHTTPClient {
123+ private struct URLSessionHTTPClient : HTTPClient {
124124 func send( _ request: URLRequest ) async throws -> ( Data , HTTPURLResponse ) {
125125 let ( data, response) = try await URLSession . shared. data ( for: request)
126126 guard let http = response as? HTTPURLResponse else {
127- throw SSHFailure . protocolViolation ( " non-http response while resolving app info " )
127+ throw Failure . protocolViolation ( " non-http response while resolving app info " )
128128 }
129129 return ( data, http)
130130 }
131131 }
132132
133- private static func resolveOAuthMethod( hostname: String ) async throws -> SSHAuthMethod {
134- let originURL = try SSHURLTools . normalizeOriginURL ( from: hostname)
135- let resolver = SSHAppInfoResolver ( client: URLSessionHTTPClient ( ) , userAgent: " cloudflared-e2e " )
133+ private static func resolveOAuthMethod( hostname: String ) async throws -> AuthMethod {
134+ let originURL = try URLTools . normalizeOriginURL ( from: hostname)
135+ let resolver = AppInfoResolver ( client: URLSessionHTTPClient ( ) , userAgent: " cloudflared-e2e " )
136136
137137 if let appInfo = try ? await resolver. resolve ( appURL: originURL) {
138138 return . oauth(
@@ -149,7 +149,7 @@ struct CloudflaredE2ECLI {
149149 )
150150 }
151151
152- private static func describe( _ state: SSHConnectionState ) - > String {
152+ private static func describe( _ state: ConnectionState ) - > String {
153153 switch state {
154154 case . idle:
155155 return " idle "
@@ -227,7 +227,7 @@ struct CloudflaredE2ECLI {
227227 private static func runTunnelProbe( localPort: UInt16 ) throws -> ProbeResult {
228228 let fd = socket ( AF_INET, SOCK_STREAM, 0 )
229229 guard fd >= 0 else {
230- throw SSHFailure . transport ( " probe failed to create socket " , retryable: true )
230+ throw Failure . transport ( " probe failed to create socket " , retryable: true )
231231 }
232232 defer { _ = close ( fd) }
233233
@@ -240,7 +240,7 @@ struct CloudflaredE2ECLI {
240240
241241 let pton = " 127.0.0.1 " . withCString { inet_pton ( AF_INET, $0, & address. sin_addr) }
242242 guard pton == 1 else {
243- throw SSHFailure . transport ( " probe failed to encode loopback " , retryable: false )
243+ throw Failure . transport ( " probe failed to encode loopback " , retryable: false )
244244 }
245245
246246 let connectResult = withUnsafePointer ( to: & address) {
@@ -249,7 +249,7 @@ struct CloudflaredE2ECLI {
249249 }
250250 }
251251 guard connectResult == 0 else {
252- throw SSHFailure . transport ( " probe failed to connect to local tunnel " , retryable: true )
252+ throw Failure . transport ( " probe failed to connect to local tunnel " , retryable: true )
253253 }
254254
255255 var timeout = timeval ( tv_sec: 2 , tv_usec: 0 )
@@ -266,7 +266,7 @@ struct CloudflaredE2ECLI {
266266 }
267267
268268 if count == 0 {
269- throw SSHFailure . transport (
269+ throw Failure . transport (
270270 " probe socket closed immediately; Cloudflare auth/upstream connection likely failed " ,
271271 retryable: false
272272 )
@@ -276,6 +276,6 @@ struct CloudflaredE2ECLI {
276276 return . openWithoutData
277277 }
278278
279- throw SSHFailure . transport ( " probe recv failed with errno \( errno) " , retryable: true )
279+ throw Failure . transport ( " probe recv failed with errno \( errno) " , retryable: true )
280280 }
281281}
0 commit comments