Skip to content

Commit

Permalink
feat(sshx): allow to disable SFTP subsystem
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklasfrahm committed Jan 8, 2023
1 parent f80973a commit 1841078
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
7 changes: 5 additions & 2 deletions pkg/sshx/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ func NewClient(config *Config, options ...Option) (*Client, error) {
}
}

if client.SFTP, err = sftp.NewClient(client.SSH); err != nil {
return nil, err
// Prevent issues with SSH servers that do not permit SFTP.
if !client.STFPDisabled {
if client.SFTP, err = sftp.NewClient(client.SSH); err != nil {
return nil, err
}
}

return client, nil
Expand Down
22 changes: 16 additions & 6 deletions pkg/sshx/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (

// Options contains the configuration for an operation.
type Options struct {
Logger *zerolog.Logger
Proxy *Client
Timeout time.Duration
Logger *zerolog.Logger
Proxy *Client
Timeout time.Duration
STFPDisabled bool
}

// Option applies a configuration option
Expand All @@ -33,9 +34,10 @@ func GetDefaultOptions() *Options {
logger := zerolog.Nop()

return &Options{
Proxy: nil,
Timeout: time.Second * 5,
Logger: &logger,
Proxy: nil,
Timeout: time.Second * 5,
Logger: &logger,
STFPDisabled: false,
}
}

Expand Down Expand Up @@ -63,3 +65,11 @@ func WithTimeout(timeout time.Duration) Option {
return nil
}
}

// WithSTFPDisabled allows to disable the SFTP client.
func WithSTFPDisabled() Option {
return func(options *Options) error {
options.STFPDisabled = true
return nil
}
}

0 comments on commit 1841078

Please sign in to comment.