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::HashSet;
use std::env;
use chrono::Utc;
use eyre::{bail, Result};
@ -161,10 +162,13 @@ impl<'a> Client<'a> {
host: Option<String>,
deleted: HashSet<String>,
) -> Result<Vec<History>> {
let host = match host {
None => hash_str(&format!("{}:{}", whoami::hostname(), whoami::username())),
Some(h) => h,
};
let host = host.unwrap_or_else(|| {
hash_str(&format!(
"{}:{}",
env::var("ATUIN_HOST_NAME").unwrap_or_else(|_| whoami::hostname()),
env::var("ATUIN_HOST_USER").unwrap_or_else(|_| whoami::username())
))
});
let url = format!(
"{}/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.");
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();
Context {

View File

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