Documentation ¶
Index ¶
- Variables
- func DerivePoolPath(repositoryID int64) string
- func DeriveReplicaPath(repositoryID int64) string
- func InjectGitalyServers(ctx context.Context, name, address, token string) (context.Context, error)
- func InjectGitalyServersEnv(ctx context.Context) (context.Context, error)
- func IsPoolRepository(repo Repository) bool
- func IsPraefectPoolRepository(repo Repository) bool
- func IsRailsPoolRepository(repo Repository) bool
- func NewRepositoryNotFoundError(storageName string, relativePath string) error
- func NewStorageNotFoundError(storageName string) error
- func QuarantineDirectoryPrefix(repo Repository) string
- func RepoPathEqual(a, b Repository) bool
- func ValidateRelativePath(rootDir, relativePath string) (string, error)
- func WriteMetadataFile(storagePath string) (returnedErr error)
- type GetRepoPathConfig
- type GetRepoPathOption
- type GitalyServers
- type Locator
- type Metadata
- type Repository
- type ServerInfo
- type ValidateRepositoryConfig
- type ValidateRepositoryOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrStorageNotSet is returned when the storage name has not been set. ErrStorageNotSet = errors.New("storage name not set") // ErrStorageNotFound is returned when operating on a storage that doesn't exist. ErrStorageNotFound = errors.New("storage name not found") // ErrRepositoryNotSet is returned when the repository has not been set. ErrRepositoryNotSet = errors.New("repository not set") // ErrRepositoryPathNotSet is returned when the repository path has not been set. ErrRepositoryPathNotSet = errors.New("repository path not set") // ErrRepositoryNotFound is returned when operating on a repository that doesn't exist. // // This somewhat duplicates the above RepositoryNotFoundError but doesn't specify which // repository was not found. With repository IDs in use, the virtual storage and relative // path won't be available everywhere anymore. ErrRepositoryNotFound = errors.New("repository not found") // ErrRepositoryAlreadyExists is returned when attempting to create a repository that // already exists. ErrRepositoryAlreadyExists = errors.New("repository already exists") // ErrRepositoryNotValid is returned when operating on a path that is not a valid Git // repository. ErrRepositoryNotValid = errors.New("repository not valid") // ErrRelativePathEscapesRoot is returned when a relative path is passed that escapes the // storage's root directory. ErrRelativePathEscapesRoot = errors.New("relative path escapes root directory") )
var ErrEmptyMetadata = errors.New("empty metadata")
ErrEmptyMetadata indicates that the gRPC metadata was not found in the context
var (
// PraefectRootPathPrefix is the root directory for all git repositories.
PraefectRootPathPrefix = "@cluster"
)
Functions ¶
func DerivePoolPath ¶ added in v16.1.0
DerivePoolPath derives an object pools's disk storage path from its repository ID. The repository ID is hashed with SHA256 and the first four hex digits of the hash are used as the two subdirectories to ensure even distribution into subdirectories. The format is @cluster/pools/ab/cd/<repository-id>. The pools have a different directory prefix from other repositories so Gitaly can identify them in OptimizeRepository and avoid pruning them.
func DeriveReplicaPath ¶ added in v16.1.0
DeriveReplicaPath derives a repository's disk storage path from its repository ID. The repository ID is hashed with SHA256 and the first four hex digits of the hash are used as the two subdirectories to ensure even distribution into subdirectories. The format is @cluster/repositories/ab/cd/<repository-id>.
func InjectGitalyServers ¶
InjectGitalyServers injects gitaly-servers metadata into an outgoing context
func InjectGitalyServersEnv ¶
InjectGitalyServersEnv injects the GITALY_SERVERS env var into an incoming context.
func IsPoolRepository ¶ added in v16.1.0
func IsPoolRepository(repo Repository) bool
IsPoolRepository returns whether the repository is an object pool.
func IsPraefectPoolRepository ¶ added in v16.1.0
func IsPraefectPoolRepository(repo Repository) bool
IsPraefectPoolRepository returns whether the repository is a Praefect generated object pool repository.
func IsRailsPoolRepository ¶ added in v16.1.0
func IsRailsPoolRepository(repo Repository) bool
IsRailsPoolRepository returns whether the repository is a pool repository generated by Rails.
func NewRepositoryNotFoundError ¶ added in v16.1.0
NewRepositoryNotFoundError returns a new error that wraps ErrRepositoryNotFound. The virtual storage and relative path are appended as error metadata.
func NewStorageNotFoundError ¶ added in v16.1.0
NewStorageNotFoundError returns a new error wrapping ErrStorageNotFound with an InvalidArgument error code and metadata.
func QuarantineDirectoryPrefix ¶
func QuarantineDirectoryPrefix(repo Repository) string
QuarantineDirectoryPrefix returns a prefix for use in the temporary directory. The prefix is based on the relative repository path and will stay stable for any given repository. This allows us to verify that a given quarantine object directory indeed belongs to the repository at hand. Ideally, this function would directly be located in the quarantine module, but this is not possible due to cyclic dependencies.
func RepoPathEqual ¶ added in v16.1.0
func RepoPathEqual(a, b Repository) bool
RepoPathEqual compares if two repositories are in the same location
func ValidateRelativePath ¶
ValidateRelativePath validates a relative path by joining it with rootDir and verifying the result is either rootDir or a path within rootDir. Returns clean relative path from rootDir to relativePath or an ErrRelativePathEscapesRoot if the resulting path is not contained within rootDir.
func WriteMetadataFile ¶
WriteMetadataFile marshals and writes a metadata file
Types ¶
type GetRepoPathConfig ¶
type GetRepoPathConfig struct { // SkipRepositoryVerification will cause GetRepoPath to skip verification the verification whether the // computed path is an actual Git repository or not. SkipRepositoryVerification bool }
GetRepoPathConfig is used to configure GetRepoPath.
type GetRepoPathOption ¶
type GetRepoPathOption func(*GetRepoPathConfig)
GetRepoPathOption can be passed to GetRepoPath to change its default behavior.
func WithRepositoryVerificationSkipped ¶
func WithRepositoryVerificationSkipped() GetRepoPathOption
WithRepositoryVerificationSkipped skips the repository path validation that ensures the Git directory is valid.
type GitalyServers ¶
type GitalyServers map[string]ServerInfo
GitalyServers hold Gitaly servers info like {"default":{"token":"x","address":"y"}}, to be passed in `gitaly-servers` metadata.
func ExtractGitalyServers ¶
func ExtractGitalyServers(ctx context.Context) (gitalyServersInfo GitalyServers, err error)
ExtractGitalyServers extracts `storage.GitalyServers` from an incoming context.
type Locator ¶
type Locator interface { // ValidateRepository validates whether the given repository is a valid Git repository. This // function can be configured by passing ValidateRepositoryOptions. ValidateRepository(Repository, ...ValidateRepositoryOption) error // GetRepoPath returns the full path of the repository referenced by an RPC Repository message. // By default, it verifies that the path is an existing git directory. However, if invoked with // the `GetRepoPathOption` produced by `WithRepositoryVerificationSkipped()`, this validation // will be skipped. The errors returned are gRPC errors with relevant error codes and should be // passed back to gRPC without further decoration. GetRepoPath(repo Repository, opts ...GetRepoPathOption) (string, error) // GetStorageByName will return the path for the storage, which is fetched by // its key. An error is return if it cannot be found. GetStorageByName(storageName string) (string, error) // CacheDir returns the path to the cache dir for a storage. CacheDir(storageName string) (string, error) // TempDir returns the path to the temp dir for a storage. TempDir(storageName string) (string, error) // StateDir returns the path to the state dir for a storage. StateDir(storageName string) (string, error) }
Locator allows to get info about location of the repository or storage at the local file system.
type Metadata ¶
type Metadata struct {
GitalyFilesystemID string `json:"gitaly_filesystem_id"`
}
Metadata contains metadata about the filesystem
func ReadMetadataFile ¶
ReadMetadataFile reads and decodes the json metadata file
type Repository ¶ added in v16.1.0
type Repository interface { GetStorageName() string GetRelativePath() string GetGitObjectDirectory() string GetGitAlternateObjectDirectories() []string }
Repository represents a storage-scoped repository.
type ServerInfo ¶
ServerInfo contains information about how to reach a Gitaly server or a Praefect virtual storage. This is necessary for Gitaly RPC's involving more than one Gitaly. Without this information, Gitaly would not know how to reach the remote peer.
func ExtractGitalyServer ¶
func ExtractGitalyServer(ctx context.Context, storageName string) (ServerInfo, error)
ExtractGitalyServer extracts server information for a specific storage
func (ServerInfo) Zero ¶
func (si ServerInfo) Zero() bool
Zero returns true when no attributes have been set.
type ValidateRepositoryConfig ¶ added in v16.1.0
type ValidateRepositoryConfig struct { // SkipStorageExistenceCheck determines whether the storage shall be checked for // existence or not. If set, the locator shall still perform parameter verification and // verify that whether the storage _would_ be valid if it existed, but not verify actual // existence. This will also skip the repository existence check. Required when // Praefect has not rewritten the repository storage name. SkipStorageExistenceCheck bool // SkipRepositoryExistenceCheck determines whether the repository shall be checked for // existence or not. If set, the locator shall still perform parameter verification and // verify that whether the repository _would_ be valid if it existed, but not verify actual // existence. SkipRepositoryExistenceCheck bool }
ValidateRepositoryConfig is used to configure ValidateRepository.
type ValidateRepositoryOption ¶ added in v16.1.0
type ValidateRepositoryOption func(*ValidateRepositoryConfig)
ValidateRepositoryOption is an option that can be passed to ValidateRepository.
func WithSkipRepositoryExistenceCheck ¶ added in v16.1.0
func WithSkipRepositoryExistenceCheck() ValidateRepositoryOption
WithSkipRepositoryExistenceCheck causes ValidateRepository to not check for repository existence. All other tests will still be performed.
func WithSkipStorageExistenceCheck ¶ added in v16.1.1
func WithSkipStorageExistenceCheck() ValidateRepositoryOption
WithSkipStorageExistenceCheck causes ValidateRepository to not check for storage existence. Repository existence check will also be skipped.