Documentation
¶
Index ¶
- Constants
- func AskConfirmation(prompt string) (bool, error)
- func BuildCredentialRegistry(cfg *config.CredentialConfig) (*credential.Registry, error)
- func CredentialRuntime() (*config.EncryptedRuntime, error)
- func EffectiveRememberPolicy(override string, cfg *config.Configuration) string
- func GetConfigFilePath() (configPath, keyPath string, err error)
- func GetConfigStore() (config.Store, *config.Repository, *config.Configuration, error)
- func GetCredentialRegistry(cfg *config.Configuration) (*credential.Registry, error)
- func GetCredentialService(repo *config.Repository, cfg *config.Configuration) (*credential.Service, error)
- func GetCurrentUser() (string, error)
- func GetLocalSudoPassword() (string, bool, error)
- func GetLocalSudoPasswordContext(ctx context.Context) (string, bool, error)
- func GetPasswordFilePath() (string, error)
- func InstallCredentialRuntime(r *config.EncryptedRuntime) (func(), error)
- func IsValidCIDR(cidrStr string) bool
- func IsValidIP(ipStr string) bool
- func ParseAddr(input string) (user, host string, port uint16, err error)
- func ParseExcludeFlag(values []string) []string
- func ParseHost(input string) (string, uint16, error)
- func ParsePort(input string) (uint16, error)
- func ReadPasswordFromTerminal(prompt string) (string, error)
- func ReadSecretFromReader(r io.Reader) (string, error)
- func ReadSecretFromStdin() (string, error)
- func RememberLocalSudoPassword(ctx context.Context, password string) error
- func ResolveExcludes(provider config.ConfigProvider, excludes []string) (map[string]struct{}, error)
- func SaveLocalSudoPassword(password string) error
- func SaveLocalSudoPasswordContext(ctx context.Context, password string) error
- func ShouldRememberConfiguredCredential(policy, targetName string, cfg *config.Configuration) bool
- func ShouldRememberCredential(policy string, targetName string) bool
- func ToAbsolutePath(path string) string
- func ValidateRememberPolicy(policy string) error
- func WarnFlagDeprecated(flagName, replacement string)
- func WarnInventorySecretFlags(cmd *cobra.Command)
- type HostInfo
- type InventoryCredentialWrite
Constants ¶
const ( ConfigFileName = "xops_config.yaml" PasswordFileName = "xops_passwords.json" ConfigKeyName = "secret.key" )
const ( // RememberPolicyAsk 默认策略:交互时询问用户是否保存,非交互时不保存 RememberPolicyAsk = "ask" // RememberPolicyAlways 总是保存凭据 RememberPolicyAlways = "always" // RememberPolicyNever 从不保存凭据(会话级) RememberPolicyNever = "never" )
Variables ¶
This section is empty.
Functions ¶
func AskConfirmation ¶ added in v0.6.0
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 ¶
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 GetLocalSudoPassword ¶
GetLocalSudoPassword 尝试从配置文件中获取本地 sudo 密码,返回 (password, found, error)
func GetLocalSudoPasswordContext ¶ added in v0.12.0
GetLocalSudoPasswordContext resolves v2 references on demand with cancellation.
func GetPasswordFilePath ¶
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 ParseExcludeFlag ¶ added in v0.11.0
ParseExcludeFlag 将 --exclude 选项的字符串值解析为规整化的列表。 支持以下输入形式:
- 单个值: "web-01"
- 逗号分隔: "web-01,web-02"
空白项会被自动过滤。
func ReadPasswordFromTerminal ¶
ReadPasswordFromTerminal 从终端安全地读取密码
func ReadSecretFromReader ¶ added in v0.12.0
ReadSecretFromReader 从指定的 Reader 流读取机密并去除末尾的换行符
func ReadSecretFromStdin ¶ added in v0.12.0
ReadSecretFromStdin 从标准输入流读取机密并去除末尾的换行符
func RememberLocalSudoPassword ¶ added in v0.12.0
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
SaveLocalSudoPassword 保存本地 sudo 密码到配置文件
func SaveLocalSudoPasswordContext ¶ added in v0.12.0
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
ShouldRememberCredential applies the policy, asking only on a terminal.
func ToAbsolutePath ¶ added in v0.2.0
ToAbsolutePath 将路径转换为绝对路径 支持 ~ 展开和相对路径转绝对路径 如果路径已经是绝对路径,直接返回
func ValidateRememberPolicy ¶ added in v0.12.0
ValidateRememberPolicy 校验 remember 策略取值
func WarnFlagDeprecated ¶ added in v0.12.0
func WarnFlagDeprecated(flagName, replacement string)
WarnFlagDeprecated 输出统一的 CLI 参数废弃警告
func WarnInventorySecretFlags ¶ added in v0.12.0
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 ¶
ParseHosts 综合处理单主机、主机文件和CSV文件中的主机信息
func ReadCSVFile ¶
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.