helper

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtoTypeAGit   = "agit"
	ProtoTypeGerrit = "gerrit"
)

Proto types

View Source
const (
	SSHVariantAuto = iota
	SSHVariantSimple
	SSHVariantSSH
	SSHVariantPlink
	SSHVariantPutty
	SSHVariantTortoisePlink
)

Define constants for SSH variant types.

Variables

View Source
var (
	UserEmailPattern = regexp.MustCompile(`^(.*?)\s*<([^@\s]+)@(\S*)>$`)
	EmailPattern     = regexp.MustCompile(`^<?([^@\s]+)@(\S+)>?$`)
)

Email patterns

View Source
var (
	// NormalArgsPattern matches args which do not need to be quoted.
	NormalArgsPattern = regexp.MustCompile(`^[0-9a-zA-Z:/%,.@+=_-]+$`)
)

Functions

func GetGitPushCommandPipe

func GetGitPushCommandPipe(proto ProtoHelper) ([]byte, error)

GetGitPushCommandPipe reads JSON from STDIN, pipe it to the helper, and output the result in JSON.

func GetLoginFromEmail

func GetLoginFromEmail(email string) string

GetLoginFromEmail gets login name from email address.

Types

type AGitProtoHelper

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

AGitProtoHelper implements helper for AGit server.

func NewAGitProtoHelper

func NewAGitProtoHelper(sshInfo *SSHInfo) *AGitProtoHelper

NewAGitProtoHelper returns AGitProtoHelper object.

func (AGitProtoHelper) GetDownloadRef

func (v AGitProtoHelper) GetDownloadRef(cr, patch string) (string, error)

GetDownloadRef returns reference name of the specific code review.

func (AGitProtoHelper) GetGitPushCommand

func (v AGitProtoHelper) GetGitPushCommand(o *common.UploadOptions) (*GitPushCommand, error)

GetGitPushCommand reads upload options and returns git push command.

func (AGitProtoHelper) GetSSHInfo

func (v AGitProtoHelper) GetSSHInfo() *SSHInfo

GetSSHInfo returns SSHInfo object.

func (AGitProtoHelper) GetType

func (v AGitProtoHelper) GetType() string

GetType returns remote server type.

type DefaultProtoHelper

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

DefaultProtoHelper implements helper for unknown remote service.

func NewDefaultProtoHelper

func NewDefaultProtoHelper(sshInfo *SSHInfo) *DefaultProtoHelper

NewDefaultProtoHelper returns DefaultProtoHelper object.

func (DefaultProtoHelper) GetDownloadRef

func (v DefaultProtoHelper) GetDownloadRef(cr, patch string) (string, error)

GetDownloadRef returns reference name of the specific code review.

func (DefaultProtoHelper) GetGitPushCommand

func (v DefaultProtoHelper) GetGitPushCommand(o *common.UploadOptions) (*GitPushCommand, error)

GetGitPushCommand reads upload options and returns git push command.

func (DefaultProtoHelper) GetSSHInfo

func (v DefaultProtoHelper) GetSSHInfo() *SSHInfo

GetSSHInfo returns SSHInfo object.

func (DefaultProtoHelper) GetType

func (v DefaultProtoHelper) GetType() string

GetType returns remote server type.

type ExternalProtoHelper

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

ExternalProtoHelper implements helper for unknown remote service.

func NewExternalProtoHelper

func NewExternalProtoHelper(sshInfo *SSHInfo) *ExternalProtoHelper

NewExternalProtoHelper returns ExternalProtoHelper object.

func (ExternalProtoHelper) GetDownloadRef

func (v ExternalProtoHelper) GetDownloadRef(cr, patch string) (string, error)

GetDownloadRef returns reference name of the specific code review.

func (ExternalProtoHelper) GetGitPushCommand

func (v ExternalProtoHelper) GetGitPushCommand(o *common.UploadOptions) (*GitPushCommand, error)

GetGitPushCommand reads upload options and returns git push command.

func (ExternalProtoHelper) GetSSHInfo

func (v ExternalProtoHelper) GetSSHInfo() *SSHInfo

GetSSHInfo returns SSHInfo object.

func (ExternalProtoHelper) GetType

func (v ExternalProtoHelper) GetType() string

GetType returns remote server type.

func (*ExternalProtoHelper) Program

