fix cache set
This commit is contained in:
parent
cae06825ce
commit
4c8baddefc
2 changed files with 10 additions and 4 deletions
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"time"
|
||||||
|
|
||||||
gocache "github.com/patrickmn/go-cache"
|
gocache "github.com/patrickmn/go-cache"
|
||||||
"github.com/tg123/sshpiper/libplugin"
|
"github.com/tg123/sshpiper/libplugin"
|
||||||
|
|
@ -69,6 +70,7 @@ func newKubernetesPlugin() (*plugin, error) {
|
||||||
k8sclient: k8sclient.CoreV1(),
|
k8sclient: k8sclient.CoreV1(),
|
||||||
lister: lister,
|
lister: lister,
|
||||||
stop: stop,
|
stop: stop,
|
||||||
|
cache: gocache.New(1*time.Minute, 10*time.Minute),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,7 +156,8 @@ func (p *plugin) createUpstream(conn libplugin.ConnMetadata, pipe *piperv1beta1.
|
||||||
|
|
||||||
if originPassword != "" {
|
if originPassword != "" {
|
||||||
u.Auth = libplugin.CreatePasswordAuth([]byte(originPassword))
|
u.Auth = libplugin.CreatePasswordAuth([]byte(originPassword))
|
||||||
return u, p.cache.Add(conn.UniqueID(), pipe, gocache.DefaultExpiration)
|
p.cache.Set(conn.UniqueID(), pipe, gocache.DefaultExpiration)
|
||||||
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
secret, err := p.k8sclient.Secrets(pipe.Namespace).Get(context.Background(), to.PrivateKeySecret.Name, metav1.GetOptions{})
|
secret, err := p.k8sclient.Secrets(pipe.Namespace).Get(context.Background(), to.PrivateKeySecret.Name, metav1.GetOptions{})
|
||||||
|
|
@ -164,7 +167,8 @@ func (p *plugin) createUpstream(conn libplugin.ConnMetadata, pipe *piperv1beta1.
|
||||||
|
|
||||||
data := secret.Data["privatekey"]
|
data := secret.Data["privatekey"]
|
||||||
if data != nil {
|
if data != nil {
|
||||||
return u, p.cache.Add(conn.UniqueID(), pipe, gocache.DefaultExpiration)
|
p.cache.Set(conn.UniqueID(), pipe, gocache.DefaultExpiration)
|
||||||
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("no password or private key found")
|
return nil, fmt.Errorf("no password or private key found")
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,8 @@ func (p *plugin) createUpstream(conn libplugin.ConnMetadata, to pipeConfigTo, or
|
||||||
// password found
|
// password found
|
||||||
if pass != "" {
|
if pass != "" {
|
||||||
u.Auth = libplugin.CreatePasswordAuth([]byte(pass))
|
u.Auth = libplugin.CreatePasswordAuth([]byte(pass))
|
||||||
return u, p.cache.Add(conn.UniqueID(), &to, cache.DefaultExpiration)
|
p.cache.Set(conn.UniqueID(), &to, cache.DefaultExpiration)
|
||||||
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// try private key
|
// try private key
|
||||||
|
|
@ -225,7 +226,8 @@ func (p *plugin) createUpstream(conn libplugin.ConnMetadata, to pipeConfigTo, or
|
||||||
|
|
||||||
if data != nil {
|
if data != nil {
|
||||||
u.Auth = libplugin.CreatePrivateKeyAuth(data)
|
u.Auth = libplugin.CreatePrivateKeyAuth(data)
|
||||||
return u, p.cache.Add(conn.UniqueID(), &to, cache.DefaultExpiration)
|
p.cache.Set(conn.UniqueID(), &to, cache.DefaultExpiration)
|
||||||
|
return u, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("no password or private key found")
|
return nil, fmt.Errorf("no password or private key found")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue