Documentation
¶
Index ¶
- Variables
- func CreateDirectorySSH(ctx context.Context, dialConfig SSHDialConfig, sshContext *GlobalSSHContext, ...) error
- func DownloadFileFromSCP(ctx context.Context, dialConfig SSHDialConfig, sshContext *GlobalSSHContext, ...) error
- func RunSSHCommand(ctx context.Context, dialConfig SSHDialConfig, sshContext *GlobalSSHContext, ...) (string, string, error)
- func ShellQuote(s string) string
- func UploadFileToSCP(ctx context.Context, dialConfig SSHDialConfig, sshContext *GlobalSSHContext, ...) error
- type Challenger
- type FileMetadata
- type GlobalSSHContext
- type Prompt
- type SSHConnectionPool
- type SSHDialConfig
- type SSHInteractiveAuth
- func (s *SSHInteractiveAuth) Answered() bool
- func (s *SSHInteractiveAuth) Banner() string
- func (s *SSHInteractiveAuth) Challenge(ctx context.Context, name, instruction string, prompts []Prompt) ([]string, error)
- func (s *SSHInteractiveAuth) Name() string
- func (s *SSHInteractiveAuth) Read() ([]Prompt, string)
- func (s *SSHInteractiveAuth) SetResponse(response []string, err error) error
- func (s *SSHInteractiveAuth) Target() (host string, port int, loginUser, credentialID string)
- type SSHInteractiveAuthStore
- func (store *SSHInteractiveAuthStore) AddAuth(auth *SSHInteractiveAuth)
- func (store *SSHInteractiveAuthStore) GetAuth(userId, authId string) (*SSHInteractiveAuth, bool)
- func (store *SSHInteractiveAuthStore) ListAuthsForUser(userId string) []*SSHInteractiveAuth
- func (store *SSHInteractiveAuthStore) NextAuthForUser(userId string) (*SSHInteractiveAuth, <-chan struct{})
- func (store *SSHInteractiveAuthStore) RemoveAuth(userId, authId string)
Constants ¶
This section is empty.
Variables ¶
var ErrAuthAnswered = errors.New("interactive auth has already been answered")
ErrAuthAnswered is returned when an auth that already has a response is answered again, say from a second browser tab.
Functions ¶
func CreateDirectorySSH ¶
func CreateDirectorySSH(ctx context.Context, dialConfig SSHDialConfig, sshContext *GlobalSSHContext, remotePath string) error
Creates remotePath on the host, including any missing parent directories, and does nothing if it is already there.
func DownloadFileFromSCP ¶
func DownloadFileFromSCP(ctx context.Context, dialConfig SSHDialConfig, sshContext *GlobalSSHContext, remotePath string, localPath string) error
Copies a single remote file to localPath over SSH
func RunSSHCommand ¶
func RunSSHCommand(ctx context.Context, dialConfig SSHDialConfig, sshContext *GlobalSSHContext, command, target string) (string, string, error)
runSSHCommand runs one command on the host and waits for it to finish, returning what it wrote to stdout and to stderr.
Both streams are returned whether the command succeeded or not: what a failing command printed is usually what explains it, and a caller that reads the output — the job id sbatch announces, say — still wants to see what came back. Whatever went to stderr is folded into the error as well, so a caller that only checks err is no worse off than before. The streams are returned as the command wrote them, trailing newline included; a caller parsing them should trim.
func ShellQuote ¶
ShellQuote wraps s for the remote login shell, which is what runs the scp command line. A path is user supplied, so it cannot be interpolated bare.
func UploadFileToSCP ¶
func UploadFileToSCP(ctx context.Context, dialConfig SSHDialConfig, sshContext *GlobalSSHContext, localPath string, remotePath string) error
Uploads a single local file to a remote endpoint
Types ¶
type Challenger ¶
type FileMetadata ¶
func GetSCPFileMetadata ¶
func GetSCPFileMetadata(ctx context.Context, dialConfig SSHDialConfig, sshContext *GlobalSSHContext, remotePath string) (*FileMetadata, error)
Reads the mode, size and name a remote scp announces for a single remote file, without transferring its contents.
type GlobalSSHContext ¶
type GlobalSSHContext struct {
InteractiveAuthStore *SSHInteractiveAuthStore
ConnectionPool *SSHConnectionPool
}
func NewGlobalSSHContext ¶
func NewGlobalSSHContext() *GlobalSSHContext
type SSHConnectionPool ¶
type SSHConnectionPool struct {
// contains filtered or unexported fields
}
SSHConnectionPool shares one authenticated connection between every caller dialing with the same config. Besides saving handshakes, this keeps an interactive login from asking the user for a password or OTP once per command.
func (*SSHConnectionPool) Close ¶
func (p *SSHConnectionPool) Close()
Close closes every pooled connection, borrowed or not.
type SSHDialConfig ¶
type SSHDialConfig struct {
// contains filtered or unexported fields
}
func NewSSHDialConfig ¶
func NewSSHDialConfig(host string, port int, sshUsername string, cred credmodel.SSHCredential, userId string) SSHDialConfig
type SSHInteractiveAuth ¶
type SSHInteractiveAuth struct {
AuthId string
CreatedAt time.Time
// contains filtered or unexported fields
}
func NewSSHInteractiveAuth ¶
func NewSSHInteractiveAuth(authId string, dialConfig SSHDialConfig) *SSHInteractiveAuth
func (*SSHInteractiveAuth) Answered ¶
func (s *SSHInteractiveAuth) Answered() bool
func (*SSHInteractiveAuth) Banner ¶
func (s *SSHInteractiveAuth) Banner() string
Banner is the text the server sent before login ("NCSA Delta System ..."), if any.
func (*SSHInteractiveAuth) Name ¶
func (s *SSHInteractiveAuth) Name() string
func (*SSHInteractiveAuth) Read ¶
func (s *SSHInteractiveAuth) Read() ([]Prompt, string)
func (*SSHInteractiveAuth) SetResponse ¶
func (s *SSHInteractiveAuth) SetResponse(response []string, err error) error
Should be set from the websocket server. Only the first call wins: closing authWaitSignal twice would panic.
type SSHInteractiveAuthStore ¶
type SSHInteractiveAuthStore struct {
// List of interactive SSH auths keyed by user ID, then by auth ID
Auths map[string]map[string]*SSHInteractiveAuth
// User ID mapping to subscriber channels
SubscriberQueue map[string]chan struct{}
// contains filtered or unexported fields
}
func (*SSHInteractiveAuthStore) AddAuth ¶
func (store *SSHInteractiveAuthStore) AddAuth(auth *SSHInteractiveAuth)
func (*SSHInteractiveAuthStore) GetAuth ¶
func (store *SSHInteractiveAuthStore) GetAuth(userId, authId string) (*SSHInteractiveAuth, bool)
func (*SSHInteractiveAuthStore) ListAuthsForUser ¶
func (store *SSHInteractiveAuthStore) ListAuthsForUser(userId string) []*SSHInteractiveAuth
func (*SSHInteractiveAuthStore) NextAuthForUser ¶
func (store *SSHInteractiveAuthStore) NextAuthForUser(userId string) (*SSHInteractiveAuth, <-chan struct{})
This is for retrieving the earliest created interactive auth for a user. It only returns auths that have not been answered yet, or nil if there are none. The returned channel closes the next time the user's auths are added or removed. Both are taken under one lock, so a change right after the call is never missed.
func (*SSHInteractiveAuthStore) RemoveAuth ¶
func (store *SSHInteractiveAuthStore) RemoveAuth(userId, authId string)