ops: factor out current_provenance() helper
The POC_PROVENANCE env var lookup was duplicated in upsert, delete_node, and rename_node. Extract to a single function. Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
199c415cf2
commit
1629a2c4e3
1 changed files with 10 additions and 9 deletions
|
|
@ -7,6 +7,13 @@ use super::types::*;
|
||||||
|
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
|
/// Provenance from POC_PROVENANCE env var, defaulting to "manual".
|
||||||
|
fn current_provenance() -> String {
|
||||||
|
Provenance::from_env()
|
||||||
|
.map(|p| p.label().to_string())
|
||||||
|
.unwrap_or_else(|| "manual".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
impl Store {
|
impl Store {
|
||||||
/// Add or update a node (appends to log + updates cache).
|
/// Add or update a node (appends to log + updates cache).
|
||||||
/// Holds StoreLock across refresh + check + write to prevent duplicate UUIDs.
|
/// Holds StoreLock across refresh + check + write to prevent duplicate UUIDs.
|
||||||
|
|
@ -37,9 +44,7 @@ impl Store {
|
||||||
/// Provenance is determined by the POC_PROVENANCE env var if set,
|
/// Provenance is determined by the POC_PROVENANCE env var if set,
|
||||||
/// otherwise defaults to Manual.
|
/// otherwise defaults to Manual.
|
||||||
pub fn upsert(&mut self, key: &str, content: &str) -> Result<&'static str, String> {
|
pub fn upsert(&mut self, key: &str, content: &str) -> Result<&'static str, String> {
|
||||||
let prov = Provenance::from_env()
|
let prov = current_provenance();
|
||||||
.map(|p| p.label().to_string())
|
|
||||||
.unwrap_or_else(|| "manual".to_string());
|
|
||||||
self.upsert_provenance(key, content, &prov)
|
self.upsert_provenance(key, content, &prov)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,9 +81,7 @@ impl Store {
|
||||||
let _lock = StoreLock::acquire()?;
|
let _lock = StoreLock::acquire()?;
|
||||||
self.refresh_nodes()?;
|
self.refresh_nodes()?;
|
||||||
|
|
||||||
let prov = Provenance::from_env()
|
let prov = current_provenance();
|
||||||
.map(|p| p.label().to_string())
|
|
||||||
.unwrap_or_else(|| "manual".to_string());
|
|
||||||
|
|
||||||
let node = self.nodes.get(key)
|
let node = self.nodes.get(key)
|
||||||
.ok_or_else(|| format!("No node '{}'", key))?;
|
.ok_or_else(|| format!("No node '{}'", key))?;
|
||||||
|
|
@ -115,9 +118,7 @@ impl Store {
|
||||||
.ok_or_else(|| format!("No node '{}'", old_key))?
|
.ok_or_else(|| format!("No node '{}'", old_key))?
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
let prov = Provenance::from_env()
|
let prov = current_provenance();
|
||||||
.map(|p| p.label().to_string())
|
|
||||||
.unwrap_or_else(|| "manual".to_string());
|
|
||||||
|
|
||||||
// New version under the new key
|
// New version under the new key
|
||||||
let mut renamed = node.clone();
|
let mut renamed = node.clone();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue