credentials

package
v0.0.0-...-bcf66f0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package credentials provides OAuth2 TokenSource built based on the gitconfig configs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeCookies

func MakeCookies(u *url.URL, token *oauth2.Token) []*http.Cookie

MakeCookies create cookies for .gitcookies.

func MakeToken

func MakeToken(ctx context.Context, g GitBinary, u *url.URL) (*oauth2.Token, error)

MakeToken creates a token for the given URL.

func TokenSourceFromConfig

func TokenSourceFromConfig(ctx context.Context, c *CredentialConfig) (oauth2.TokenSource, error)

TokenSourceFromConfig returns a TokenSource configured based on gitconfig.

Types

type CredentialConfig

type CredentialConfig struct {
	// An account to be used. This can take one of the following values. If
	// empty, it defaults to `gcloud`.
	//
	// *   `gcloud`
	//
	//     Use the default account of `gcloud`.
	//
	// *   `application-default`
	//
	//     Use the applicaiton default credentials.
	//
	// *   Google Account emails
	//
	//     Get an access token by using `gcloud auth print-access-token
	//     EMAIL`. The account specified here must be registered in gcloud
	//     by using `gcloud auth login`
	//
	// *   Service account emails
	//     (`SERVICE_ACCOUNT@YOUR_PROJECT.iam.gserviceaccount.com`)
	//
	//     Start from the application default credentials, use IAM Service
	//     Account Credentials API to obtain the specified service account
	//     credentials. The account used for the application default service
	//     account must have `iam.serviceAccounts.getAccessToken` for the
	//     account specified here.
	//
	//     In a rare situation where you need a multi-hop delegation, you can
	//     specify a list of delegated service account emails in
	//     `ServiceAccountDelegateEmails`.
	Account string

	// OAuth2 scopes. If empty, it defaults to
	// `https://www.googleapis.com/auth/cloud-platform`.
	//
	// This config is usually not effective unless you use service account
	// emails for `Account`.
	Scopes []string

	// List of service account email addresses for multi-hop authentication.
	// See the description of `Account`.
	ServiceAccountDelegateEmails []string

	// Path to gcloud executable.
	GcloudPath string
}

CredentialConfig is the configuration for credentials.

type GitBinary

type GitBinary struct {
	// Path is a path to the Git binary.
	Path string
	// Configs are the additional Git configs specified via "-c".
	Configs []string
}

GitBinary is a path to Git binary.

func FindGitBinary

func FindGitBinary() (GitBinary, error)

FindGitBinary finds a git binary from the PATH.

func (GitBinary) BoolConfig

func (g GitBinary) BoolConfig(ctx context.Context, key string) (bool, error)

func (GitBinary) CredentialConfigFromGitConfig

func (g GitBinary) CredentialConfigFromGitConfig(ctx context.Context, u *url.URL) (*CredentialConfig, error)

ConfigFromGitConfig creates a CredentialConfig from git-config.

func (GitBinary) ListURLs

func (g GitBinary) ListURLs(ctx context.Context) ([]*url.URL, error)

ListURLs returns a list of URLs specified for "google" section.

func (GitBinary) PathConfig

func (g GitBinary) PathConfig(ctx context.Context, key string) (string, error)

func (GitBinary) StringConfig

func (g GitBinary) StringConfig(ctx context.Context, key string) (string, error)

func (GitBinary) StringListConfig

func (g GitBinary) StringListConfig(ctx context.Context, key string) ([]string, error)

func (GitBinary) WithURL

func (g GitBinary) WithURL(u *url.URL) GitConfigAccessor

WithURL binds an URL for git-config. This makes it specify --get-urlmatch.

type GitConfigAccessor

type GitConfigAccessor interface {
	// BoolConfig returns a gitconfig config value as a boolean.
	BoolConfig(ctx context.Context, key string) (bool, error)
	// PathConfig returns a gitconfig config value as a string path.
	PathConfig(ctx context.Context, key string) (string, error)
	// StringConfig returns a gitconfig config value as a string.
	StringConfig(ctx context.Context, key string) (string, error)
	// StringListConfig returns a gitconfig config value as a string slice.
	// The value is split by comma.
	StringListConfig(ctx context.Context, key string) ([]string, error)
}

GitConfigAccessor is an interface for reading git-config.

Jump to

Keyboard shortcuts

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