feat(worker): add egress credentials option to proxy (#1531)

pull/1536/head^2
Louis Ruch 5 years ago committed by GitHub
parent bc240da52b
commit 8b5e4a175a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,6 +12,3 @@ const (
// the worker
StatusTimeout = 5 * time.Second
)
// CredentialData represents the secret data of the credential
type CredentialData interface{}

@ -1,11 +1,35 @@
package proxy
import (
"github.com/hashicorp/boundary/internal/credential"
)
// Option - how Options are passed as arguments.
type Option func(*options)
type Option func(*Options)
// GetOpts - iterate the inbound Options and return a struct.
func GetOpts(opt ...Option) Options {
opts := getDefaultOptions()
for _, o := range opt {
o(&opts)
}
return opts
}
// options = how options are represented
type options struct{}
// Options = how options are represented
type Options struct {
WithEgressCredentials []credential.Credential
}
func getDefaultOptions() Options {
return Options{
WithEgressCredentials: nil,
}
}
func getDefaultOptions() options {
return options{}
// WithEgressCredentials provides an optional egress credentials to use when establishing a proxy
func WithEgressCredentials(creds []credential.Credential) Option {
return func(o *Options) {
o.WithEgressCredentials = creds
}
}

@ -0,0 +1,30 @@
package proxy
import (
"testing"
"github.com/hashicorp/boundary/internal/credential"
"github.com/stretchr/testify/assert"
)
type cred struct {
id string
secret string
}
func (c cred) GetPublicId() string { return c.id }
func (c cred) Secret() credential.SecretData { return c.secret }
func Test_GetOpts(t *testing.T) {
t.Parallel()
t.Run("WithEgressCredentials", func(t *testing.T) {
assert := assert.New(t)
c := cred{id: "test", secret: "hello"}
opts := GetOpts(WithEgressCredentials([]credential.Credential{c}))
testOpts := getDefaultOptions()
assert.NotEqual(opts, testOpts)
testOpts.WithEgressCredentials = []credential.Credential{c}
assert.Equal(opts, testOpts)
})
}

@ -27,6 +27,8 @@ func init() {
//
// handleTcpProxyV1 blocks until an error (EOF on happy path) is received on either
// connection.
//
// All options are ignored.
func handleTcpProxyV1(ctx context.Context, conf proxy.Config, _ ...proxy.Option) {
const op = "tcp.HandleTcpProxyV1"
si := conf.SessionInfo

Loading…
Cancel
Save