@@ -77,6 +77,8 @@ pub enum Action<'a> {
77
77
Get ( Operation < ' a > ) ,
78
78
Login ( LoginOptions < ' a > ) ,
79
79
Logout ,
80
+ #[ serde( other) ]
81
+ Unknown ,
80
82
}
81
83
82
84
impl < ' a > Display for Action < ' a > {
@@ -85,6 +87,7 @@ impl<'a> Display for Action<'a> {
85
87
Action :: Get ( _) => f. write_str ( "get" ) ,
86
88
Action :: Login ( _) => f. write_str ( "login" ) ,
87
89
Action :: Logout => f. write_str ( "logout" ) ,
90
+ Action :: Unknown => f. write_str ( "<unknown>" ) ,
88
91
}
89
92
}
90
93
}
@@ -133,6 +136,8 @@ pub enum Operation<'a> {
133
136
/// The name of the crate
134
137
name : & ' a str ,
135
138
} ,
139
+ #[ serde( other) ]
140
+ Unknown ,
136
141
}
137
142
138
143
/// Message sent by the credential helper
@@ -147,6 +152,8 @@ pub enum CredentialResponse {
147
152
} ,
148
153
Login ,
149
154
Logout ,
155
+ #[ serde( other) ]
156
+ Unknown ,
150
157
}
151
158
152
159
#[ derive( Serialize , Deserialize , Clone , Debug ) ]
@@ -159,6 +166,8 @@ pub enum CacheControl {
159
166
Expires ( #[ serde( with = "time::serde::timestamp" ) ] OffsetDateTime ) ,
160
167
/// Cache this result and use it for all subsequent requests in the current Cargo invocation.
161
168
Session ,
169
+ #[ serde( other) ]
170
+ Unknown ,
162
171
}
163
172
164
173
/// Credential process JSON protocol version. Incrementing
@@ -177,36 +186,37 @@ pub trait Credential {
177
186
178
187
/// Runs the credential interaction
179
188
pub fn main ( credential : impl Credential ) {
180
- let result = doit ( credential) ;
189
+ let result = doit ( credential) . map_err ( |e| Error :: Other ( e ) ) ;
181
190
if result. is_err ( ) {
182
191
serde_json:: to_writer ( std:: io:: stdout ( ) , & result)
183
192
. expect ( "failed to serialize credential provider error" ) ;
184
193
println ! ( ) ;
185
194
}
186
195
}
187
196
188
- fn doit ( credential : impl Credential ) -> Result < ( ) , Error > {
197
+ fn doit (
198
+ credential : impl Credential ,
199
+ ) -> Result < ( ) , Box < dyn std:: error:: Error + Send + Sync + ' static > > {
189
200
let hello = CredentialHello {
190
201
v : vec ! [ PROTOCOL_VERSION_1 ] ,
191
202
} ;
192
- serde_json:: to_writer ( std:: io:: stdout ( ) , & hello) . map_err ( Box :: new ) ?;
203
+ serde_json:: to_writer ( std:: io:: stdout ( ) , & hello) ?;
193
204
println ! ( ) ;
194
205
195
206
loop {
196
207
let mut buffer = String :: new ( ) ;
197
- let len = std:: io:: stdin ( ) . read_line ( & mut buffer) . map_err ( Box :: new ) ?;
208
+ let len = std:: io:: stdin ( ) . read_line ( & mut buffer) ?;
198
209
if len == 0 {
199
210
return Ok ( ( ) ) ;
200
211
}
201
- let request: CredentialRequest = serde_json:: from_str ( & buffer) . map_err ( Box :: new ) ?;
212
+ let request: CredentialRequest = serde_json:: from_str ( & buffer) ?;
202
213
if request. v != PROTOCOL_VERSION_1 {
203
214
return Err ( format ! ( "unsupported protocol version {}" , request. v) . into ( ) ) ;
204
215
}
205
216
serde_json:: to_writer (
206
217
std:: io:: stdout ( ) ,
207
218
& credential. perform ( & request. registry , & request. action , & request. args ) ,
208
- )
209
- . map_err ( Box :: new) ?;
219
+ ) ?;
210
220
println ! ( ) ;
211
221
}
212
222
}
0 commit comments