Use opaque type for auth token

So we cannot accidentially output it, as it does not implement
`Display`.
This commit is contained in:
2022-05-28 22:20:53 +02:00
parent 461c69dacb
commit d9f416018d
4 changed files with 27 additions and 19 deletions

View File

@@ -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()))
}