Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8539e0308d | ||
|
|
ef53278466 |
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"sha256": {
|
"sha256": {
|
||||||
"aarch64-apple-darwin": "910820e932ae36b65e313a23fa66c5ca5c0a0aa93fc00dc3dbf8441be1a2bcb5",
|
"aarch64-apple-darwin": "f7859070acf2b34527a14fa031e0deff8a07540e61a32138b1a5f1b19c4025e4",
|
||||||
"x86_64-unknown-linux-musl": "9964dc4ff29edc7289503d52b07ae45de9a604343d6003710718bc11c3d87076"
|
"x86_64-unknown-linux-musl": "202c05f892e29f16e5446b4e6b51ec24f8fd55ee73fc1359b202fe7bfa8cc28f"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+13
-8
@@ -1,9 +1,19 @@
|
|||||||
//! Profile: `<config>/profiles/NAME.toml`. One profile = one identity (own HOME/auth), budget and gate.
|
//! Profile: `./.hx/profiles/NAME.toml` (repo-local, checked first), else `<config>/profiles/NAME.toml`. One profile = one identity (own HOME/auth), budget and gate.
|
||||||
|
|
||||||
use anyhow::{Context, Result, bail};
|
use anyhow::{Context, Result, bail};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
/// `./.hx/profiles/NAME.toml` when it exists (repo-local wins), else `<config>/profiles/NAME.toml`.
|
||||||
|
fn profile_path(name: &str) -> PathBuf {
|
||||||
|
let file = format!("{name}.toml");
|
||||||
|
let local = PathBuf::from(".hx/profiles").join(&file);
|
||||||
|
if local.is_file() {
|
||||||
|
return local;
|
||||||
|
}
|
||||||
|
crate::config_dir().join("profiles").join(file)
|
||||||
|
}
|
||||||
|
|
||||||
/// [`Profile::add_allow`] on a file.
|
/// [`Profile::add_allow`] on a file.
|
||||||
fn add_allow_at(path: &std::path::Path, entry: &str) -> Result<bool> {
|
fn add_allow_at(path: &std::path::Path, entry: &str) -> Result<bool> {
|
||||||
crate::policy::check_entry(entry)?;
|
crate::policy::check_entry(entry)?;
|
||||||
@@ -172,9 +182,7 @@ impl Profile {
|
|||||||
if name.is_empty() || name.contains(['/', '.']) {
|
if name.is_empty() || name.contains(['/', '.']) {
|
||||||
bail!("bad profile name {name:?}");
|
bail!("bad profile name {name:?}");
|
||||||
}
|
}
|
||||||
let path = crate::config_dir()
|
let path = profile_path(name);
|
||||||
.join("profiles")
|
|
||||||
.join(format!("{name}.toml"));
|
|
||||||
let s = match std::fs::read_to_string(&path) {
|
let s = match std::fs::read_to_string(&path) {
|
||||||
// only the implicit profile may be missing; a typo in any other name must still fail
|
// only the implicit profile may be missing; a typo in any other name must still fail
|
||||||
Err(e) if name == "default" && e.kind() == std::io::ErrorKind::NotFound => {
|
Err(e) if name == "default" && e.kind() == std::io::ErrorKind::NotFound => {
|
||||||
@@ -192,10 +200,7 @@ impl Profile {
|
|||||||
if name.is_empty() || name.contains(['/', '.']) {
|
if name.is_empty() || name.contains(['/', '.']) {
|
||||||
bail!("bad profile name {name:?}");
|
bail!("bad profile name {name:?}");
|
||||||
}
|
}
|
||||||
let path = crate::config_dir()
|
add_allow_at(&profile_path(name), entry)
|
||||||
.join("profiles")
|
|
||||||
.join(format!("{name}.toml"));
|
|
||||||
add_allow_at(&path, entry)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn account<'a>(&'a self, profile: &'a str) -> &'a str {
|
pub fn account<'a>(&'a self, profile: &'a str) -> &'a str {
|
||||||
|
|||||||
Reference in new issue
Block a user