@@ -7,6 +7,8 @@ use hyper::client::HttpConnector;
77use hyper_tls:: HttpsConnector ;
88use log:: { error, info} ;
99use smpl_jwt:: Jwt ;
10+ use std:: fs;
11+ use std:: str:: FromStr ;
1012use std:: sync:: atomic:: { AtomicBool , Ordering } ;
1113use std:: sync:: { Arc , RwLock } ;
1214use std:: time:: Duration ;
@@ -17,7 +19,7 @@ type HyperClient = Arc<hyper::Client<HttpsConnector<HttpConnector>, hyper::Body>
1719
1820pub struct State {
1921 token : Option < goauth:: auth:: Token > ,
20- credentials_path : String ,
22+ credentials_string : String ,
2123 project : Option < String > ,
2224 hyper_client : HyperClient ,
2325 running : Arc < AtomicBool > ,
@@ -46,10 +48,10 @@ impl Clone for Client {
4648}
4749
4850impl Client {
49- pub fn new ( credentials_path : String ) -> Result < Self , error:: Error > {
51+ pub fn from_string ( credentials_string : String ) -> Result < Self , error:: Error > {
5052 let mut client = Client ( Arc :: new ( RwLock :: new ( State {
5153 token : None ,
52- credentials_path ,
54+ credentials_string ,
5355 project : None ,
5456 hyper_client : setup_hyper ( ) ,
5557 running : Arc :: new ( AtomicBool :: new ( true ) ) ,
@@ -61,6 +63,11 @@ impl Client {
6163 }
6264 }
6365
66+ pub fn new ( credentials_path : String ) -> Result < Self , error:: Error > {
67+ let credentials_string = fs:: read_to_string ( credentials_path) . unwrap ( ) ;
68+ Self :: from_string ( credentials_string)
69+ }
70+
6471 pub fn subscribe ( & self , name : String ) -> Subscription {
6572 Subscription {
6673 client : Some ( self . clone ( ) ) ,
@@ -127,7 +134,7 @@ impl Client {
127134
128135 fn get_token ( & mut self ) -> Result < goauth:: auth:: Token , goauth:: error:: GOErr > {
129136 let credentials =
130- goauth:: credentials:: Credentials :: from_file ( & self . 0 . read ( ) . unwrap ( ) . credentials_path )
137+ goauth:: credentials:: Credentials :: from_str ( & self . 0 . read ( ) . unwrap ( ) . credentials_string )
131138 . unwrap ( ) ;
132139
133140 self . set_project ( credentials. project ( ) ) ;
0 commit comments