Documentation
¶
Overview ¶
Package iron provides an interface to IRODS.
Index ¶
- Constants
- Variables
- func DefaultDialFunc(ctx context.Context, env Env, clientName string) (net.Conn, error)
- func SystemOpenBrowser(url string) error
- type Bot
- type Client
- func (c *Client) Close() error
- func (c *Client) ComputeChecksums(ctx context.Context, remote string, options transfer.Options) error
- func (c *Client) Connect(ctx context.Context) (Conn, error)
- func (c *Client) ConnectAvailable(ctx context.Context, n int) ([]Conn, error)
- func (c *Client) CopyDir(ctx context.Context, remote1, remote2 string, options transfer.Options) error
- func (c *Client) Download(ctx context.Context, local, remote string, options transfer.Options) error
- func (c *Client) DownloadDir(ctx context.Context, local, remote string, options transfer.Options) error
- func (c *Client) Env() Env
- func (c *Client) FromReader(ctx context.Context, r io.Reader, remote string, appendToFile bool, ...) error
- func (c *Client) Option() Option
- func (c *Client) Pool(size int) (*Pool, error)
- func (c *Client) RemoveDir(ctx context.Context, remote string, options transfer.Options) error
- func (c *Client) ReplaceDefaultPool(pool *Pool) *Pool
- func (c *Client) ToWriter(ctx context.Context, w io.Writer, remote string, options transfer.Options) error
- func (c *Client) Upload(ctx context.Context, local, remote string, options transfer.Options) error
- func (c *Client) UploadDir(ctx context.Context, local, remote string, options transfer.Options) error
- func (c *Client) Verify(ctx context.Context, local, remote string) error
- type Conn
- func Dial(ctx context.Context, env Env, clientName string) (Conn, error)
- func NewConn(ctx context.Context, transport net.Conn, env Env, clientName string) (Conn, error)
- func NewPromptConn(ctx context.Context, transport net.Conn, env Env, prompt Prompt, ...) (Conn, error)
- func PromptDial(ctx context.Context, env Env, prompt Prompt, clientName string) (Conn, error)
- type DialFunc
- type Env
- type HandshakeFunc
- type Option
- type PersistentState
- type Pool
- type Prompt
Constants ¶
const ( ClientServerRefuseTLS = "CS_NEG_REFUSE" ClientServerRequireTLS = "CS_NEG_REQUIRE" ClientServerDontCare = "CS_NEG_DONT_CARE" )
const ( SSLVerifyServerCert = "cert" SSLVerifyServerHost = "host" SSLVerifyServerNone = "none" )
Variables ¶
var AuthenticateURL = regexp.MustCompile(`Please authenticate at (https?://[^\s]+)`)
var DefaultEnv = Env{ Port: 1247, AuthScheme: native, EncryptionAlgorithm: "AES-256-CBC", EncryptionSaltSize: 8, EncryptionKeySize: 32, EncryptionNumHashRounds: 8, Username: "rods", SSLVerifyServer: SSLVerifyServerCert, ClientServerNegotiation: "request_server_negotiation", ClientServerNegotiationPolicy: "CS_NEG_REQUIRE", DefaultResource: "demoResc", DialTimeout: time.Minute, HandshakeTimeout: time.Minute, GeneratedPasswordTimeout: time.Hour, }
DefaultEnv contains the default IRODS connection parameters. Use ApplyDefaults() to apply the default values to an environment.
var ErrNoConnectionsAvailable = errors.New("no connections available")
var ErrNotImplemented = fmt.Errorf("not implemented")
var ErrSSLNegotiationFailed = fmt.Errorf("SSL negotiation failed")
var ErrTLSRequired = fmt.Errorf("TLS is required for authentication but not enabled")
var ErrTransport = errors.New("transport error")
var ErrUnknownSSLVerifyPolicy = fmt.Errorf("unknown SSL verification policy")
var ErrUnsupportedPlatform = errors.New("unsupported platform")
var ErrUnsupportedVersion = fmt.Errorf("unsupported server version")
var HandshakeTimeout = time.Minute
Functions ¶
func DefaultDialFunc ¶
func SystemOpenBrowser ¶ added in v0.4.9
Types ¶
type Client ¶
func New ¶
New creates a new Client instance with the provided environment settings, maximum connections, and options. The environment settings are used for dialing new connections. The maximum number of connections is the maximum number of connections that can be established at any given time. The options are used to customize the behavior of the client.
func (*Client) Close ¶
Close closes all connections managed by the client, ensuring that any errors encountered during the closing process are aggregated and returned. The method is safe to call multiple times and locks the client during execution to prevent concurrent modifications to the connections.
func (*Client) ComputeChecksums ¶ added in v0.4.56
func (c *Client) ComputeChecksums(ctx context.Context, remote string, options transfer.Options) error
ComputeChecksums computes the checksums of a remote directory on the iRODS server using client recursion. The remote file refers to an iRODS path.
func (*Client) Connect ¶
Connect returns a new connection to the iRODS server. It will first try to reuse an available connection. If all connections are busy, it will create a new one up to the maximum number of connections. If the maximum number of connections has been reached, it will block until a connection becomes available, or reuse an existing connection in case AllowConcurrentUse is enabled.
func (*Client) ConnectAvailable ¶ added in v0.3.11
ConnectAvailable returns a list of available connections to the iRODS server, up to the specified number. If no connections are available, it will return an empty list. Retrieved connections must be closed by the caller. If n is negative, it will return all available connections.
func (*Client) CopyDir ¶ added in v0.4.16
func (c *Client) CopyDir(ctx context.Context, remote1, remote2 string, options transfer.Options) error
CopyDir copies a remote directory to another remote directory from the iRODS server using client recursion. The remote files refers to an iRODS path.
func (*Client) Download ¶ added in v0.3.9
func (c *Client) Download(ctx context.Context, local, remote string, options transfer.Options) error
Download downloads a remote file from the iRODS server using parallel transfers. The local file refers to the local file system. The remote file refers to an iRODS path.
func (*Client) DownloadDir ¶ added in v0.3.11
func (c *Client) DownloadDir(ctx context.Context, local, remote string, options transfer.Options) error
DownloadDir downloads a remote directory from the iRODS server using parallel transfers. The local file refers to the local file system. The remote file refers to an iRODS path.
func (*Client) FromReader ¶ added in v0.4.37
func (c *Client) FromReader(ctx context.Context, r io.Reader, remote string, appendToFile bool, options transfer.Options) error
FromReader streams an io.Reader to a remote file on the iRODS server using parallel transfers. The remote file refers to an iRODS path.
func (*Client) Pool ¶ added in v0.3.12
Pool returns a subset of connections that can be used for dedicated API calls. The connections remain in the pool until the pool is Closed. The call will block until the requested number of connections are available.
func (*Client) RemoveDir ¶ added in v0.4.13
RemoveDir removes a remote directory from the iRODS server using client recursion. The remote file refers to an iRODS path.
func (*Client) ReplaceDefaultPool ¶ added in v0.4.37
ReplaceDefaultPool sets the default pool, i.e. the pool from which connections are taken if client.Connect() is called. The previous default pool will be returned. Use with care, it will overwrite the default pool, but subpools of the existing pool will retain their original parent pool, and the caller is responsible for closing the returned original pool.
func (*Client) ToWriter ¶ added in v0.4.37
func (c *Client) ToWriter(ctx context.Context, w io.Writer, remote string, options transfer.Options) error
ToWriter streams a remote file from the iRODS server to an io.Writer using parallel transfers. The remote file refers to an iRODS path.
func (*Client) Upload ¶ added in v0.3.9
Upload uploads a local file to the iRODS server using parallel transfers. The local file refers to the local file system. The remote file refers to an iRODS path.
func (*Client) UploadDir ¶ added in v0.3.11
func (c *Client) UploadDir(ctx context.Context, local, remote string, options transfer.Options) error
UploadDir uploads a local directory to the iRODS server using parallel transfers. The local file refers to the local file system. The remote file refers to an iRODS path.
type Conn ¶
type Conn interface {
// Env returns the connection environment
Env() Env
// Transport returns the underlying net.Conn
Transport() net.Conn
// ServerVersion returns the version that the iRODS server reports
// e.g. "4.3.2"
ServerVersion() string
// ClientSignature returns the client signature
ClientSignature() string
// NativePassword returns the native password
// In case of PAM authentication, this is the generated password
NativePassword() string
// Request sends an API request for the given API number and expects a response.
// Both request and response should represent a type such as in `msg/types.go`.
// The request and response will be marshaled and unmarshaled automatically.
// If a negative IntInfo is returned, an appropriate error will be returned.
// This method is thread-safe.
Request(ctx context.Context, apiNumber msg.APINumber, request, response any) error
// RequestWithBuffers behaves as Request, with provided buffers for the request
// and response binary data. Both requestBuf and responseBuf could be nil.
// This method is thread-safe.
RequestWithBuffers(ctx context.Context, apiNumber msg.APINumber, request, response any, requestBuf, responseBuf []byte) error
// API returns an API using the current connection.
API() *api.API
// Close closes the connection.
// It is safe to call Close multiple times.
// This method is thread-safe but will obviously make future requests fail.
Close() error
// RegisterCloseHandler registers a function to be called when the connection is
// about to closed. It is used to clean up state before the connection is closed.
// The CloseHandler can be unregistered by calling the returned function.
RegisterCloseHandler(handler func() error) context.CancelFunc
// ConnectedAt returns the time when the connection was established.
ConnectedAt() time.Time
// TransportErrors returns the number of transport errors encountered on this connection.
TransportErrors() int
// SQLErrors returns the number of SQL errors encountered on this connection.
SQLErrors() int
}
func Dial ¶
Dial connects to an IRODS server and creates a new connection. The caller is responsible for closing the connection when it is no longer needed.
func NewConn ¶
NewConn initializes a new Conn instance with the provided network connection and environment settings. It performs a handshake as part of the initialization process and returns the constructed Conn instance. Returns an error if the handshake fails.
func NewPromptConn ¶ added in v0.4.4
func NewPromptConn(ctx context.Context, transport net.Conn, env Env, prompt Prompt, clientName string) (Conn, error)
NewPromptConn initializes a new Conn instance with the provided network connection and environment settings. It performs a handshake as part of the initialization process and returns the constructed Conn instance. For interactive authentication, the provided prompt will be used. Returns an error if the handshake fails.
func PromptDial ¶ added in v0.4.4
PromptDial connects to an IRODS server and creates a new connection. Prompt is used for possible interactive authentication. The caller is responsible for closing the connection when it is no longer needed.
type Env ¶
type Env struct {
// Credentials and settings
Host string `json:"irods_host"`
Port int `json:"irods_port"`
Zone string `json:"irods_zone_name"`
AuthScheme string `json:"irods_authentication_scheme"`
EncryptionAlgorithm string `json:"irods_encryption_algorithm"`
EncryptionSaltSize int `json:"irods_encryption_salt_size"`
EncryptionKeySize int `json:"irods_encryption_key_size"`
EncryptionNumHashRounds int `json:"irods_encryption_num_hash_rounds"`
Username string `json:"irods_user_name"`
Password string `json:"irods_password,omitempty"`
SSLCACertificateFile string `json:"irods_ssl_ca_certificate_file"`
SSLVerifyServer string `json:"irods_ssl_verify_server"`
ClientServerNegotiation string `json:"irods_client_server_negotiation"`
ClientServerNegotiationPolicy string `json:"irods_client_server_policy"`
DefaultResource string `json:"irods_default_resource"`
ProxyUsername string `json:"irods_proxy_user"` // Authenticate with proxy credentials
ProxyZone string `json:"irods_proxy_zone"` // Authenticate with proxy credentials
IrodsAuthenticationUID *int `json:"irods_authentication_uid,omitempty"`
// For pam authentication, request to generate a password that is valid for the given TTL.
// The server will determine the actual TTL based on the server thresholds.
// This value is rounded down to the nearest hour. If zero, the timeout will default to 2m1s.
GeneratedPasswordTimeout time.Duration `json:"-"`
// Persistent state for PAM interactive authentication
PersistentState PersistentState `json:"-"` // If provided, this will be used for PAM authentication as persistent store
// Advanced dial settings
SSLServerName string `json:"-"` // If provided, this will be used for server verification, instead of the hostname
DialTimeout time.Duration `json:"-"` // If provided, this will be used for dial timeout
HandshakeTimeout time.Duration `json:"-"` // If provided, this will be used for the handshake timeout
}
Env contains the IRODS connection parameters to establish a connection.
func (*Env) ApplyDefaults ¶
func (env *Env) ApplyDefaults()
ApplyDefaults sets default values for the environment fields if they are not already set. It uses the values from DefaultEnv for most fields. If the ProxyUsername and ProxyZone are not specified, it uses the Username and Zone respectively. Additionally, if PamTTL is not set or is less than or equal to zero, it defaults to 60
func (*Env) LoadFromFile ¶
LoadFromFile reads an environment configuration from a JSON file at the given path, overwriting the fields of the receiver.
type Option ¶
type Option struct {
// ClientName is passed to the server as the client type
ClientName string
// DeferConnectionToFirstUse will defer the creation of the initial connection to
// the first use of the Connect() method.
DeferConnectionToFirstUse bool
// AtFirstUse is an optional function that is called when the first connection is established,
// before the connection is returned to the caller of Connect().
AtFirstUse func(*api.API)
// Maximum number of connections that can be established at any given time.
MaxConns int
// AllowConcurrentUse will allow multiple goroutines to use the same connection concurrently,
// if the maximum number of connections has been reached and no connection is available.
// Connect() will cycle through the existing connections.
AllowConcurrentUse bool
// Admin is a flag that indicates whether the client should act in admin mode.
Admin bool
// Experimental: UseNativeProtocol will force the use of the native protocol.
// This is an experimental feature and may be removed in a future version.
UseNativeProtocol bool
// EnvCallback is an optional function that returns the environment settings for the connection
// when a new connection is established. If not provided, the default environment settings are used.
// This is useful in combination with the DeferConnectionToFirstUse option, to prepare the client
// before the connection parameters are known. The returned time.Time is the time until which the
// environment settings are valid, or zero if they are valid indefinitely.
EnvCallback func() (Env, time.Time, error)
// AuthenticationPrompt is an optional function that overrides the default pompt function.
// It is used to prompt the user for information when authenticating with the server,
// if the authentication scheme is pam_interactive.
AuthenticationPrompt Prompt
// DialFunc is an optional function that overrides the default dial function.
DialFunc DialFunc
// HandshakeFunc is an optional function that overrides the default handshake function.
HandshakeFunc HandshakeFunc
// DiscardConnectionAge is the maximum age of a connection before it is discarded.
DiscardConnectionAge time.Duration
}
type PersistentState ¶ added in v0.4.10
type PersistentState interface {
Load(m map[string]any) error // Load returns the current persistent state into the given map.
Save(m map[string]any) error // Save persists the given state. Later calls to Load will reconstruct the same map contents.
}
PersistentState refers to the pstate used for PAM interactive authentication The functions must be thread-safe if multiple clients/connections are used concurrently.
type Pool ¶ added in v0.3.11
Pool returns a subset of connections that can be used for dedicated API calls. The connections remain in the pool until the pool is Closed.
func (*Pool) Close ¶ added in v0.3.11
Close returns all connections managed by the pool to the parent pool. Connections that were not returned to the pool yet, will be returned to the parent pool later.
func (*Pool) Connect ¶ added in v0.3.11
Connect returns a new connection to the iRODS server. It will first try to reuse an available connection. If all connections are busy, it will create a new one up to the maximum number of connections. If the maximum number of connections has been reached, it will block until a connection becomes available, or reuse an existing connection in case AllowConcurrentUse is enabled.
func (*Pool) ConnectAvailable ¶ added in v0.3.11
ConnectAvailable returns a list of available connections to the iRODS server, up to the specified number. If no connections are available, it will return an empty list. Retrieved connections must be closed by the caller. If n is negative, it will return all available connections.