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 GetPasswordFilePath() (string, error)
- func InstallCredentialRuntime(r *config.EncryptedRuntime) (func(), error)
- func IsInteractiveTerminal() bool
- func IsValidCIDR(cidrStr string) bool
- func IsValidIP(ipStr string) bool
- func KeyNeedsPassphrase(path string) (bool, error)
- 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 PromptPassphraseIfEncryptedKey(keyPath, currentPassphrase string) (string, error)
- func ReadLineFromTerminal(prompt string) (string, error)
- func ReadPasswordFromTerminal(prompt string) (string, error)
- func ReadSecretFromReader(r io.Reader) (string, error)
- func ReadSecretFromStdin() (string, error)
- func ReadSecretLineFromReader(r io.Reader, maxBytes int64) (string, error)
- func ReadSecretLineFromStdin() (string, error)
- func ResolveExcludes(provider config.ConfigProvider, excludes []string) (map[string]struct{}, 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
- type CredentialCommandOptions
- func (o *CredentialCommandOptions) RegisterDeleteFlags(cmd *cobra.Command)
- func (o *CredentialCommandOptions) RegisterSetFlags(cmd *cobra.Command)
- func (o *CredentialCommandOptions) RunDelete(cmd *cobra.Command, query string) error
- func (o *CredentialCommandOptions) RunSet(cmd *cobra.Command, query string) error
- type CredentialTargetScope
- type HostInfo
- type InventoryCredentialWrite
- type InventorySecretInput
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 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 IsInteractiveTerminal ¶ added in v0.16.0
func IsInteractiveTerminal() bool
IsInteractiveTerminal 判断标准输入是否为交互式终端
func KeyNeedsPassphrase ¶ added in v0.16.0
KeyNeedsPassphrase checks whether the private key at path is encrypted and requires a passphrase.
func ParseExcludeFlag ¶ added in v0.11.0
ParseExcludeFlag 将 --exclude 选项的字符串值解析为规整化的列表。 支持以下输入形式:
- 单个值: "web-01"
- 逗号分隔: "web-01,web-02"
空白项会被自动过滤。
func PromptPassphraseIfEncryptedKey ¶ added in v0.16.0
PromptPassphraseIfEncryptedKey prompts for a passphrase on interactive terminals when keyPath points to an encrypted private key and no passphrase has been provided.
func ReadLineFromTerminal ¶ added in v0.16.0
ReadLineFromTerminal 从交互式终端读取一行文本输入
func ReadPasswordFromTerminal ¶
ReadPasswordFromTerminal 从终端安全地读取密码
func ReadSecretFromReader ¶ added in v0.12.0
ReadSecretFromReader 从指定的 Reader 流读取机密并去除末尾的换行符
func ReadSecretFromStdin ¶ added in v0.12.0
ReadSecretFromStdin 从标准输入流读取机密并去除末尾的换行符
func ReadSecretLineFromReader ¶ added in v0.16.0
ReadSecretLineFromReader 从指定的 Reader 流逐字节读取单行机密(直到 \n 或 EOF), 不预先缓冲后续字节,防止吞掉流中后续数据,并去除末尾的 \r 和 \n。
func ReadSecretLineFromStdin ¶ added in v0.16.0
ReadSecretLineFromStdin 从标准输入流读取单行机密
func ResolveExcludes ¶ added in v0.11.0
func ResolveExcludes(provider config.ConfigProvider, excludes []string) (map[string]struct{}, error)
ResolveExcludes 将用户输入的排除项(可能是别名/IP/User@Host)解析为对应的 NodeID 集合。 对于无法匹配的输入,会返回错误(包含未匹配项列表),避免静默放过导致执行到本应排除的主机。
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 策略取值
Types ¶
type CredentialCommandOptions ¶ added in v0.16.0
type CredentialCommandOptions struct {
Scope CredentialTargetScope
KindStr string
StoreID string
RuleName string
PasswordStdin bool
PassphraseStdin bool
KindPassword bool
KindPassphrase bool
KindTOTP bool
KindSudo bool
ChallengeRule string
ForceNode bool
ForceIdentity bool
}
CredentialCommandOptions holds flags for setting or deleting a credential.
func (*CredentialCommandOptions) RegisterDeleteFlags ¶ added in v0.16.0
func (o *CredentialCommandOptions) RegisterDeleteFlags(cmd *cobra.Command)
RegisterDeleteFlags registers flags for a credential delete command.
func (*CredentialCommandOptions) RegisterSetFlags ¶ added in v0.16.0
func (o *CredentialCommandOptions) RegisterSetFlags(cmd *cobra.Command)
RegisterSetFlags registers flags for a credential set command.
type CredentialTargetScope ¶ added in v0.16.0
type CredentialTargetScope int
CredentialTargetScope controls how a credential command resolves its target argument.
const ( CredentialScopeIdentity CredentialTargetScope = iota CredentialScopeNode CredentialScopeAuto )
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.
type InventorySecretInput ¶ added in v0.13.0
type InventorySecretInput struct {
// contains filtered or unexported fields
}
InventorySecretInput reads explicit credential replacements without putting their values in command arguments. An omitted flag leaves the secret unchanged.
func (*InventorySecretInput) Read ¶ added in v0.13.0
func (s *InventorySecretInput) Read(cmd *cobra.Command) (password, passphrase string, err error)
func (*InventorySecretInput) RegisterFlags ¶ added in v0.13.0
func (s *InventorySecretInput) RegisterFlags(cmd *cobra.Command)
func (*InventorySecretInput) UsesStdin ¶ added in v0.16.0
func (s *InventorySecretInput) UsesStdin() bool
UsesStdin reports whether standard input is reserved for reading a secret.