TCP client command (#1696)

* add cli commands

* add jwt cache test

* add tcptunnel test

* add stdin/stdout support

* use cryptutil hash function

* doc updates

* fix log timestamp
This commit is contained in:
Caleb Doxsey 2020-12-17 12:37:28 -07:00 committed by GitHub
parent 4fbbf28a16
commit 61ab4e4837
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 923 additions and 0 deletions

View file

@ -0,0 +1,60 @@
package tcptunnel
import (
"crypto/tls"
"github.com/pomerium/pomerium/internal/cliutil"
"github.com/pomerium/pomerium/internal/log"
)
type config struct {
jwtCache cliutil.JWTCache
dstHost string
proxyHost string
tlsConfig *tls.Config
}
func getConfig(options ...Option) *config {
cfg := new(config)
if jwtCache, err := cliutil.NewLocalJWTCache(); err == nil {
WithJWTCache(jwtCache)(cfg)
} else {
log.Error().Err(err).Msg("tcptunnel: error creating local JWT cache, using in-memory JWT cache")
WithJWTCache(cliutil.NewMemoryJWTCache())(cfg)
}
for _, o := range options {
o(cfg)
}
return cfg
}
// An Option modifies the config.
type Option func(*config)
// WithDestinationHost returns an option to configure the destination host.
func WithDestinationHost(dstHost string) Option {
return func(cfg *config) {
cfg.dstHost = dstHost
}
}
// WithJWTCache returns an option to configure the jwt cache.
func WithJWTCache(jwtCache cliutil.JWTCache) Option {
return func(cfg *config) {
cfg.jwtCache = jwtCache
}
}
// WithProxyHost returns an option to configure the proxy host.
func WithProxyHost(proxyHost string) Option {
return func(cfg *config) {
cfg.proxyHost = proxyHost
}
}
// WithTLSConfig returns an option to configure the tls config.
func WithTLSConfig(tlsConfig *tls.Config) Option {
return func(cfg *config) {
cfg.tlsConfig = tlsConfig
}
}