Files
herolib/lib/core
kristof de spiegeleer 2c5986295e Merge branch 'development_bizmodel' into development_generator_docusaurus
* development_bizmodel: (93 commits)
  s
  Revert "test: add cmdline parser tests"
  test: add cmdline parser tests
  markdown code
  ...
  revert
  ...
  ..deployments
  ...
  bump version to 1.0.21
  ...
  bump version to 1.0.20
  ...
  fix tests and example
  bump version to 1.0.19
  bump version to 1.0.18
  bump version to 1.0.17
  ...
  ...
  bump version to 1.0.16
  ...

# Conflicts:
#	lib/web/docusaurus/config.v
2025-03-08 10:55:58 +01:00
..
...
2025-02-07 11:59:52 +03:00
2025-02-06 06:26:44 +03:00
...
2025-03-07 10:09:39 +01:00
2025-01-23 14:16:02 +01:00
2025-02-06 06:26:44 +03:00
...
2024-12-30 08:01:17 +01:00
2025-01-27 17:18:39 +02:00
2024-12-25 11:44:17 +01:00
fix
2024-12-25 19:17:23 +01:00
2024-12-25 11:18:08 +01:00
2025-01-01 17:44:06 +01:00
2025-01-01 17:44:06 +01:00
2025-01-01 17:44:06 +01:00
2025-01-01 17:44:06 +01:00
2025-01-01 17:44:06 +01:00
2025-01-01 17:44:06 +01:00
2025-01-01 17:44:06 +01:00

Core Module

The Core module provides fundamental system-level functionality for the Hero framework. It handles platform detection, system operations, and provides essential utilities used throughout the framework.

Main Features

Platform Management

  • Platform detection (OSX, Ubuntu, Alpine, Arch)
  • CPU architecture detection (Intel, ARM)
  • System information retrieval (hostname, init system)
  • Cross-platform compatibility utilities

Memory Database

  • Thread-safe in-memory key-value store
  • Global state management
  • Caching for system information

Sudo Operations

  • Permission management and verification
  • Sudo requirement detection
  • Path access rights checking
  • Command elevation handling

Submodules

  • base: Context and session management
  • httpconnection: HTTP client functionality
  • logger: Logging infrastructure
  • pathlib: Path manipulation and handling
  • playbook: Execution playbooks
  • redisclient: Redis database client
  • rootpath: Root path management
  • smartid: Identifier management
  • texttools: Text manipulation utilities
  • vexecutor: Command execution

Platform Support

The module supports multiple platforms:

  • macOS (Intel and ARM)
  • Ubuntu
  • Alpine Linux
  • Arch Linux

And CPU architectures:

  • x86_64 (Intel)
  • ARM64/AArch64

Usage

The core module provides essential functionality used by other Hero framework components. Key features include:

Interactivity Check & Influence on delete

import freeflowuniverse.herolib.installers.lang.golang
import freeflowuniverse.herolib.core

core.interactive_set()! //make sure the sudo works so we can do things even if it requires those rights

//this will allow files which are in sudo area to still get them removed but its important interactive is set on the context.
golang.install(reset:false)!

Platform Detection

// Check platform type
if core.is_linux()! {
    // Linux-specific code
}

// Check CPU architecture
if core.is_linux_arm()! {
    // ARM-specific code
}

Memory Database

// Store values
core.memdb_set('key', 'value')

// Retrieve values
value := core.memdb_get('key')

Sudo Operations

The sudo operations module provides comprehensive permission management and command elevation handling:

// Check if sudo is required for the current user
if core.sudo_required()! {
    // Handle sudo requirements
    // Returns false if user is root or on macOS
    // Returns true if user has sudo privileges
}

// Verify path permissions and accessibility
path := core.sudo_path_check('/path/to/check')! {
    // Returns the path if accessible
    // Errors if path requires sudo rights
}

// Check if a path is accessible without sudo
if core.sudo_path_ok('/usr/local/bin')! {
    // Returns false for protected directories like:
    // /usr/, /boot, /etc, /root/
    // Returns true if path is accessible
}

// Check and modify commands that require sudo
cmd := core.sudo_cmd_check('ufw enable')! {
    // Automatically adds 'sudo' prefix if:
    // 1. Command requires elevated privileges
    // 2. User doesn't have sudo rights
    // 3. Running in interactive mode
}

// Check if current process has sudo rights
if core.sudo_rights_check()! {
    // Returns true if:
    // - Running as root user
    // - Has necessary sudo privileges
}