Documentation
¶
Index ¶
- func ParseCopyEndpoint(raw string) (targetPart string, pathPart string, isRemote bool)
- func StoreForConfig(cfg *config.Config) credentials.Store
- type CopyOptions
- type InitOptions
- type InitResult
- type LogoutResult
- type OpenedSFTPSession
- type OpenedSession
- type Service
- func (s *Service) BindGopass(targetInput, ref string) (string, error)
- func (s *Service) BindSSHKey(targetInput, identityPath string, allowSubmission bool, ...) (string, error)
- func (s *Service) ConnectInteractive(ctx context.Context, targetInput string) error
- func (s *Service) Copy(ctx context.Context, operands []string, opts CopyOptions) (*transport.TransferResult, error)
- func (s *Service) Download(ctx context.Context, targetInput string, remoteSources []string, ...) (*transport.TransferResult, error)
- func (s *Service) DownloadOnSession(ctx context.Context, sc *sftp.Client, rootCtx *transport.SFTPRootContext, ...) (*transport.TransferResult, error)
- func (s *Service) ExecuteCommand(ctx context.Context, targetInput string, command string, timeout time.Duration, ...) (*transport.ExecResult, *StageTimings, error)
- func (s *Service) ForgetTarget(ctx context.Context, targetInput string, interactive bool) (string, error)
- func (s *Service) LoadAccessKey(ctx context.Context, interactive bool) (string, string, error)
- func (s *Service) Logout(ctx context.Context, interactive bool) (*LogoutResult, error)
- func (s *Service) MigrateStore(ctx context.Context, targetMode string, interactive bool) (int, error)
- func (s *Service) NewCoreClient(ctx context.Context, interactive bool) (*jumpserver.Client, error)
- func (s *Service) OpenConnection(ctx context.Context, targetInput string, protocol string, interactive bool, ...) (*OpenedSession, error)
- func (s *Service) OpenConnectionWithAction(ctx context.Context, targetInput string, protocol string, ...) (*OpenedSession, error)
- func (s *Service) OpenSFTPSession(ctx context.Context, targetInput string, requiredAction string, ...) (*OpenedSFTPSession, error)
- func (s *Service) ServiceKey() string
- func (s *Service) SetTargetPassword(ctx context.Context, targetInput string, interactive bool) (string, error)
- func (s *Service) StreamCommand(ctx context.Context, targetInput, command string, stdin io.Reader, ...) (int, error)
- func (s *Service) Upload(ctx context.Context, targetInput string, localSources []string, ...) (*transport.TransferResult, error)
- func (s *Service) UploadOnSession(ctx context.Context, sc *sftp.Client, rootCtx *transport.SFTPRootContext, ...) (*transport.TransferResult, error)
- type StageTimings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseCopyEndpoint ¶
ParseCopyEndpoint 区分本地路径与远端 `目标:路径` 规格(兼容 Windows 盘符路径如 `C:\...` 或 `D:/...`)。
func StoreForConfig ¶
func StoreForConfig(cfg *config.Config) credentials.Store
Types ¶
type CopyOptions ¶
type InitOptions ¶
type InitOptions struct {
ConfigPath string
CoreURL string
KoKoHost string
KoKoPort int
Fingerprint string
CAFile string
ProxyURL string
OrgID string
StoreMode string // "", "keyring", "file"
Username string
UseAccessKey bool
AccessKeyFile string
KeyID string // 仅供测试注入,CLI 不通过参数传 secret
KeySecret string // 仅供测试注入,CLI 不通过参数传 secret
CustomStore credentials.Store
HTTPTransport http.RoundTripper
PromptPass func(string) (string, error)
PromptText func(string) (string, error)
Out io.Writer
SkipHostCheck bool // 仅供无 SSH 的纯 API 单元测试使用
}
type InitResult ¶
type InitResult struct {
ConfigPath string `json:"config_path"`
Origin string `json:"core_url"`
Username string `json:"jumpserver_user"`
CredentialStore string `json:"credential_store"`
CreatedAK bool `json:"created_ak"`
KoKoFingerprint string `json:"koko_host_fingerprint"`
}
func Initialize ¶
func Initialize(ctx context.Context, opts InitOptions) (*InitResult, error)
type LogoutResult ¶
type OpenedSFTPSession ¶
type OpenedSFTPSession struct {
Session *OpenedSession
Client *sftp.Client
RootCtx *transport.SFTPRootContext
}
func (*OpenedSFTPSession) Close ¶
func (o *OpenedSFTPSession) Close()
type OpenedSession ¶
type OpenedSession struct {
Conn *transport.Connection
ResolvedTarget config.ResolvedTarget
ResolvedAsset *jumpserver.ResolvedAsset
Timings StageTimings
// contains filtered or unexported fields
}
type Service ¶
type Service struct {
Config *config.Config
Store credentials.Store
HTTPTransport http.RoundTripper
PromptPass func(prompt string) (string, error)
PromptText func(prompt string) (string, error)
Stderr io.Writer
}
func NewService ¶
func NewService(cfg *config.Config, customStore credentials.Store) *Service
func (*Service) BindSSHKey ¶
func (*Service) ConnectInteractive ¶
ConnectInteractive 打开交互终端;实现“目标登录成功后才保存密码”,并在密码错误或失效时允许重新输入一次(不循环重试)。
func (*Service) Copy ¶
func (s *Service) Copy(ctx context.Context, operands []string, opts CopyOptions) (*transport.TransferResult, error)
Copy 解析 scp 风格的 `源... 目标` 参数并执行上传或下载。
func (*Service) Download ¶
func (s *Service) Download( ctx context.Context, targetInput string, remoteSources []string, localDst string, opts CopyOptions, ) (*transport.TransferResult, error)
func (*Service) DownloadOnSession ¶
func (s *Service) DownloadOnSession( ctx context.Context, sc *sftp.Client, rootCtx *transport.SFTPRootContext, fileRoots []string, canonicalTarget string, remoteSources []string, localDst string, opts CopyOptions, ) (*transport.TransferResult, error)
func (*Service) ExecuteCommand ¶
func (s *Service) ExecuteCommand( ctx context.Context, targetInput string, command string, timeout time.Duration, cwd string, interactive bool, ) (*transport.ExecResult, *StageTimings, error)
ExecuteCommand 执行单条远端命令;在交互终端首次输入密码且执行成功时自动保存,错误时不保存。
func (*Service) ForgetTarget ¶
func (*Service) LoadAccessKey ¶
func (*Service) MigrateStore ¶
func (*Service) NewCoreClient ¶
func (*Service) OpenConnection ¶
func (s *Service) OpenConnection( ctx context.Context, targetInput string, protocol string, interactive bool, overridePassword string, ) (*OpenedSession, error)
OpenConnection 执行完整安全连接流水线: 1. KoKo 主机密钥验证(失败时绝不读取 AK 或目标凭据) 2. 本人 API 身份与资产授权解析(优先命中本地 asset_id 缓存) 3. 读取或终端提示目标凭据 4. 创建一次性普通连接令牌并登录 KoKo
func (*Service) OpenConnectionWithAction ¶
func (*Service) OpenSFTPSession ¶
func (s *Service) OpenSFTPSession( ctx context.Context, targetInput string, requiredAction string, interactive bool, ) (*OpenedSFTPSession, error)
OpenSFTPSession 建立经 JumpServer 的 SFTP 会话并探测目标根目录映射; 支持“目标服务器登录成功后才保存密码”,在密码错误时最多允许交互重输一次。
func (*Service) ServiceKey ¶
func (*Service) SetTargetPassword ¶
func (*Service) StreamCommand ¶
func (s *Service) StreamCommand(ctx context.Context, targetInput, command string, stdin io.Reader, stdout, stderr io.Writer) (int, error)
StreamCommand 打开连接并以透传方式运行远端命令(供 js rsh / rsync -e 使用)。 非交互:不提示输入,凭据必须已保存;所有诊断信息只写 stderr,stdout 保持协议纯净。
func (*Service) Upload ¶
func (s *Service) Upload( ctx context.Context, targetInput string, localSources []string, rawRemoteDst string, opts CopyOptions, ) (*transport.TransferResult, error)
func (*Service) UploadOnSession ¶
func (s *Service) UploadOnSession( ctx context.Context, sc *sftp.Client, rootCtx *transport.SFTPRootContext, fileRoots []string, canonicalTarget string, localSources []string, rawRemoteDst string, opts CopyOptions, ) (*transport.TransferResult, error)
type StageTimings ¶
type StageTimings struct {
HostVerifyMs int64 `json:"host_verify_ms"`
AssetResolveMs int64 `json:"asset_resolve_ms"`
CredentialReadMs int64 `json:"credential_read_ms"`
TokenCreateMs int64 `json:"token_create_ms"`
KoKoAuthMs int64 `json:"koko_auth_ms"`
TotalMs int64 `json:"total_ms"`
AssetCacheHit bool `json:"asset_cache_hit"`
}
Click to show internal directories.
Click to hide internal directories.