spike a quick cache without expiration
This commit is contained in:
parent
34e8c01baa
commit
9b50079755
@ -74,7 +74,7 @@ func NewClient(osEnv Env, gitEnv Env) (*Client, error) {
|
|||||||
creds := &commandCredentialHelper{
|
creds := &commandCredentialHelper{
|
||||||
SkipPrompt: !osEnv.Bool("GIT_TERMINAL_PROMPT", true),
|
SkipPrompt: !osEnv.Bool("GIT_TERMINAL_PROMPT", true),
|
||||||
}
|
}
|
||||||
sshResolver := &sshAuthClient{os: osEnv}
|
sshResolver := withSSHCache(&sshAuthClient{os: osEnv})
|
||||||
|
|
||||||
c := &Client{
|
c := &Client{
|
||||||
Endpoints: NewEndpointFinder(gitEnv),
|
Endpoints: NewEndpointFinder(gitEnv),
|
||||||
|
@ -16,6 +16,31 @@ type SSHResolver interface {
|
|||||||
Resolve(Endpoint, string) (sshAuthResponse, error)
|
Resolve(Endpoint, string) (sshAuthResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func withSSHCache(ssh SSHResolver) SSHResolver {
|
||||||
|
return &sshCache{
|
||||||
|
endpoints: make(map[string]*sshAuthResponse),
|
||||||
|
ssh: ssh,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type sshCache struct {
|
||||||
|
endpoints map[string]*sshAuthResponse
|
||||||
|
ssh SSHResolver
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *sshCache) Resolve(e Endpoint, method string) (sshAuthResponse, error) {
|
||||||
|
key := strings.Join([]string{e.SshUserAndHost, e.SshPort, e.SshPath, method}, "//")
|
||||||
|
if res, ok := c.endpoints[key]; ok {
|
||||||
|
return *res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := c.ssh.Resolve(e, method)
|
||||||
|
if err == nil {
|
||||||
|
c.endpoints[key] = &res
|
||||||
|
}
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
type sshAuthResponse struct {
|
type sshAuthResponse struct {
|
||||||
Message string `json:"-"`
|
Message string `json:"-"`
|
||||||
Href string `json:"href"`
|
Href string `json:"href"`
|
||||||
|
Loading…
Reference in New Issue
Block a user