Merge branch 'development' into development_tmux
* development: ... ... ... ... # Conflicts: # examples/osal/sshagent.vsh # examples/osal/sshagent/sshagent_example.v # examples/osal/tmux.vsh # lib/osal/sshagent/agent.v # lib/osal/sshagent/builder_integration.v # lib/osal/tmux/tmux_pane.v # lib/osal/tmux/tmux_scan.v # lib/osal/tmux/tmux_session.v # lib/osal/tmux/tmux_window.v
This commit is contained in:
65
examples/osal/sshagent.vsh
Normal file
65
examples/osal/sshagent.vsh
Normal file
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.osal.sshagent
|
||||
import freeflowuniverse.herolib.builder
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
console.print_header('SSH Agent Management Example')
|
||||
|
||||
// Create SSH agent with single instance guarantee
|
||||
mut agent := sshagent.new_single()!
|
||||
println('SSH Agent initialized and ensured single instance')
|
||||
|
||||
// Show diagnostics
|
||||
diag := agent.diagnostics()
|
||||
console.print_header('SSH Agent Diagnostics:')
|
||||
for key, value in diag {
|
||||
console.print_item('${key}: ${value}')
|
||||
}
|
||||
|
||||
// Show current agent status
|
||||
println(agent)
|
||||
|
||||
// Example: Generate a test key if no keys exist
|
||||
if agent.keys.len == 0 {
|
||||
console.print_header('No keys found, generating example key...')
|
||||
mut key := agent.generate('example_key', '')!
|
||||
console.print_debug('Generated key: ${key}')
|
||||
|
||||
// Load the generated key
|
||||
key.load()!
|
||||
console.print_debug('Key loaded into agent')
|
||||
}
|
||||
|
||||
// Example: Push key to remote node (uncomment and modify for actual use)
|
||||
/*
|
||||
console.print_header('Testing remote node key deployment...')
|
||||
mut b := builder.new()!
|
||||
|
||||
// Create connection to remote node
|
||||
mut node := b.node_new(
|
||||
ipaddr: 'root@192.168.1.100:22' // Replace with actual remote host
|
||||
name: 'test_node'
|
||||
)!
|
||||
|
||||
if agent.keys.len > 0 {
|
||||
key_name := agent.keys[0].name
|
||||
console.print_debug('Pushing key "${key_name}" to remote node...')
|
||||
|
||||
// Push the key
|
||||
agent.push_key_to_node(mut node, key_name)!
|
||||
|
||||
// Verify access
|
||||
if agent.verify_key_access(mut node, key_name)! {
|
||||
console.print_debug('✓ SSH key access verified')
|
||||
} else {
|
||||
console.print_debug('✗ SSH key access verification failed')
|
||||
}
|
||||
|
||||
// Optional: Remove key from remote (for testing)
|
||||
// agent.remove_key_from_node(mut node, key_name)!
|
||||
// console.print_debug('Key removed from remote node')
|
||||
}
|
||||
*/
|
||||
|
||||
console.print_header('SSH Agent example completed successfully')
|
||||
51
examples/osal/sshagent/sshagent_example.v
Normal file
51
examples/osal/sshagent/sshagent_example.v
Normal file
@@ -0,0 +1,51 @@
|
||||
module main
|
||||
|
||||
import freeflowuniverse.herolib.osal.sshagent
|
||||
import freeflowuniverse.herolib.osal.linux
|
||||
|
||||
fn do1() ! {
|
||||
mut agent := sshagent.new()!
|
||||
println(agent)
|
||||
k := agent.get(name: 'kds') or { panic('notgound') }
|
||||
println(k)
|
||||
|
||||
mut k2 := agent.get(name: 'books') or { panic('notgound') }
|
||||
k2.load()!
|
||||
println(k2.agent)
|
||||
|
||||
println(agent)
|
||||
|
||||
k2.forget()!
|
||||
println(k2.agent)
|
||||
|
||||
// println(agent)
|
||||
}
|
||||
|
||||
fn test_user_mgmt() ! {
|
||||
mut lf := linux.new()!
|
||||
// Test user creation
|
||||
lf.user_create(
|
||||
name: 'testuser'
|
||||
sshkey: 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM3/2K7R8A/l0kM0/d'
|
||||
)!
|
||||
|
||||
// Test ssh key creation
|
||||
lf.sshkey_create(
|
||||
username: 'testuser'
|
||||
sshkey_name: 'testkey'
|
||||
)!
|
||||
|
||||
// Test ssh key deletion
|
||||
lf.sshkey_delete(
|
||||
username: 'testuser'
|
||||
sshkey_name: 'testkey'
|
||||
)!
|
||||
|
||||
// Test user deletion
|
||||
lf.user_delete(name: 'testuser')!
|
||||
}
|
||||
|
||||
fn main() {
|
||||
do1() or { panic(err) }
|
||||
test_user_mgmt() or { panic(err) }
|
||||
}
|
||||
19
examples/osal/tmux.vsh
Executable file
19
examples/osal/tmux.vsh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run
|
||||
|
||||
import freeflowuniverse.herolib.osal.tmux
|
||||
|
||||
mut t := tmux.new()!
|
||||
if !t.is_running()! {
|
||||
t.start()!
|
||||
}
|
||||
if t.session_exist('main') {
|
||||
t.session_delete('main')!
|
||||
}
|
||||
// Create session first, then create window
|
||||
mut session := t.session_create(name: 'main')!
|
||||
session.window_new(name: 'test', cmd: 'mc', reset: true)!
|
||||
|
||||
// Or use the convenience method
|
||||
// t.window_new(session_name: 'main', name: 'test', cmd: 'mc', reset: true)!
|
||||
|
||||
println(t)
|
||||
@@ -6,7 +6,7 @@ import time
|
||||
|
||||
mut t := tmux.new()!
|
||||
if !t.is_running()! {
|
||||
t.start()!
|
||||
t.start()!
|
||||
}
|
||||
|
||||
// Create a session and window
|
||||
@@ -18,15 +18,15 @@ time.sleep(1000 * time.millisecond)
|
||||
|
||||
// Get the active pane
|
||||
if mut pane := window.pane_active() {
|
||||
// Get process info for the pane and its children
|
||||
process_map := pane.processinfo()!
|
||||
|
||||
println('Process tree for pane ${pane.id}:')
|
||||
for process in process_map.processes {
|
||||
println(' PID: ${process.pid}, CPU: ${process.cpu_perc}%, Memory: ${process.mem_perc}%, Command: ${process.cmd}')
|
||||
}
|
||||
|
||||
// Get just the main process info
|
||||
main_process := pane.processinfo_main()!
|
||||
println('\nMain process: PID ${main_process.pid}, Command: ${main_process.cmd}')
|
||||
}
|
||||
// Get process info for the pane and its children
|
||||
process_map := pane.processinfo()!
|
||||
|
||||
println('Process tree for pane ${pane.id}:')
|
||||
for process in process_map.processes {
|
||||
println(' PID: ${process.pid}, CPU: ${process.cpu_perc}%, Memory: ${process.mem_perc}%, Command: ${process.cmd}')
|
||||
}
|
||||
|
||||
// Get just the main process info
|
||||
main_process := pane.processinfo_main()!
|
||||
println('\nMain process: PID ${main_process.pid}, Command: ${main_process.cmd}')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user