git

package
v2.8.21 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 51 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSSHKeyExchangeAlgorithms = SupportedSSHKeyExchangeAlgorithms

List of default key exchange algorithms to use. We use those that are available by default, we can become more opinionated later on (when we support configuration of algorithms to use).

View Source
var ErrInvalidRepoURL = fmt.Errorf("repo URL is invalid")
View Source
var SupportedSSHKeyExchangeAlgorithms = []string{
	"curve25519-sha256",
	"curve25519-sha256@libssh.org",
	"ecdh-sha2-nistp256",
	"ecdh-sha2-nistp384",
	"ecdh-sha2-nistp521",
	"diffie-hellman-group-exchange-sha256",
	"diffie-hellman-group14-sha256",
	"diffie-hellman-group14-sha1",
}

List of all currently supported algorithms for SSH key exchange Unfortunately, crypto/ssh does not offer public constants or list for this.

Functions

func GetRepoHTTPClient

func GetRepoHTTPClient(repoURL string, insecure bool, creds Creds, proxyURL string, noProxy string) *http.Client

Returns a HTTP client object suitable for go-git to use using the following pattern:

  • If insecure is true, always returns a client with certificate verification turned off.
  • If one or more custom certificates are stored for the repository, returns a client with those certificates in the list of root CAs used to verify the server's certificate.
  • Otherwise (and on non-fatal errors), a default HTTP client is returned.

func IsCommitSHA

func IsCommitSHA(sha string) bool

IsCommitSHA returns whether or not a string is a 40 character SHA-1

func IsHTTPSURL

func IsHTTPSURL(url string) bool

IsHTTPSURL returns true if supplied URL is HTTPS URL

func IsHTTPURL

func IsHTTPURL(url string) bool

IsHTTPURL returns true if supplied URL is HTTP URL

func IsSSHURL

func IsSSHURL(url string) (bool, string)

IsSSHURL returns true if supplied URL is SSH URL

func IsTruncatedCommitSHA

func IsTruncatedCommitSHA(sha string) bool

IsTruncatedCommitSHA returns whether or not a string is a truncated SHA-1

func NormalizeGitURL

func NormalizeGitURL(repo string) string

NormalizeGitURL normalizes a git URL for purposes of comparison, as well as preventing redundant local clones (by normalizing various forms of a URL to a consistent location). Prefer using SameURL() over this function when possible. This algorithm may change over time and should not be considered stable from release to release

func SameURL

func SameURL(leftRepo, rightRepo string) bool

SameURL returns whether or not the two repository URLs are equivalent in location

func TestRepo

func TestRepo(repo string, creds Creds, insecure bool, enableLfs bool, proxy string, noProxy string) error

TestRepo tests if a repo exists and is accessible with the given credentials

Types

type Client

type Client interface {
	Root() string
	Init() error
	Fetch(revision string) error
	Submodule() error
	Checkout(revision string, submoduleEnabled bool) error
	LsRefs() (*Refs, error)
	LsRemote(revision string) (string, error)
	LsFiles(path string, enableNewGitFileGlobbing bool) ([]string, error)
	LsLargeFiles() ([]string, error)
	CommitSHA() (string, error)
	RevisionMetadata(revision string) (*RevisionMetadata, error)
	VerifyCommitSignature(string) (string, error)
	IsAnnotatedTag(string) bool
	ChangedFiles(revision string, targetRevision string) ([]string, error)
	IsRevisionPresent(revision string) bool
}

Client is a generic git client interface

func NewClient

func NewClient(rawRepoURL string, creds Creds, insecure bool, enableLfs bool, proxy string, noProxy string, opts ...ClientOpts) (Client, error)

func NewClientExt

func NewClientExt(rawRepoURL string, root string, creds Creds, insecure bool, enableLfs bool, proxy string, noProxy string, opts ...ClientOpts) (Client, error)

type ClientOpts

type ClientOpts func(c *nativeGitClient)

func WithCache

func WithCache(cache gitRefCache, loadRefFromCache bool) ClientOpts

WithCache sets git revisions cacher as well as specifies if client should tries to use cached resolved revision

func WithEventHandlers

func WithEventHandlers(handlers EventHandlers) ClientOpts

WithEventHandlers sets the git client event handlers

type Creds

type Creds interface {
	Environ() (io.Closer, []string, error)
}

type CredsStore

type CredsStore interface {
	Add(username string, password string) string
	Remove(id string)
	// Environ returns the environment variables that should be set to use the credentials for the given credential ID.
	Environ(id string) []string
}

