@@ -11,9 +11,9 @@ pub struct CustomServiceAccount {
1111impl CustomServiceAccount {
1212 const GOOGLE_APPLICATION_CREDENTIALS : & ' static str = "GOOGLE_APPLICATION_CREDENTIALS" ;
1313
14- pub async fn new ( ) -> Result < Self , GCPAuthError > {
14+ pub async fn new ( ) -> Result < Self , Error > {
1515 let path = std:: env:: var ( Self :: GOOGLE_APPLICATION_CREDENTIALS )
16- . map_err ( |_| GCPAuthError :: AplicationProfileMissing ) ?;
16+ . map_err ( |_| Error :: AplicationProfileMissing ) ?;
1717 let credentials = ApplicationCredentials :: from_file ( path) . await ?;
1818 Ok ( Self {
1919 credentials,
@@ -29,11 +29,7 @@ impl ServiceAccount for CustomServiceAccount {
2929 self . tokens . get ( & key) . cloned ( )
3030 }
3131
32- async fn refresh_token (
33- & mut self ,
34- client : & HyperClient ,
35- scopes : & [ & str ] ,
36- ) -> Result < ( ) , GCPAuthError > {
32+ async fn refresh_token ( & mut self , client : & HyperClient , scopes : & [ & str ] ) -> Result < ( ) , Error > {
3733 use crate :: jwt:: Claims ;
3834 use crate :: jwt:: JWTSigner ;
3935 use crate :: jwt:: GRANT_TYPE ;
@@ -43,9 +39,7 @@ impl ServiceAccount for CustomServiceAccount {
4339 let signer = JWTSigner :: new ( & self . credentials . private_key ) ?;
4440
4541 let claims = Claims :: new ( & self . credentials , scopes, None ) ;
46- let signed = signer
47- . sign_claims ( & claims)
48- . map_err ( GCPAuthError :: TLSError ) ?;
42+ let signed = signer. sign_claims ( & claims) . map_err ( Error :: TLSError ) ?;
4943 let rqbody = form_urlencoded:: Serializer :: new ( String :: new ( ) )
5044 . extend_pairs ( & [ ( "grant_type" , GRANT_TYPE ) , ( "assertion" , signed. as_str ( ) ) ] )
5145 . finish ( ) ;
@@ -57,7 +51,7 @@ impl ServiceAccount for CustomServiceAccount {
5751 let token = client
5852 . request ( request)
5953 . await
60- . map_err ( GCPAuthError :: OAuthConnectionError ) ?
54+ . map_err ( Error :: OAuthConnectionError ) ?
6155 . deserialize ( )
6256 . await ?;
6357 let key = scopes. iter ( ) . map ( |x| ( * x) . to_string ( ) ) . collect ( ) ;
@@ -90,10 +84,10 @@ pub struct ApplicationCredentials {
9084}
9185
9286impl ApplicationCredentials {
93- async fn from_file < T : AsRef < Path > > ( path : T ) -> Result < ApplicationCredentials , GCPAuthError > {
87+ async fn from_file < T : AsRef < Path > > ( path : T ) -> Result < ApplicationCredentials , Error > {
9488 let content = fs:: read_to_string ( path)
9589 . await
96- . map_err ( GCPAuthError :: AplicationProfilePath ) ?;
97- Ok ( serde_json:: from_str ( & content) . map_err ( GCPAuthError :: AplicationProfileFormat ) ?)
90+ . map_err ( Error :: AplicationProfilePath ) ?;
91+ Ok ( serde_json:: from_str ( & content) . map_err ( Error :: AplicationProfileFormat ) ?)
9892 }
9993}
0 commit comments