Documentation ¶
Index ¶
- Constants
- Variables
- func GetSidechannel(ctx context.Context) (net.Conn, error)
- type CustomHookError
- type DisabledManager
- func (DisabledManager) PostReceiveHook(context.Context, *gitalypb.Repository, []string, []string, io.Reader, ...) error
- func (DisabledManager) PreReceiveHook(context.Context, *gitalypb.Repository, []string, []string, io.Reader, ...) error
- func (DisabledManager) ProcReceiveHook(ctx context.Context, repo *gitalypb.Repository, env []string, stdin io.Reader, ...) error
- func (DisabledManager) ProcReceiveRegistry() *ProcReceiveRegistry
- func (DisabledManager) ReferenceTransactionHook(context.Context, ReferenceTransactionState, []string, io.Reader) error
- func (DisabledManager) UpdateHook(context.Context, *gitalypb.Repository, string, string, string, []string, ...) error
- type GitLabHookManager
- func (m *GitLabHookManager) Check(ctx context.Context) (*gitlab.CheckInfo, error)
- func (m *GitLabHookManager) PostReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, ...) error
- func (m *GitLabHookManager) PreReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, ...) error
- func (m *GitLabHookManager) ProcReceiveRegistry() *ProcReceiveRegistry
- func (m *GitLabHookManager) ReferenceTransactionHook(ctx context.Context, state ReferenceTransactionState, env []string, ...) error
- func (m *GitLabHookManager) UpdateHook(ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, ...) error
- type InvalidSidechannelAddressError
- type Manager
- type MockManager
- func (m *MockManager) PostReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, ...) error
- func (m *MockManager) PreReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, ...) error
- func (m *MockManager) ProcReceiveHook(ctx context.Context, repo *gitalypb.Repository, env []string, stdin io.Reader, ...) error
- func (m *MockManager) ProcReceiveRegistry() *ProcReceiveRegistry
- func (m *MockManager) ReferenceTransactionHook(ctx context.Context, state ReferenceTransactionState, env []string, ...) error
- func (m *MockManager) UpdateHook(ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, ...) error
- type NotAllowedError
- type ProcReceiveHandler
- type ProcReceiveRegistry
- type ReferenceTransactionState
- type ReferenceUpdate
- type SidechannelWaiter
- type Transaction
- type TransactionRegistry
Constants ¶
const ( // ReferenceTransactionPrepared indicates all reference updates have been queued to the // transaction and were locked on disk. ReferenceTransactionPrepared = ReferenceTransactionState(iota) // ReferenceTransactionCommitted indicates the reference transaction was committed and all // references now have their respective new value. ReferenceTransactionCommitted // ReferenceTransactionAborted indicates the transaction was aborted, no changes were // performed and the reference locks have been released. ReferenceTransactionAborted )
Variables ¶
var ( // NopPreReceive does nothing for the pre-receive hook NopPreReceive = func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error { return nil } // NopPostReceive does nothing for the post-receive hook NopPostReceive = func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error { return nil } // NopUpdate does nothing for the update hook NopUpdate = func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, env []string, stdout, stderr io.Writer) error { return nil } // NopReferenceTransaction does nothing for the reference transaction hook NopReferenceTransaction = func(t *testing.T, ctx context.Context, state ReferenceTransactionState, env []string, stdin io.Reader) error { return nil } )
Functions ¶
Types ¶
type CustomHookError ¶
type CustomHookError struct {
// contains filtered or unexported fields
}
CustomHookError is returned in case custom hooks return an error.
func NewCustomHookError ¶
func NewCustomHookError(e error) CustomHookError
NewCustomHookError creates a new CustomHookError.
func (CustomHookError) Error ¶
func (e CustomHookError) Error() string
func (CustomHookError) Unwrap ¶
func (e CustomHookError) Unwrap() error
type DisabledManager ¶
type DisabledManager struct{}
DisabledManager never executes hooks and simply returns a nil error.
func (DisabledManager) PostReceiveHook ¶
func (DisabledManager) PostReceiveHook(context.Context, *gitalypb.Repository, []string, []string, io.Reader, io.Writer, io.Writer) error
PostReceiveHook ignores its parameters and returns a nil error.
func (DisabledManager) PreReceiveHook ¶
func (DisabledManager) PreReceiveHook(context.Context, *gitalypb.Repository, []string, []string, io.Reader, io.Writer, io.Writer) error
PreReceiveHook ignores its parameters and returns a nil error.
func (DisabledManager) ProcReceiveHook ¶ added in v16.8.0
func (DisabledManager) ProcReceiveHook(ctx context.Context, repo *gitalypb.Repository, env []string, stdin io.Reader, stdout, stderr io.Writer) error
ProcReceiveHook ignores its parameters and returns a nil error.
func (DisabledManager) ProcReceiveRegistry ¶ added in v16.8.0
func (DisabledManager) ProcReceiveRegistry() *ProcReceiveRegistry
ProcReceiveRegistry returns nil.
func (DisabledManager) ReferenceTransactionHook ¶
func (DisabledManager) ReferenceTransactionHook(context.Context, ReferenceTransactionState, []string, io.Reader) error
ReferenceTransactionHook ignores its parameters and returns a nil error.
type GitLabHookManager ¶
type GitLabHookManager struct {
// contains filtered or unexported fields
}
GitLabHookManager is a hook manager containing Git hook business logic. It uses the GitLab API to authenticate and track ongoing hook calls.
func NewManager ¶
func NewManager( cfg config.Cfg, locator storage.Locator, logger log.Logger, gitCmdFactory git.CommandFactory, txManager transaction.Manager, gitlabClient gitlab.Client, txRegistry TransactionRegistry, procReceiveRegistry *ProcReceiveRegistry, ) *GitLabHookManager
NewManager returns a new hook manager
func (*GitLabHookManager) PostReceiveHook ¶
func (*GitLabHookManager) PreReceiveHook ¶
func (m *GitLabHookManager) PreReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error
PreReceiveHook will try to authenticate the changes against the GitLab API. If successful, it will execute custom hooks with the given parameters, push options and environment.
func (*GitLabHookManager) ProcReceiveRegistry ¶ added in v16.8.0
func (m *GitLabHookManager) ProcReceiveRegistry() *ProcReceiveRegistry
ProcReceiveRegistry provides the ProcReceiveRegistry assigned to the Manager. The registry allows RPCs to hook into the proc-receive handler.
func (*GitLabHookManager) ReferenceTransactionHook ¶
func (m *GitLabHookManager) ReferenceTransactionHook(ctx context.Context, state ReferenceTransactionState, env []string, stdin io.Reader) error
func (*GitLabHookManager) UpdateHook ¶
func (m *GitLabHookManager) UpdateHook(ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, env []string, stdout, stderr io.Writer) error
type InvalidSidechannelAddressError ¶
type InvalidSidechannelAddressError struct {
// contains filtered or unexported fields
}
InvalidSidechannelAddressError is returned by GetSidechannel if improper address is used.
func (InvalidSidechannelAddressError) Error ¶
func (e InvalidSidechannelAddressError) Error() string
type Manager ¶
type Manager interface { // PreReceiveHook executes the pre-receive Git hook and any installed custom hooks. stdin // must contain all references to be updated and match the format specified in githooks(5). PreReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error // PostReceiveHook executes the post-receive Git hook and any installed custom hooks. stdin // must contain all references to be updated and match the format specified in githooks(5). PostReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error // UpdateHook executes the update Git hook and any installed custom hooks for the reference // `ref` getting updated from `oldValue` to `newValue`. UpdateHook(ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, env []string, stdout, stderr io.Writer) error // ReferenceTransactionHook executes the reference-transaction Git hook. stdin must contain // all references to be updated and match the format specified in githooks(5). ReferenceTransactionHook(ctx context.Context, state ReferenceTransactionState, env []string, stdin io.Reader) error // ProcReceiveRegistry provides the ProcReceiveRegistry assigned to the Manager. The registry // allows RPCs to hook into the proc-receive handler. ProcReceiveRegistry() *ProcReceiveRegistry }
Manager is an interface providing the ability to execute Git hooks.
func NewMockManager ¶
func NewMockManager( t *testing.T, preReceive func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error, postReceive func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error, update func(t *testing.T, ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, env []string, stdout, stderr io.Writer) error, referenceTransaction func(t *testing.T, ctx context.Context, state ReferenceTransactionState, env []string, stdin io.Reader) error, procReceiveRegistry *ProcReceiveRegistry, ) Manager
NewMockManager returns a mocked hook Manager with the stubbed functions
type MockManager ¶
type MockManager struct {
// contains filtered or unexported fields
}
MockManager mocks the Manager interface for Git hooks (e.g. pre-receive, post-receive)
func (*MockManager) PostReceiveHook ¶
func (m *MockManager) PostReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error
PostReceiveHook executes the mocked post-receive hook
func (*MockManager) PreReceiveHook ¶
func (m *MockManager) PreReceiveHook(ctx context.Context, repo *gitalypb.Repository, pushOptions, env []string, stdin io.Reader, stdout, stderr io.Writer) error
PreReceiveHook executes the mocked pre-receive hook
func (*MockManager) ProcReceiveHook ¶ added in v16.8.0
func (m *MockManager) ProcReceiveHook(ctx context.Context, repo *gitalypb.Repository, env []string, stdin io.Reader, stdout, stderr io.Writer) error
ProcReceiveHook executes the mocked proc-receive hook
func (*MockManager) ProcReceiveRegistry ¶ added in v16.8.0
func (m *MockManager) ProcReceiveRegistry() *ProcReceiveRegistry
ProcReceiveRegistry provides the ProcReceiveRegistry.
func (*MockManager) ReferenceTransactionHook ¶
func (m *MockManager) ReferenceTransactionHook(ctx context.Context, state ReferenceTransactionState, env []string, stdin io.Reader) error
ReferenceTransactionHook executes the mocked reference transaction hook
func (*MockManager) UpdateHook ¶
func (m *MockManager) UpdateHook(ctx context.Context, repo *gitalypb.Repository, ref, oldValue, newValue string, env []string, stdout, stderr io.Writer) error
UpdateHook executes the mocked update hook
type NotAllowedError ¶
type NotAllowedError struct { // Message is the error message returned by Rails. Message string // Protocol is the protocol used. Protocol string // userID is the ID of the user as whom we have performed access checks. UserID string // Changes is the changes we have requested. Changes []byte }
NotAllowedError is needed to report internal API errors that are made by the pre-receive hook.
func (NotAllowedError) Error ¶
func (e NotAllowedError) Error() string
type ProcReceiveHandler ¶ added in v16.7.0
type ProcReceiveHandler interface { // TransactionID provides the storage.TransactionID associated with the // handler. TransactionID() storage.TransactionID // Atomic denotes whether the push was atomic. Atomic() bool // ReferenceUpdates provides the reference updates to be made. ReferenceUpdates() []ReferenceUpdate // AcceptUpdate tells the registry to accept a given reference update. AcceptUpdate(referenceName git.ReferenceName) error // RejectUpdate tells the registry to reject a given reference update, along // with a reason. RejectUpdate(referenceName git.ReferenceName, reason string) error // Close must be called to clean up the proc-receive hook. If the user // of the handler encounters an error, it should be transferred to the // hook too. Close(rpcErr error) error }
ProcReceiveHandler provides the mechanism for RPCs which invoked git-receive-pack(1) to interact with the proc-receive hook. It provides access to a list of references that a transaction is attempting to update, and functions to accept or reject individual updates.
func NewProcReceiveHandler ¶ added in v16.7.0
func NewProcReceiveHandler(env []string, stdin io.Reader, stdout io.Writer) (ProcReceiveHandler, <-chan error, error)
NewProcReceiveHandler returns a ProcReceiveHandler implementation. The function, returns the handler along with a channel which indicates completion of the handlers usage.
ProcReceiveHandler is used to intercept git-receive-pack(1)'s execute-commands code. This allows us to intercept reference updates before writing to the disk via the proc-receive hook (https://git-scm.com/docs/githooks#proc-receive).
The handler is transmitted to RPCs which executed git-receive-pack(1), so they can accept or reject individual reference updates.
type ProcReceiveRegistry ¶ added in v16.7.0
type ProcReceiveRegistry struct {
// contains filtered or unexported fields
}
ProcReceiveRegistry is the registry which provides the proc-receive handlers (https://git-scm.com/docs/githooks#proc-receive) against a provided transaction ID.
The registry allows RPCs which perform commands that execute git-receive-pack(1) to hook into the proc-receive handler. The RPC must register itself with the registry by calling RegisterWaiter(), this provides a channel where the handler will be provided along with a registry cleanup function.
When the handler for the associated transaction ID is added to the registry via the Transmit() function, it will be propagated to the channel.
func NewProcReceiveRegistry ¶ added in v16.7.0
func NewProcReceiveRegistry() *ProcReceiveRegistry
NewProcReceiveRegistry creates a new registry by allocating the required variables.
func (*ProcReceiveRegistry) RegisterWaiter ¶ added in v16.7.0
func (r *ProcReceiveRegistry) RegisterWaiter(id storage.TransactionID) (<-chan ProcReceiveHandler, func(), error)
RegisterWaiter registers a waiter against the provided transactionID. The function returns a channel to obtain the handler, a cleanup function which must be called and an error if any.
func (*ProcReceiveRegistry) Transmit ¶ added in v16.7.0
func (r *ProcReceiveRegistry) Transmit(ctx context.Context, handler ProcReceiveHandler) error
Transmit transmits a handler to its waiter.
type ReferenceTransactionState ¶
type ReferenceTransactionState int
ReferenceTransactionState is the state of the Git reference transaction. It reflects the first parameter of the reference-transaction hook. See githooks(1) for more information.
type ReferenceUpdate ¶ added in v16.7.0
ReferenceUpdate denotes a single reference update to be made.
type SidechannelWaiter ¶
type SidechannelWaiter struct {
// contains filtered or unexported fields
}
SidechannelWaiter provides cleanup and error propagation for a sidechannel callback.
func SetupSidechannel ¶
func SetupSidechannel(ctx context.Context, payload git.HooksPayload, callback func(*net.UnixConn) error) (_ context.Context, _ *SidechannelWaiter, err error)
SetupSidechannel creates a sidechannel listener in a tempdir and launches a goroutine that will run the callback if the listener receives a connection. The address of the listener is stored in the returned context, so that the caller can propagate it to a server. The caller must Close the SidechannelWaiter to prevent resource leaks.
func (*SidechannelWaiter) Close ¶
func (wt *SidechannelWaiter) Close() error
Close cleans up sidechannel resources. If the callback is already running, Close will block until the callback is done.
func (*SidechannelWaiter) Wait ¶
func (wt *SidechannelWaiter) Wait() error
Wait waits for the callback to run and returns its error value.
type Transaction ¶ added in v16.5.0
type Transaction interface { RecordInitialReferenceValues(context.Context, map[git.ReferenceName]git.ObjectID) error UpdateReferences(storagemgr.ReferenceUpdates) }
Transaction is the interface of storagemgr.Transaction. It's used for mocking in the tests.
type TransactionRegistry ¶ added in v16.5.0
type TransactionRegistry interface {
Get(storage.TransactionID) (Transaction, error)
}
TransactionRegistry is the interface of storagemgr.TransactionRegistry. It's used for mocking in the tests.
func NewTransactionRegistry ¶ added in v16.5.0
func NewTransactionRegistry(txRegistry *storagemgr.TransactionRegistry) TransactionRegistry
NewTransactionRegistry wraps a storagemgr.TransactionRegistry to adapt it to the interface used by the manager.