@@ -13,17 +13,14 @@ use crate::Token;
1313#[ derive( Debug ) ]
1414pub ( crate ) struct GCloudAuthorizedUser {
1515 gcloud : PathBuf ,
16+ project_id : Option < String > ,
1617}
1718
1819impl GCloudAuthorizedUser {
1920 pub ( crate ) fn new ( ) -> Result < Self , Error > {
20- which ( "gcloud" )
21- . map_err ( |_| GCloudNotFound )
22- . map ( |path| Self { gcloud : path } )
23- }
24-
25- fn project_id ( & self ) -> Result < String , Error > {
26- run ( & self . gcloud , & [ "config" , "get-value" , "project" ] )
21+ let gcloud = which ( "gcloud" ) . map_err ( |_| GCloudNotFound ) ?;
22+ let project_id = run ( & gcloud, & [ "config" , "get-value" , "project" ] ) . ok ( ) ;
23+ Ok ( Self { gcloud, project_id } )
2724 }
2825
2926 fn token ( & self ) -> Result < Token , Error > {
@@ -37,7 +34,7 @@ impl GCloudAuthorizedUser {
3734#[ async_trait]
3835impl ServiceAccount for GCloudAuthorizedUser {
3936 async fn project_id ( & self , _: & HyperClient ) -> Result < String , Error > {
40- self . project_id ( )
37+ self . project_id . clone ( ) . ok_or ( Error :: NoProjectId )
4138 }
4239
4340 fn get_token ( & self , _scopes : & [ & str ] ) -> Option < Token > {
@@ -73,7 +70,7 @@ mod tests {
7370 #[ ignore]
7471 fn gcloud ( ) {
7572 let gcloud = GCloudAuthorizedUser :: new ( ) . unwrap ( ) ;
76- println ! ( "{:?}" , gcloud. project_id( ) ) ;
73+ println ! ( "{:?}" , gcloud. project_id) ;
7774 println ! ( "{:?}" , gcloud. token( ) ) ;
7875 }
7976}
0 commit comments