gitserver

package
v1.24.3 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	OperationUpload   = "upload"
	OperationDownload = "download"
)
View Source
const GitUploackPack = "application/x-git-upload-pack-advertisement"

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(w http.ResponseWriter, data interface{})

func CallGit

func CallGit(wd string, args ...string) ([]byte, error)

func Created

func Created(w http.ResponseWriter, location string)

func GitServiceCall

func GitServiceCall(w http.ResponseWriter, r *http.Request, repopath, servicename string, args ...string)

func HeadersMap

func HeadersMap(headers http.Header) map[string]string

func InternalServerError

func InternalServerError(w http.ResponseWriter, data interface{})

func LFSBatchMatcher

func LFSBatchMatcher(r *http.Request, m *mux.RouteMatch) bool

func LoggingMiddleware

func LoggingMiddleware(h http.Handler) http.Handler

func NotFound

func NotFound(w http.ResponseWriter)

func OK

func OK(w http.ResponseWriter, data interface{})

func RawResponse

func RawResponse(w http.ResponseWriter, code int, header map[string]string, body interface{})

func SetHeaderCacheForever

func SetHeaderCacheForever(w http.ResponseWriter)

func SetHeaderNoCache

func SetHeaderNoCache(w http.ResponseWriter)

func UpperCaseAndUnderscore

func UpperCaseAndUnderscore(r rune) rune

Types

type Batch

type Batch struct {
	// Should be download or upload.
	Operation string `json:"operation,omitempty"`

	//  An optional Array of String identifiers for transfer adapters that the client has configured.
	//  If omitted, the basic transfer adapter MUST be assumed by the server.
	Transfers []string `json:"transfers,omitempty"`

	// String identifier of the transfer adapter that the server prefers.
	// This MUST be one of the given transfer identifiers from the request.
	// Servers can assume the basic transfer adapter if none were given.
	// The Git LFS client will use the basic transfer adapter if the transfer property is omitted.
	Transfer string `json:"transfer,omitempty"`

	// Optional object describing the server ref that the objects belong to. Note: Added in v2.4.
	Ref BatchRef `json:"ref,omitempty"`

	// An Array of objects to download/upload.
	Objects []BatchObject `json:"objects,omitempty"`

	// The hash algorithm used to name Git LFS objects for this repository. Optional;
	// defaults to sha256 if not specified.
	HashAlgo string `json:"hash_algo,omitempty"`
}

nolint: tagliatelle

type BatchError

type BatchError struct {
	// String error message.
	Message string `json:"message"`

	// Optional String unique identifier for the request. Useful for debugging.
	RequestID string `json:"request_id"`

	// Optional String to give the user a place to report errors.
	DocumentURL string `json:"document_url"`
}

LFS servers can respond with these other HTTP status codes:

401 - The authentication credentials are needed, but were not sent. Git LFS will attempt to get the authentication for the request and retry immediately. 403 - The user has read, but not write access. Only applicable when the operation in the request is "upload." 404 - The Repository does not exist for the user. 422 - Validation error with one or more of the objects in the request. This means that none of the requested objects to upload are valid.

nolint: tagliatelle

type BatchObject

type BatchObject struct {
	// String OID of the LFS object.
	OID string `json:"oid,omitempty"`

	// Integer byte size of the LFS object. Must be at least zero.
	Size int64 `json:"size,omitempty"`

	// Optional boolean specifying whether the request for this specific object is authenticated.
	// If omitted or false, Git LFS will attempt to find credentials for this URL.
	// (https://github.com/git-lfs/git-lfs/blob/main/docs/api/authentication.md)
	Authenticated bool `json:"authenticated,omitempty"`

	// Object containing the next actions for this object.
	// Applicable actions depend on which operation is specified in the request.
	// How these properties are interpreted depends on which transfer adapter the client will be using.
	Actions map[string]Link `json:"actions,omitempty"`

	// Describing error if this object.
	Error *ObjectError `json:"error,omitempty"`
}

type BatchRef

type BatchRef struct {
	// Fully-qualified server refspec.
	Name string `json:"name"`
}

type LFSMetaManager

type LFSMetaManager interface {
	// Upload get upload url and verify url for a given object
	Upload(ctx context.Context, path string, oid string) (*Link, error)
	// Download get download url for a given object
	Download(ctx context.Context, path string, oid string) (*Link, error)
	// Verify verfiy object exists
	Verify(ctx context.Context, path string, oid string) (*BatchObject, error)
}
type Link struct {
	// String URL to download/upload the object.
	Href string `json:"href,omitempty"`

	// Optional hash of String HTTP header key/value pairs to apply to the request.
	Header map[string]string `json:"header,omitempty"`

	// Whole number of seconds after local client time when transfer will expire.
	// Preferred over expires_at if both are provided. Maximum of 2147483647, minimum of -2147483647.
	ExpireIn int `json:"expire_in,omitempty"`

	// String uppercase RFC 3339-formatted timestamp with second precision
	// for when the given action expires (usually due to a temporary token).
	ExpiresAt time.Time `json:"expires_at,omitempty"`
}

nolint: tagliatelle

type ObjectError

