File tree 3 files changed +38
-1
lines changed
3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change
1
+ edition = " 2015"
2
+ wrap_comments = true
Original file line number Diff line number Diff line change 30
30
Ok ( response)
31
31
}
32
32
33
+ pub async fn initialize_user ( access_token : & str ) -> Result < String , Error > {
34
+ let url = format ! ( "{}/users" , build_api_url( ) ) ;
35
+
36
+ let mut sp = Spinner :: new ( Spinners :: Dots , "" . into ( ) ) ;
37
+
38
+ let client = Client :: new ( ) ;
39
+ let resp = client
40
+ . post ( url)
41
+ . header ( "Authorization" , format ! ( "Bearer {}" , access_token) )
42
+ . header ( "agent" , build_agent_header ( ) )
43
+ . send ( )
44
+ . await ?;
45
+
46
+ sp. stop_with_symbol ( "" . into ( ) ) ;
47
+
48
+ check_response_update_header ( & resp) ?;
49
+ let response = resp. json :: < serde_json:: Value > ( ) . await ?;
50
+
51
+ let userid = response
52
+ . as_object ( )
53
+ . and_then ( |o| o. get ( "userId" ) )
54
+ . and_then ( |x| x. as_str ( ) )
55
+ . unwrap_or_default ( )
56
+ . to_owned ( ) ;
57
+
58
+ Ok ( userid)
59
+ }
60
+
33
61
pub async fn create_api_key (
34
62
access_token : & str ,
35
63
project : & str ,
Original file line number Diff line number Diff line change 1
- use miette:: bail;
1
+ use miette:: { bail, Context as _ , IntoDiagnostic as _ } ;
2
2
use reqwest:: StatusCode ;
3
3
use serde:: { Deserialize , Serialize } ;
4
4
use std:: { collections:: HashMap , time:: Duration } ;
5
5
6
+ use crate :: api;
7
+
6
8
async fn find_login_url ( ) -> ( String , String ) {
7
9
let mut params = HashMap :: new ( ) ;
8
10
params. insert ( "client_id" , "gpJ63MG5g1V1PKufM9WHGjjeAe7yCT8L" ) ;
@@ -94,6 +96,11 @@ pub async fn run() -> miette::Result<String> {
94
96
let ( status, access_token) = poll_token ( & device_code) . await ;
95
97
96
98
if status. is_success ( ) {
99
+ api:: account:: initialize_user ( & access_token)
100
+ . await
101
+ . into_diagnostic ( )
102
+ . context ( "initializing user" ) ?;
103
+
97
104
println ! ( "login successful!" ) ;
98
105
return Ok ( access_token) ;
99
106
}
You can’t perform that action at this time.
0 commit comments