func (v *ExternalProtoHelper) Program() string

Program is program name of remote helper.

type GerritProtoHelper

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

GerritProtoHelper wraps helper for gerrit server.

func NewGerritProtoHelper

func NewGerritProtoHelper(sshInfo *SSHInfo) *GerritProtoHelper

NewGerritProtoHelper returns GerritProtoHelper object.

func (GerritProtoHelper) GetDownloadRef

func (v GerritProtoHelper) GetDownloadRef(cr, patch string) (string, error)

GetDownloadRef returns reference name of the specific code review.

func (GerritProtoHelper) GetGitPushCommand

func (v GerritProtoHelper) GetGitPushCommand(o *common.UploadOptions) (*GitPushCommand, error)

GetGitPushCommand reads upload options and returns git push command.

func (GerritProtoHelper) GetSSHInfo

func (v GerritProtoHelper) GetSSHInfo() *SSHInfo

GetSSHInfo returns SSHInfo object.

func (GerritProtoHelper) GetType

func (v GerritProtoHelper) GetType() string

GetType returns remote server type.

type GitPushCommand

type GitPushCommand struct {
	Cmd       string   `json:"cmd,omitempty"`
	Args      []string `json:"args,omitempty"`
	Env       []string `json:"env,omitempty"`
	GitConfig []string `json:"gitconfig,omitempty"`
}

GitPushCommand holds command and args for git command.

type ProtoHelper

type ProtoHelper interface {
	GetType() string
	GetSSHInfo() *SSHInfo
	GetGitPushCommand(*common.UploadOptions) (*GitPushCommand, error)
	GetDownloadRef(string, string) (string, error)
}

ProtoHelper defines interface for proto helper.

func NewProtoHelper

func NewProtoHelper(sshInfo *SSHInfo) ProtoHelper

NewProtoHelper returns proto helper for specific proto type.

type SSHCmd

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

SSHCmd is composor for SSH command.

func NewSSHCmd

func NewSSHCmd() *SSHCmd

NewSSHCmd returns SSHCmd by inspecting environments like `GIT_SSH_COMMAND`.

func (*SSHCmd) Args

func (v *SSHCmd) Args() []string

Args returns default ssh arguments.

func (*SSHCmd) Command

func (v *SSHCmd) Command(host string, port int, envs []string) ([]string, []string)

Command returns command and environments used for ssh connection.

func (*SSHCmd) SSH

func (v *SSHCmd) SSH() string

SSH returns ssh program name.

func (*SSHCmd) Variant

func (v *SSHCmd) Variant() int

Variant indicates ssh variant type.

type SSHInfo

type SSHInfo struct {
	Host         string `json:"host,omitempty"`
	Port         int    `json:"port,omitempty"`
	ProtoType    string `json:"type,omitempty"`
	ProtoVersion int    `json:"version,omitempty"`
	User         string `json:"user,omitempty"`

	Expire int64 `json:"-"`
}

SSHInfo wraps host and port which ssh_info returned.

func (SSHInfo) ToJSON

func (v SSHInfo) ToJSON() string

ToJSON encodes ssh_info to JSON.

type SSHInfoQuery

type SSHInfoQuery struct {
	CacheFile string

	Changed bool
	// contains filtered or unexported fields
}

SSHInfoQuery wraps cache to accelerate query of ssh_info API.

func NewSSHInfoQuery

func NewSSHInfoQuery(cacheFile string) *SSHInfoQuery

NewSSHInfoQuery creates new query object. file is name of the cache.

func (SSHInfoQuery) GetSSHInfo

func (v SSHInfoQuery) GetSSHInfo(address string, useCache bool) (*SSHInfo, error)

GetSSHInfo queries ssh_info for address.

type ShellCmd

type ShellCmd struct {
	Cmd  string
	Args []string
}

ShellCmd is used to parse shell command.

func NewShellCmd

func NewShellCmd(cmd string, withArgs bool) *ShellCmd

NewShellCmd creates ShellCmd object from command line.

func NewShellCmdFromArgs

func NewShellCmdFromArgs(args ...string) *ShellCmd

NewShellCmdFromArgs creates ShellCmd from command args.

func (ShellCmd) QuoteCommand

func (v ShellCmd) QuoteCommand() string

QuoteCommand quotes command args which has space.

Jump to

Keyboard shortcuts

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