type EventHandlers

type EventHandlers struct {
	OnLsRemote func(repo string) func()
	OnFetch    func(repo string) func()
}

type GenericHTTPSCreds

type GenericHTTPSCreds interface {
	HasClientCert() bool
	GetClientCertData() string
	GetClientCertKey() string
	Environ() (io.Closer, []string, error)
}

func NewGitHubAppCreds

func NewGitHubAppCreds(appID int64, appInstallId int64, privateKey string, baseURL string, repoURL string, clientCertData string, clientCertKey string, insecure bool, proxy string, noProxy string, store CredsStore) GenericHTTPSCreds

NewGitHubAppCreds provide github app credentials

func NewHTTPSCreds

func NewHTTPSCreds(username string, password string, clientCertData string, clientCertKey string, insecure bool, proxy string, noProxy string, store CredsStore, forceBasicAuth bool) GenericHTTPSCreds

type GitHubAppCreds

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

GitHubAppCreds to authenticate as GitHub application

func (GitHubAppCreds) Environ

func (g GitHubAppCreds) Environ() (io.Closer, []string, error)

func (GitHubAppCreds) GetClientCertData

func (g GitHubAppCreds) GetClientCertData() string

func (GitHubAppCreds) GetClientCertKey

func (g GitHubAppCreds) GetClientCertKey() string

func (GitHubAppCreds) HasClientCert

func (g GitHubAppCreds) HasClientCert() bool

type GoogleCloudCreds

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

GoogleCloudCreds to authenticate to Google Cloud Source repositories

func NewGoogleCloudCreds

func NewGoogleCloudCreds(jsonData string, store CredsStore) GoogleCloudCreds

func (GoogleCloudCreds) Environ

func (c GoogleCloudCreds) Environ() (io.Closer, []string, error)

type HTTPSCreds

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

HTTPS creds implementation

func (HTTPSCreds) BasicAuthHeader

func (c HTTPSCreds) BasicAuthHeader() string

func (HTTPSCreds) Environ

func (c HTTPSCreds) Environ() (io.Closer, []string, error)

Get additional required environment variables for executing git client to access specific repository via HTTPS.

func (HTTPSCreds) GetClientCertData

func (c HTTPSCreds) GetClientCertData() string

func (HTTPSCreds) GetClientCertKey

func (c HTTPSCreds) GetClientCertKey() string

func (HTTPSCreds) HasClientCert

func (g HTTPSCreds) HasClientCert() bool

type NoopCredsStore

type NoopCredsStore struct{}

func (NoopCredsStore) Add

func (d NoopCredsStore) Add(username string, password string) string

func (NoopCredsStore) Environ

func (d NoopCredsStore) Environ(id string) []string

func (NoopCredsStore) Remove

func (d NoopCredsStore) Remove(id string)

type NopCloser

type NopCloser struct{}

nop implementation

func (NopCloser) Close

func (c NopCloser) Close() error

type NopCreds

type NopCreds struct{}

func (NopCreds) Environ

func (c NopCreds) Environ() (io.Closer, []string, error)

type PublicKeysWithOptions

type PublicKeysWithOptions struct {
	KexAlgorithms []string
	gitssh.PublicKeys
}

PublicKeysWithOptions is an auth method for go-git's SSH client that inherits from PublicKeys, but provides the possibility to override some client options.

func (*PublicKeysWithOptions) ClientConfig

func (a *PublicKeysWithOptions) ClientConfig() (*ssh.ClientConfig, error)

ClientConfig returns a custom SSH client configuration

func (*PublicKeysWithOptions) Name

func (a *PublicKeysWithOptions) Name() string

Name returns the name of the auth method

func (*PublicKeysWithOptions) String

func (a *PublicKeysWithOptions) String() string

String returns the configured user and auth method name as string

type Refs

type Refs struct {
	Branches []string
	Tags     []string
}

this should match reposerver/repository/repository.proto/RefsList

type RevisionMetadata

type RevisionMetadata struct {
	Author  string
	Date    time.Time
	Tags    []string
	Message string
}

type SSHCreds

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

SSH implementation

func NewSSHCreds

func NewSSHCreds(sshPrivateKey string, caPath string, insecureIgnoreHostKey bool, store CredsStore, proxy string, noProxy string) SSHCreds

func (SSHCreds) Environ

func (c SSHCreds) Environ() (io.Closer, []string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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