feat(worker): add egress credentials option to proxy (#1531)
This commit is contained in:
1 parent
bc240da52b
commit
8b5e4a175a
4 files changed
+62
-9
No files matched your search
@@ -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)
|
||||
|
||||
// options = how options are represented
|
||||
type options struct{}
|
||||
|
||||
func getDefaultOptions() options {
|
||||
return 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 {
|
||||
WithEgressCredentials []credential.Credential
|
||||
}
|
||||
|
||||
func getDefaultOptions() Options {
|
||||
return Options{
|
||||
WithEgressCredentials: nil,
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
Reference in new issue
Block a user