@@ -9,7 +9,7 @@ use std::str::FromStr;
9
9
use std:: thread:: spawn;
10
10
use std:: time:: Duration ;
11
11
12
- use anyhow:: { bail, Context } ;
12
+ use anyhow:: { anyhow , bail, Context } ;
13
13
use camino:: Utf8PathBuf ;
14
14
use drawbridge_client:: types:: { RepositoryContext , TagContext , UserContext } ;
15
15
use drawbridge_client:: Client ;
@@ -100,14 +100,20 @@ fn parse_user(slug: &str) -> (String, &str) {
100
100
}
101
101
102
102
pub fn get_token (
103
+ oidc_domain : & impl Borrow < Url > ,
103
104
provided_token : & Option < impl AsRef < str > > ,
104
105
helper : & Option < impl AsRef < OsStr > > ,
105
106
) -> anyhow:: Result < String > {
107
+ let oidc_domain = oidc_domain
108
+ . borrow ( )
109
+ . host_str ( )
110
+ . ok_or_else ( || anyhow ! ( "invalid OpenID Connect domain" ) ) ?;
106
111
if let Some ( token) = provided_token {
107
112
Ok ( token. as_ref ( ) . into ( ) )
108
113
} else if let Some ( helper) = helper {
109
114
let output = Command :: new ( helper)
110
115
. arg ( "show" )
116
+ . arg ( oidc_domain)
111
117
. output ( )
112
118
. context ( "Failed to execute credential helper" ) ?;
113
119
stderr ( )
@@ -121,19 +127,20 @@ pub fn get_token(
121
127
bail ! ( "Credential helper was killed" )
122
128
}
123
129
} else {
124
- keyring:: Entry :: new ( "enarx" , " oidc_domain" )
130
+ keyring:: Entry :: new ( "enarx" , oidc_domain)
125
131
. get_password ( )
126
132
. context ( "Failed to read credentials from keyring" )
127
133
}
128
134
}
129
135
130
136
pub fn client (
131
137
host : & str ,
138
+ oidc_domain : & impl Borrow < Url > ,
132
139
insecure_token : & Option < String > ,
133
140
ca_bundle : & Option < Utf8PathBuf > ,
134
141
helper : & Option < impl AsRef < OsStr > > ,
135
142
) -> anyhow:: Result < Client > {
136
- let token = get_token ( insecure_token, helper) ?;
143
+ let token = get_token ( oidc_domain , insecure_token, helper) ?;
137
144
138
145
let url = format ! ( "https://{host}" ) ;
139
146
@@ -215,11 +222,16 @@ pub fn login(
215
222
. context ( "Failed to exchange device code for a token" ) ?;
216
223
217
224
// TODO: graceful timeout, so that users are not forced to Ctrl+C if the server errors
225
+ let oidc_domain = oidc_domain
226
+ . borrow ( )
227
+ . host_str ( )
228
+ . ok_or_else ( || anyhow ! ( "invalid OpenID Connect domain" ) ) ?;
218
229
let secret = res. access_token ( ) . secret ( ) ;
219
230
if let Some ( helper) = helper {
220
231
let mut helper = Command :: new ( helper)
221
232
. stdin ( Stdio :: piped ( ) )
222
233
. arg ( "insert" )
234
+ . arg ( oidc_domain)
223
235
. spawn ( )
224
236
. context ( "Failed to spawn credential helper command" ) ?;
225
237
let mut stdin = helper. stdin . take ( ) . context ( "Failed to open stdin" ) ?;
@@ -242,7 +254,7 @@ pub fn login(
242
254
}
243
255
}
244
256
} else {
245
- keyring:: Entry :: new ( "enarx" , " oidc_domain" )
257
+ keyring:: Entry :: new ( "enarx" , oidc_domain)
246
258
. set_password ( secret)
247
259
. context ( "Failed to save user credentials" ) ?;
248
260
}
0 commit comments