@@ -17,25 +17,46 @@ mod write {
17
17
out. write_all ( value) ?;
18
18
out. write_all ( b"\n " )
19
19
}
20
- for ( key, value) in [ ( "url" , & self . url ) , ( "path" , & self . path ) ] {
20
+ let Context {
21
+ protocol,
22
+ host,
23
+ path,
24
+ username,
25
+ password,
26
+ oauth_refresh_token,
27
+ password_expiry_utc,
28
+ url,
29
+ // We only decode quit and interpret it, but won't get to pass it on as it means to stop the
30
+ // credential helper invocation chain.
31
+ quit : _,
32
+ } = self ;
33
+ for ( key, value) in [ ( "url" , url) , ( "path" , path) ] {
21
34
if let Some ( value) = value {
22
35
validate ( key, value. as_slice ( ) . into ( ) )
23
36
. map_err ( |err| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , err) ) ?;
24
37
write_key ( & mut out, key, value. as_ref ( ) ) . ok ( ) ;
25
38
}
26
39
}
27
40
for ( key, value) in [
28
- ( "protocol" , & self . protocol ) ,
29
- ( "host" , & self . host ) ,
30
- ( "username" , & self . username ) ,
31
- ( "password" , & self . password ) ,
41
+ ( "protocol" , protocol) ,
42
+ ( "host" , host) ,
43
+ ( "username" , username) ,
44
+ ( "password" , password) ,
45
+ ( "oauth_refresh_token" , oauth_refresh_token) ,
32
46
] {
33
47
if let Some ( value) = value {
34
48
validate ( key, value. as_str ( ) . into ( ) )
35
49
. map_err ( |err| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , err) ) ?;
36
50
write_key ( & mut out, key, value. as_bytes ( ) . as_bstr ( ) ) . ok ( ) ;
37
51
}
38
52
}
53
+ if let Some ( value) = password_expiry_utc {
54
+ let key = "password_expiry_utc" ;
55
+ let value = value. to_string ( ) ;
56
+ validate ( key, value. as_str ( ) . into ( ) )
57
+ . map_err ( |err| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , err) ) ?;
58
+ write_key ( & mut out, key, value. as_bytes ( ) . as_bstr ( ) ) . ok ( ) ;
59
+ }
39
60
Ok ( ( ) )
40
61
}
41
62
@@ -70,6 +91,17 @@ pub mod decode {
70
91
/// Decode ourselves from `input` which is the format written by [`write_to()`][Self::write_to()].
71
92
pub fn from_bytes ( input : & [ u8 ] ) -> Result < Self , Error > {
72
93
let mut ctx = Context :: default ( ) ;
94
+ let Context {
95
+ protocol,
96
+ host,
97
+ path,
98
+ username,
99
+ password,
100
+ oauth_refresh_token,
101
+ password_expiry_utc,
102
+ url,
103
+ quit,
104
+ } = & mut ctx;
73
105
for res in input. lines ( ) . take_while ( |line| !line. is_empty ( ) ) . map ( |line| {
74
106
let mut it = line. splitn ( 2 , |b| * b == b'=' ) ;
75
107
match (
@@ -84,23 +116,27 @@ pub mod decode {
84
116
} ) {
85
117
let ( key, value) = res?;
86
118
match key {
87
- "protocol" | "host" | "username" | "password" => {
119
+ "protocol" | "host" | "username" | "password" | "oauth_refresh_token" => {
88
120
if !value. is_utf8 ( ) {
89
121
return Err ( Error :: IllformedUtf8InValue { key : key. into ( ) , value } ) ;
90
122
}
91
123
let value = value. to_string ( ) ;
92
124
* match key {
93
- "protocol" => & mut ctx. protocol ,
94
- "host" => & mut ctx. host ,
95
- "username" => & mut ctx. username ,
96
- "password" => & mut ctx. password ,
125
+ "protocol" => & mut * protocol,
126
+ "host" => host,
127
+ "username" => username,
128
+ "password" => password,
129
+ "oauth_refresh_token" => oauth_refresh_token,
97
130
_ => unreachable ! ( "checked field names in match above" ) ,
98
131
} = Some ( value) ;
99
132
}
100
- "url" => ctx. url = Some ( value) ,
101
- "path" => ctx. path = Some ( value) ,
133
+ "password_expiry_utc" => {
134
+ * password_expiry_utc = value. to_str ( ) . ok ( ) . and_then ( |value| value. parse ( ) . ok ( ) ) ;
135
+ }
136
+ "url" => * url = Some ( value) ,
137
+ "path" => * path = Some ( value) ,
102
138
"quit" => {
103
- ctx . quit = gix_config_value:: Boolean :: try_from ( value. as_ref ( ) ) . ok ( ) . map ( Into :: into) ;
139
+ * quit = gix_config_value:: Boolean :: try_from ( value. as_ref ( ) ) . ok ( ) . map ( Into :: into) ;
104
140
}
105
141
_ => { }
106
142
}
0 commit comments