utils

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigFileName   = "xops_config.yaml"
	PasswordFileName = "xops_passwords.json"
	ConfigKeyName    = "secret.key"
)

Variables

This section is empty.

Functions

func GetConfigFilePath

func GetConfigFilePath() (configPath, keyPath string)

func GetConfigStore

GetConfigStore 返回配置存储、Provider、配置对象及其可能发生的错误

func GetCurrentUser

func GetCurrentUser() string

func GetLocalSudoPassword

func GetLocalSudoPassword() string

GetLocalSudoPassword 尝试从配置文件中获取本地 sudo 密码

func GetPasswordFilePath

func GetPasswordFilePath() string

func IsValidCIDR

func IsValidCIDR(cidrStr string) bool

IsValidCIDR 检查给定的字符串是否是有效的CIDR表示法

func IsValidIP

func IsValidIP(ipStr string) bool

IsValidIP 检查给定的字符串是否是有效的IP地址

func ParseAddr

func ParseAddr(input string) (string, string, uint16)

ParseAddr 解析 user@host:port 格式的字符串

func ParseHost

func ParseHost(input string) (string, uint16)

ParseHost 解析 host:port 格式的字符串

func ParsePort

func ParsePort(input string) uint16

ParsePort 解析端口字符串

func ReadPasswordFromTerminal

func ReadPasswordFromTerminal(prompt string) (string, error)

ReadPasswordFromTerminal 从终端安全地读取密码

func ToAbsolutePath added in v0.2.0

func ToAbsolutePath(path string) string

ToAbsolutePath 将路径转换为绝对路径 支持 ~ 展开和相对路径转绝对路径 如果路径已经是绝对路径,直接返回

Types

type HostInfo

type HostInfo struct {
	Host       string
	Port       uint16
	Alias      string
	User       string
	Password   string
	KeyPath    string
	Passphrase string
}

HostInfo 存储从CSV或参数中解析出的主机信息

func ParseHosts

func ParseHosts(ip, hostFile, csvFile string) ([]HostInfo, error)

ParseHosts 综合处理单主机、主机文件和CSV文件中的主机信息

func ReadCSVFile

func ReadCSVFile(path string) ([]HostInfo, error)

ReadCSVFile 从指定路径读取CSV文件并解析为主机列表

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL