Documentation ¶
Index ¶
- Variables
- func CurrentAuth(ctx context.Context) (*arvados.User, *arvados.APIClientAuthorization, error)
- func CurrentTx(ctx context.Context) (*sqlx.Tx, error)
- func New(ctx context.Context, getdb func(context.Context) (*sqlx.DB, error)) (context.Context, finishFunc)
- func NewTx(ctx context.Context) (*sqlx.Tx, error)
- func NewWithToken(ctx context.Context, cluster *arvados.Cluster, token string) context.Context
- func NewWithTransaction(ctx context.Context, tx *sqlx.Tx) context.Context
- func WrapCallsInTransactions(getdb func(context.Context) (*sqlx.DB, error)) func(api.RoutableFunc) api.RoutableFunc
- func WrapCallsWithAuth(cluster *arvados.Cluster) func(api.RoutableFunc) api.RoutableFunc
- type DBConnector
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func CurrentAuth ¶
CurrentAuth returns the arvados.User whose privileges should be used in the given context, and the arvados.APIClientAuthorization the caller presented in order to authenticate the current request.
Returns ErrUnauthenticated if the current request was not authenticated (no token provided, token is expired, etc).
func CurrentTx ¶
CurrentTx returns a transaction that will be committed after the current API call completes, or rolled back if the current API call returns an error.
func New ¶
func New(ctx context.Context, getdb func(context.Context) (*sqlx.DB, error)) (context.Context, finishFunc)
New returns a new child context that can be used with CurrentTx(). It does not open a database transaction until the first call to CurrentTx().
The caller must eventually call the returned finishtx() func to commit or rollback the transaction, if any.
func example(ctx context.Context) (err error) { ctx, finishtx := New(ctx, getdb) defer finishtx(&err) // ... tx, err := CurrentTx(ctx) if err != nil { return fmt.Errorf("example: %s", err) } return tx.ExecContext(...) }
If *err is nil, finishtx() commits the transaction and assigns any resulting error to *err.
If *err is non-nil, finishtx() rolls back the transaction, and does not modify *err.
func NewTx ¶
NewTx starts a new transaction. The caller is responsible for calling Commit or Rollback. This is suitable for database queries that are separate from the API transaction (see CurrentTx), e.g., ones that will be committed even if the API call fails, or held open after the API call finishes.
func NewWithToken ¶
NewWithToken returns a context with the provided auth token.
The incoming context must come from WrapCallsInTransactions or NewWithTransaction.
Used for attaching system auth to background threads.
Also useful for tests, where context doesn't necessarily come from a router that uses WrapCallsWithAuth.
The returned context comes with its own token lookup cache, so NewWithToken is not appropriate to use in a per-request code path.
func NewWithTransaction ¶
NewWithTransaction returns a child context in which the given transaction will be used by any localdb API call that needs one. The caller is responsible for calling Commit or Rollback on tx.
func WrapCallsInTransactions ¶
func WrapCallsInTransactions(getdb func(context.Context) (*sqlx.DB, error)) func(api.RoutableFunc) api.RoutableFunc
WrapCallsInTransactions returns a call wrapper (suitable for assigning to router.router.WrapCalls) that starts a new transaction for each API call, and commits only if the call succeeds.
The wrapper calls getdb() to get a database handle before each API call.
func WrapCallsWithAuth ¶
func WrapCallsWithAuth(cluster *arvados.Cluster) func(api.RoutableFunc) api.RoutableFunc
WrapCallsWithAuth returns a call wrapper (suitable for assigning to router.router.WrapCalls) that makes CurrentUser(ctx) et al. work from inside the wrapped functions.
The incoming context must come from WrapCallsInTransactions or NewWithTransaction.
Types ¶
type DBConnector ¶
type DBConnector struct { PostgreSQL arvados.PostgreSQL // contains filtered or unexported fields }
func (*DBConnector) Close ¶
func (dbc *DBConnector) Close() error