Use opaque type for auth token
So we cannot accidentially output it, as it does not implement `Display`.
This commit is contained in:
13
src/auth.rs
13
src/auth.rs
@@ -1,6 +1,15 @@
|
||||
use std::process;
|
||||
|
||||
pub fn get_token_from_command(command: &str) -> Result<String, String> {
|
||||
#[derive(Clone)]
|
||||
pub struct AuthToken(String);
|
||||
|
||||
impl AuthToken {
|
||||
pub fn access(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_token_from_command(command: &str) -> Result<AuthToken, String> {
|
||||
let output = process::Command::new("/usr/bin/env")
|
||||
.arg("sh")
|
||||
.arg("-c")
|
||||
@@ -32,5 +41,5 @@ pub fn get_token_from_command(command: &str) -> Result<String, String> {
|
||||
.next()
|
||||
.ok_or_else(|| String::from("Output did not contain any newline"))?;
|
||||
|
||||
Ok(token.to_string())
|
||||
Ok(AuthToken(token.to_string()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user