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 ReadAuthFile(authFile string, uid *int) (string, error)
- func SystemOpenBrowser(url string) error
- func WriteAuthFile(authFile string, uid *int, password string) error
- type Bot
- type Client
- func (c *Client) Close() error
- func (c *Client) Connect(ctx context.Context) (Conn, error)
- func (c *Client) ConnectAvailable(ctx context.Context, n int) ([]Conn, error)
- func (c *Client) Env() Env
- func (c *Client) Option() Option
- func (c *Client) Pool(size int) (*Pool, error)
- func (c *Client) ReplaceDefaultPool(pool *Pool) *Pool
- func (c *Client) RunWorker(options transfer.Options, callback func(worker *transfer.Worker)) (err 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 Dialer
- type DiscardPersistentState
- type Env
- type FilePersistentState
- 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 ErrAuthFilePathNotSet = errors.New("auth file path is not set")
var ErrNoConnectionsAvailable = errors.New("no connections available")
var ErrNoPersistentPassword = errors.New("no persistent password 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 ReadAuthFile ¶ added in v0.4.85
ReadAuthFile reads the contents of a file and decodes it according to the iRODS scramble algorithm. If no uid is given, the uid of the file is used to decode the contents. The file is expected to have been created with the iRODS `iinit` command.
func SystemOpenBrowser ¶ added in v0.4.9
func WriteAuthFile ¶ added in v0.4.85
WriteAuthFile writes the given password to a file using the iRODS scramble algorithm. The file is expected to be the .irodsA file used by the iinit command. The file is created if it doesn't exist, and the permissions are set to 0600. If the file is already present, the content is overwritten. The uid of the file owner is used to encode the password.
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) 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) 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) 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) RunWorker ¶ added in v0.3.11
func (c *Client) RunWorker(options transfer.Options, callback func(worker *transfer.Worker)) (err error)
RunWorker creates a new pool with the given number of threads and creates a new transfer.Worker with it. The callback function is called with the created worker. It waits for the worker and returns its error along with any pool cleanup error.
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 DiscardPersistentState ¶ added in v0.4.85
type DiscardPersistentState struct{}
DiscardPersistentState represents a persistent state that discards all data. It is used when no persistent storage is desired.
func (*DiscardPersistentState) Load ¶ added in v0.4.85
func (s *DiscardPersistentState) Load(m map[string]any) error
func (*DiscardPersistentState) LoadPassword ¶ added in v0.4.85
func (s *DiscardPersistentState) LoadPassword() (string, error)
func (*DiscardPersistentState) Save ¶ added in v0.4.85
func (s *DiscardPersistentState) Save(m map[string]any) error
func (*DiscardPersistentState) SavePassword ¶ added in v0.4.85
func (s *DiscardPersistentState) SavePassword(password string) error
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,omitempty"`
EncryptionAlgorithm string `json:"irods_encryption_algorithm,omitempty"`
EncryptionSaltSize int `json:"irods_encryption_salt_size,omitempty"`
EncryptionKeySize int `json:"irods_encryption_key_size,omitempty"`
EncryptionNumHashRounds int `json:"irods_encryption_num_hash_rounds,omitempty"`
Username string `json:"irods_user_name"`
Password string `json:"irods_password,omitempty"`
SSLCACertificateFile string `json:"irods_ssl_ca_certificate_file,omitempty"`
SSLVerifyServer string `json:"irods_ssl_verify_server,omitempty"`
ClientServerNegotiation string `json:"irods_client_server_negotiation,omitempty"`
ClientServerNegotiationPolicy string `json:"irods_client_server_policy,omitempty"`
DefaultResource string `json:"irods_default_resource,omitempty"`
ProxyUsername string `json:"irods_proxy_user,omitempty"` // Authenticate with proxy credentials
ProxyZone string `json:"irods_proxy_zone,omitempty"` // Authenticate with proxy credentials
// Alternative location for the irods authentication file.
// Only used in the env.LoadFromFile and env.LoadPersistentState methods to locate the authentication file.
AuthenticationFile string `json:"irods_authentication_file,omitempty"`
// The UID to use for authentication. This is only relevant when using the authentication file.
AuthenticationUID *int `json:"irods_authentication_uid,omitempty"`
// The current working directory for iRODS clients.
// This is not used by the iron library, but can be used by the client to determine the initial working directory.
WorkingDirectory string `json:"irods_cwd,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 authentication
PersistentState PersistentState `json:"-"` // If provided, this will be used as persistent store for authentication information
// 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) ApplyPersistentAuth ¶ added in v0.4.85
func (env *Env) ApplyPersistentAuth()
ApplyPersistentAuth applies the persistent authentication state to env. It tries to read a cached password, switching env.AuthScheme to "native" on success.
func (*Env) LoadFromFile ¶
LoadFromFile reads an environment configuration from a JSON file at the given path, overwriting the fields of the receiver. It will also load the persistent state from the file-based storage if available.
func (*Env) LoadPersistentState ¶ added in v0.4.85
LoadPersistentState loads the persistent state from the file-based storage if available. It reads the cached password from the file and applies it to the environment.
type FilePersistentState ¶ added in v0.4.85
type FilePersistentState struct {
AuthenticationFile string
AuthenticationUID *int
StateFile string
}
FilePersistentState represents a persistent state stored in a file. It includes the authentication file, the authentication UID, and the state file.
func (*FilePersistentState) Load ¶ added in v0.4.85
func (p *FilePersistentState) Load(m map[string]any) error
func (*FilePersistentState) LoadPassword ¶ added in v0.4.85
func (p *FilePersistentState) LoadPassword() (string, error)
func (*FilePersistentState) Save ¶ added in v0.4.85
func (p *FilePersistentState) Save(m map[string]any) error
func (*FilePersistentState) SavePassword ¶ added in v0.4.85
func (p *FilePersistentState) SavePassword(password string) error
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
// ForceReauthentication is a flag that indicates whether the client should discard any previously stored credentials
// and force reauthentication with the server.
ForceReauthentication bool
// 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 {
LoadPassword() (string, error) // LoadPassword retrieves the stored native password.
SavePassword(password string) error // SavePassword persists the stored native password.
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 stored native password for pam_password authentication or from iinit - 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.
