storage

package
v14.10.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyMetadata = errors.New("empty metadata")

ErrEmptyMetadata indicates that the gRPC metadata was not found in the context

View Source
var ErrRelativePathEscapesRoot = errors.New("relative path escapes root directory")

nolint: revive,stylecheck // This is unintentionally missing documentation.

Functions

func InjectGitalyServers added in v14.4.0

func InjectGitalyServers(ctx context.Context, name, address, token string) (context.Context, error)

InjectGitalyServers injects gitaly-servers metadata into an outgoing context

func IsGitDirectory

func IsGitDirectory(dir string) bool

IsGitDirectory checks if the directory passed as first argument looks like a valid git directory.

func QuarantineDirectoryPrefix

func QuarantineDirectoryPrefix(repo repository.GitRepo) 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 ValidateRelativePath

func ValidateRelativePath(rootDir, relativePath string) (string, error)

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

func WriteMetadataFile(storagePath string) error

WriteMetadataFile marshals and writes a metadata file

Types

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 added in v14.4.0

func ExtractGitalyServers(ctx context.Context) (gitalyServersInfo GitalyServers, err error)

ExtractGitalyServers extracts `storage.GitalyServers` from an incoming context.

type Locator

type Locator interface {
	// GetRepoPath returns the full path of the repository referenced by an
	// RPC Repository message. It verifies the path is an existing git directory.
	// The errors returned are gRPC errors with relevant error codes and should
	// be passed back to gRPC without further decoration.
	GetRepoPath(repo repository.GitRepo) (string, error)
	// GetPath returns the path of the repo passed as first argument. An error is
	// returned when either the storage can't be found or the path includes
	// constructs trying to perform directory traversal.
	GetPath(repo repository.GitRepo) (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 stogare.
	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

func ReadMetadataFile(storagePath string) (Metadata, error)

ReadMetadataFile reads and decodes the json metadata file

type ServerInfo

type ServerInfo struct {
	Address string `json:"address"`
	Token   string `json:"token"`
}

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 added in v14.4.0

func ExtractGitalyServer(ctx context.Context, storageName string) (ServerInfo, error)

ExtractGitalyServer extracts server information for a specific storage

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL