Skip to content

Commit

Permalink
remove identity from clientOptions
Browse files Browse the repository at this point in the history
Summary: remove identity from clientOptions

Reviewed By: podtserkovskiy

Differential Revision: D60105421

fbshipit-source-id: 0d996c35a03fd9369da2d71390e728f04217cb7a
  • Loading branch information
awalterschulze authored and facebook-github-bot committed Jul 23, 2024
1 parent 0b60afc commit 6619d45
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 33 deletions.
20 changes: 13 additions & 7 deletions thrift/lib/go/thrift/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ import (

// clientOptions thrift and connectivity options for the thrift client
type clientOptions struct {
protocol ProtocolID
conn net.Conn
transport TransportID
persistentHeaders map[string]string
identity string
protocol ProtocolID
timeout time.Duration
conn net.Conn
persistentHeaders map[string]string
}

// ClientOption is a single configuration setting for the thrift client
Expand Down Expand Up @@ -78,7 +77,7 @@ func WithPersistentHeader(name, value string) ClientOption {
// WithIdentity sets the Header identity field
func WithIdentity(name string) ClientOption {
return func(opts *clientOptions) error {
opts.identity = name
opts.persistentHeaders[IdentityHeader] = name
return nil
}
}
Expand Down Expand Up @@ -142,12 +141,20 @@ func DialTLS(addr string, timeout time.Duration, tlsConfig *tls.Config) (net.Con
return tls.Client(conn, config), nil
}

func newDefaultPersistentHeaders() map[string]string {
// set Identity Headers
return map[string]string{
IDVersionHeader: IDVersion,
IdentityHeader: "",
}
}

// newOptions creates a new options objects and inits it
func newOptions(opts ...ClientOption) (*clientOptions, error) {
res := &clientOptions{
protocol: ProtocolIDCompact,
transport: TransportIDHeader,
persistentHeaders: map[string]string{},
persistentHeaders: newDefaultPersistentHeaders(),
}
for _, opt := range opts {
if err := opt(res); err != nil {
Expand All @@ -165,7 +172,6 @@ func setOptions(protocol Protocol, options *clientOptions) error {
if err := proto.SetProtocolID(options.protocol); err != nil {
return err
}
setIdentity(proto, options.identity)
proto.SetTimeout(options.timeout)
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion thrift/lib/go/thrift/header_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func TestHeaderProtocolHeaders(t *testing.T) {
t.Fatalf("failed to set persistent header")
}

setIdentity(proto1, "batman")
proto1.SetPersistentHeader(IDVersionHeader, IDVersion)
proto1.SetPersistentHeader(IdentityHeader, "batman")
if gotIdentity, ok := proto1.GetPersistentHeader(IdentityHeader); !ok || gotIdentity != "batman" {
t.Fatalf("failed to set identity")
}
Expand Down
6 changes: 4 additions & 2 deletions thrift/lib/go/thrift/header_transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ func TestHeaderHeaders(t *testing.T) {
assertEq(t, false, ok)
assertEq(t, 0, len(trans1.GetResponseHeaders()))

setIdentity(trans1, "localhost")
trans1.SetPersistentHeader(IDVersionHeader, IDVersion)
trans1.SetPersistentHeader(IdentityHeader, "localhost")
trans1.SetRequestHeader("thrift_protocol", "compact")
trans1.SetRequestHeader("thrift_transport", "header")
trans1.SetRequestHeader("preferred_cheese", "cheddar")
Expand Down Expand Up @@ -376,7 +377,8 @@ func BenchmarkHeaderFlush(b *testing.B) {
tmb := newMockSocket()
trans1 := newHeaderTransport(tmb)

setIdentity(trans1, "localhost")
trans1.SetPersistentHeader(IDVersionHeader, IDVersion)
trans1.SetPersistentHeader(IdentityHeader, "localhost")
trans1.SetRequestHeader("thrift_protocol", "compact")
trans1.SetRequestHeader("thrift_transport", "header")
trans1.SetRequestHeader("preferred_cheese", "cheddar")
Expand Down
23 changes: 0 additions & 23 deletions thrift/lib/go/thrift/identity.go

This file was deleted.

0 comments on commit 6619d45

Please sign in to comment.