MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / load_edge_token

Function load_edge_token

crates/openshell-bootstrap/src/edge_token.rs:43–69  ·  view source on GitHub ↗

Load a stored edge authentication token for a gateway. Returns `None` if no token file exists or the file is empty. Falls back to the legacy `cf_token` path for backwards compatibility. When loading from the legacy path, migrates the token to the new path with proper permissions.

(gateway_name: &str)

Source from the content-addressed store, hash-verified

41/// When loading from the legacy path, migrates the token to the new path
42/// with proper permissions.
43pub fn load_edge_token(gateway_name: &str) -> Option<String> {
44 // Try the new path first.
45 if let Some(path) = edge_token_path(gateway_name).ok().filter(|p| p.exists()) {
46 let contents = std::fs::read_to_string(&path).ok()?;
47 let token = contents.trim().to_string();
48 if !token.is_empty() {
49 return Some(token);
50 }
51 }
52
53 // Fall back to the legacy cf_token path.
54 let legacy_path = legacy_token_path(gateway_name)
55 .ok()
56 .filter(|p| p.exists())?;
57 let contents = std::fs::read_to_string(&legacy_path).ok()?;
58 let token = contents.trim().to_string();
59 if token.is_empty() {
60 return None;
61 }
62
63 // Migrate: write to new path with proper permissions, then remove legacy.
64 if store_edge_token(gateway_name, &token).is_ok() {
65 let _ = std::fs::remove_file(&legacy_path);
66 }
67
68 Some(token)
69}
70
71/// Remove a stored edge authentication token.
72pub fn remove_edge_token(gateway_name: &str) -> Result<()> {

Callers 2

apply_authFunction · 0.85
completion_grpc_clientFunction · 0.85

Calls 5

edge_token_pathFunction · 0.85
legacy_token_pathFunction · 0.85
store_edge_tokenFunction · 0.85
existsMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected