@@ -4,40 +4,26 @@ use tokio::sync::watch;
4
4
5
5
pub use linkerd_app_core:: identity:: client:: spire as client;
6
6
7
- #[ cfg( target_os = "linux" ) ]
8
- const UNIX_PREFIX : & str = "unix:" ;
9
- #[ cfg( target_os = "linux" ) ]
10
7
const TONIC_DEFAULT_URI : & str = "http://[::]:50051" ;
11
8
12
9
#[ derive( Clone , Debug ) ]
13
10
pub struct Config {
14
- pub socket_addr : Arc < String > ,
11
+ pub workload_api_addr : Arc < String > ,
15
12
pub backoff : ExponentialBackoff ,
16
13
}
17
14
18
15
// Connects to SPIRE workload API via Unix Domain Socket
19
16
pub struct Client {
20
- #[ cfg_attr( not( target_os = "linux" ) , allow( dead_code) ) ]
21
17
config : Config ,
22
18
}
23
19
24
20
// === impl Client ===
25
-
26
- #[ cfg( target_os = "linux" ) ]
27
21
impl From < Config > for Client {
28
22
fn from ( config : Config ) -> Self {
29
23
Self { config }
30
24
}
31
25
}
32
26
33
- #[ cfg( not( target_os = "linux" ) ) ]
34
- impl From < Config > for Client {
35
- fn from ( _: Config ) -> Self {
36
- panic ! ( "Spire is supported on Linux only" )
37
- }
38
- }
39
-
40
- #[ cfg( target_os = "linux" ) ]
41
27
impl tower:: Service < ( ) > for Client {
42
28
type Response = tonic:: Response < watch:: Receiver < client:: SvidUpdate > > ;
43
29
type Error = Error ;
@@ -51,25 +37,43 @@ impl tower::Service<()> for Client {
51
37
}
52
38
53
39
fn call ( & mut self , _req : ( ) ) -> Self :: Future {
54
- let socket = self . config . socket_addr . clone ( ) ;
40
+ let addr = self . config . workload_api_addr . clone ( ) ;
55
41
let backoff = self . config . backoff ;
56
42
Box :: pin ( async move {
57
- use tokio:: net:: UnixStream ;
58
43
use tonic:: transport:: { Endpoint , Uri } ;
59
44
60
- // Strip the 'unix:' prefix for tonic compatibility.
61
- let stripped_path = socket
62
- . strip_prefix ( UNIX_PREFIX )
63
- . unwrap_or ( socket. as_str ( ) )
64
- . to_string ( ) ;
65
-
66
45
// We will ignore this uri because uds do not use it
67
46
// if your connector does use the uri it will be provided
68
47
// as the request to the `MakeConnection`.
69
48
let chan = Endpoint :: try_from ( TONIC_DEFAULT_URI ) ?
70
49
. connect_with_connector ( tower:: util:: service_fn ( move |_: Uri | {
71
- use futures:: TryFutureExt ;
72
- UnixStream :: connect ( stripped_path. clone ( ) ) . map_ok ( hyper_util:: rt:: TokioIo :: new)
50
+ #[ cfg( unix) ]
51
+ {
52
+ use futures:: TryFutureExt ;
53
+
54
+ // The 'unix:' scheme must be stripped from socket paths.
55
+ let path = addr. strip_prefix ( "unix:" ) . unwrap_or ( addr. as_str ( ) ) ;
56
+
57
+ tokio:: net:: UnixStream :: connect ( path. to_string ( ) )
58
+ . map_ok ( hyper_util:: rt:: TokioIo :: new)
59
+ }
60
+
61
+ #[ cfg( windows) ]
62
+ {
63
+ use tokio:: net:: windows:: named_pipe;
64
+ let named_pipe_path = addr. clone ( ) ;
65
+ let client = named_pipe:: ClientOptions :: new ( )
66
+ . open ( named_pipe_path. as_str ( ) )
67
+ . map ( hyper_util:: rt:: TokioIo :: new) ;
68
+
69
+ futures:: future:: ready ( client)
70
+ }
71
+
72
+ #[ cfg( not( any( unix, windows) ) ) ]
73
+ {
74
+ compile_error ! ( "Spire is supported only on Windows and Unix systems." ) ;
75
+ futures:: future:: pending ( )
76
+ }
73
77
} ) )
74
78
. await ?;
75
79
@@ -80,21 +84,3 @@ impl tower::Service<()> for Client {
80
84
} )
81
85
}
82
86
}
83
-
84
- #[ cfg( not( target_os = "linux" ) ) ]
85
- impl tower:: Service < ( ) > for Client {
86
- type Response = tonic:: Response < watch:: Receiver < client:: SvidUpdate > > ;
87
- type Error = Error ;
88
- type Future = futures:: future:: BoxFuture < ' static , Result < Self :: Response , Self :: Error > > ;
89
-
90
- fn poll_ready (
91
- & mut self ,
92
- _cx : & mut std:: task:: Context < ' _ > ,
93
- ) -> std:: task:: Poll < Result < ( ) , Self :: Error > > {
94
- unimplemented ! ( "Spire is supported on Linux only" )
95
- }
96
-
97
- fn call ( & mut self , _req : ( ) ) -> Self :: Future {
98
- unimplemented ! ( "Spire is supported on Linux only" )
99
- }
100
- }
0 commit comments