diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-04-24 09:36:43 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-05-07 08:55:03 -0300 |
| commit | d5bcd6cfea9dee8086cad0a4f5d8e3fccbf80445 (patch) | |
| tree | 1a06355485a62058fd5b0a31fae7034988b0d1d1 | |
| parent | 96dc3a48a316310e6e68b1cc5ab378bba9d98729 (diff) | |
| download | mullvadvpn-d5bcd6cfea9dee8086cad0a4f5d8e3fccbf80445.tar.xz mullvadvpn-d5bcd6cfea9dee8086cad0a4f5d8e3fccbf80445.zip | |
Read credentials from RPC connection file
| -rw-r--r-- | mullvad-ipc-client/src/lib.rs | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/mullvad-ipc-client/src/lib.rs b/mullvad-ipc-client/src/lib.rs index 95a467d72d..8139b6d714 100644 --- a/mullvad-ipc-client/src/lib.rs +++ b/mullvad-ipc-client/src/lib.rs @@ -40,6 +40,11 @@ error_chain! { ) } + MissingRpcCredentials(file_path: String) { + description("no credentials found in RPC connection file") + display("no credentials found in RPC connection file {}", file_path) + } + ReadRpcFileError(file_path: String) { description("Failed to read RPC connection information") display("Failed to read RPC connection information from {}", file_path) @@ -65,16 +70,20 @@ static NO_ARGS: [u8; 0] = []; pub struct DaemonRpcClient { address: String, + credentials: String, } impl DaemonRpcClient { pub fn new() -> Result<Self> { - let address = Self::read_rpc_file()?; + let (address, credentials) = Self::read_rpc_file()?; - Ok(DaemonRpcClient { address }) + Ok(DaemonRpcClient { + address, + credentials, + }) } - fn read_rpc_file() -> Result<String> { + fn read_rpc_file() -> Result<(String, String)> { let file_path = rpc_file_path()?; let file_path_string = || file_path.display().to_string(); let rpc_file = @@ -89,10 +98,16 @@ impl DaemonRpcClient { let reader = BufReader::new(rpc_file); let mut lines = reader.lines(); - lines + let address = lines .next() .ok_or_else(|| ErrorKind::EmptyRpcFile(file_path_string()))? - .chain_err(|| ErrorKind::ReadRpcFileError(file_path_string())) + .chain_err(|| ErrorKind::ReadRpcFileError(file_path_string()))?; + let credentials = lines + .next() + .ok_or_else(|| ErrorKind::MissingRpcCredentials(file_path_string()))? + .chain_err(|| ErrorKind::ReadRpcFileError(file_path_string()))?; + + Ok((address, credentials)) } pub fn auth(&self, credentials: &str) -> Result<()> { |
