mirror of https://github.com/hashicorp/boundary
feat(worker): add egress credentials option to proxy (#1531)
parent
bc240da52b
commit
8b5e4a175a
@ -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)
|
||||
})
|
||||
}
|
||||
Loading…
Reference in new issue