Skip to contents

Registers a function that csdb calls when a database connection fails. Use it to refresh a Kerberos ticket, or other authentication credentials, before the next connection attempt.

Usage

csdb_set_auth_hook(hook)

Arguments

hook

A function with no arguments that performs authentication, or NULL to clear the hook.

Value

Invisibly returns the previous hook (if any).

See also

DBConnection_v9, whose connect() method calls the registered hook once, after its first failed attempt. The introduction vignette, vignette("csdb", package = "csdb"), does not mention this function.

Other auth hook functions: csdb_get_auth_hook()

Examples

# The hook is held in the csdb.auth_hook option. Setting one returns
# the previous hook, so it can be put back afterwards.
previous <- csdb_set_auth_hook(function() invisible(NULL))
is.function(csdb_get_auth_hook())
#> [1] TRUE
csdb_set_auth_hook(previous)
csdb_get_auth_hook()
#> NULL

# \donttest{
# A real hook refreshes a credential, for example a Kerberos ticket.
# Registering the hook does not call it, so this block runs on a
# machine that has no such script.
previous <- csdb_set_auth_hook(function() {
  system2("/bin/authenticate.sh", stdout = NULL)
})
is.function(csdb_get_auth_hook())
#> [1] TRUE

# Put back whatever was registered before.
csdb_set_auth_hook(previous)
# }