utils

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 13 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 AskConfirmation added in v0.6.0

func AskConfirmation(prompt string) bool

AskConfirmation 弹出提示,获取用户确认

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 ParseExcludeFlag added in v0.11.0

func ParseExcludeFlag(values []string) []string

ParseExcludeFlag 将 --exclude 选项的字符串值解析为规整化的列表。 支持以下输入形式:

  • 单个值: "web-01"
  • 逗号分隔: "web-01,web-02"

空白项会被自动过滤。

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 ResolveExcludes added in v0.11.0

func ResolveExcludes(provider config.ConfigProvider, excludes []string) (map[string]struct{}, error)

ResolveExcludes 将用户输入的排除项(可能是别名/IP/User@Host)解析为对应的 NodeID 集合。 对于无法匹配的输入,会返回错误(包含未匹配项列表),避免静默放过导致执行到本应排除的主机。

func SaveLocalSudoPassword added in v0.8.0

func SaveLocalSudoPassword(password string) error

SaveLocalSudoPassword 保存本地 sudo 密码到配置文件

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