utils

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigFileName   = "xops_config.yaml"
	PasswordFileName = "xops_passwords.json"
	ConfigKeyName    = "secret.key"
)
View Source
const (
	// RememberPolicyAsk 默认策略:交互时询问用户是否保存,非交互时不保存
	RememberPolicyAsk = "ask"
	// RememberPolicyAlways 总是保存凭据
	RememberPolicyAlways = "always"
	// RememberPolicyNever 从不保存凭据(会话级)
	RememberPolicyNever = "never"
)

Variables

This section is empty.

Functions

func AskConfirmation added in v0.6.0

func AskConfirmation(prompt string) (bool, error)

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

func BuildCredentialRegistry added in v0.12.0

func BuildCredentialRegistry(cfg *config.CredentialConfig) (*credential.Registry, error)

BuildCredentialRegistry uses the owner's runtime when present. Library callers without an owner retain the fail-closed factory behavior for offline stores.

func CredentialRuntime added in v0.12.0

func CredentialRuntime() (*config.EncryptedRuntime, error)

CredentialRuntime returns the current command's borrowed runtime.

func EffectiveRememberPolicy added in v0.12.0

func EffectiveRememberPolicy(override string, cfg *config.Configuration) string

EffectiveRememberPolicy applies command override, configuration, then ask.

func GetConfigFilePath

func GetConfigFilePath() (configPath, keyPath string, err error)

GetConfigFilePath 获取默认配置与密钥路径

func GetConfigStore

func GetConfigStore() (config.Store, *config.Repository, *config.Configuration, error)

GetConfigStore returns the storage bootstrap handle, the sole durable repository, and a defensive configuration snapshot.

func GetCredentialRegistry added in v0.12.0

func GetCredentialRegistry(cfg *config.Configuration) (*credential.Registry, error)

GetCredentialRegistry 根据配置构建只读凭据注册表(若未配置返回 nil)

func GetCredentialService added in v0.12.0

func GetCredentialService(repo *config.Repository, cfg *config.Configuration) (*credential.Service, error)

GetCredentialService 根据配置和存储仓库实例化凭据服务

func GetCurrentUser

func GetCurrentUser() (string, error)

GetCurrentUser 获取当前用户名

func GetLocalSudoPassword

func GetLocalSudoPassword() (string, bool, error)

GetLocalSudoPassword 尝试从配置文件中获取本地 sudo 密码,返回 (password, found, error)

func GetLocalSudoPasswordContext added in v0.12.0

func GetLocalSudoPasswordContext(ctx context.Context) (string, bool, error)

GetLocalSudoPasswordContext resolves v2 references on demand with cancellation.

func GetPasswordFilePath

func GetPasswordFilePath() (string, error)

GetPasswordFilePath 获取默认密码本文件路径

func InstallCredentialRuntime added in v0.12.0

func InstallCredentialRuntime(r *config.EncryptedRuntime) (func(), error)

InstallCredentialRuntime lends the command owner's runtime to all CLI services. The returned function detaches it; the owner still must wait for Close.

func IsValidCIDR

func IsValidCIDR(cidrStr string) bool

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

func IsValidIP

func IsValidIP(ipStr string) bool

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

func ParseAddr

func ParseAddr(input string) (user, host string, port uint16, err error)

ParseAddr 解析 [user@]host[:port] 格式的字符串,支持 IPv6

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, error)

ParseHost 解析 host:port 或 [ipv6]:port 或裸 ipv6 格式的字符串

func ParsePort

func ParsePort(input string) (uint16, error)

ParsePort 解析端口字符串

func ReadPasswordFromTerminal

func ReadPasswordFromTerminal(prompt string) (string, error)

ReadPasswordFromTerminal 从终端安全地读取密码

func ReadSecretFromReader added in v0.12.0

func ReadSecretFromReader(r io.Reader) (string, error)

ReadSecretFromReader 从指定的 Reader 流读取机密并去除末尾的换行符

func ReadSecretFromStdin added in v0.12.0

func ReadSecretFromStdin() (string, error)

ReadSecretFromStdin 从标准输入流读取机密并去除末尾的换行符

func RememberLocalSudoPassword added in v0.12.0

func RememberLocalSudoPassword(ctx context.Context, password string) error

RememberLocalSudoPassword applies the configured policy after successful sudo. none always leaves the secret in the session, including on new installations.

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 SaveLocalSudoPasswordContext added in v0.12.0

func SaveLocalSudoPasswordContext(ctx context.Context, password string) error

SaveLocalSudoPasswordContext persists the local sudo password with caller cancellation applied to the configuration transaction.

func ShouldRememberConfiguredCredential added in v0.12.0

func ShouldRememberConfiguredCredential(policy, targetName string, cfg *config.Configuration) bool

ShouldRememberConfiguredCredential skips confirmation when persistence is disabled or no writable default store is configured, without probing stores.

func ShouldRememberCredential added in v0.12.0

func ShouldRememberCredential(policy string, targetName string) bool

ShouldRememberCredential applies the policy, asking only on a terminal.

func ToAbsolutePath added in v0.2.0

func ToAbsolutePath(path string) string

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

func ValidateRememberPolicy added in v0.12.0

func ValidateRememberPolicy(policy string) error

ValidateRememberPolicy 校验 remember 策略取值

func WarnFlagDeprecated added in v0.12.0

func WarnFlagDeprecated(flagName, replacement string)

WarnFlagDeprecated 输出统一的 CLI 参数废弃警告

func WarnInventorySecretFlags added in v0.12.0

func WarnInventorySecretFlags(cmd *cobra.Command)

WarnInventorySecretFlags covers both identity and host compatibility flags.

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) (hosts []HostInfo, err error)

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

type InventoryCredentialWrite added in v0.12.0

type InventoryCredentialWrite struct {
	// contains filtered or unexported fields
}

InventoryCredentialWrite keeps secret material outside inventory models. Metadata creation may precede Save; a failed Save never falls back to YAML.

func PrepareInventoryCredential added in v0.12.0

func PrepareInventoryCredential(repo *config.Repository, target credential.Target, identity models.Identity, password, passphrase, keyPath string, updater credential.ConfigUpdater) (*InventoryCredentialWrite, error)

PrepareInventoryCredential validates the destination before metadata changes. A nil write means that neither a new secret nor a key replacement was supplied.

func (*InventoryCredentialWrite) Clear added in v0.12.0

func (w *InventoryCredentialWrite) Clear()

Clear releases the write's temporary secret on every caller return path.

func (*InventoryCredentialWrite) Save added in v0.12.0

func (w *InventoryCredentialWrite) Save(ctx context.Context, version string) error

Save commits a secret and its authentication metadata using the exact version of the initial edit snapshot. Creation callers use the version of their preceding metadata creation. Key-only writes unlink old passphrases.

Jump to

Keyboard shortcuts

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