home-manager
This commit is contained in:
+1
-3
@@ -1,12 +1,10 @@
|
||||
use color_eyre::Report;
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
use ratatui::{prelude::CrosstermBackend, widgets::ListState, DefaultTerminal, Terminal};
|
||||
use ratatui_form::{Email, Form};
|
||||
use ratatui::{prelude::CrosstermBackend, widgets::ListState, Terminal};
|
||||
use std::{io, path::Path};
|
||||
|
||||
use crate::{
|
||||
event::{AppEvent, Event, EventHandler},
|
||||
form::FormState,
|
||||
manifest::{load_manifest, Manifest},
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ pub struct Manifest {
|
||||
#[serde(rename = "masterKeys")]
|
||||
pub master_keys: Vec<String>,
|
||||
pub hosts: BTreeMap<String, HostInfo>,
|
||||
#[serde(rename = "homeIdentities", default)]
|
||||
pub home_identities: Vec<String>,
|
||||
pub secrets: BTreeMap<String, SecretInfo>,
|
||||
}
|
||||
|
||||
@@ -28,6 +30,8 @@ pub struct SecretInfo {
|
||||
#[serde(rename = "neededForUsers")]
|
||||
pub needed_for_users: bool,
|
||||
pub keys: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub home: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq)]
|
||||
|
||||
@@ -91,25 +91,29 @@ fn render_secret_detail(state: &App, area: Rect, buf: &mut Buffer) {
|
||||
Span::styled(scope, Style::default().fg(Color::White)),
|
||||
]));
|
||||
if !secret.global {
|
||||
// Hosts
|
||||
let hosts_str = if secret.hosts.is_empty() {
|
||||
if secret.global {
|
||||
manifest
|
||||
.hosts
|
||||
.keys()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
} else {
|
||||
"none".to_string()
|
||||
}
|
||||
// Hosts / identities. Home-manager identities are coloured distinctly
|
||||
// so it is obvious which targets are user (home) rather than system.
|
||||
let mut host_spans: Vec<Span> = vec![Span::styled(
|
||||
" Hosts: ",
|
||||
Style::default().fg(Color::DarkGray),
|
||||
)];
|
||||
if secret.hosts.is_empty() {
|
||||
host_spans.push(Span::styled("none", Style::default().fg(Color::White)));
|
||||
} else {
|
||||
secret.hosts.join(", ")
|
||||
};
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(" Hosts: ", Style::default().fg(Color::DarkGray)),
|
||||
Span::styled(hosts_str, Style::default().fg(Color::White)),
|
||||
]));
|
||||
for (i, identity) in secret.hosts.iter().enumerate() {
|
||||
if i > 0 {
|
||||
host_spans.push(Span::styled(", ", Style::default().fg(Color::DarkGray)));
|
||||
}
|
||||
let is_home = manifest.home_identities.contains(identity);
|
||||
let style = if is_home {
|
||||
Style::default().fg(Color::Magenta)
|
||||
} else {
|
||||
Style::default().fg(Color::White)
|
||||
};
|
||||
host_spans.push(Span::styled(identity.clone(), style));
|
||||
}
|
||||
}
|
||||
lines.push(Line::from(host_spans));
|
||||
}
|
||||
|
||||
// Recipients
|
||||
@@ -128,6 +132,14 @@ fn render_secret_detail(state: &App, area: Rect, buf: &mut Buffer) {
|
||||
Span::styled("yes", Style::default().fg(Color::Yellow)),
|
||||
]));
|
||||
}
|
||||
|
||||
// Home-manager: shown when this secret is consumed by a home-manager user.
|
||||
if secret.home {
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(" Home-mgr: ", Style::default().fg(Color::DarkGray)),
|
||||
Span::styled("yes", Style::default().fg(Color::Magenta)),
|
||||
]));
|
||||
}
|
||||
while lines.len() < 6 {
|
||||
lines.push(Line::from(""));
|
||||
}
|
||||
@@ -151,14 +163,22 @@ fn render_secret_detail(state: &App, area: Rect, buf: &mut Buffer) {
|
||||
let label = if manifest.master_keys.contains(key) {
|
||||
Span::styled(" (master)", Style::default().fg(Color::Magenta))
|
||||
} else {
|
||||
// Try to find which host owns this key
|
||||
let host_label = manifest
|
||||
// Try to find which identity owns this key. Home identities are
|
||||
// tagged and coloured distinctly from system identities.
|
||||
match manifest
|
||||
.hosts
|
||||
.iter()
|
||||
.find(|(_, info)| info.keys.contains(key))
|
||||
.map(|(name, _)| format!(" ({})", name))
|
||||
.unwrap_or_default();
|
||||
Span::styled(host_label, Style::default().fg(Color::Cyan))
|
||||
{
|
||||
Some((name, _)) if manifest.home_identities.contains(name) => Span::styled(
|
||||
format!(" ({name}, home)"),
|
||||
Style::default().fg(Color::Magenta),
|
||||
),
|
||||
Some((name, _)) => {
|
||||
Span::styled(format!(" ({name})"), Style::default().fg(Color::Cyan))
|
||||
}
|
||||
None => Span::raw(""),
|
||||
}
|
||||
};
|
||||
|
||||
lines.push(Line::from(vec![
|
||||
@@ -168,7 +188,7 @@ fn render_secret_detail(state: &App, area: Rect, buf: &mut Buffer) {
|
||||
]));
|
||||
}
|
||||
|
||||
let paragraph = Paragraph::new(lines).block(block).render(area, buf);
|
||||
Paragraph::new(lines).block(block).render(area, buf);
|
||||
}
|
||||
|
||||
fn render_placeholder(area: Rect, buf: &mut Buffer, title: &str, message: &str) {
|
||||
|
||||
Reference in New Issue
Block a user