type ObjectError struct {
	// LFS object error codes should match HTTP status codes where possible:
	// 404 - The object does not exist on the server.
	// 409 - The specified hash algorithm disagrees with the server's acceptable options.
	// 410 - The object was removed by the owner.
	// 422 - Validation error.
	Code int `json:"code,omitempty"`
	// String error message.
	Message string `json:"message,omitempty"`
}

type Options

type Options struct {
	Listen            string // http server listen address
	UseGitHTTPBackend bool   // use git httpbackend CGI to serve git http requests
}

func NewDefaultOptions

func NewDefaultOptions() *Options

type S3ContentManager

type S3ContentManager struct {
	// contains filtered or unexported fields
}

func NewS3ContentManager

func NewS3ContentManager(ctx context.Context, opts *S3ContentManagerOptions) (*S3ContentManager, error)

func (*S3ContentManager) Download

func (m *S3ContentManager) Download(ctx context.Context, dir string, oid string) (*Link, error)

Download get download url for a given object

func (*S3ContentManager) Upload

func (m *S3ContentManager) Upload(ctx context.Context, dir string, oid string) (*Link, error)

Upload get upload url and verify url for a given object

func (*S3ContentManager) Verify

func (m *S3ContentManager) Verify(ctx context.Context, path string, oid string) (*BatchObject, error)

type S3ContentManagerOptions

type S3ContentManagerOptions struct {
	URL          string // the s3 url
	Bucket       string // the bucket name lfs objects will be stored in
	Region       string // the region of the bucket
	Credential   aws.Credentials
	LinkExpireIn time.Duration // the upload/download/verify link expire in,0 means never expired
}

type Server

type Server struct {
	GitBase string
	LFS     LFSMetaManager
}

func (*Server) CreateRepository

func (s *Server) CreateRepository(w http.ResponseWriter, r *http.Request)

nolint: gomnd

func (*Server) GetAlternative

func (s *Server) GetAlternative(w http.ResponseWriter, r *http.Request)

func (*Server) GetHTTPAlternative

func (s *Server) GetHTTPAlternative(w http.ResponseWriter, r *http.Request)

func (*Server) GetHead

func (s *Server) GetHead(w http.ResponseWriter, r *http.Request)

func (*Server) GetIdxFile

func (s *Server) GetIdxFile(w http.ResponseWriter, r *http.Request)

func (*Server) GetInfoPacks

func (s *Server) GetInfoPacks(w http.ResponseWriter, r *http.Request)

func (*Server) GetInfoRefs

func (s *Server) GetInfoRefs(w http.ResponseWriter, r *http.Request)

func (*Server) GetInfoRefsWithService

func (s *Server) GetInfoRefsWithService(w http.ResponseWriter, r *http.Request)

func (*Server) GetLooseObject

func (s *Server) GetLooseObject(w http.ResponseWriter, r *http.Request)

func (*Server) GetPackFile

func (s *Server) GetPackFile(w http.ResponseWriter, r *http.Request)

func (*Server) GitHTTPBackend

func (s *Server) GitHTTPBackend(w http.ResponseWriter, r *http.Request)

func (*Server) LFSBatch

func (s *Server) LFSBatch(w http.ResponseWriter, r *http.Request)

LFSBatch takes a batch of operations and returns a response with the status of each operation. https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#git-lfs-batch-api

func (*Server) LFSDelete

func (s *Server) LFSDelete(w http.ResponseWriter, r *http.Request)

func (*Server) LFSDownload

func (s *Server) LFSDownload(w http.ResponseWriter, r *http.Request)

func (*Server) LFSUpdate

func (s *Server) LFSUpdate(w http.ResponseWriter, r *http.Request)

func (*Server) LFSUpload

func (s *Server) LFSUpload(w http.ResponseWriter, r *http.Request)

func (*Server) LFSVerify

func (s *Server) LFSVerify(w http.ResponseWriter, r *http.Request)

func (*Server) ListFiles

func (s *Server) ListFiles(w http.ResponseWriter, r *http.Request)

func (*Server) OnRepository

func (s *Server) OnRepository(w http.ResponseWriter, r *http.Request, fun func(repofs fs.FS))

func (*Server) ReceivePack

func (s *Server) ReceivePack(w http.ResponseWriter, r *http.Request)

func (*Server) RemoveRepository

func (s *Server) RemoveRepository(w http.ResponseWriter, r *http.Request)

func (*Server) RepositoryPath

func (s *Server) RepositoryPath(r *http.Request) string

func (*Server) Run

func (s *Server) Run(ctx context.Context, opts *Options) error
Example
ctx := context.Background()
url := "http://s3.example.com"
s3opts := &S3ContentManagerOptions{
	URL:    url,
	Bucket: "git-lfs",
	Credential: aws.Credentials{
		AccessKeyID:     "",
		SecretAccessKey: "",
	},
	LinkExpireIn: time.Hour,
}
s3lfs, err := NewS3ContentManager(ctx, s3opts)
if err != nil {
	panic(err)
}
opts := NewDefaultOptions()
opts.UseGitHTTPBackend = true

s := Server{
	GitBase: "/var/www/git",
	LFS:     s3lfs,
}
if err := s.Run(ctx, opts); err != nil {
	panic(err)
}
Output:

func (*Server) UploadPack

func (s *Server) UploadPack(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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