Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyFileAuth(ctx context.Context, file string, env *iron.Env)
- func Fprintcolorln(w io.Writer, color string, args ...any)
- func GetWorkdirFromFile(file string) (string, error)
- func GetZone(arg string, t ArgType) string
- func Name(path string) string
- func ReadAuthFile(authFile string, uid *int) (string, error)
- func SkipInit(cmd *cobra.Command) bool
- func StoreWorkdirInFile(ctx context.Context, file, workdir string) error
- func WriteAuthFile(authFile, password string, uid *int) error
- type App
- func (a *App) ArgTypes(cmd *cobra.Command) []ArgType
- func (a *App) CheckUpdate(ctx context.Context)
- func (a *App) Close() error
- func (a *App) Command() *cobra.Command
- func (a *App) CompleteArgs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
- func (a *App) ConfigStore() ConfigStore
- func (a *App) ConfigStoreArgs() []string
- func (a *App) Exec(ctx context.Context, stdout, stderr io.Writer, args ...string) error
- func (a *App) Init(ctx context.Context, zone string) error
- func (a *App) LatestVersion(ctx context.Context) (*semver.Version, error)
- func (a *App) Loader() Loader
- func (a *App) Name() string
- func (a *App) PasswordStore() PasswordStore
- func (a *App) Path(path string) string
- func (a *App) PathIn(path, workdir string) string
- func (a *App) PreRun(cmd *cobra.Command, args []string) error
- func (a *App) PreRunAuth(cmd *cobra.Command, args []string) error
- func (a *App) PreRunAuthConfigStore(cmd *cobra.Command, args []string) error
- func (a *App) PreRunShell(cmd *cobra.Command, args []string) error
- func (a *App) ResetClient() error
- func (a *App) Update(ctx context.Context, path string, allowDowngrade bool) error
- func (a *App) Version() *semver.Version
- type ArgType
- type ConfigStore
- type ContextKey
- type InitError
- type JSONPrinter
- type Loader
- type Option
- func WithCommandHook(hook func(*cobra.Command, bool)) Option
- func WithConfigStore(store ConfigStore, argLabels []string) Option
- func WithDefaultWorkdir(workdir string) Option
- func WithDefaultWorkdirFromFile(file string) Option
- func WithLoader(loader Loader) Option
- func WithName(name string) Option
- func WithPasswordStore(store PasswordStore) Option
- func WithUpdater(updater *selfupdate.Updater, repo selfupdate.RepositorySlug) Option
- func WithVersion(version string) Option
- type PasswordStore
- type Printer
- type TablePrinter
- type WorkdirStore
Constants ¶
const SOCKSProxyEnv = "SOCKS_PROXY"
SOCKSProxyEnv is the environment variable consulted by FileLoader (and WrapLoaderWithSOCKS5) to configure an outbound SOCKS5 proxy for iRODS connections. The value can either be a bare host:port pair or a fully qualified socks5:// (or socks5h://) URL with optional user:password credentials.
Variables ¶
var ( Reset = "\033[00m" Red = "\033[31m" Green = "\033[32m" Yellow = "\033[33m" Blue = "\033[34m" Magenta = "\033[35m" Cyan = "\033[36m" Gray = "\033[37m" LightGray = "\033[38m" White = "\033[97m" NoColor = "\033[39m" Bold = "\033[01m" NoBold = "\033[22m" HeaderBackground = "\033[48;5;6m" RowBackground = "\033[48;5;14m" AltRowBackground = "\033[48;5;111m" // 153,111 81,117 NoBackground = "\033[49m" Underline = "\033[4m" NoUnderline = "\033[24m" )
var ArgumentRE = regexp.MustCompile("(<[a-zA-Z0-9 _-]+>)")
var ErrAmbiguousTarget = errors.New("ambiguous command, please specify a target collection or directory with a trailing slash")
var IrodsArguments = []ArgType{Path, ObjectPath, CollectionPath, TargetPath}
Functions ¶
func ApplyFileAuth ¶ added in v0.4.69
ApplyFileAuth applies the file-based authentication state to env, mirroring what FileLoader does internally. It tries to read a cached password from the .irodsA file (or the file specified by IRODS_AUTHENTICATION_FILE) next to the irods_environment.json path, switching env.AuthScheme to "native" on success. For pam_interactive it configures a PersistentState backed by the .irodsA.json file in the same directory, so that subsequent runs can re-use the cached PAM token instead of prompting again.
This is exported so callers that reload or modify env after the initial Loader call (e.g. an interactive UI that lets the user change AuthScheme) can re-apply the auth file logic against the modified env.
func GetWorkdirFromFile ¶ added in v0.4.4
GetWorkdirFromFile returns the working directory as stored in an irods environment file. The file is expected to have been created with the iRODS `icd` command.
func ReadAuthFile ¶ added in v0.4.0
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 StoreWorkdirInFile ¶ added in v0.4.4
StoreWorkdirInFile stores the working directory in an irods environment file. The file is expected to have been created with the iRODS `icd` command.
func WriteAuthFile ¶ added in v0.4.4
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 App ¶
type App struct {
*iron.Client
Admin bool
Debug int
Native bool
Workdir string
PamTTL time.Duration
NonInteractive bool
// Prompt overrides the iron.Prompt used during authentication. When
// nil, Init falls back to iron.Bot{} for NonInteractive runs and to
// iron.StdPrompt otherwise (the default chosen by iron.New).
Prompt iron.Prompt
// contains filtered or unexported fields
}
func (*App) CheckUpdate ¶ added in v0.4.18
func (*App) CompleteArgs ¶ added in v0.4.0
func (a *App) CompleteArgs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
CompleteArgs implements shell completion for the given command and arguments. It tries to find the zone of the previous arguments and detect the argument type of the last given argument. If the zone cannot be determined, or if there are at least two different zones involved in the arguments, it returns a default directive. See completeArgument for the actual completion logic.
func (*App) ConfigStore ¶ added in v0.4.69
func (a *App) ConfigStore() ConfigStore
ConfigStore returns the configured ConfigStore, or nil if none.
func (*App) ConfigStoreArgs ¶ added in v0.4.69
ConfigStoreArgs returns the positional argument labels expected by the ConfigStore (e.g. ["user name", "zone name", "host"]). Returns nil if no ConfigStore is configured.
func (*App) Exec ¶ added in v0.4.69
Exec runs a single iron CLI command (e.g. "mkdir", "-p", "/zone/home/peter") against the App's already-initialized Client. It is intended for embedding callers (such as iron-gui) that drive the App outside of cobra. The command's stdout / stderr are routed to the supplied writers (nil falls back to os.Stdout / os.Stderr). The App.Client must already be set.
func (*App) Init ¶ added in v0.4.0
Init loads the iRODS environment for the given zone (empty string = the Loader's default) and constructs the underlying iron.Client. It is the cobra-independent core of Init: callers that drive the App outside of cobra (e.g. iron-gui) can use it directly. Stamp the context with ForceReauthentication=true to bypass cached credentials.
On failure, returns InitError wrapping the underlying error (and any partially-loaded env, when available). On success, App.Client is set and App.Workdir is defaulted if it was empty.
func (*App) LatestVersion ¶ added in v0.4.18
func (*App) Loader ¶ added in v0.4.69
Loader returns the configured environment Loader, or nil if none.
func (*App) Name ¶ added in v0.4.69
Name returns the application name (used for client telemetry, prompts, etc.).
func (*App) PasswordStore ¶ added in v0.4.69
func (a *App) PasswordStore() PasswordStore
PasswordStore returns the configured PasswordStore, or nil if none.
func (*App) PreRun ¶ added in v0.4.69
PreRun sets up the client for most commands. It is used under the PersistentPreRunE hook. To override, either adjust SkipInit or implement your own PersistentPreRunE hook.
func (*App) PreRunAuth ¶ added in v0.4.69
PreRunAuth sets up the client for the "auth" command. It ensures a previous client is closed, useful for the shell.
func (*App) PreRunAuthConfigStore ¶ added in v0.4.69
PreRunAuthConfigStore sets up the client for the "auth" command, in case two or more arguments are provided and a ConfigStore is configured.
func (*App) PreRunShell ¶ added in v0.4.69
PreRunShell calls PreRun but does not fail on error, instead it writes an invitation to authenticate. Useful for the shell only.
func (*App) ResetClient ¶ added in v0.4.29
ResetClient closes the client and sets it to nil This is used for the shell in combination with the "auth" command, to switch between zones.
type ConfigStore ¶ added in v0.4.9
ConfigStore is a function that can store an iRODS environment e.g. to a file, based on CLI parameters to generate the configuration. The function must return the configured zone or an error. The returned zone name will subsequentially be passed to the Loader, and using the resulting iRODS environment, a first iRODS connection can be established. Lastly, the password will be persisted using the PasswordStore function.
type ContextKey ¶ added in v0.4.4
type ContextKey string
var ForceReauthentication ContextKey = "force_reauthentication"
type JSONPrinter ¶ added in v0.4.0
func (*JSONPrinter) Flush ¶ added in v0.4.0
func (jp *JSONPrinter) Flush()
func (*JSONPrinter) Setup ¶ added in v0.4.24
func (jp *JSONPrinter) Setup(hasACL, hasMeta, _, hasReplicas bool)
type Loader ¶ added in v0.4.0
Loader is a function that loads an iRODS environment e.g. from a file. The requested zone will be autodetected from the command, if possible, and can be used by the loader in a multi-zone environments to determine the right connection parameters. If no zone can be detected, an empty string is passed. In this case, the Loader might fall back to a default zone, or return ErrZoneRequired.
func FileLoader ¶ added in v0.4.0
FileLoader loads an irods environment from a file and returns a Loader. The environment is loaded from the file, and the password is read from the .irodsA file in the same directory, or the file specified by the IRODS_AUTHENTICATION_FILE environment variable if set.
If the SOCKS_PROXY environment variable is set, the returned Loader's DialFunc routes iRODS connections through that SOCKS5 proxy. See WrapLoaderWithSOCKS5 for the accepted proxy URL formats.
func WrapLoaderWithSOCKS5 ¶ added in v0.4.71
WrapLoaderWithSOCKS5 returns a Loader that routes connections through the given SOCKS5 proxy. If proxyURL is empty, loader is returned unchanged. The proxyURL accepts the same forms as the SOCKS_PROXY environment variable: a bare host:port (socks5:// is assumed) or a full socks5://[user:pass@]host:port URL.
type Option ¶ added in v0.4.0
type Option func(*App)
func WithCommandHook ¶ added in v0.4.76
func WithConfigStore ¶ added in v0.4.9
func WithConfigStore(store ConfigStore, argLabels []string) Option
WithConfigStore returns an Option that configures an App with a ConfigStore and positional arguments for the store. The ConfigStore is used to store the iRODS environment configuration, and the positional arguments are used to generate and parse the CLI command. At least 2 arguments are expected.
func WithDefaultWorkdir ¶ added in v0.4.3
WithDefaultWorkdir sets the default working directory for the App. This option is used to specify the default working directory when creating a new App. The default working directory is used when the user does not specify a working directory when running commands.
func WithDefaultWorkdirFromFile ¶ added in v0.4.4
func WithLoader ¶ added in v0.4.0
WithLoader sets the Loader for the App, which is used to load the environment from a file, or other source.
func WithName ¶ added in v0.4.0
WithName sets the name of the App. This name is used to generate the name of the command line tool when running the App. The name is used to generate the command line tool help text and to generate the command line tool completion. The name is also used to generate the configuration file name when persisting the App's configuration.
func WithPasswordStore ¶ added in v0.4.4
func WithPasswordStore(store PasswordStore) Option
WithPasswordStore sets the password store function for the App. This function is used to store the password for the iRODS environment after the user has authenticated with the environment. The password store function is called with the password and the App's context. The password store function is expected to store the password securely and to be able to retrieve the password later.
func WithUpdater ¶ added in v0.4.19
func WithUpdater(updater *selfupdate.Updater, repo selfupdate.RepositorySlug) Option
func WithVersion ¶ added in v0.4.20
WithVersion sets the version for the App.
type PasswordStore ¶ added in v0.4.4
PasswordStore is a function that can persist an irods password, if wanted, for use in subsequent commands.
func FilePasswordStore ¶ added in v0.4.4
func FilePasswordStore(file string) PasswordStore
type TablePrinter ¶ added in v0.4.0
type TablePrinter struct {
Writer interface {
io.Writer
Flush() error
}
Zone string
// contains filtered or unexported fields
}
func (*TablePrinter) Flush ¶ added in v0.4.0
func (tp *TablePrinter) Flush()
func (*TablePrinter) Print ¶ added in v0.4.0
func (tp *TablePrinter) Print(name string, i api.Record)
func (*TablePrinter) Setup ¶ added in v0.4.24
func (tp *TablePrinter) Setup(hasACL, hasMeta, hasCollectionSizes, hasReplicas bool)