add support to override hostname and username via env var (#1041)

This commit is contained in:
Peter Brunner 2023-06-12 12:58:46 -04:00 committed by GitHub
parent 8655c93853
commit a6da5340e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 7 deletions

View file

@ -1,5 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::HashSet; use std::collections::HashSet;
use std::env;
use chrono::Utc; use chrono::Utc;
use eyre::{bail, Result}; use eyre::{bail, Result};
@ -161,10 +162,13 @@ impl<'a> Client<'a> {
host: Option<String>, host: Option<String>,
deleted: HashSet<String>, deleted: HashSet<String>,
) -> Result<Vec<History>> { ) -> Result<Vec<History>> {
let host = match host { let host = host.unwrap_or_else(|| {
None => hash_str(&format!("{}:{}", whoami::hostname(), whoami::username())), hash_str(&format!(
Some(h) => h, "{}:{}",
}; env::var("ATUIN_HOST_NAME").unwrap_or_else(|_| whoami::hostname()),
env::var("ATUIN_HOST_USER").unwrap_or_else(|_| whoami::username())
))
});
let url = format!( let url = format!(
"{}/sync/history?sync_ts={}&history_ts={}&host={}", "{}/sync/history?sync_ts={}&history_ts={}&host={}",

View file

@ -43,7 +43,11 @@ pub fn current_context() -> Context {
eprintln!("ERROR: Failed to find $ATUIN_SESSION in the environment. Check that you have correctly set up your shell."); eprintln!("ERROR: Failed to find $ATUIN_SESSION in the environment. Check that you have correctly set up your shell.");
std::process::exit(1); std::process::exit(1);
}; };
let hostname = format!("{}:{}", whoami::hostname(), whoami::username()); let hostname = format!(
"{}:{}",
env::var("ATUIN_HOST_NAME").unwrap_or_else(|_| whoami::hostname()),
env::var("ATUIN_HOST_USER").unwrap_or_else(|_| whoami::username())
);
let cwd = utils::get_current_dir(); let cwd = utils::get_current_dir();
Context { Context {

View file

@ -49,8 +49,13 @@ impl History {
let session = session let session = session
.or_else(|| env::var("ATUIN_SESSION").ok()) .or_else(|| env::var("ATUIN_SESSION").ok())
.unwrap_or_else(|| uuid_v7().as_simple().to_string()); .unwrap_or_else(|| uuid_v7().as_simple().to_string());
let hostname = let hostname = hostname.unwrap_or_else(|| {
hostname.unwrap_or_else(|| format!("{}:{}", whoami::hostname(), whoami::username())); format!(
"{}:{}",
env::var("ATUIN_HOST_NAME").unwrap_or_else(|_| whoami::hostname()),
env::var("ATUIN_HOST_USER").unwrap_or_else(|_| whoami::username())
)
});
Self { Self {
id: uuid_v7().as_simple().to_string(), id: uuid_v7().as_simple().to_string(),