diff --git a/api/proxy/option.go b/api/proxy/option.go index 4470b8a44f..ecfd290167 100644 --- a/api/proxy/option.go +++ b/api/proxy/option.go @@ -9,7 +9,7 @@ import ( "net/netip" "time" - "github.com/hashicorp/boundary/api/sessions" + "github.com/hashicorp/boundary/api" "github.com/hashicorp/boundary/api/targets" ) @@ -38,7 +38,7 @@ type Options struct { WithSessionAuthorizationData *targets.SessionAuthorizationData WithSkipSessionTeardown bool withSessionTeardownTimeout time.Duration - withSessionsClient *sessions.Client + withApiClient *api.Client } // Option is a function that takes in an options struct and sets values or @@ -132,10 +132,10 @@ func WithSessionTeardownTimeout(with time.Duration) Option { } } -// WithSessionsClient provides an optional sessions client -func WithSessionsClient(with *sessions.Client) Option { +// WithApiClient provides an optional sessions client +func WithApiClient(with *api.Client) Option { return func(o *Options) error { - o.withSessionsClient = with + o.withApiClient = with return nil } } diff --git a/api/proxy/option_test.go b/api/proxy/option_test.go index 19ddfd29b8..8525010507 100644 --- a/api/proxy/option_test.go +++ b/api/proxy/option_test.go @@ -10,7 +10,6 @@ import ( "time" "github.com/hashicorp/boundary/api" - "github.com/hashicorp/boundary/api/sessions" "github.com/hashicorp/boundary/api/targets" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -102,12 +101,11 @@ func Test_GetOpts(t *testing.T) { assert := assert.New(t) opts, err := getOpts() require.NoError(t, err) - assert.Nil(opts.withSessionsClient) + assert.Nil(opts.withApiClient) client, err := api.NewClient(nil) require.NoError(t, err) - sessClient := sessions.NewClient(client) - opts, err = getOpts(WithSessionsClient(sessClient)) + opts, err = getOpts(WithApiClient(client)) require.NoError(t, err) - assert.Equal(sessClient, opts.withSessionsClient) + assert.Equal(client, opts.withApiClient) }) } diff --git a/api/proxy/proxy.go b/api/proxy/proxy.go index bb6805a6d6..c5148d8060 100644 --- a/api/proxy/proxy.go +++ b/api/proxy/proxy.go @@ -15,6 +15,7 @@ import ( "sync/atomic" "time" + "github.com/hashicorp/boundary/api" "github.com/hashicorp/boundary/api/sessions" "github.com/hashicorp/boundary/api/targets" cleanhttp "github.com/hashicorp/go-cleanhttp" @@ -38,7 +39,7 @@ type ClientProxy struct { connectionsLeft *atomic.Int32 connsLeftCh chan int32 callerConnectionsLeftCh chan int32 - sessionsClient *sessions.Client + apiClient *api.Client sessionAuthzData *targets.SessionAuthorizationData createTime time.Time expiration time.Time @@ -99,7 +100,7 @@ func New(ctx context.Context, authzToken string, opt ...Option) (*ClientProxy, e callerConnectionsLeftCh: opts.WithConnectionsLeftCh, started: new(atomic.Bool), skipSessionTeardown: opts.WithSkipSessionTeardown, - sessionsClient: opts.withSessionsClient, + apiClient: opts.withApiClient, } if opts.WithListener != nil { @@ -263,12 +264,12 @@ func (p *ClientProxy) Start(opt ...Option) (retErr error) { p.cancel() return } - if p.sessionsClient != nil { + if p.apiClient != nil { // If we can tell that the session for the connection we just // closed is terminated, we can close the listener, otherwise // might as well leave it open so the next connection can be // tried. - sess, err := p.sessionsClient.Read(p.ctx, p.sessionAuthzData.SessionId) + sess, err := sessions.NewClient(p.apiClient).Read(p.ctx, p.sessionAuthzData.SessionId) if err != nil || sess == nil || sess.Item == nil || sess.Item.TerminationReason == "" { return }